diff --git a/scripts/cc-cli/src/commands/bond.ts b/scripts/cc-cli/src/commands/bond.ts index 01c3b469d6..2c39b94ea7 100644 --- a/scripts/cc-cli/src/commands/bond.ts +++ b/scripts/cc-cli/src/commands/bond.ts @@ -38,7 +38,7 @@ async function bondAction(options: OptionValues) { checkAddress(options.controller, api); // If no amount error and exit - if (!options.amount || !parseInt(options.amount, 10)) { + if (!options.amount || !parseFloat(options.amount)) { console.log("Must specify amount to bond"); process.exit(1); } @@ -49,7 +49,7 @@ async function bondAction(options: OptionValues) { const stashKeyring = initKeyringPair(stashSeed); const stashAddress = stashKeyring.address; const balance = await getBalance(stashAddress, api); - const amount = parseInt(options.amount, 10); + const amount = parseFloat(options.amount); checkBalanceAgainstBondAmount(balance, amount); const rewardDestination = options.rewardDestination @@ -59,7 +59,7 @@ async function bondAction(options: OptionValues) { console.log("Creating bond transaction..."); console.log("Controller address:", options.controller); console.log("Reward destination:", rewardDestination); - console.log("Amount:", parseInt(options.amount, 10)); + console.log("Amount:", parseFloat(options.amount)); await promptContinue(); diff --git a/scripts/cc-cli/src/commands/send.ts b/scripts/cc-cli/src/commands/send.ts index 3f89606dde..82a2d50c15 100644 --- a/scripts/cc-cli/src/commands/send.ts +++ b/scripts/cc-cli/src/commands/send.ts @@ -5,7 +5,7 @@ import { getSeedFromOptions, initKeyringPair, } from "../utils/account"; -import { toMicrounits } from "../utils/balance"; +import { parseCTCString } from "../utils/balance"; export function makeSendCommand() { const cmd = new Command("send"); @@ -38,7 +38,7 @@ async function sendAction(options: OptionValues) { // Send transaction const tx = api.tx.balances.transfer( options.to, - toMicrounits(options.amount).toString() + parseCTCString(options.amount).toString() ); const hash = await tx.signAndSend(stash); diff --git a/scripts/cc-cli/src/commands/unbond.ts b/scripts/cc-cli/src/commands/unbond.ts index 015655d831..0a38d8c96f 100644 --- a/scripts/cc-cli/src/commands/unbond.ts +++ b/scripts/cc-cli/src/commands/unbond.ts @@ -1,7 +1,7 @@ import { Command, OptionValues } from "commander"; import { newApi } from "../api"; import { getSeedFromOptions, initKeyringPair } from "../utils/account"; -import { toMicrounits } from "../utils/balance"; +import { parseCTCString, toMicrounits } from "../utils/balance"; export function makeUnbondCommand() { const cmd = new Command("unbond"); @@ -27,7 +27,7 @@ async function unbondAction(options: OptionValues) { const stash = initKeyringPair(seed); // Unbond transaction - const tx = api.tx.staking.unbond(toMicrounits(options.amount).toString()); + const tx = api.tx.staking.unbond(parseCTCString(options.amount).toString()); const hash = await tx.signAndSend(stash); diff --git a/scripts/cc-cli/src/utils/balance.ts b/scripts/cc-cli/src/utils/balance.ts index 9ed0615afc..b35e69b1d7 100644 --- a/scripts/cc-cli/src/utils/balance.ts +++ b/scripts/cc-cli/src/utils/balance.ts @@ -3,7 +3,7 @@ import { BN } from "creditcoin-js"; const MICROUNITS_PER_CTC = new BN("1000000000000000000"); export function parseCTCString(amount: string): BN { - return new BN(amount).mul(MICROUNITS_PER_CTC); + return new BN(parseFloat(amount)).mul(MICROUNITS_PER_CTC); } export function toMicrounits(amount: number | BN): BN {