Skip to content

Commit

Permalink
Update single balance by token id format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed Feb 5, 2019
1 parent c173b15 commit 35b6f40
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const repl = require("repl")
const SLP = require("./lib/SLP").default
const clone = require("git-clone")

program.version("1.1.0", "-v, --version")
program.version("1.1.1", "-v, --version")

program
.command("new <name>")
Expand Down
11 changes: 7 additions & 4 deletions lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ var Utils = /** @class */ (function () {
return [4 /*yield*/, bitboxNetwork.getTokenInformation(tokenId)];
case 2:
tokenMetadata = _a.sent();
val = balances.slpTokenBalances[tokenId]
.div(Math.pow(10, tokenMetadata.decimals))
.toString();
return [2 /*return*/, val];
return [2 /*return*/, {
tokenId: tokenId,
balance: balances.slpTokenBalances[tokenId]
.div(Math.pow(10, tokenMetadata.decimals))
.toString(),
decimalCount: tokenMetadata.decimals
}];
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion 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": "slp-sdk",
"version": "1.1.0",
"version": "1.1.1",
"description": "SLP SDK powered by BITBOX",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 7 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ class Utils {
let val: any
let tokenMetadata: any = await bitboxNetwork.getTokenInformation(tokenId)

val = balances.slpTokenBalances[tokenId]
.div(10 ** tokenMetadata.decimals)
.toString()
return val
return {
tokenId: tokenId,
balance: balances.slpTokenBalances[tokenId]
.div(10 ** tokenMetadata.decimals)
.toString(),
decimalCount: tokenMetadata.decimals
}
}

async validateTxid(
Expand Down
9 changes: 8 additions & 1 deletion test/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ describe("#Utils", () => {
"simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk",
"df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
)
assert.equal(balance, "617")

const data = {
tokenId:
"df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb",
balance: "617",
decimalCount: 8
}
assert.deepEqual(balance, data)
} catch (error) {
throw error
}
Expand Down

0 comments on commit 35b6f40

Please sign in to comment.