Skip to content

Commit

Permalink
fix: added float parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pLabarta committed Jun 20, 2023
1 parent 7b5901c commit af06650
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions scripts/cc-cli/src/commands/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions scripts/cc-cli/src/commands/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions scripts/cc-cli/src/commands/unbond.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion scripts/cc-cli/src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af06650

Please sign in to comment.