From 3d20539fbdeff8a343c9fa40a2b5c917896aa835 Mon Sep 17 00:00:00 2001 From: Huiqi ZHENG Date: Tue, 5 Apr 2022 15:08:44 +0200 Subject: [PATCH] fix bch address convert issue --- src/families/bitcoin/logic.ts | 5 ++--- src/families/bitcoin/specs.ts | 4 +++- src/families/bitcoin/transaction.ts | 5 +---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/families/bitcoin/logic.ts b/src/families/bitcoin/logic.ts index d7c682e2fc..9957284ca1 100644 --- a/src/families/bitcoin/logic.ts +++ b/src/families/bitcoin/logic.ts @@ -1,5 +1,4 @@ import cashaddr from "cashaddrjs"; -import bchaddr from "bchaddrjs"; import { Currency, isValidAddress } from "./wallet-btc"; import { RecipientRequired, InvalidAddress } from "@ledgerhq/errors"; import type { Account, CryptoCurrency, CryptoCurrencyIds } from "./../../types"; @@ -143,8 +142,8 @@ type CoinLogic = { injectGetAddressParams?: (arg0: Account) => any; }; -const bchToCashaddrAddressWithoutPrefix = (recipient) => - recipient ? bchaddr.toCashAddress(recipient).split(":")[1] : recipient; +export const bchToCashaddrAddressWithoutPrefix = (recipient) => + recipient ? recipient.substring(recipient.indexOf(":") + 1) : recipient; export const perCoinLogic: Record< CryptoCurrencyIds, diff --git a/src/families/bitcoin/specs.ts b/src/families/bitcoin/specs.ts index 138836a167..14bfb23fa5 100644 --- a/src/families/bitcoin/specs.ts +++ b/src/families/bitcoin/specs.ts @@ -257,7 +257,9 @@ const bitcoinLikeMutations = ({ test: ({ account }) => { expect( account.bitcoinResources?.utxos - .filter((u) => u.blockHeight && u.blockHeight < account.blockHeight) // Exclude pending UTXOs and the Utxos just written into new block + .filter( + (u) => u.blockHeight && u.blockHeight < account.blockHeight - 10 + ) // Exclude pending UTXOs and the Utxos just written into new block (10 blocks time) .reduce((p, c) => p.plus(c.value), new BigNumber(0)) .toString() ).toBe("0"); diff --git a/src/families/bitcoin/transaction.ts b/src/families/bitcoin/transaction.ts index 37e1d0134e..e95d0ec3d0 100644 --- a/src/families/bitcoin/transaction.ts +++ b/src/families/bitcoin/transaction.ts @@ -1,5 +1,5 @@ import { BigNumber } from "bignumber.js"; -import bchaddr from "bchaddrjs"; +import { bchToCashaddrAddressWithoutPrefix } from "./logic"; import cashaddr from "cashaddrjs"; import type { Transaction, @@ -134,9 +134,6 @@ function bchExplicit(str: string): string { return str; } -const bchToCashaddrAddressWithoutPrefix = (recipient) => - recipient ? bchaddr.toCashAddress(recipient).split(":")[1] : recipient; - export type CoinLogic = { hasExtraData?: boolean; hasExpiryHeight?: boolean;