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 75d5755e..2efd50c8 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,8 @@ 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; } @@ -121,6 +133,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 7de11ebf..a5adb5d0 100644 --- a/src/smartcontracts/interaction.ts +++ b/src/smartcontracts/interaction.ts @@ -259,7 +259,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 {