From ae070be0110468901543d833f118c310a8495e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 11 Mar 2019 22:49:22 +0100 Subject: [PATCH] Use the decimals of OceanToken to return the correct balance. --- src/keeper/contracts/Token.ts | 4 ++++ src/ocean/Account.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/keeper/contracts/Token.ts b/src/keeper/contracts/Token.ts index 6f5d8fb..93d96fa 100644 --- a/src/keeper/contracts/Token.ts +++ b/src/keeper/contracts/Token.ts @@ -13,6 +13,10 @@ export default class OceanToken extends ContractBase { return this.sendFrom("approve", [to, price], from) } + public async decimals(): Promise { + return this.call("decimals", []) + } + public async balanceOf(address: string): Promise { return this.call("balanceOf", [address]) .then((balance: string) => new BigNumber(balance).toNumber()) diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index f9255d8..74cf779 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -33,7 +33,8 @@ export default class Account extends OceanBase { * @return {Promise} */ public async getOceanBalance(): Promise { - return (await Keeper.getInstance()).token.balanceOf(this.id) + const token = (await Keeper.getInstance()).token + return await token.balanceOf(this.id) / (10 ** await token.decimals()) } /**