Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 16 additions & 3 deletions src/balance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BigNumber } from "bignumber.js";
import { Token } from "./token";
import { ErrInvalidArgument } from "./errors";
import { Egld } from "./balanceBuilder";

Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, I think the number of decimals has to be passed as well into this component, if we want to use it for different tokens

// however, "tokenIdentifier" and "decimals" still have to be available.
getNonce(): BigNumber {
return this.nonce;
}
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/smartcontracts/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down