From 725e4bc37052c6493fb8a93dcab0b13cf32d02d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 10 Apr 2022 15:55:21 +0300 Subject: [PATCH 1/2] Try to decouple Balance from Token (preparatory refactoring - for future PRs). --- src/balance.ts | 18 +++++++++++++++--- src/smartcontracts/interaction.ts | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/balance.ts b/src/balance.ts index 75d5755e..2797bf76 100644 --- a/src/balance.ts +++ b/src/balance.ts @@ -1,5 +1,4 @@ import { BigNumber } from "bignumber.js"; -import { Token } from "./token"; import { ErrInvalidArgument } from "./errors"; import { Egld } from "./balanceBuilder"; @@ -11,18 +10,27 @@ const DEFAULT_BIGNUMBER_DECIMAL_PLACES = 18; BigNumber.set({ DECIMAL_PLACES: DEFAULT_BIGNUMBER_DECIMAL_PLACES, ROUNDING_MODE: 1 }); +interface ITokenDefinition { + getTokenIdentifier(): string; + isEgld(): boolean; + decimals: number; +} + /** * Balance, as an immutable object. */ export class Balance { - readonly token: Token; + // TODO: Rename class to "Tokens" or "TokenAmount" etc. + // "Balance" is not an appropriate name. + + readonly token: ITokenDefinition; private readonly nonce: BigNumber = new BigNumber(0); private readonly value: BigNumber = new BigNumber(0); /** * Creates a Balance object. */ - public constructor(token: Token, nonce: BigNumber.Value, value: BigNumber.Value) { + public constructor(token: ITokenDefinition, nonce: BigNumber.Value, value: BigNumber.Value) { this.token = token; this.nonce = new BigNumber(nonce); this.value = new BigNumber(value); @@ -32,6 +40,8 @@ export class Balance { * Creates a balance object from an EGLD value (denomination will be applied). */ static egld(value: BigNumber.Value): Balance { + // TODO: We should decouple the [built] object from it's [builder] (that is, "Egld"), if possible + // (perhaps not possible yet). return Egld(value); } @@ -89,6 +99,7 @@ export class Balance { }; } + // TODO: We should not keep a property of a token instance (its nonce) here, in the "Tokens" (still called "Balance") class. getNonce(): BigNumber { return this.nonce; } @@ -121,6 +132,7 @@ export class Balance { } checkSameToken(other: Balance) { + // TODO: Fix or remove. Comparing by reference isn't necessarily correct here. if (this.token != other.token) { throw new ErrInvalidArgument("Different token types"); } diff --git a/src/smartcontracts/interaction.ts b/src/smartcontracts/interaction.ts index 8e6c949a..c55648ba 100644 --- a/src/smartcontracts/interaction.ts +++ b/src/smartcontracts/interaction.ts @@ -272,7 +272,7 @@ class TokenTransfersWithinInteraction { private getTypedTokenIdentifier(transfer: Balance): TypedValue { // Important: for NFTs, this has to be the "collection" name, actually. // We will reconsider adding the field "collection" on "Token" upon merging "ApiProvider" and "ProxyProvider". - return BytesValue.fromUTF8(transfer.token.identifier); + return BytesValue.fromUTF8(transfer.token.getTokenIdentifier()); } private getTypedTokenNonce(transfer: Balance): TypedValue { From 515bf2d00de92c6540c82a91b7e780fddf80d41f Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Mon, 11 Apr 2022 16:33:50 +0300 Subject: [PATCH 2/2] Prepare pre-release. --- package-lock.json | 4 ++-- package.json | 2 +- src/balance.ts | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c70267c7..c2a043fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@elrondnetwork/erdjs", - "version": "10.0.0-alpha.5", + "version": "10.0.1-beta.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@elrondnetwork/erdjs", - "version": "10.0.0-alpha.5", + "version": "10.0.1-beta.0", "license": "GPL-3.0-or-later", "dependencies": { "@elrondnetwork/transaction-decoder": "0.1.0", diff --git a/package.json b/package.json index a237c42d..ab7132f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@elrondnetwork/erdjs", - "version": "10.0.0-alpha.5", + "version": "10.0.1-beta.0", "description": "Smart Contracts interaction framework", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/balance.ts b/src/balance.ts index 2797bf76..2efd50c8 100644 --- a/src/balance.ts +++ b/src/balance.ts @@ -100,6 +100,7 @@ export class Balance { } // TODO: We should not keep a property of a token instance (its nonce) here, in the "Tokens" (still called "Balance") class. + // however, "tokenIdentifier" and "decimals" still have to be available. getNonce(): BigNumber { return this.nonce; }