From c16e594e5d121aff2afcdccf718f49be3001ca5f Mon Sep 17 00:00:00 2001 From: hzheng-ledger Date: Wed, 30 Aug 2023 09:35:14 +0200 Subject: [PATCH] fix: cosmos unit tests --- libs/ledger-live-common/src/families/cosmos/specs.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/ledger-live-common/src/families/cosmos/specs.ts b/libs/ledger-live-common/src/families/cosmos/specs.ts index cba8eed66ca0..ae7e0d9f908d 100644 --- a/libs/ledger-live-common/src/families/cosmos/specs.ts +++ b/libs/ledger-live-common/src/families/cosmos/specs.ts @@ -28,13 +28,15 @@ import cryptoFactory from "./chain/chain"; import { canDelegate, canRedelegate, canUndelegate, getMaxDelegationAvailable } from "./logic"; import { acceptTransaction } from "./speculos-deviceActions"; import { Operation } from "@ledgerhq/types-live"; -import BigNumber from "bignumber.js"; const maxAccounts = 16; // amounts of delegation are not exact so we are applying an approximation function approximateValue(value): string { - return "~" + new BigNumber(value).div(100).integerValue().times(100).toString(); + const firstThreeDigits = parseInt(value.toString().slice(0, 3), 10); + const firstTwoDigits = Math.round(firstThreeDigits / 10).toString(); + const tailZeroCount = value.toString().length - 2; + return "~" + firstTwoDigits + "0".repeat(tailZeroCount); } function approximateExtra(extra: CosmosOperationExtraRaw) {