From 037633a273b11dadd47ecc9cd0ca38eb2dec4e6a Mon Sep 17 00:00:00 2001 From: Martin Cayuelas Date: Fri, 26 Apr 2024 17:27:14 +0200 Subject: [PATCH 1/3] chore: LLM currency unit settings + drop all remaining usage of Account#unit --- .../blockchain/estimateMaxSpendable.ts | 7 +- apps/cli/src/commands/live/balanceHistory.ts | 16 +-- apps/cli/src/commands/ptx/swap.ts | 15 ++- apps/cli/src/scan.ts | 1 - .../Claim/fields/DelegationSelectorField.tsx | 2 +- .../Modals/Undelegate/fields/Validator.tsx | 2 +- .../fields/DelegationSelectorField.tsx | 2 +- .../swap-migrations/useSwapLiveAppHook.tsx | 12 +- .../Send/fields/RecipientField.react.test.tsx | 10 -- .../e2e/specs/delegate/cosmos.spec.ts | 9 +- .../e2e/specs/send/currencies.spec.ts | 7 +- .../src/components/AccountCard.tsx | 7 +- .../src/components/AccountGraphCard.tsx | 7 +- .../src/components/AccountSelector.tsx | 7 +- .../src/components/DelegationDrawer.tsx | 5 +- .../src/components/DeviceAction/index.tsx | 3 + .../src/components/DeviceAction/rendering.tsx | 18 ++- .../src/components/EditFeeUnit.tsx | 7 +- .../src/components/OperationIcon.tsx | 2 +- .../src/components/OperationRow/index.tsx | 16 ++- .../AccountSettingsNavigator.tsx | 10 +- .../RootNavigator/BaseNavigator.tsx | 9 ++ .../RootNavigator/SettingsNavigator.tsx | 10 ++ .../types/AccountSettingsNavigator.ts | 7 +- .../RootNavigator/types/BaseNavigator.ts | 3 + .../RootNavigator/types/SettingsNavigator.ts | 4 + .../src/components/SubAccountRow.tsx | 5 +- .../src/components/ValidateOnDevice.tsx | 18 +-- .../Web3AppWebview/liveSDKLogic.test.ts | 5 - .../src/const/navigation.ts | 2 +- .../Rewards/ClaimRewardsFlow/01-Started.tsx | 5 +- .../src/families/algorand/Rewards/index.tsx | 5 +- .../src/families/algorand/SendRowsFee.tsx | 5 +- .../families/algorand/operationDetails.tsx | 4 +- .../cardano/DelegationFlow/02-Summary.tsx | 7 +- .../families/cardano/Delegations/index.tsx | 5 +- .../cardano/UndelegationFlow/01-Summary.tsx | 11 +- .../celo/AccountBalanceSummaryFooter.tsx | 4 +- .../src/families/celo/Delegations/Row.tsx | 5 +- .../src/families/celo/Delegations/index.tsx | 6 +- .../src/families/celo/Delegations/utils.tsx | 6 +- .../src/families/celo/LockFlow/01-Amount.tsx | 8 +- .../families/celo/RevokeFlow/01-Summary.tsx | 5 +- .../families/celo/RevokeFlow/VoteAmount.tsx | 4 +- .../src/families/celo/SendRowsFee.tsx | 5 +- .../families/celo/UnlockFlow/01-Amount.tsx | 8 +- .../src/families/celo/ValidatorRow.tsx | 6 +- .../src/families/celo/VoteFlow/02-Summary.tsx | 11 +- .../src/families/celo/VoteFlow/VoteAmount.tsx | 4 +- .../celo/WithdrawFlow/WithdrawAmount.tsx | 6 +- .../src/families/celo/operationDetails.tsx | 4 +- .../cosmos/AccountBalanceSummaryFooter.tsx | 4 +- .../ClaimRewardsFlow/01-SelectValidator.tsx | 5 +- .../ClaimRewardsFlow/02-SelectMethod.tsx | 9 +- .../cosmos/DelegationFlow/02-Summary.tsx | 11 +- .../src/families/cosmos/Delegations/index.tsx | 9 +- .../src/families/cosmos/SendRowsFee.tsx | 5 +- .../cosmos/TransactionConfirmFields.tsx | 5 +- .../src/families/cosmos/operationDetails.tsx | 4 +- .../cosmos/shared/02-SelectAmount.tsx | 4 +- .../families/cosmos/shared/ValidatorRow.tsx | 5 +- .../Drawer/hooks/useDrawerItems.tsx | 4 +- .../Body/components/Rewards/Rewards.tsx | 9 +- .../elrond/components/Details/Details.tsx | 4 +- .../components/PickMethod/PickMethod.tsx | 9 +- .../PickValidator/PickValidator.tsx | 5 +- .../components/PickAmount/PickAmount.tsx | 4 +- .../PickValidator/components/Item/Item.tsx | 5 +- .../SetDelegation/SetDelegation.tsx | 9 +- .../components/PickAmount/PickAmount.tsx | 4 +- .../WithdrawFunds/WithdrawFunds.tsx | 9 +- .../elrond/components/Summary/Summary.tsx | 4 +- .../near/AccountBalanceSummaryFooter.tsx | 4 +- .../families/near/StakingFlow/02-Summary.tsx | 11 +- .../src/families/near/operationDetails.tsx | 4 +- .../families/near/shared/02-SelectAmount.tsx | 4 +- .../src/families/near/shared/ValidatorRow.tsx | 10 +- .../polkadot/AccountBalanceSummaryFooter.tsx | 7 +- .../families/polkadot/BondFlow/02-Amount.tsx | 7 +- .../polkadot/NominateFlow/01-Validators.tsx | 8 +- .../polkadot/NominateFlow/drawerInfo.tsx | 7 +- .../polkadot/Nominations/NominationRow.tsx | 5 +- .../polkadot/Nominations/UnlockingRow.tsx | 5 +- .../polkadot/Nominations/drawerInfo.tsx | 6 +- .../families/polkadot/Nominations/index.tsx | 6 +- .../polkadot/RebondFlow/01-Amount.tsx | 9 +- .../src/families/polkadot/SendRowsFee.tsx | 5 +- .../polkadot/UnbondFlow/01-Amount.tsx | 7 +- .../families/polkadot/operationDetails.tsx | 24 ++-- .../src/families/ripple/RippleFeeRow.tsx | 7 +- .../solana/DelegationFlow/SelectAmount.tsx | 4 +- .../solana/DelegationFlow/SelectValidator.tsx | 10 +- .../solana/DelegationFlow/Summary.tsx | 7 +- .../src/families/solana/Delegations/index.tsx | 9 +- .../src/families/solana/SendRowsFee.tsx | 5 +- .../src/families/solana/operationDetails.tsx | 6 +- .../families/stellar/ScreenEditCustomFees.tsx | 7 +- .../src/families/stellar/StellarFeeRow.tsx | 9 +- .../src/families/tezos/AccountBodyHeader.tsx | 10 +- .../families/tezos/DelegationDetailsModal.tsx | 9 +- .../families/tezos/DelegationFlow/Summary.tsx | 9 +- .../src/families/tezos/TezosFeeRow.tsx | 8 +- .../tron/AccountBalanceSummaryFooter.tsx | 4 +- .../src/families/tron/Votes/index.tsx | 5 +- .../src/families/tron/operationDetails.tsx | 11 +- .../src/helpers/CurrencySettingsDefaults.ts | 5 +- .../src/hooks/useAccountUnit.ts | 16 +++ .../src/reducers/settings.ts | 68 ++++++++--- apps/ledger-live-mobile/src/reducers/types.ts | 5 +- .../src/screens/Account/AccountHeader.tsx | 5 +- .../AccountSettings/AccountUnitsRow.tsx | 41 ------- .../AccountSettings/EditAccountUnits.tsx | 71 ------------ .../src/screens/AccountSettings/index.tsx | 2 - .../src/screens/Accounts/AccountRow.tsx | 5 +- .../src/screens/FreezeFunds/02-Amount.tsx | 8 +- .../src/screens/OperationDetails/Content.tsx | 7 +- .../RequestAccount/02-SelectAccount.tsx | 4 +- .../screens/SendFunds/02-SelectRecipient.tsx | 2 +- .../src/screens/SendFunds/03a-AmountCoin.tsx | 7 +- .../SendFunds/SummaryAmountSection.tsx | 5 +- .../screens/SendFunds/SummaryTotalSection.tsx | 106 ++++++++---------- .../Currencies/CurrencySettings.tsx | 7 +- .../Currencies/CurrencyUnitsRow.tsx | 49 ++++++++ .../Currencies/EditCurrencyUnits.tsx | 74 ++++++++++++ .../src/screens/Swap/Form/Summary/index.tsx | 5 +- .../src/screens/Swap/Form/TxForm/From.tsx | 8 +- .../src/screens/Swap/History/OperationRow.tsx | 9 +- .../Swap/SubScreens/OperationDetails.tsx | 27 +++-- .../screens/Swap/SubScreens/SelectAccount.tsx | 8 +- .../Swap/SubScreens/SelectProvider.tsx | 6 +- .../src/screens/UnfreezeFunds/01-Amount.tsx | 5 +- apps/ledger-live-mobile/src/types/common.ts | 7 ++ apps/web-tools/pages/logsviewer.tsx | 1 - apps/web-tools/pages/sync.tsx | 1 - .../src/account/helpers.test.ts | 43 +------ libs/coin-framework/src/account/helpers.ts | 13 --- .../src/account/pending.test.ts | 1 - .../src/bridge/jsHelpers.test.ts | 1 - libs/coin-framework/src/bridge/jsHelpers.ts | 1 - libs/coin-framework/src/formatters.ts | 8 +- libs/coin-framework/src/mocks/account.ts | 5 +- .../src/serialization/account.ts | 5 - .../src/bridge.integration.test.ts | 2 - .../src/deviceTransactionConfig.ts | 4 +- .../coin-algorand/src/formatters.ts | 4 +- .../coin-algorand/src/transaction.ts | 6 +- .../coin-bitcoin/src/datasets/bitcoin.ts | 2 - .../coin-bitcoin/src/datasets/digibyte.ts | 2 - .../coin-bitcoin/src/datasets/litecoin.ts | 2 - .../coin-bitcoin/src/formatters.ts | 4 +- .../coin-bitcoin/src/hw-signMessage.test.ts | 1 - .../coin-bitcoin/src/transaction.ts | 4 +- .../src/__tests__/fixtures/common.fixtures.ts | 1 - .../getFormattedFeeFields.test.ts | 2 +- .../coin-evm/src/datasets/ethereum1.ts | 1 - .../editTransaction/getFormattedFeeFields.ts | 7 +- libs/coin-modules/coin-evm/src/transaction.ts | 6 +- .../coin-near/src/bridge.integration.test.ts | 1 - .../coin-near/src/speculos-deviceActions.ts | 8 +- .../coin-modules/coin-near/src/transaction.ts | 4 +- .../coin-polkadot/src/bridge/formatters.ts | 4 +- .../coin-polkadot/src/bridge/transaction.ts | 4 +- .../src/test/bridgeDatasetTest.ts | 3 - .../coin-polkadot/src/types/bridge.fixture.ts | 1 - .../src/__tests__/accounts/groupPerDay.ts | 1 - .../__tests__/migration/account-migration.ts | 1 - .../src/account/formatters.ts | 29 +++-- .../ledger-live-common/src/account/helpers.ts | 2 - libs/ledger-live-common/src/bot/formatters.ts | 2 +- .../src/bridge/mockHelpers.ts | 1 - .../src/exchange/swap/getExchangeRates.ts | 7 +- .../exchange/swap/hooks/v5/useFetchRates.ts | 6 +- .../src/exchange/swap/initSwap.ts | 4 +- .../src/exchange/swap/mock.ts | 6 +- .../bridge.integration.test.ts.snap | 5 - .../bridge.integration.test.ts.snap | 65 ----------- .../bridge.integration.test.ts.snap | 2 - .../src/families/cardano/account.ts | 4 +- .../families/cardano/datasets/rawAccount.1.ts | 1 - .../cardano/deviceTransactionConfig.ts | 20 ++-- .../src/families/cardano/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 3 - .../casper/bridge.integration.test.ts | 1 - .../src/families/casper/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 2 - .../celo/datasets/celo.scanAccounts.1.ts | 2 - .../src/families/celo/transaction.ts | 4 +- .../src/families/cosmos/banner.test.ts | 1 - .../axelar.integration.test.ts.snap | 2 - .../coreum.integration.test.ts.snap | 3 - .../cosmos.integration.test.ts.snap | 6 - .../desmos.integration.test.ts.snap | 2 - .../injective.integration.test.ts.snap | 2 - .../onomy.integration.test.ts.snap | 2 - .../osmosis.integration.test.ts.snap | 2 - .../persistence.integration.test.ts.snap | 3 - .../quicksilver.integration.test.ts.snap | 2 - .../seiNetwork.integration.test.ts.snap | 2 - .../stargaze.integration.test.ts.snap | 2 - .../umee.integration.test.ts.snap | 2 - .../src/families/cosmos/datasets/axelar.ts | 1 - .../src/families/cosmos/datasets/coreum.ts | 1 - .../src/families/cosmos/datasets/cosmos.ts | 2 - .../src/families/cosmos/datasets/desmos.ts | 1 - .../src/families/cosmos/datasets/dydx.ts | 1 - .../src/families/cosmos/datasets/injective.ts | 1 - .../src/families/cosmos/datasets/onomy.ts | 1 - .../src/families/cosmos/datasets/osmosis.ts | 2 - .../families/cosmos/datasets/persistence.ts | 1 - .../families/cosmos/datasets/quicksilver.ts | 1 - .../families/cosmos/datasets/secretNetwork.ts | 1 - .../families/cosmos/datasets/seiNetwork.ts | 1 - .../src/families/cosmos/datasets/stargaze.ts | 1 - .../src/families/cosmos/datasets/umee.ts | 1 - .../cosmos/deviceTransactionConfig.ts | 8 +- .../src/families/cosmos/formatters.ts | 4 +- .../src/families/cosmos/react.test.ts | 4 +- .../src/families/cosmos/react.ts | 4 +- .../src/families/cosmos/transaction.ts | 8 +- .../bridge.integration.test.ts.snap | 3 - .../src/families/crypto_org/account.ts | 4 +- .../src/families/crypto_org/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 2 - .../elrond/bridge.integration.test.ts | 1 - .../src/families/elrond/datasets/elrond1.ts | 1 - .../elrond/deviceTransactionConfig.ts | 4 +- .../src/families/elrond/formatters.ts | 4 +- .../elrond/js-getTransactionStatus.ts | 22 ++-- .../families/elrond/speculos-deviceActions.ts | 16 +-- .../src/families/elrond/transaction.ts | 4 +- .../filecoin/bridge.integration.test.ts | 1 - .../src/families/filecoin/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 1 - .../hedera/bridge.integration.test.ts | 1 - .../families/hedera/speculos-deviceActions.ts | 9 +- ...s-estimateMaxSpendable.integration.test.ts | 7 -- .../hedera/tests/js-transaction.test.ts | 7 -- .../families/hedera/tests/transaction.test.ts | 15 ++- .../hedera/tests/utils.integration.test.ts | 7 -- .../src/families/hedera/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 2 - .../bridge.integration.test.ts | 1 - .../families/internet_computer/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 3 - .../src/families/near/banner.test.ts | 1 - .../src/families/near/react.ts | 4 +- .../bridge.integration.test.ts.snap | 4 - .../ripple/bridge.integration.test.ts | 1 - .../src/families/ripple/transaction.ts | 6 +- .../bridge.integration.test.ts.snap | 2 - .../src/families/solana/banner.test.ts | 1 - .../solana/bridge.integration.test.ts | 1 - .../src/families/solana/transaction.ts | 16 ++- .../bridge.integration.test.ts.snap | 5 - .../stacks/bridge.integration.test.ts | 1 - .../src/families/stacks/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 6 - .../stellar/bridge.integration.test.ts | 5 - .../stellar/speculos-deviceActions.ts | 3 +- .../src/families/stellar/transaction.ts | 6 +- .../families/tezos/bridge.integration.test.ts | 1 - .../families/tezos/fixtures/makeAccount.ts | 1 - .../src/families/tezos/transaction.ts | 10 +- .../bridge.integration.test.ts.snap | 8 -- .../families/tron/bridge.integration.test.ts | 4 - .../src/families/tron/bridge/js.ts | 4 +- .../src/families/tron/data.mock.ts | 4 - .../tron/synchronisation.integration.test.ts | 1 - .../src/families/tron/transaction.ts | 4 +- .../bridge.integration.test.ts.snap | 3 - .../src/families/vechain/account.ts | 4 +- .../src/families/vechain/datasets/vechain.ts | 3 - .../src/families/vechain/transaction.ts | 4 +- .../useAccountsWithFundsListener.test.tsx | 10 -- .../src/hw/signMessage/index.test.ts | 5 - .../src/mock/fixtures/cryptoCurrencies.ts | 5 - libs/ledgerjs/packages/types-live/README.md | 6 +- .../packages/types-live/src/account.ts | 5 +- libs/live-countervalues-react/src/index.tsx | 4 +- libs/live-wallet/src/liveqr/cross.ts | 1 - .../src/liveqr/importAccounts.test.ts | 3 - libs/live-wallet/src/ordering.test.ts | 5 - 282 files changed, 891 insertions(+), 1094 deletions(-) create mode 100644 apps/ledger-live-mobile/src/hooks/useAccountUnit.ts delete mode 100644 apps/ledger-live-mobile/src/screens/AccountSettings/AccountUnitsRow.tsx delete mode 100644 apps/ledger-live-mobile/src/screens/AccountSettings/EditAccountUnits.tsx create mode 100644 apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencyUnitsRow.tsx create mode 100644 apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/EditCurrencyUnits.tsx diff --git a/apps/cli/src/commands/blockchain/estimateMaxSpendable.ts b/apps/cli/src/commands/blockchain/estimateMaxSpendable.ts index 52e6362cf624..5d9944bc602d 100644 --- a/apps/cli/src/commands/blockchain/estimateMaxSpendable.ts +++ b/apps/cli/src/commands/blockchain/estimateMaxSpendable.ts @@ -1,14 +1,15 @@ import { concat, from } from "rxjs"; import { concatMap } from "rxjs/operators"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { scan, scanCommonOpts } from "../../scan"; import type { ScanCommonOpts } from "../../scan"; import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName"; +import { AccountLike } from "@ledgerhq/types-live"; -const format = (account, value) => { - const unit = getAccountUnit(account); +const format = (account: AccountLike, value) => { + const unit = getAccountCurrency(account).units[0]; const name = getDefaultAccountName(account); const amount = formatCurrencyUnit(unit, value, { showCode: true, diff --git a/apps/cli/src/commands/live/balanceHistory.ts b/apps/cli/src/commands/live/balanceHistory.ts index a90f05cdb3cc..e7272c8cd282 100644 --- a/apps/cli/src/commands/live/balanceHistory.ts +++ b/apps/cli/src/commands/live/balanceHistory.ts @@ -11,17 +11,17 @@ import { import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { scan, scanCommonOpts } from "../../scan"; import type { ScanCommonOpts } from "../../scan"; -import type { PortfolioRange } from "@ledgerhq/types-live"; +import type { Account, BalanceHistory, PortfolioRange } from "@ledgerhq/types-live"; import { getDefaultAccountNameForCurrencyIndex } from "@ledgerhq/live-wallet/accountName"; -const histoFormatters = { +const histoFormatters: Record unknown> = { default: (histo, account) => histo .map( ({ date, value }) => date.toISOString() + " " + - formatCurrencyUnit(account.unit, new BigNumber(value), { + formatCurrencyUnit(account.currency.units[0], new BigNumber(value), { showCode: true, disableRounding: true, }), @@ -33,19 +33,21 @@ const histoFormatters = { "".padStart(22) + getDefaultAccountNameForCurrencyIndex(account) + ": " + - formatCurrencyUnit(account.unit, account.balance, { + formatCurrencyUnit(account.currency.units[0], account.balance, { showCode: true, disableRounding: true, }) + "\n" + asciichart.plot( - history.map(h => h.value.div(new BigNumber(10).pow(account.unit.magnitude)).toNumber()), + history.map( + h => h.value / new BigNumber(10).pow(account.currency.units[0].magnitude).toNumber(), + ), { height: 10, format: value => formatCurrencyUnit( - account.unit, - new BigNumber(value).times(new BigNumber(10).pow(account.unit.magnitude)), + account.currency.units[0], + new BigNumber(value).times(new BigNumber(10).pow(account.currency.units[0].magnitude)), { showCode: true, disableRounding: true, diff --git a/apps/cli/src/commands/ptx/swap.ts b/apps/cli/src/commands/ptx/swap.ts index 72c58f16f2f3..19dfeadf5bed 100644 --- a/apps/cli/src/commands/ptx/swap.ts +++ b/apps/cli/src/commands/ptx/swap.ts @@ -19,7 +19,6 @@ import type { } from "@ledgerhq/live-common/exchange/swap/types"; import { initSwap, getExchangeRates } from "@ledgerhq/live-common/exchange/swap/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import invariant from "invariant"; import { Account, SignedOperation, SubAccount } from "@ledgerhq/types-live"; @@ -89,11 +88,15 @@ const exec = async (opts: SwapJobOpts) => { } console.log("\t:id:\t\t", fromAccount.id); - const formattedAmount = formatCurrencyUnit(getAccountUnit(fromAccount), fromAccount.balance, { - disableRounding: true, - alwaysShowSign: false, - showCode: true, - }); + const formattedAmount = formatCurrencyUnit( + getAccountCurrency(fromAccount).units[0], + fromAccount.balance, + { + disableRounding: true, + alwaysShowSign: false, + showCode: true, + }, + ); console.log("\t:balance:\t", fromAccount.spendableBalance.toString(), ` [ ${formattedAmount} ]`); diff --git a/apps/cli/src/scan.ts b/apps/cli/src/scan.ts index 0a890a855c31..bc37b74e0e3c 100644 --- a/apps/cli/src/scan.ts +++ b/apps/cli/src/scan.ts @@ -324,7 +324,6 @@ export function scan(arg: ScanCommonOpts): Observable { id, derivationMode, currency, - unit: currency.units[0], index, freshAddress: xpubOrAddress, freshAddressPath, diff --git a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Claim/fields/DelegationSelectorField.tsx b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Claim/fields/DelegationSelectorField.tsx index 2a2352ace7fb..9828cffeafb8 100644 --- a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Claim/fields/DelegationSelectorField.tsx +++ b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Claim/fields/DelegationSelectorField.tsx @@ -45,7 +45,7 @@ const renderItem = (item: { data: OptionType }) => { - {balance} {"EGLD"} {/* FIXME Should be getAccountUnit(account).code */} + {balance} {"EGLD"} ); diff --git a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Undelegate/fields/Validator.tsx b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Undelegate/fields/Validator.tsx index 09e11ef6c7b6..dc5dcf489306 100644 --- a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Undelegate/fields/Validator.tsx +++ b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Undelegate/fields/Validator.tsx @@ -41,7 +41,7 @@ const Item = (item: { data: DelegationType }) => { - {amount} {"EGLD"} {/* FIXME Should be getAccountUnit(account).code */} + {amount} {"EGLD"} ); diff --git a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Withdraw/fields/DelegationSelectorField.tsx b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Withdraw/fields/DelegationSelectorField.tsx index aed282d68497..d75e5e29c8b5 100644 --- a/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Withdraw/fields/DelegationSelectorField.tsx +++ b/apps/ledger-live-desktop/src/renderer/families/elrond/components/Modals/Withdraw/fields/DelegationSelectorField.tsx @@ -42,7 +42,7 @@ const renderItem = (item: { data: EnhancedUnbonding }) => { - {balance} {"EGLD"} {/* FIXME Should be getAccountUnit(account).code */} + {balance} {"EGLD"} ); diff --git a/apps/ledger-live-desktop/src/renderer/hooks/swap-migrations/useSwapLiveAppHook.tsx b/apps/ledger-live-desktop/src/renderer/hooks/swap-migrations/useSwapLiveAppHook.tsx index 00e836091b8c..02b76aa2afa5 100644 --- a/apps/ledger-live-desktop/src/renderer/hooks/swap-migrations/useSwapLiveAppHook.tsx +++ b/apps/ledger-live-desktop/src/renderer/hooks/swap-migrations/useSwapLiveAppHook.tsx @@ -12,14 +12,11 @@ import { } from "~/renderer/screens/exchange/Swap2/Form/SwapWebView"; import { rateSelector } from "~/renderer/actions/swap"; import { getEnv } from "@ledgerhq/live-env"; -import { - getAccountUnit, - getFeesCurrency, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getFeesCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import BigNumber from "bignumber.js"; import { walletSelector } from "~/renderer/reducers/wallet"; +import { useMaybeAccountUnit } from "../useAccountUnit"; export type UseSwapLiveAppHookProps = { manifestID: string | null; @@ -51,10 +48,11 @@ export const useSwapLiveAppHook = (props: UseSwapLiveAppHookProps) => { swapTransaction.swap.from.account && getMainAccount(swapTransaction.swap.from.account, swapTransaction.swap.from.parentAccount); const estimatedFeesUnit = mainFromAccount && getFeesCurrency(mainFromAccount); + + const unit = useMaybeAccountUnit(mainFromAccount); const estimatedFees = useMemo(() => { - const unit = mainFromAccount && getAccountUnit(mainFromAccount); return unit && BigNumber(formatCurrencyUnit(unit, swapTransaction.status.estimatedFees)); - }, [mainFromAccount, swapTransaction.status.estimatedFees]); + }, [swapTransaction.status.estimatedFees, unit]); const walletState = useSelector(walletSelector); diff --git a/apps/ledger-live-desktop/src/renderer/modals/Send/fields/RecipientField.react.test.tsx b/apps/ledger-live-desktop/src/renderer/modals/Send/fields/RecipientField.react.test.tsx index 54150c7e9343..457c0132952c 100644 --- a/apps/ledger-live-desktop/src/renderer/modals/Send/fields/RecipientField.react.test.tsx +++ b/apps/ledger-live-desktop/src/renderer/modals/Send/fields/RecipientField.react.test.tsx @@ -53,11 +53,6 @@ const ethMockAccount: Account = { operations: [], operationsCount: 0, pendingOperations: [], - unit: { - name: "ether", - code: "ETH", - magnitude: 18, - }, currency: eth, lastSyncDate: new Date("2023-02-14T11:01:19.252Z"), swapHistory: [], @@ -86,11 +81,6 @@ const polygonMockAccount: Account = { operations: [], operationsCount: 0, pendingOperations: [], - unit: { - name: "matic", - code: "MATIC", - magnitude: 18, - }, currency: polygon, lastSyncDate: new Date("2023-02-14T11:01:19.252Z"), swapHistory: [], diff --git a/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts b/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts index e2e804112801..05b60cbca9f5 100644 --- a/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts @@ -10,6 +10,7 @@ import DeviceAction from "../../models/DeviceAction"; import { knownDevice } from "../../models/devices"; import { BigNumber } from "bignumber.js"; import { formattedAmount } from "../../models/common"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; let portfolioPage: PortfolioPage; let stakePage: StakePage; @@ -58,8 +59,12 @@ describe("Cosmos delegate flow", () => { const [assestsDelagated, assestsRemaining] = await stakePage.setAmount(delegatedPercent); expect(await stakePage.cosmosDelegationSummaryValidator()).toEqual("Ledger"); - expect(assestsRemaining).toEqual(formattedAmount(testedAccount.unit, remainingAmount)); - expect(assestsDelagated).toEqual(formattedAmount(testedAccount.unit, delegatedAmount, true)); + expect(assestsRemaining).toEqual( + formattedAmount(getAccountCurrency(testedAccount).units[0], remainingAmount), + ); + expect(assestsDelagated).toEqual( + formattedAmount(getAccountCurrency(testedAccount).units[0], delegatedAmount, true), + ); await stakePage.summaryContinue(); await deviceAction.selectMockDevice(); diff --git a/apps/ledger-live-mobile/e2e/specs/send/currencies.spec.ts b/apps/ledger-live-mobile/e2e/specs/send/currencies.spec.ts index 2df193a05ea1..864481871a65 100644 --- a/apps/ledger-live-mobile/e2e/specs/send/currencies.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/send/currencies.spec.ts @@ -5,6 +5,7 @@ import { getCryptoCurrencyById, setSupportedCurrencies, } from "@ledgerhq/live-common/currencies/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { loadAccounts, loadBleState, loadConfig } from "../../bridge/server"; import PortfolioPage from "../../models/wallet/portfolioPage"; import SendPage from "../../models/trade/sendPage"; @@ -64,9 +65,11 @@ describe("Send flow", () => { const halfBalance = account.balance.div(2); const amount = // half of the balance, formatted with the same unit as what the input should use - formatCurrencyUnit(account.unit, halfBalance, { useGrouping: false }); + formatCurrencyUnit(getAccountCurrency(account).units[0], halfBalance, { + useGrouping: false, + }); - const amountWithCode = formattedAmount(account.unit, halfBalance); + const amountWithCode = formattedAmount(getAccountCurrency(account).units[0], halfBalance); await portfolioPage.openViaDeeplink(); await sendPage.openViaDeeplink(); diff --git a/apps/ledger-live-mobile/src/components/AccountCard.tsx b/apps/ledger-live-mobile/src/components/AccountCard.tsx index 9ffe52b6fd28..e731c7775c18 100644 --- a/apps/ledger-live-mobile/src/components/AccountCard.tsx +++ b/apps/ledger-live-mobile/src/components/AccountCard.tsx @@ -1,6 +1,6 @@ import React, { ReactNode } from "react"; import { getAccountSpendableBalance } from "@ledgerhq/live-common/account/index"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import { getTagDerivationMode } from "@ledgerhq/coin-framework/derivation"; import { AccountLike, Account, DerivationMode } from "@ledgerhq/types-live"; import { Flex, Tag, Text } from "@ledgerhq/native-ui"; @@ -13,6 +13,7 @@ import CurrencyIcon from "./CurrencyIcon"; import CurrencyUnitValue from "./CurrencyUnitValue"; import CounterValue from "./CounterValue"; import { useMaybeAccountName } from "~/reducers/wallet"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; export type Props = CardProps & { account?: AccountLike | null; @@ -41,9 +42,9 @@ const AccountCard = ({ const accountNameFromStore = useMaybeAccountName(account); const accountName = overridesName || accountNameFromStore; const parentName = useMaybeAccountName(parentAccount); - if (!account) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !unit) return null; const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); const tag = account.type === "Account" && account?.derivationMode !== undefined && diff --git a/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx b/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx index 9e226081db00..588384f494f2 100644 --- a/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx +++ b/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx @@ -8,7 +8,7 @@ import { BalanceHistoryWithCountervalue, } from "@ledgerhq/types-live"; import { Unit, Currency } from "@ledgerhq/types-cryptoassets"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Box, Flex, Text, Transitions, InfiniteLoader, GraphTabs, Tag } from "@ledgerhq/native-ui"; import { useTranslation } from "react-i18next"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -31,6 +31,7 @@ import { BaseNavigatorStackParamList } from "./RootNavigator/types/BaseNavigator import { GraphPlaceholder } from "./Graph/Placeholder"; import { tokensWithUnsupportedGraph } from "./Graph/tokensWithUnsupportedGraph"; import { useAccountName, useMaybeAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const { width } = getWindowDimensions(); @@ -80,7 +81,7 @@ function AccountGraphCard({ parentAccount, }: Props) { const currency = getAccountCurrency(account); - + const unit = useAccountUnit(account); const { colors } = useTheme(); const { t } = useTranslation(); @@ -143,7 +144,7 @@ function AccountGraphCard({ onSwitchAccountCurrency={onSwitchAccountCurrency} counterValueUnit={counterValueCurrency.units[0]} useCounterValue={useCounterValue} - cryptoCurrencyUnit={getAccountUnit(account)} + cryptoCurrencyUnit={unit} item={hoveredItem || history[history.length - 1]} valueChange={valueChange} parentAccount={parentAccount} diff --git a/apps/ledger-live-mobile/src/components/AccountSelector.tsx b/apps/ledger-live-mobile/src/components/AccountSelector.tsx index 443b3de88401..4e2472db7cd3 100644 --- a/apps/ledger-live-mobile/src/components/AccountSelector.tsx +++ b/apps/ledger-live-mobile/src/components/AccountSelector.tsx @@ -11,7 +11,12 @@ import { accountsSelector } from "~/reducers/accounts"; import { walletSelector } from "~/reducers/wallet"; import { accountNameWithDefaultSelector } from "@ledgerhq/live-wallet/store"; -const SEARCH_KEYS = ["name", "account.unit.code", "account.token.name", "account.token.ticker"]; +const SEARCH_KEYS = [ + "name", + "account.currency.units[0].code", + "account.token.name", + "account.token.ticker", +]; type Props = { list: AccountLike[]; diff --git a/apps/ledger-live-mobile/src/components/DelegationDrawer.tsx b/apps/ledger-live-mobile/src/components/DelegationDrawer.tsx index 6bf8c5f596ab..2981626b1ea3 100644 --- a/apps/ledger-live-mobile/src/components/DelegationDrawer.tsx +++ b/apps/ledger-live-mobile/src/components/DelegationDrawer.tsx @@ -3,7 +3,7 @@ import React from "react"; import type { ComponentType } from "react"; import { View, StyleSheet, ScrollView } from "react-native"; import type { StyleProp, ViewStyle } from "react-native"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; import type { AccountLike } from "@ledgerhq/types-live"; // TODO move to component @@ -19,6 +19,7 @@ import CurrencyUnitValue from "./CurrencyUnitValue"; import CounterValue from "./CounterValue"; import CurrencyIcon from "./CurrencyIcon"; import { normalize } from "~/helpers/normalizeSize"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const { height } = getWindowDimensions(); type Props = { @@ -50,7 +51,7 @@ export default function DelegationDrawer({ }: Props) { const currency = getAccountCurrency(account); const color = getCurrencyColor(currency); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const iconWidth = normalize(64); return ( diff --git a/apps/ledger-live-mobile/src/components/DeviceAction/index.tsx b/apps/ledger-live-mobile/src/components/DeviceAction/index.tsx index a0605df888dc..b5e1fb4e9cc6 100644 --- a/apps/ledger-live-mobile/src/components/DeviceAction/index.tsx +++ b/apps/ledger-live-mobile/src/components/DeviceAction/index.tsx @@ -56,6 +56,7 @@ import DeviceActionProgress from "../DeviceActionProgress"; import { PartialNullable } from "~/types/helpers"; import ModalLock from "../ModalLock"; import { walletSelector } from "~/reducers/wallet"; +import { settingsStoreSelector } from "~/reducers/settings"; type LedgerError = InstanceType>; @@ -233,6 +234,7 @@ export function DeviceActionDefaultRendering({ }, [error, onError]); const walletState = useSelector(walletSelector); + const settingsState = useSelector(settingsStoreSelector); if (displayUpgradeWarning && appAndVersion) { return renderWarningOutdated({ @@ -403,6 +405,7 @@ export function DeviceActionDefaultRendering({ amountExpectedTo: status.amountExpectedTo, estimatedFees: status.estimatedFees, walletState, + settingsState, }); } diff --git a/apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx b/apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx index 647bcd247bc7..1fbe4eb6be27 100644 --- a/apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx +++ b/apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx @@ -29,7 +29,6 @@ import { DownloadMedium } from "@ledgerhq/native-ui/assets/icons"; import BigNumber from "bignumber.js"; import { ExchangeRate, ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types"; import { - getAccountUnit, getMainAccount, getAccountCurrency, getFeesCurrency, @@ -42,7 +41,7 @@ import { StackNavigationProp } from "@react-navigation/stack"; import { ParamListBase } from "@react-navigation/native"; import isFirmwareUpdateVersionSupported from "@ledgerhq/live-common/hw/isFirmwareUpdateVersionSupported"; import ProviderIcon from "../ProviderIcon"; -import { lastSeenDeviceSelector } from "~/reducers/settings"; +import { currencySettingsForAccountSelector, lastSeenDeviceSelector } from "~/reducers/settings"; import { urls } from "~/utils/urls"; import Alert from "../Alert"; import { lighten, Theme } from "../../colors"; @@ -62,6 +61,7 @@ import CurrencyIcon from "../CurrencyIcon"; import ModalLock from "../ModalLock"; import Config from "react-native-config"; import { WalletState, accountNameWithDefaultSelector } from "@ledgerhq/live-wallet/store"; +import { SettingsState } from "~/reducers/types"; export const Wrapper = styled(Flex).attrs({ flex: 1, @@ -242,6 +242,7 @@ export function renderConfirmSwap({ amountExpectedTo, estimatedFees, walletState, + settingsState, }: RawProps & { device: Device; transaction: Transaction; @@ -250,12 +251,21 @@ export function renderConfirmSwap({ amountExpectedTo?: string | null; estimatedFees?: string | null; walletState: WalletState; + settingsState: SettingsState; }) { const providerName = getProviderName(exchangeRate.provider); const noticeType = getNoticeType(exchangeRate.provider); const alertProperties = noticeType.learnMore ? { learnMoreUrl: urls.swap.learnMore } : {}; const fromAccountName = accountNameWithDefaultSelector(walletState, exchange.fromAccount); const toAccountName = accountNameWithDefaultSelector(walletState, exchange.toAccount); + + const unitFrom = currencySettingsForAccountSelector(settingsState, { + account: exchange.fromAccount, + }).unit; + const unitTo = currencySettingsForAccountSelector(settingsState, { + account: exchange.toAccount, + }).unit; + return ( @@ -277,7 +287,7 @@ export function renderConfirmSwap({ @@ -287,7 +297,7 @@ export function renderConfirmSwap({ ( (route.params as { transaction: Transaction })?.transaction, ); - const feeCustomUnit = (transaction as { feeCustomUnit?: Unit }).feeCustomUnit || account.unit; + + const unit = useAccountUnit(account); + const feeCustomUnit = (transaction as { feeCustomUnit?: Unit }).feeCustomUnit || unit; const editTxFeeByFamily = useEditTxFeeByFamily(); function onRequestClose() { @@ -147,7 +150,7 @@ export default function EditFreeUnit({ account, field }: Props) { )} > - {account.unit.code} + {unit.code} diff --git a/apps/ledger-live-mobile/src/components/OperationIcon.tsx b/apps/ledger-live-mobile/src/components/OperationIcon.tsx index c9337d27e181..2fbe778187d8 100644 --- a/apps/ledger-live-mobile/src/components/OperationIcon.tsx +++ b/apps/ledger-live-mobile/src/components/OperationIcon.tsx @@ -64,7 +64,7 @@ export default connect((state: State, props: OwnProps) => { const { account, parentAccount, operation } = props; const { type } = operation; const mainAccount = getMainAccount(account, parentAccount); - const currencySettings = currencySettingsForAccountSelector(state, props); + const currencySettings = currencySettingsForAccountSelector(state.settings, props); const isConfirmed = isConfirmedOperation( operation, mainAccount, diff --git a/apps/ledger-live-mobile/src/components/OperationRow/index.tsx b/apps/ledger-live-mobile/src/components/OperationRow/index.tsx index c8d138e85b0c..bb80f7084ea2 100644 --- a/apps/ledger-live-mobile/src/components/OperationRow/index.tsx +++ b/apps/ledger-live-mobile/src/components/OperationRow/index.tsx @@ -9,11 +9,7 @@ import { isEditableOperation, isStuckOperation, } from "@ledgerhq/live-common/operation"; -import { - getMainAccount, - getAccountCurrency, - getAccountUnit, -} from "@ledgerhq/live-common/account/index"; +import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Account, Operation, AccountLike } from "@ledgerhq/types-live"; import { Box, Flex, InfiniteLoader, Text } from "@ledgerhq/native-ui"; import { WarningMedium } from "@ledgerhq/native-ui/assets/icons"; @@ -33,6 +29,7 @@ import { BaseNavigation } from "../RootNavigator/types/helpers"; import { currencySettingsForAccountSelector } from "~/reducers/settings"; import type { State } from "~/reducers/types"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type FamilyOperationDetailsIntersection = UnionToIntersection< (typeof perFamilyOperationDetails)[keyof typeof perFamilyOperationDetails] @@ -124,10 +121,12 @@ function OperationRow({ const isNftOperation = ["NFT_IN", "NFT_OUT"].includes(operation.type) && operation.contract && operation.tokenId; + const unit = useAccountUnit(account); + const renderAmountCellExtra = useCallback(() => { const mainAccount = getMainAccount(account, parentAccount); const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); + const specific = mainAccount?.currency?.family ? (perFamilyOperationDetails[ mainAccount.currency.family as keyof typeof perFamilyOperationDetails @@ -142,7 +141,7 @@ function OperationRow({ return SpecificAmountCell ? ( ) : null; - }, [account, operation, parentAccount]); + }, [account, operation, parentAccount, unit]); const { colors } = useTheme(); const amount = getOperationAmountNumber(operation); @@ -150,7 +149,7 @@ function OperationRow({ const mainAccount = getMainAccount(account, parentAccount); const accountName = useAccountName(account); const currencySettings = useSelector((s: State) => - currencySettingsForAccountSelector(s, { + currencySettingsForAccountSelector(s.settings, { account: mainAccount, }), ); @@ -165,7 +164,6 @@ function OperationRow({ ? colors.success.c50 : colors.warning.c50; - const unit = getAccountUnit(account); const text = ; const isOptimistic = operation.blockHeight === null; const isOperationStuck = diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/AccountSettingsNavigator.tsx b/apps/ledger-live-mobile/src/components/RootNavigator/AccountSettingsNavigator.tsx index 52931e418d56..429452e4dc2b 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/AccountSettingsNavigator.tsx +++ b/apps/ledger-live-mobile/src/components/RootNavigator/AccountSettingsNavigator.tsx @@ -5,7 +5,6 @@ import { useTheme } from "styled-components/native"; import { ScreenName } from "~/const"; import Accounts from "~/screens/Accounts"; import AccountSettingsMain from "~/screens/AccountSettings"; -import EditAccountUnits from "~/screens/AccountSettings/EditAccountUnits"; import EditAccountName from "~/screens/AccountSettings/EditAccountName"; import AdvancedLogs from "~/screens/AccountSettings/AdvancedLogs"; import AccountOrder from "~/screens/Accounts/AccountOrder"; @@ -13,6 +12,7 @@ import AddAccount from "~/screens/Accounts/AddAccount"; import CurrencySettings from "~/screens/Settings/CryptoAssets/Currencies/CurrencySettings"; import { getStackNavigatorConfig } from "~/navigation/navigatorConfig"; import { AccountSettingsNavigatorParamList } from "./types/AccountSettingsNavigator"; +import EditCurrencyUnits from "~/screens/Settings/CryptoAssets/Currencies/EditCurrencyUnits"; const Stack = createStackNavigator(); @@ -30,13 +30,6 @@ export default function AccountSettingsNavigator() { headerRight: () => null, }} /> - + (); @@ -164,6 +165,14 @@ export default function BaseNavigator() { })} {...noNanoBuyNanoWallScreenOptions} /> + + (); @@ -154,6 +155,15 @@ export default function SettingsNavigator() { })} {...noNanoBuyNanoWallScreenOptions} /> + + + ; } diff --git a/apps/ledger-live-mobile/src/components/Web3AppWebview/liveSDKLogic.test.ts b/apps/ledger-live-mobile/src/components/Web3AppWebview/liveSDKLogic.test.ts index d88a961566b2..a7c961651b57 100644 --- a/apps/ledger-live-mobile/src/components/Web3AppWebview/liveSDKLogic.test.ts +++ b/apps/ledger-live-mobile/src/components/Web3AppWebview/liveSDKLogic.test.ts @@ -107,11 +107,6 @@ const createAccount = (id: string, crypto: CryptoCurrency = defaultEthCryptoFami creationDate: new Date(), blockHeight: 8168983, currency: crypto, - unit: { - name: "satoshi", - code: "BTC", - magnitude: 5, - }, operationsCount: 0, operations: [], pendingOperations: [], diff --git a/apps/ledger-live-mobile/src/const/navigation.ts b/apps/ledger-live-mobile/src/const/navigation.ts index 5e25c33998d1..11d1e9b790b5 100644 --- a/apps/ledger-live-mobile/src/const/navigation.ts +++ b/apps/ledger-live-mobile/src/const/navigation.ts @@ -24,6 +24,7 @@ export enum ScreenName { CryptoAssetsSettings = "CryptoAssetsSettings", CurrenciesList = "CurrenciesList", CurrencySettings = "CurrencySettings", + EditCurrencyUnits = "EditCurrencyUnits", DebugBLE = "DebugBLE", DebugBLEBenchmark = "DebugBLEBenchmark", DebugBLEDevicePairing = "DebugBLEDevicePairing", @@ -72,7 +73,6 @@ export enum ScreenName { DeviceConnect = "DeviceConnect", DisplayResult = "DisplayResult", EditAccountName = "EditAccountName", - EditAccountUnits = "EditAccountUnits", EditDeviceName = "EditDeviceName", Exchange = "Exchange", ExchangeBuy = "ExchangeBuy", diff --git a/apps/ledger-live-mobile/src/families/algorand/Rewards/ClaimRewardsFlow/01-Started.tsx b/apps/ledger-live-mobile/src/families/algorand/Rewards/ClaimRewardsFlow/01-Started.tsx index 8f9dc35d5f3d..6b3c15588286 100644 --- a/apps/ledger-live-mobile/src/families/algorand/Rewards/ClaimRewardsFlow/01-Started.tsx +++ b/apps/ledger-live-mobile/src/families/algorand/Rewards/ClaimRewardsFlow/01-Started.tsx @@ -3,7 +3,7 @@ import React, { useCallback } from "react"; import { View, StyleSheet, SafeAreaView } from "react-native"; import { Trans } from "react-i18next"; import { useSelector } from "react-redux"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/helpers"; +import { getMainAccount } from "@ledgerhq/live-common/account/helpers"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; @@ -25,6 +25,7 @@ import Illustration from "~/images/illustration/Illustration"; import type { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { AlgorandClaimRewardsFlowParamList } from "./type"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps< AlgorandClaimRewardsFlowParamList, @@ -40,7 +41,7 @@ export default function DelegationStarted({ navigation, route }: Props) { const bridge = getAccountBridge(mainAccount, undefined); invariant(mainAccount && mainAccount.algorandResources, "algorand Account required"); const { rewards } = mainAccount.algorandResources; - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const { transaction, status } = useBridgeTransaction(() => { const t = bridge.createTransaction(mainAccount); return { diff --git a/apps/ledger-live-mobile/src/families/algorand/Rewards/index.tsx b/apps/ledger-live-mobile/src/families/algorand/Rewards/index.tsx index bf497f796202..0d43d5901000 100644 --- a/apps/ledger-live-mobile/src/families/algorand/Rewards/index.tsx +++ b/apps/ledger-live-mobile/src/families/algorand/Rewards/index.tsx @@ -2,7 +2,7 @@ import invariant from "invariant"; import React, { useCallback } from "react"; import { useTranslation } from "react-i18next"; import { useNavigation } from "@react-navigation/native"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Box, Button, Flex, Text } from "@ledgerhq/native-ui"; import { InfoMedium } from "@ledgerhq/native-ui/assets/icons"; import { AlgorandAccount } from "@ledgerhq/live-common/families/algorand/types"; @@ -11,6 +11,7 @@ import AccountSectionLabel from "~/components/AccountSectionLabel"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import CounterValue from "~/components/CounterValue"; import { ScreenName, NavigatorName } from "~/const"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -21,7 +22,7 @@ const RewardsSection = ({ account }: { account: AlgorandAccount }) => { const { rewards } = account.algorandResources; const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { t } = useTranslation(); const navigation = useNavigation(); diff --git a/apps/ledger-live-mobile/src/families/algorand/SendRowsFee.tsx b/apps/ledger-live-mobile/src/families/algorand/SendRowsFee.tsx index 803837fe44f6..c322721b6802 100644 --- a/apps/ledger-live-mobile/src/families/algorand/SendRowsFee.tsx +++ b/apps/ledger-live-mobile/src/families/algorand/SendRowsFee.tsx @@ -4,7 +4,7 @@ import type { AccountLike, Account } from "@ledgerhq/types-live"; import { Trans } from "react-i18next"; import type { Transaction as AlgorandTransaction } from "@ledgerhq/live-common/families/algorand/types"; import type { Transaction } from "@ledgerhq/live-common/generated/types"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { getMainAccount } from "@ledgerhq/live-common/account/helpers"; import { CompositeScreenProps, useTheme } from "@react-navigation/native"; import SummaryRow from "~/screens/SendFunds/SummaryRow"; @@ -19,6 +19,7 @@ import type { BaseNavigatorStackParamList } from "~/components/RootNavigator/typ import { ScreenName } from "~/const"; import type { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import type { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { transaction: Transaction; @@ -38,7 +39,7 @@ export default function AlgorandFeeRow({ account, parentAccount, transaction }: }, []); const fees = (transaction as AlgorandTransaction).fees; const mainAccount = getMainAccount(account, parentAccount); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/families/algorand/operationDetails.tsx b/apps/ledger-live-mobile/src/families/algorand/operationDetails.tsx index 976a0195dc7d..98d86bdbe748 100644 --- a/apps/ledger-live-mobile/src/families/algorand/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/algorand/operationDetails.tsx @@ -3,7 +3,6 @@ import { View, StyleSheet } from "react-native"; import { useTranslation } from "react-i18next"; import type { Operation, OperationType } from "@ledgerhq/types-live"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { useSelector } from "react-redux"; import { IconsLegacy } from "@ledgerhq/native-ui"; import Section from "~/screens/OperationDetails/Section"; @@ -15,6 +14,7 @@ import { AlgorandOperationExtra, } from "@ledgerhq/live-common/families/algorand/types"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { operation: AlgorandOperation; @@ -23,7 +23,7 @@ type Props = { function OperationDetailsExtra({ operation, account }: Props) { const { t } = useTranslation(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const discreet = useSelector(discreetModeSelector); const { locale } = useSettings(); const formattedRewards = operation.extra.rewards?.gt(0) diff --git a/apps/ledger-live-mobile/src/families/cardano/DelegationFlow/02-Summary.tsx b/apps/ledger-live-mobile/src/families/cardano/DelegationFlow/02-Summary.tsx index 4f0c45860f3a..bb3fa248eba8 100644 --- a/apps/ledger-live-mobile/src/families/cardano/DelegationFlow/02-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/cardano/DelegationFlow/02-Summary.tsx @@ -6,7 +6,7 @@ import { Trans, useTranslation } from "react-i18next"; import { Animated, SafeAreaView, StyleSheet, View } from "react-native"; import { useSelector } from "react-redux"; import Icon from "react-native-vector-icons/Feather"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -39,6 +39,7 @@ import { rgba } from "../../../colors"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CardanoDelegationFlowParamList } from "./types"; import TranslatedError from "~/components/TranslatedError"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps< CardanoDelegationFlowParamList, @@ -291,7 +292,7 @@ function SummaryWords({ onChangePool: () => void; status: TransactionStatus; }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { t } = useTranslation(); const { colors } = useTheme(); const [rotateAnim] = useState(() => new Animated.Value(0)); @@ -529,7 +530,7 @@ function SummaryWords({ } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/cardano/Delegations/index.tsx b/apps/ledger-live-mobile/src/families/cardano/Delegations/index.tsx index aeea5258f198..81de384fca97 100644 --- a/apps/ledger-live-mobile/src/families/cardano/Delegations/index.tsx +++ b/apps/ledger-live-mobile/src/families/cardano/Delegations/index.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useState, useMemo } from "react"; import { View, StyleSheet, Linking } from "react-native"; import { useNavigation, useTheme } from "@react-navigation/native"; import { useTranslation } from "react-i18next"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import type { CardanoAccount, CardanoDelegation, @@ -30,6 +30,7 @@ import DelegationRow from "./Row"; import PoolImage from "../shared/PoolImage"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: CardanoAccount; @@ -44,7 +45,7 @@ function Delegations({ account }: Props) { const mainAccount = getMainAccount(account, undefined); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const navigation = useNavigation(); const { cardanoResources } = account; diff --git a/apps/ledger-live-mobile/src/families/cardano/UndelegationFlow/01-Summary.tsx b/apps/ledger-live-mobile/src/families/cardano/UndelegationFlow/01-Summary.tsx index 1d8bf09a383d..b59c6bd49c8e 100644 --- a/apps/ledger-live-mobile/src/families/cardano/UndelegationFlow/01-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/cardano/UndelegationFlow/01-Summary.tsx @@ -5,11 +5,7 @@ import React, { ReactNode, useCallback, useMemo } from "react"; import { Trans, useTranslation } from "react-i18next"; import { SafeAreaView, StyleSheet, View } from "react-native"; import { useSelector } from "react-redux"; -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -31,6 +27,7 @@ import { rgba } from "../../../colors"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CardanoUndelegationFlowParamList } from "./types"; import TranslatedError from "~/components/TranslatedError"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps< CardanoUndelegationFlowParamList, @@ -193,7 +190,7 @@ const styles = StyleSheet.create({ }); function SummaryWords({ account }: { account: AccountLike; currentDelegation: CardanoDelegation }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { t } = useTranslation(); const { colors } = useTheme(); @@ -242,7 +239,7 @@ function SummaryWords({ account }: { account: AccountLike; currentDelegation: Ca } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/celo/AccountBalanceSummaryFooter.tsx b/apps/ledger-live-mobile/src/families/celo/AccountBalanceSummaryFooter.tsx index e24e1ac95046..fcd5f15e592e 100644 --- a/apps/ledger-live-mobile/src/families/celo/AccountBalanceSummaryFooter.tsx +++ b/apps/ledger-live-mobile/src/families/celo/AccountBalanceSummaryFooter.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useState } from "react"; import { ScrollView, StyleSheet } from "react-native"; import { useTranslation } from "react-i18next"; import { getCryptoCurrencyById } from "@ledgerhq/live-common/currencies/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { getCryptoCurrencyIcon } from "@ledgerhq/live-common/reactNative"; import type { Account } from "@ledgerhq/types-live"; import invariant from "invariant"; @@ -12,6 +11,7 @@ import InfoModal from "~/modals/Info"; import type { ModalInfo } from "~/modals/Info"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import InfoItem from "~/components/BalanceSummaryInfoItem"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: Account; @@ -27,7 +27,7 @@ function AccountBalanceSummaryFooter({ account }: Props) { const { spendableBalance, celoResources } = celoAccount; const { lockedBalance, nonvotingLockedBalance } = celoResources; const withdrawableBalanceAmount = withdrawableBalance(celoAccount); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const onCloseModal = useCallback(() => { setInfoName(undefined); }, []); diff --git a/apps/ledger-live-mobile/src/families/celo/Delegations/Row.tsx b/apps/ledger-live-mobile/src/families/celo/Delegations/Row.tsx index 521f1e6c2070..90246e7c26d8 100644 --- a/apps/ledger-live-mobile/src/families/celo/Delegations/Row.tsx +++ b/apps/ledger-live-mobile/src/families/celo/Delegations/Row.tsx @@ -11,6 +11,7 @@ import ArrowRight from "~/icons/ArrowRight"; import LText from "~/components/LText"; import ValidatorImage from "../../cosmos/shared/ValidatorImage"; import { formatAmount } from "./utils"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: CeloAccount; @@ -33,7 +34,7 @@ export default function DelegationRow({ const { t } = useTranslation(); const { validatorGroup, amount } = vote; const validatorName = getValidatorName(vote) ?? ""; - + const unit = useAccountUnit(account); return ( - {formatAmount(account, vote.amount ?? 0)} + {formatAmount(vote.amount ?? 0, unit)} diff --git a/apps/ledger-live-mobile/src/families/celo/Delegations/index.tsx b/apps/ledger-live-mobile/src/families/celo/Delegations/index.tsx index 37d4d7acbc5b..bd52113b98a2 100644 --- a/apps/ledger-live-mobile/src/families/celo/Delegations/index.tsx +++ b/apps/ledger-live-mobile/src/families/celo/Delegations/index.tsx @@ -38,6 +38,7 @@ import { formatAmount } from "./utils"; import CheckCircle from "~/icons/CheckCircle"; import Loader from "~/icons/Loader"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: Account; @@ -132,6 +133,7 @@ function Delegations({ account }: Props) { ); const accountName = useAccountName(account); + const unit = useAccountUnit(account); const data = useMemo(() => { const v = vote; @@ -230,7 +232,7 @@ function Delegations({ account }: Props) { Component: ( <> - {formatAmount(account as CeloAccount, vote.amount ?? 0)} + {formatAmount(vote.amount ?? 0, unit)} ), @@ -244,10 +246,10 @@ function Delegations({ account }: Props) { t, getValidatorName, accountName, - account, colors.green, colors.warning, colors.grey, + unit, onOpenExplorer, ]); diff --git a/apps/ledger-live-mobile/src/families/celo/Delegations/utils.tsx b/apps/ledger-live-mobile/src/families/celo/Delegations/utils.tsx index 93a0e2cc5b0f..7aaaa024279a 100644 --- a/apps/ledger-live-mobile/src/families/celo/Delegations/utils.tsx +++ b/apps/ledger-live-mobile/src/families/celo/Delegations/utils.tsx @@ -1,10 +1,8 @@ import BigNumber from "bignumber.js"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; -import { CeloAccount } from "@ledgerhq/live-common/families/celo/types"; +import { Unit } from "@ledgerhq/types-cryptoassets"; -export const formatAmount = (account: CeloAccount, amount: BigNumber) => { - const unit = getAccountUnit(account); +export const formatAmount = (amount: BigNumber, unit: Unit) => { return formatCurrencyUnit(unit, new BigNumber(amount), { disableRounding: false, alwaysShowSign: false, diff --git a/apps/ledger-live-mobile/src/families/celo/LockFlow/01-Amount.tsx b/apps/ledger-live-mobile/src/families/celo/LockFlow/01-Amount.tsx index ae2d94fd76be..0536476ce625 100644 --- a/apps/ledger-live-mobile/src/families/celo/LockFlow/01-Amount.tsx +++ b/apps/ledger-live-mobile/src/families/celo/LockFlow/01-Amount.tsx @@ -14,7 +14,7 @@ import { Trans } from "react-i18next"; import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { Transaction as CeloTransaction } from "@ledgerhq/live-common/families/celo/types"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -31,6 +31,7 @@ import { getFirstStatusError, hasStatusError } from "../../helpers"; import SendRowsFee from "../SendRowsFee"; import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CeloLockFlowParamList } from "./types"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite>; @@ -108,12 +109,11 @@ export default function LockAmount({ navigation, route }: Props) { }, [account, navigation, transaction, status]); const blur = useCallback(() => Keyboard.dismiss(), []); - - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); diff --git a/apps/ledger-live-mobile/src/families/celo/RevokeFlow/01-Summary.tsx b/apps/ledger-live-mobile/src/families/celo/RevokeFlow/01-Summary.tsx index 8dc29c66e4c3..4959d192f1a2 100644 --- a/apps/ledger-live-mobile/src/families/celo/RevokeFlow/01-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/celo/RevokeFlow/01-Summary.tsx @@ -1,4 +1,4 @@ -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; @@ -23,6 +23,7 @@ import Line from "../components/Line"; import Words from "../components/Words"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CeloRevokeFlowFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -210,7 +211,7 @@ function SummaryWords({ onChangeValidator: () => void; onChangeAmount: () => void; }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, new BigNumber(amount), { disableRounding: true, alwaysShowSign: false, diff --git a/apps/ledger-live-mobile/src/families/celo/RevokeFlow/VoteAmount.tsx b/apps/ledger-live-mobile/src/families/celo/RevokeFlow/VoteAmount.tsx index 2c0c8314fd14..32803b1eb9ca 100644 --- a/apps/ledger-live-mobile/src/families/celo/RevokeFlow/VoteAmount.tsx +++ b/apps/ledger-live-mobile/src/families/celo/RevokeFlow/VoteAmount.tsx @@ -13,7 +13,6 @@ import { useSelector } from "react-redux"; import { Trans } from "react-i18next"; import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { Transaction as CeloTransaction } from "@ledgerhq/live-common/families/celo/types"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -29,6 +28,7 @@ import SendRowsFee from "../SendRowsFee"; import { getFirstStatusError } from "../../helpers"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CeloRevokeFlowFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -93,7 +93,7 @@ export default function VoteAmount({ navigation, route }: Props) { const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); diff --git a/apps/ledger-live-mobile/src/families/celo/SendRowsFee.tsx b/apps/ledger-live-mobile/src/families/celo/SendRowsFee.tsx index feef6ecc8909..0773c148e5b4 100644 --- a/apps/ledger-live-mobile/src/families/celo/SendRowsFee.tsx +++ b/apps/ledger-live-mobile/src/families/celo/SendRowsFee.tsx @@ -4,7 +4,7 @@ import type { Account, AccountLike } from "@ledgerhq/types-live"; import { Trans } from "react-i18next"; import type { Transaction } from "@ledgerhq/live-common/generated/types"; import type { Transaction as CeloTransaction } from "@ledgerhq/live-common/families/celo/types"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { CompositeScreenProps, useTheme } from "@react-navigation/native"; import SummaryRow from "~/screens/SendFunds/SummaryRow"; import LText from "~/components/LText"; @@ -23,6 +23,7 @@ import type { CeloRevokeFlowFlowParamList } from "./RevokeFlow/types"; import type { CeloUnlockFlowParamList } from "./UnlockFlow/types"; import type { CeloVoteFlowParamList } from "./VoteFlow/types"; import type { CeloWithdrawFlowParamList } from "./WithdrawFlow/types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -47,7 +48,7 @@ export default function CeloFeeRow({ account, transaction }: Props) { }, []); const fees = (transaction as CeloTransaction).fees; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/families/celo/UnlockFlow/01-Amount.tsx b/apps/ledger-live-mobile/src/families/celo/UnlockFlow/01-Amount.tsx index 10847b1853b4..9ebcd22b7899 100644 --- a/apps/ledger-live-mobile/src/families/celo/UnlockFlow/01-Amount.tsx +++ b/apps/ledger-live-mobile/src/families/celo/UnlockFlow/01-Amount.tsx @@ -14,7 +14,7 @@ import { Trans } from "react-i18next"; import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { Transaction as CeloTransaction } from "@ledgerhq/live-common/families/celo/types"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -30,6 +30,7 @@ import { getFirstStatusError, hasStatusError } from "../../helpers"; import SendRowsFee from "../SendRowsFee"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { CeloUnlockFlowParamList } from "./types"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -109,11 +110,12 @@ export default function UnlockAmount({ navigation, route }: Props) { const blur = useCallback(() => Keyboard.dismiss(), []); - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); diff --git a/apps/ledger-live-mobile/src/families/celo/ValidatorRow.tsx b/apps/ledger-live-mobile/src/families/celo/ValidatorRow.tsx index d78af93e659c..ef1eda1c5830 100644 --- a/apps/ledger-live-mobile/src/families/celo/ValidatorRow.tsx +++ b/apps/ledger-live-mobile/src/families/celo/ValidatorRow.tsx @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { isDefaultValidatorGroupAddress } from "@ledgerhq/live-common/families/celo/logic"; import { AccountLike } from "@ledgerhq/types-live"; import { Text } from "@ledgerhq/native-ui"; @@ -11,6 +10,7 @@ import BigNumber from "bignumber.js"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import Touchable from "~/components/Touchable"; import ValidatorImage from "./ValidatorImage"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const ValidatorRow = ({ onPress, @@ -26,7 +26,7 @@ const ValidatorRow = ({ amount: BigNumber; }) => { const { colors } = useTheme(); - + const unit = useAccountUnit(account); const onPressT = useCallback(() => { onPress(validator, vote); }, [onPress, validator, vote]); @@ -68,7 +68,7 @@ const ValidatorRow = ({ - + diff --git a/apps/ledger-live-mobile/src/families/celo/VoteFlow/02-Summary.tsx b/apps/ledger-live-mobile/src/families/celo/VoteFlow/02-Summary.tsx index c5d91c6bde24..d36418276fb7 100644 --- a/apps/ledger-live-mobile/src/families/celo/VoteFlow/02-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/celo/VoteFlow/02-Summary.tsx @@ -1,8 +1,4 @@ -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -35,6 +31,7 @@ import Line from "../components/Line"; import Words from "../components/Words"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CeloVoteFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; @@ -280,7 +277,7 @@ function SummaryWords({ onChangeValidator: () => void; onChangeAmount: () => void; }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, new BigNumber(amount), { disableRounding: true, alwaysShowSign: false, @@ -309,7 +306,7 @@ function SummaryWords({ } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/celo/VoteFlow/VoteAmount.tsx b/apps/ledger-live-mobile/src/families/celo/VoteFlow/VoteAmount.tsx index 57160e7d6726..c485f83ac5c2 100644 --- a/apps/ledger-live-mobile/src/families/celo/VoteFlow/VoteAmount.tsx +++ b/apps/ledger-live-mobile/src/families/celo/VoteFlow/VoteAmount.tsx @@ -13,7 +13,6 @@ import { useSelector } from "react-redux"; import { Trans } from "react-i18next"; import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { accountScreenSelector } from "~/reducers/accounts"; import { ScreenName } from "~/const"; @@ -28,6 +27,7 @@ import SendRowsFee from "../SendRowsFee"; import { getFirstStatusError } from "../../helpers"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { CeloVoteFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite>; @@ -89,7 +89,7 @@ export default function VoteAmount({ navigation, route }: Props) { const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); diff --git a/apps/ledger-live-mobile/src/families/celo/WithdrawFlow/WithdrawAmount.tsx b/apps/ledger-live-mobile/src/families/celo/WithdrawFlow/WithdrawAmount.tsx index 07495e57ef31..38ca4bf8fffe 100644 --- a/apps/ledger-live-mobile/src/families/celo/WithdrawFlow/WithdrawAmount.tsx +++ b/apps/ledger-live-mobile/src/families/celo/WithdrawFlow/WithdrawAmount.tsx @@ -6,7 +6,6 @@ import { useSelector } from "react-redux"; import { Trans } from "react-i18next"; import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { getMainAccount } from "@ledgerhq/live-common/account/helpers"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; @@ -29,6 +28,7 @@ import Words from "../components/Words"; import ErrorAndWarning from "../components/ErrorAndWarning"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { CeloWithdrawFlowParamList } from "./types"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -81,7 +81,8 @@ export default function WithdrawAmount({ navigation, route }: Props) { }); }; - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { pendingWithdrawals } = (account as CeloAccount).celoResources; if (pendingWithdrawals) { @@ -89,7 +90,6 @@ export default function WithdrawAmount({ navigation, route }: Props) { onChange(pendingWithdrawals[0].index); } } - const unit = getAccountUnit(account); const formatAmount = (val: BigNumber) => { return formatCurrencyUnit(unit, val, { disableRounding: true, diff --git a/apps/ledger-live-mobile/src/families/celo/operationDetails.tsx b/apps/ledger-live-mobile/src/families/celo/operationDetails.tsx index a4b45fbadb0e..475cec9af4d3 100644 --- a/apps/ledger-live-mobile/src/families/celo/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/celo/operationDetails.tsx @@ -8,7 +8,6 @@ import { OperationType } from "@ledgerhq/types-live"; import { useCeloPreloadData } from "@ledgerhq/live-common/families/celo/react"; import { CeloAccount, CeloOperation } from "@ledgerhq/live-common/families/celo/types"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { useRoute } from "@react-navigation/native"; import Section from "~/screens/OperationDetails/Section"; import { discreetModeSelector } from "~/reducers/settings"; @@ -16,6 +15,7 @@ import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator"; import { ScreenName } from "~/const"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { operation: CeloOperation; @@ -29,7 +29,7 @@ const OperationDetailsExtra = ({ operation, type, account }: Props) => { const { t } = useTranslation(); const discreet = useSelector(discreetModeSelector); const { locale } = useSettings(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { validatorGroups: celoValidators } = useCeloPreloadData(); const { extra } = operation; const optimisticOperation = useRoute().params?.operation ?? null; diff --git a/apps/ledger-live-mobile/src/families/cosmos/AccountBalanceSummaryFooter.tsx b/apps/ledger-live-mobile/src/families/cosmos/AccountBalanceSummaryFooter.tsx index 561bd062c5ae..cd0f36a73987 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/AccountBalanceSummaryFooter.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/AccountBalanceSummaryFooter.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useState } from "react"; import { ScrollView } from "react-native"; import { useTranslation } from "react-i18next"; import BigNumber from "bignumber.js"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { getCryptoCurrencyIcon } from "@ledgerhq/live-common/reactNative"; import { CosmosAccount } from "@ledgerhq/live-common/families/cosmos/types"; import { CosmosAPI } from "@ledgerhq/live-common/families/cosmos/api/Cosmos"; @@ -14,6 +13,7 @@ import InfoModal from "~/modals/Info"; import type { ModalInfo } from "~/modals/Info"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import InfoItem from "~/components/BalanceSummaryInfoItem"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: CosmosAccount; @@ -32,7 +32,7 @@ function AccountBalanceSummaryFooter({ account }: Props) { const info = useInfo(account); const { spendableBalance, cosmosResources } = account; const { delegatedBalance, unbondingBalance } = cosmosResources || {}; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const onCloseModal = useCallback(() => { setInfoName(undefined); }, []); diff --git a/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/01-SelectValidator.tsx b/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/01-SelectValidator.tsx index 236129ec5f7a..0e4452c6c16c 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/01-SelectValidator.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/01-SelectValidator.tsx @@ -9,7 +9,7 @@ import type { Transaction, } from "@ledgerhq/live-common/families/cosmos/types"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getMainAccount, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { useCosmosFamilyMappedDelegations } from "@ledgerhq/live-common/families/cosmos/react"; import { useTheme } from "@react-navigation/native"; @@ -19,6 +19,7 @@ import Item from "../shared/Item"; import type { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { CosmosClaimRewardsFlowParamList } from "./types"; import BigNumber from "bignumber.js"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps< CosmosClaimRewardsFlowParamList, @@ -44,7 +45,7 @@ function ClaimRewardsSelectValidator({ navigation, route }: Props) { }; }).transaction as Transaction; invariant(transaction && transaction.validators, "transaction and validators required"); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const delegations = useCosmosFamilyMappedDelegations(mainAccount, "claimReward"); const onSelect = useCallback( (validator: CosmosValidatorItem, value?: BigNumber | null) => { diff --git a/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/02-SelectMethod.tsx b/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/02-SelectMethod.tsx index cec34ca3f263..050460d709c8 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/02-SelectMethod.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/ClaimRewardsFlow/02-SelectMethod.tsx @@ -6,11 +6,7 @@ import { Trans } from "react-i18next"; import { useSelector } from "react-redux"; import type { CosmosAccount, Transaction } from "@ledgerhq/live-common/families/cosmos/types"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { - getAccountUnit, - getMainAccount, - getAccountCurrency, -} from "@ledgerhq/live-common/account/index"; +import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { useTheme } from "@react-navigation/native"; import cosmosBase from "@ledgerhq/live-common/families/cosmos/chain/cosmosBase"; @@ -27,6 +23,7 @@ import TranslatedError from "~/components/TranslatedError"; import ValidatorImage from "../shared/ValidatorImage"; import type { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { CosmosClaimRewardsFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const options = [ { @@ -62,7 +59,7 @@ function ClaimRewardsAmount({ navigation, route }: Props) { invariant(account && account.cosmosResources, "account and cosmos transaction required"); const bridge = getAccountBridge(account, undefined); const mainAccount = getMainAccount(account, undefined); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const currency = getAccountCurrency(mainAccount); const bridgeTransaction = useBridgeTransaction(() => { const tx = route.params.transaction; diff --git a/apps/ledger-live-mobile/src/families/cosmos/DelegationFlow/02-Summary.tsx b/apps/ledger-live-mobile/src/families/cosmos/DelegationFlow/02-Summary.tsx index 7af15e201ae9..11cdb715ff40 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/DelegationFlow/02-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/DelegationFlow/02-Summary.tsx @@ -1,8 +1,4 @@ -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -34,6 +30,7 @@ import ValidatorImage from "../shared/ValidatorImage"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { CosmosDelegationFlowParamList } from "./types"; import Config from "react-native-config"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps< CosmosDelegationFlowParamList, @@ -356,7 +353,7 @@ function SummaryWords({ onChangeValidator: () => void; onChangeAmount: () => void; }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, amount, { disableRounding: true, alwaysShowSign: false, @@ -388,7 +385,7 @@ function SummaryWords({ } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/cosmos/Delegations/index.tsx b/apps/ledger-live-mobile/src/families/cosmos/Delegations/index.tsx index d2690a290721..377a59b11a8b 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/Delegations/index.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/Delegations/index.tsx @@ -3,11 +3,7 @@ import React, { useCallback, useState, useMemo, useEffect } from "react"; import { View, StyleSheet, Linking } from "react-native"; import { useNavigation, useRoute, useTheme } from "@react-navigation/native"; import { useTranslation } from "react-i18next"; -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { getDefaultExplorerView, getAddressExplorer } from "@ledgerhq/live-common/explorers"; import { useCosmosFamilyMappedDelegations, @@ -60,6 +56,7 @@ import { getAccountBannerProps as getCosmosBannerProps } from "../utils"; import ValidatorImage from "../shared/ValidatorImage"; import { useCanShowStake } from "~/screens/Account/hooks/useCanShowStake"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: CosmosAccount; @@ -75,7 +72,7 @@ function Delegations({ account }: Props) { const delegations: CosmosMappedDelegation[] = useCosmosFamilyMappedDelegations(mainAccount); const currency = getAccountCurrency(mainAccount); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(account); const navigation = useNavigation(); const route = useRoute(); diff --git a/apps/ledger-live-mobile/src/families/cosmos/SendRowsFee.tsx b/apps/ledger-live-mobile/src/families/cosmos/SendRowsFee.tsx index b8159aaf56a4..a980ef9b64e1 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/SendRowsFee.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/SendRowsFee.tsx @@ -4,7 +4,7 @@ import type { Account, AccountLike } from "@ledgerhq/types-live"; import { Trans } from "react-i18next"; import type { Transaction } from "@ledgerhq/live-common/generated/types"; import type { Transaction as CosmosTransaction } from "@ledgerhq/live-common/families/cosmos/types"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { CompositeScreenProps, useTheme } from "@react-navigation/native"; import SummaryRow from "~/screens/SendFunds/SummaryRow"; import LText from "~/components/LText"; @@ -18,6 +18,7 @@ import type { SendFundsNavigatorStackParamList } from "~/components/RootNavigato import { ScreenName } from "~/const"; import type { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import type { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -36,7 +37,7 @@ export default function CosmosFeeRow({ account, transaction }: Props) { Linking.openURL(urls.feesMoreInfo); }, []); const fees = (transaction as CosmosTransaction).fees; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( @@ -55,7 +55,7 @@ function DelegationAmount({ navigation, route }: Props) { ); const bridge = getAccountBridge(account, undefined); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const initialValue = useMemo(() => route?.params?.value ?? BigNumber(0), [route]); const redelegatedBalance = route?.params?.redelegatedBalance ?? BigNumber(0); const mode = route?.params?.mode ?? "delegation"; diff --git a/apps/ledger-live-mobile/src/families/cosmos/shared/ValidatorRow.tsx b/apps/ledger-live-mobile/src/families/cosmos/shared/ValidatorRow.tsx index 86c79959de5f..9cc3c044e77a 100644 --- a/apps/ledger-live-mobile/src/families/cosmos/shared/ValidatorRow.tsx +++ b/apps/ledger-live-mobile/src/families/cosmos/shared/ValidatorRow.tsx @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { CosmosValidatorItem } from "@ledgerhq/live-common/families/cosmos/types"; import cosmosBase from "@ledgerhq/live-common/families/cosmos/chain/cosmosBase"; import { AccountLike } from "@ledgerhq/types-live"; @@ -9,6 +8,7 @@ import { StyleSheet, View } from "react-native"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import Touchable from "~/components/Touchable"; import ValidatorImage from "./ValidatorImage"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const ValidatorRow = ({ onPress, @@ -22,6 +22,7 @@ const ValidatorRow = ({ const onPressT = useCallback(() => { onPress(validator); }, [validator, onPress]); + const unit = useAccountUnit(account); return ( - + diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Drawer/hooks/useDrawerItems.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Drawer/hooks/useDrawerItems.tsx index 9764343e66c2..47c630f6d259 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Drawer/hooks/useDrawerItems.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Drawer/hooks/useDrawerItems.tsx @@ -1,7 +1,6 @@ import React, { useCallback, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { Linking } from "react-native"; import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers"; @@ -15,6 +14,7 @@ import Touchable from "~/components/Touchable"; import styles from "../styles"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the hook declaration. @@ -24,7 +24,7 @@ const useDrawerItems = (data: DrawerPropsType["data"], account: ElrondAccount) = const { type, validator, claimableRewards, seconds } = data; const { t } = useTranslation(); - const unit = useMemo(() => getAccountUnit(account), [account]); + const unit = useAccountUnit(account); const [isDelegation, isUndelegation] = useMemo( () => [type === "delegation", type === "undelegation"], [type], diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Rewards/Rewards.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Rewards/Rewards.tsx index 07a3e2f8dc67..0185ee6f1a43 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Rewards/Rewards.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Body/components/Rewards/Rewards.tsx @@ -2,11 +2,7 @@ import React, { useCallback, useMemo } from "react"; import { useNavigation } from "@react-navigation/native"; import { View } from "react-native"; import { useTranslation } from "react-i18next"; -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import BigNumber from "bignumber.js"; import type { StackNavigationProp } from "@react-navigation/stack"; @@ -21,6 +17,7 @@ import LText from "~/components/LText"; import { ScreenName, NavigatorName } from "~/const"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -30,7 +27,7 @@ const Rewards = (props: RewardsPropsType) => { const { account, delegations } = props; const { t } = useTranslation(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const navigation: StackNavigationProp = useNavigation(); const currency = getAccountCurrency(getMainAccount(account, undefined)); diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Details/Details.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Details/Details.tsx index e59af815263d..94521c5f7a33 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Details/Details.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Details/Details.tsx @@ -2,7 +2,6 @@ import React, { useCallback } from "react"; import { Linking, View } from "react-native"; import { useTranslation } from "react-i18next"; import { useElrondPreloadData } from "@ledgerhq/live-common/families/elrond/react"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { BigNumber } from "bignumber.js"; import { useSelector } from "react-redux"; @@ -14,6 +13,7 @@ import type { DetailsPropsType } from "./types"; import Section from "~/screens/OperationDetails/Section"; import { discreetModeSelector } from "~/reducers/settings"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -25,7 +25,7 @@ const Details = (props: DetailsPropsType) => { const discreet = useSelector(discreetModeSelector); const { locale } = useSettings(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { extra } = operation; const contract = operation && operation.contract ? operation.contract : ""; diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickMethod/PickMethod.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickMethod/PickMethod.tsx index ef9b6ec7204a..3ab03bb93487 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickMethod/PickMethod.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickMethod/PickMethod.tsx @@ -5,11 +5,7 @@ import { Trans } from "react-i18next"; import { BigNumber } from "bignumber.js"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus"; -import { - getAccountUnit, - getMainAccount, - getAccountCurrency, -} from "@ledgerhq/live-common/account/index"; +import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { MIN_DELEGATION_AMOUNT } from "@ledgerhq/live-common/families/elrond/constants"; @@ -31,6 +27,7 @@ import { ScreenName } from "~/const"; import { TransactionMethodEnum } from "./enums"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -47,7 +44,7 @@ const PickMethod = (props: PickMethodPropsType) => { const mainAccount = getMainAccount(account, undefined); const currency = getAccountCurrency(mainAccount); const bridge: AccountBridge = getAccountBridge(account); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const methods = [TransactionMethodEnum.claimRewards, TransactionMethodEnum.reDelegateRewards]; const currentDelegation = useMemo( diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickValidator/PickValidator.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickValidator/PickValidator.tsx index d9165836be72..06d7ffcb6498 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickValidator/PickValidator.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Claim/components/PickValidator/PickValidator.tsx @@ -2,7 +2,7 @@ import React, { useMemo, useCallback } from "react"; import { View, FlatList } from "react-native"; import { useTheme } from "@react-navigation/native"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getMainAccount, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import BigNumber from "bignumber.js"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; @@ -12,6 +12,7 @@ import Item from "./components/Item"; import type { onSelectType, PickValidatorPropsType } from "./types"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -24,7 +25,7 @@ const PickValidator = (props: PickValidatorPropsType) => { const mainAccount = getMainAccount(account, undefined); const bridge = getAccountBridge(account, undefined); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); /* * Initialize a new transaction on mount and set the mode to "claimRewards". diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickAmount/PickAmount.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickAmount/PickAmount.tsx index 9b2086bd3b22..a4973ad85398 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickAmount/PickAmount.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickAmount/PickAmount.tsx @@ -3,7 +3,6 @@ import { View, Keyboard, TouchableOpacity, TouchableWithoutFeedback, Platform } import { Trans } from "react-i18next"; import { BigNumber } from "bignumber.js"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { useTheme } from "styled-components/native"; @@ -23,6 +22,7 @@ import KeyboardView from "~/components/KeyboardView"; import styles from "./styles"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -33,7 +33,7 @@ const PickAmount = (props: PickAmountPropsType) => { const { navigation, route } = props; const { account, validators } = route.params; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { locale } = useSettings(); const bridge = getAccountBridge(account); const transaction = route.params.transaction as Transaction; diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickValidator/components/Item/Item.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickValidator/components/Item/Item.tsx index 7bb82aec5ed3..083730a44812 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickValidator/components/Item/Item.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/PickValidator/components/Item/Item.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { Text } from "@ledgerhq/native-ui"; import { useTheme } from "@react-navigation/native"; import { Trans } from "react-i18next"; @@ -16,6 +15,7 @@ import LedgerLogo from "~/icons/LiveLogo"; import type { ItemPropsType } from "./types"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -25,6 +25,7 @@ const Item = (props: ItemPropsType) => { const { colors } = useTheme(); const { onSelect, item, account } = props; const name = item.identity.name || item.contract; + const unit = useAccountUnit(account); /* * Return null in case the item has a setting of disabled. @@ -64,7 +65,7 @@ const Item = (props: ItemPropsType) => { diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/SetDelegation/SetDelegation.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/SetDelegation/SetDelegation.tsx index e43bebfccf1a..707f34d8aa64 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/SetDelegation/SetDelegation.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Delegate/components/SetDelegation/SetDelegation.tsx @@ -6,11 +6,7 @@ import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus"; import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { Text } from "@ledgerhq/native-ui"; import { Trans } from "react-i18next"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; @@ -34,6 +30,7 @@ import { rgba } from "../../../../../../../colors"; import type { SetDelegationPropsType } from "./types"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -48,7 +45,7 @@ const SetDelegation = (props: SetDelegationPropsType) => { const color = getCurrencyColor(currency); const bridge = getAccountBridge(account); const mainAccount = getMainAccount(account, undefined); - const unit = useMemo(() => getAccountUnit(account), [account]); + const unit = useAccountUnit(account); /* * Find the validator that'll be picked by default, which is the one from Ledger. diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Undelegate/components/PickAmount/PickAmount.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Undelegate/components/PickAmount/PickAmount.tsx index 87b9369c7dfb..85d2b065f35d 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Undelegate/components/PickAmount/PickAmount.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Undelegate/components/PickAmount/PickAmount.tsx @@ -4,7 +4,6 @@ import { Trans } from "react-i18next"; import { BigNumber } from "bignumber.js"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { useTheme } from "styled-components/native"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; @@ -22,6 +21,7 @@ import KeyboardView from "~/components/KeyboardView"; import styles from "./styles"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -32,7 +32,7 @@ const PickAmount = (props: PickAmountPropsType) => { const { navigation, route } = props; const { amount, account, validator } = route.params; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const bridge = getAccountBridge(account, undefined); const { locale } = useSettings(); diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Withdraw/components/WithdrawFunds/WithdrawFunds.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Withdraw/components/WithdrawFunds/WithdrawFunds.tsx index 478628f2d369..851d8207b1a4 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Flows/Withdraw/components/WithdrawFunds/WithdrawFunds.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Flows/Withdraw/components/WithdrawFunds/WithdrawFunds.tsx @@ -4,11 +4,7 @@ import { Trans } from "react-i18next"; import { useTheme } from "@react-navigation/native"; import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { - getAccountUnit, - getMainAccount, - getAccountCurrency, -} from "@ledgerhq/live-common/account/index"; +import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import Button from "~/components/Button"; @@ -22,6 +18,7 @@ import { ScreenName } from "~/const"; import type { WithdrawFundsPropsType } from "./types"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Handle the component declaration. @@ -35,7 +32,7 @@ const WithdrawFunds = (props: WithdrawFundsPropsType) => { const mainAccount = getMainAccount(account, undefined); const currency = getAccountCurrency(mainAccount); const bridge = getAccountBridge(account); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const name = validator.identity.name || validator.contract; /* diff --git a/apps/ledger-live-mobile/src/families/elrond/components/Summary/Summary.tsx b/apps/ledger-live-mobile/src/families/elrond/components/Summary/Summary.tsx index 77cb11df1c8d..731e33cdc814 100644 --- a/apps/ledger-live-mobile/src/families/elrond/components/Summary/Summary.tsx +++ b/apps/ledger-live-mobile/src/families/elrond/components/Summary/Summary.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useMemo, useEffect, useState, FC } from "react"; import { ScrollView } from "react-native"; import { useTranslation } from "react-i18next"; import { BigNumber } from "bignumber.js"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import type { ElrondAccount } from "@ledgerhq/live-common/families/elrond/types"; import type { DelegationType } from "../../types"; @@ -13,6 +12,7 @@ import InfoItem from "~/components/BalanceSummaryInfoItem"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import styles from "./styles"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; /* * Create a higher order component that will return null if balance is zero (thus unable to delegate). @@ -29,7 +29,7 @@ const Summary = (props: SummaryPropsType) => { const { t } = useTranslation(); const account = props.account as ElrondAccount; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); /* * Declare the data state (for the dynamic information modal) and the delegation resources state (tracking server updates). diff --git a/apps/ledger-live-mobile/src/families/near/AccountBalanceSummaryFooter.tsx b/apps/ledger-live-mobile/src/families/near/AccountBalanceSummaryFooter.tsx index 4906d59ffc15..cf90e1be0e0f 100644 --- a/apps/ledger-live-mobile/src/families/near/AccountBalanceSummaryFooter.tsx +++ b/apps/ledger-live-mobile/src/families/near/AccountBalanceSummaryFooter.tsx @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { getCryptoCurrencyById } from "@ledgerhq/live-common/currencies/index"; import { NearAccount } from "@ledgerhq/live-common/families/near/types"; import { getCryptoCurrencyIcon } from "@ledgerhq/live-common/reactNative"; @@ -8,6 +7,7 @@ import { TFunction, useTranslation } from "react-i18next"; import { ScrollView } from "react-native"; import InfoItem from "~/components/BalanceSummaryInfoItem"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; import type { ModalInfo } from "~/modals/Info"; import InfoModal from "~/modals/Info"; @@ -23,7 +23,7 @@ function AccountBalanceSummaryFooter({ account }: Props) { const { spendableBalance, nearResources } = account; const { storageUsageBalance, stakedBalance, pendingBalance, availableBalance } = nearResources || {}; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const onCloseModal = useCallback(() => { setInfoName(undefined); }, []); diff --git a/apps/ledger-live-mobile/src/families/near/StakingFlow/02-Summary.tsx b/apps/ledger-live-mobile/src/families/near/StakingFlow/02-Summary.tsx index daeec3afd37a..731d038d12d1 100644 --- a/apps/ledger-live-mobile/src/families/near/StakingFlow/02-Summary.tsx +++ b/apps/ledger-live-mobile/src/families/near/StakingFlow/02-Summary.tsx @@ -1,8 +1,4 @@ -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; @@ -36,6 +32,7 @@ import TranslatedError from "~/components/TranslatedError"; import { getFirstStatusError, hasStatusError } from "../../helpers"; import type { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { NearStakingFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -348,7 +345,7 @@ function SummaryWords({ onChangeValidator: () => void; onChangeAmount: () => void; }) { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, amount, { disableRounding: true, alwaysShowSign: false, @@ -377,7 +374,7 @@ function SummaryWords({ } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/near/operationDetails.tsx b/apps/ledger-live-mobile/src/families/near/operationDetails.tsx index 38e4a54c5998..f314bf8b4490 100644 --- a/apps/ledger-live-mobile/src/families/near/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/near/operationDetails.tsx @@ -3,11 +3,11 @@ import { useTranslation } from "react-i18next"; import type { Account, Operation } from "@ledgerhq/types-live"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { BigNumber } from "bignumber.js"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { useSelector } from "react-redux"; import Section from "~/screens/OperationDetails/Section"; import { discreetModeSelector } from "~/reducers/settings"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: Account; @@ -19,11 +19,11 @@ function OperationDetailsExtra({ account, operation }: Props) { const discreet = useSelector(discreetModeSelector); const { locale } = useSettings(); + const unit = useAccountUnit(account); if (operation.type !== "STAKE") { return null; } - const unit = getAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, new BigNumber(operation.value), { disableRounding: true, alwaysShowSign: false, diff --git a/apps/ledger-live-mobile/src/families/near/shared/02-SelectAmount.tsx b/apps/ledger-live-mobile/src/families/near/shared/02-SelectAmount.tsx index 9f5f34367205..282c999fd38a 100644 --- a/apps/ledger-live-mobile/src/families/near/shared/02-SelectAmount.tsx +++ b/apps/ledger-live-mobile/src/families/near/shared/02-SelectAmount.tsx @@ -14,7 +14,6 @@ import { useSelector } from "react-redux"; import { BigNumber } from "bignumber.js"; import type { NearAccount } from "@ledgerhq/live-common/families/near/types"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { useTheme } from "styled-components/native"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -31,6 +30,7 @@ import { NearStakingFlowParamList } from "../StakingFlow/types"; import { NearUnstakingFlowParamList } from "../UnstakingFlow/types"; import { NearWithdrawingFlowParamList } from "../WithdrawingFlow/types"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = | StackNavigatorProps @@ -47,7 +47,7 @@ function StakingAmount({ navigation, route }: Props) { "account and near transaction required", ); const bridge = getAccountBridge(account, undefined); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const initialValue = useMemo(() => route?.params?.value ?? new BigNumber(0), [route]); const [value, setValue] = useState(() => initialValue); const max = useMemo(() => route?.params?.max ?? new BigNumber(0), [route]); diff --git a/apps/ledger-live-mobile/src/families/near/shared/ValidatorRow.tsx b/apps/ledger-live-mobile/src/families/near/shared/ValidatorRow.tsx index b51341e3ada1..44ed2fef1d55 100644 --- a/apps/ledger-live-mobile/src/families/near/shared/ValidatorRow.tsx +++ b/apps/ledger-live-mobile/src/families/near/shared/ValidatorRow.tsx @@ -1,5 +1,4 @@ import { BigNumber } from "bignumber.js"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { NearValidatorItem } from "@ledgerhq/live-common/families/near/types"; import { FIGMENT_NEAR_VALIDATOR_ADDRESS } from "@ledgerhq/live-common/families/near/constants"; import { AccountLike } from "@ledgerhq/types-live"; @@ -10,6 +9,7 @@ import { StyleSheet, View } from "react-native"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import Touchable from "~/components/Touchable"; import ValidatorImage from "./ValidatorImage"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const ValidatorRow = ({ onPress, @@ -23,7 +23,7 @@ const ValidatorRow = ({ const onPressT = useCallback(() => { onPress(validator); }, [validator, onPress]); - + const unit = useAccountUnit(account); return ( - + diff --git a/apps/ledger-live-mobile/src/families/polkadot/AccountBalanceSummaryFooter.tsx b/apps/ledger-live-mobile/src/families/polkadot/AccountBalanceSummaryFooter.tsx index 66bbd7ec6a44..f224b7c69f00 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/AccountBalanceSummaryFooter.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/AccountBalanceSummaryFooter.tsx @@ -6,7 +6,6 @@ import BigNumber from "bignumber.js"; import { useTheme } from "@react-navigation/native"; import { usePolkadotPreloadData } from "@ledgerhq/live-common/families/polkadot/react"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { getCryptoCurrencyIcon } from "@ledgerhq/live-common/reactNative"; import { hasMinimumBondBalance } from "@ledgerhq/live-common/families/polkadot/logic"; import { PolkadotAccount } from "@ledgerhq/live-common/families/polkadot/types"; @@ -18,6 +17,7 @@ import BondedIcon from "~/icons/LinkIcon"; import UnbondingIcon from "~/icons/Clock"; import Unbonded from "~/icons/Undelegate"; import WarningIcon from "~/icons/Warning"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: PolkadotAccount; @@ -38,8 +38,7 @@ function AccountBalanceSummaryFooter({ account }: Props) { unlockingBalance: _unlockingBalance, unlockedBalance, } = polkadotResources || {}; - const unit = getAccountUnit(account); - + const unit = useAccountUnit(account); // NOTE: All balances are including the next one... // So we exclude each other for better understanding and ensure sum of all balances // is equal to the total balance. @@ -109,7 +108,7 @@ function useInfo(account: PolkadotAccount): Record { const { t } = useTranslation(); const preloaded = usePolkadotPreloadData(); const minimumBondBalance = new BigNumber(preloaded.minimumBondBalance); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const minimumBondBalanceStr = formatCurrencyUnit(unit, minimumBondBalance, { disableRounding: true, alwaysShowSign: false, diff --git a/apps/ledger-live-mobile/src/families/polkadot/BondFlow/02-Amount.tsx b/apps/ledger-live-mobile/src/families/polkadot/BondFlow/02-Amount.tsx index 362137eb4e0b..636e428c4779 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/BondFlow/02-Amount.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/BondFlow/02-Amount.tsx @@ -17,7 +17,7 @@ import invariant from "invariant"; import { useTheme } from "@react-navigation/native"; import type { Transaction as PolkadotTransaction } from "@ledgerhq/live-common/families/polkadot/types"; import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { isFirstBond } from "@ledgerhq/live-common/families/polkadot/logic"; import { PolkadotAccount } from "@ledgerhq/live-common/families/polkadot/types"; @@ -39,6 +39,7 @@ import FlowErrorBottomModal from "../components/FlowErrorBottomModal"; import SendRowsFee from "../SendRowsFee"; import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { PolkadotBondFlowParamList } from "./types"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; const options = [ { @@ -163,10 +164,10 @@ export default function PolkadotBondAmount({ navigation, route }: Props) { }, [bridge, transaction, setTransaction], ); - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); const rewardDestination = (transaction as { rewardDestination?: string }).rewardDestination || ""; const firstBond = isFirstBond(mainAccount); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); diff --git a/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/01-Validators.tsx b/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/01-Validators.tsx index 94fff54328c6..97da803cba85 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/01-Validators.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/01-Validators.tsx @@ -55,6 +55,7 @@ import type { PolkadotNominateFlowParamList } from "./types"; import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator"; import FirstLetterIcon from "~/components/FirstLetterIcon"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -116,7 +117,9 @@ function NominateSelectValidator({ navigation, route }: Props) { const { staking, validators: polkadotValidators } = preloaded; const minimumBondBalance = BigNumber(preloaded.minimumBondBalance); const hasMinBondBalance = hasMinimumBondBalance(mainAccount); - const minBondBalance = formatCurrencyUnit(mainAccount.unit, minimumBondBalance, { + const unit = useAccountUnit(mainAccount); + + const minBondBalance = formatCurrencyUnit(unit, minimumBondBalance, { disableRounding: true, alwaysShowSign: false, showCode: true, @@ -218,9 +221,10 @@ function NominateSelectValidator({ navigation, route }: Props) { onOpenExplorer, maxNominatorRewardedPerValidator, validator: drawerValidator, + unit, }) : [], - [drawerValidator, t, account, maxNominatorRewardedPerValidator, onOpenExplorer], + [drawerValidator, t, account, onOpenExplorer, maxNominatorRewardedPerValidator, unit], ); const renderItem: SectionListRenderItem = useCallback( ({ item }) => { diff --git a/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/drawerInfo.tsx b/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/drawerInfo.tsx index 17e20aff6ac9..2f52f176c9a7 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/drawerInfo.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/NominateFlow/drawerInfo.tsx @@ -1,6 +1,6 @@ import React from "react"; import { View, StyleSheet } from "react-native"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useTheme } from "@react-navigation/native"; import type { TFunction } from "i18next"; import type { AccountLike } from "@ledgerhq/types-live"; @@ -12,6 +12,7 @@ import CounterValue from "~/components/CounterValue"; import ExternalLink from "~/icons/ExternalLink"; import NominationDrawer from "../components/NominationDrawer"; import { Unpacked } from "~/types/helpers"; +import { Unit } from "@ledgerhq/types-cryptoassets"; type NominationDrawerData = React.ComponentProps["data"]; type NominationDrawerDatum = Unpacked; @@ -22,6 +23,7 @@ type Props = { validator: PolkadotValidator; maxNominatorRewardedPerValidator: number; onOpenExplorer: (address: string) => void; + unit: Unit; }; export function getDrawerInfo({ @@ -30,9 +32,10 @@ export function getDrawerInfo({ validator, maxNominatorRewardedPerValidator, onOpenExplorer, + unit, }: Props): NominationDrawerData { const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); + const totalStake = validator.totalBonded; const formattedCommission = validator.commission ? `${validator.commission.multipliedBy(100).toFixed(2)} %` diff --git a/apps/ledger-live-mobile/src/families/polkadot/Nominations/NominationRow.tsx b/apps/ledger-live-mobile/src/families/polkadot/Nominations/NominationRow.tsx index 17280ba05fe5..4635808d7a95 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/Nominations/NominationRow.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/Nominations/NominationRow.tsx @@ -7,7 +7,7 @@ import { PolkadotValidator, } from "@ledgerhq/live-common/families/polkadot/types"; import { Account } from "@ledgerhq/types-live"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useTheme } from "styled-components/native"; import { Flex, Text } from "@ledgerhq/native-ui"; @@ -16,6 +16,7 @@ import CounterValue from "~/components/CounterValue"; import LText from "~/components/LText"; import ArrowRight from "~/icons/ArrowRight"; import FirstLetterIcon from "~/components/FirstLetterIcon"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { nomination: PolkadotNomination; @@ -34,7 +35,7 @@ export default function NominationRow({ nomination, validator, account, onPress // const total = validator?.totalBonded ?? null; // const commission = validator?.commission ?? null; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/families/polkadot/Nominations/UnlockingRow.tsx b/apps/ledger-live-mobile/src/families/polkadot/Nominations/UnlockingRow.tsx index 962270fc83f4..8767fc9cb399 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/Nominations/UnlockingRow.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/Nominations/UnlockingRow.tsx @@ -3,13 +3,14 @@ import isBefore from "date-fns/isBefore"; import React, { useMemo } from "react"; import { View, StyleSheet } from "react-native"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useTheme } from "@react-navigation/native"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import CounterValue from "~/components/CounterValue"; import LText from "~/components/LText"; import DateFromNow from "~/components/DateFromNow"; import { WithdrawAction } from "./Actions"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { amount: BigNumber; @@ -28,7 +29,7 @@ export default function UnlockingRow({ isLast = false, }: Props) { const { colors } = useTheme(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); const isUnlocked = useMemo( () => completionDate && isBefore(completionDate, new Date(Date.now())), diff --git a/apps/ledger-live-mobile/src/families/polkadot/Nominations/drawerInfo.tsx b/apps/ledger-live-mobile/src/families/polkadot/Nominations/drawerInfo.tsx index c25e6c198b48..d3a7f896dd92 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/Nominations/drawerInfo.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/Nominations/drawerInfo.tsx @@ -1,6 +1,6 @@ import React from "react"; import { View, StyleSheet } from "react-native"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useTheme } from "@react-navigation/native"; import { TFunction } from "i18next"; import { Account } from "@ledgerhq/types-live"; @@ -14,6 +14,7 @@ import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import CounterValue from "~/components/CounterValue"; import ExternalLink from "~/icons/ExternalLink"; import NominationDrawer from "../components/NominationDrawer"; +import { Unit } from "@ledgerhq/types-cryptoassets"; type NominationDrawerData = React.ComponentProps["data"]; @@ -23,6 +24,7 @@ type Props = { validator?: PolkadotValidator; nomination: PolkadotNomination; onOpenExplorer: (address: string) => void; + unit: Unit; }; export function getDrawerInfo({ @@ -31,9 +33,9 @@ export function getDrawerInfo({ nomination, validator, onOpenExplorer, + unit, }: Props): NominationDrawerData { const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); const amount = nomination.value; const totalStake = validator?.totalBonded; const formattedCommission = validator?.commission diff --git a/apps/ledger-live-mobile/src/families/polkadot/Nominations/index.tsx b/apps/ledger-live-mobile/src/families/polkadot/Nominations/index.tsx index fcda7d91e771..6643927ac72d 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/Nominations/index.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/Nominations/index.tsx @@ -45,6 +45,7 @@ import Illustration from "~/images/illustration/Illustration"; import EarnLight from "~/images/illustration/Light/_003.png"; import EarnDark from "~/images/illustration/Dark/_003.png"; import FirstLetterIcon from "~/components/FirstLetterIcon"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -66,6 +67,8 @@ export default function Nominations(props: Props) { const { polkadotResources } = mainAccount; + const unit = useAccountUnit(account); + const { lockedBalance, unlockedBalance, nominations, unlockings } = polkadotResources || {}; const [nomination, setNomination] = useState(); @@ -207,9 +210,10 @@ export default function Nominations(props: Props) { onOpenExplorer, nomination: mappedNomination?.nomination, validator: mappedNomination?.validator, + unit, }) : [], - [mappedNomination, t, account, onOpenExplorer], + [mappedNomination, t, account, onOpenExplorer, unit], ); const electionOpen = staking?.electionClosed !== undefined ? !staking?.electionClosed : false; diff --git a/apps/ledger-live-mobile/src/families/polkadot/RebondFlow/01-Amount.tsx b/apps/ledger-live-mobile/src/families/polkadot/RebondFlow/01-Amount.tsx index 690e76e728f9..aca2322df0f8 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/RebondFlow/01-Amount.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/RebondFlow/01-Amount.tsx @@ -15,7 +15,7 @@ import { Trans } from "react-i18next"; import { useTheme } from "@react-navigation/native"; import type { Transaction as PolkadotTransaction } from "@ledgerhq/live-common/families/polkadot/types"; import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { StackScreenProps } from "@react-navigation/stack"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -32,6 +32,7 @@ import FlowErrorBottomModal from "../components/FlowErrorBottomModal"; import SendRowsFee from "../SendRowsFee"; import { BaseComposite } from "~/components/RootNavigator/types/helpers"; import { PolkadotRebondFlowParamList } from "./type"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type NavigationProps = BaseComposite< StackScreenProps @@ -105,10 +106,12 @@ export default function PolkadotRebondAmount({ navigation, route }: NavigationPr }); }, [account, navigation, transaction, status]); const blur = useCallback(() => Keyboard.dismiss(), []); - if (!account || !transaction) return null; + + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); + const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); const hasErrors = hasStatusError(status); diff --git a/apps/ledger-live-mobile/src/families/polkadot/SendRowsFee.tsx b/apps/ledger-live-mobile/src/families/polkadot/SendRowsFee.tsx index 30d0856829aa..59e4ec1c24c2 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/SendRowsFee.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/SendRowsFee.tsx @@ -4,7 +4,7 @@ import type { Account, AccountLike } from "@ledgerhq/types-live"; import type { Transaction } from "@ledgerhq/live-common/generated/types"; import type { Transaction as PolkadotTransaction } from "@ledgerhq/live-common/families/polkadot/types"; import { Trans } from "react-i18next"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { CompositeScreenProps, useTheme } from "@react-navigation/native"; import SummaryRow from "~/screens/SendFunds/SummaryRow"; import LText from "~/components/LText"; @@ -19,6 +19,7 @@ import { ScreenName } from "~/const"; import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; import { PolkadotBondFlowParamList } from "./BondFlow/types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Navigation = CompositeScreenProps< | StackNavigatorProps @@ -44,7 +45,7 @@ export default function PolkadotFeeRow({ account, transaction }: Props) { const fees = (transaction as PolkadotTransaction).fees ? (transaction as PolkadotTransaction).fees : null; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( ; @@ -102,10 +103,10 @@ export default function PolkadotUnbondAmount({ navigation, route }: Props) { }); }, [account, navigation, transaction, status]); const blur = useCallback(() => Keyboard.dismiss(), []); - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : getFirstStatusError(status, "errors"); const warning = getFirstStatusError(status, "warnings"); const hasErrors = hasStatusError(status); diff --git a/apps/ledger-live-mobile/src/families/polkadot/operationDetails.tsx b/apps/ledger-live-mobile/src/families/polkadot/operationDetails.tsx index 1004a8a531c9..39fc2349c9a1 100644 --- a/apps/ledger-live-mobile/src/families/polkadot/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/polkadot/operationDetails.tsx @@ -34,6 +34,7 @@ import OperationStatusWrapper from "~/icons/OperationStatusIcon/Wrapper"; import NominationInfo from "./components/NominationInfo"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; function getURLWhatIsThis(op: PolkadotOperation): string | undefined { if (op.type !== "IN" && op.type !== "OUT") { @@ -59,11 +60,12 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt const discreet = useSelector(discreetModeSelector); const { locale } = useSettings(); const { extra } = operation; + const unit = useAccountUnit(account); switch (type) { case "OUT": case "IN": { - const value = formatCurrencyUnit(account.unit, extra.transferAmount ?? new BigNumber(0), { + const value = formatCurrencyUnit(unit, extra.transferAmount ?? new BigNumber(0), { showCode: true, discreet, disableRounding: true, @@ -88,7 +90,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt ); } case "BOND": { - const value = formatCurrencyUnit(account.unit, extra.bondedAmount ?? new BigNumber(0), { + const value = formatCurrencyUnit(unit, extra.bondedAmount ?? new BigNumber(0), { showCode: true, discreet, disableRounding: true, @@ -102,7 +104,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt ); } case "UNBOND": { - const value = formatCurrencyUnit(account.unit, extra.unbondedAmount ?? new BigNumber(0), { + const value = formatCurrencyUnit(unit, extra.unbondedAmount ?? new BigNumber(0), { showCode: true, discreet, disableRounding: true, @@ -116,16 +118,12 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt ); } case "WITHDRAW_UNBONDED": { - const value = formatCurrencyUnit( - account.unit, - extra.withdrawUnbondedAmount ?? new BigNumber(0), - { - showCode: true, - discreet, - disableRounding: true, - locale: locale, - }, - ); + const value = formatCurrencyUnit(unit, extra.withdrawUnbondedAmount ?? new BigNumber(0), { + showCode: true, + discreet, + disableRounding: true, + locale: locale, + }); return ( <> diff --git a/apps/ledger-live-mobile/src/families/ripple/RippleFeeRow.tsx b/apps/ledger-live-mobile/src/families/ripple/RippleFeeRow.tsx index c1ea360a1163..68be5655f60d 100644 --- a/apps/ledger-live-mobile/src/families/ripple/RippleFeeRow.tsx +++ b/apps/ledger-live-mobile/src/families/ripple/RippleFeeRow.tsx @@ -26,6 +26,7 @@ import type { import type { SendFundsNavigatorStackParamList } from "~/components/RootNavigator/types/SendFundsNavigator"; import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Navigation = CompositeNavigationProp< StackNavigatorNavigation, @@ -59,7 +60,9 @@ export default function RippleFeeRow({ account, transaction, parentAccount }: Pr const extraInfoFees = useCallback(() => { Linking.openURL(urls.feesMoreInfo); }, []); - if (account.type !== "Account") return null; + + const unit = useMaybeAccountUnit(account); + if (account.type !== "Account" || !unit) return null; const fee = (transaction as RippleTransaction).fee; const feeCustomUnit = (transaction as RippleTransaction).feeCustomUnit; return ( @@ -80,7 +83,7 @@ export default function RippleFeeRow({ account, transaction, parentAccount }: Pr {fee ? ( - + ) : null} diff --git a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectAmount.tsx b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectAmount.tsx index 95bb13715c12..142d3d44a3bb 100644 --- a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectAmount.tsx +++ b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectAmount.tsx @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; @@ -37,6 +36,7 @@ import QueuedDrawer from "~/components/QueuedDrawer"; import { GenericInformationBody } from "~/components/GenericInformationBody"; import { ExternalLinkMedium, InformationFill } from "@ledgerhq/native-ui/assets/icons"; import { urls } from "~/utils/urls"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; @@ -122,7 +122,7 @@ export default function DelegationSelectAmount({ navigation, route }: Props) { const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); const onMaxSpendableLearnMore = useCallback(() => Linking.openURL(urls.maxSpendable), []); diff --git a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectValidator.tsx b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectValidator.tsx index d0f487a4b902..493c2579225d 100644 --- a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectValidator.tsx +++ b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/SelectValidator.tsx @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { useValidators } from "@ledgerhq/live-common/families/solana/react"; import { ValidatorsAppValidator } from "@ledgerhq/live-common/families/solana/validator-app/index"; import { AccountLike } from "@ledgerhq/types-live"; @@ -19,6 +18,7 @@ import ValidatorImage from "../shared/ValidatorImage"; import SelectValidatorSearchBox from "../../tron/VoteFlow/01-SelectValidator/SearchBox"; import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { SolanaDelegationFlowParamList } from "./types"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = BaseComposite< StackNavigatorProps @@ -182,7 +182,7 @@ const ValidatorRow = ({ const onPressT = useCallback(() => { onPress(validator); }, [validator, onPress]); - + const unit = useAccountUnit(account); return ( - + diff --git a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/Summary.tsx b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/Summary.tsx index b05f89b366d2..41dd28164dc2 100644 --- a/apps/ledger-live-mobile/src/families/solana/DelegationFlow/Summary.tsx +++ b/apps/ledger-live-mobile/src/families/solana/DelegationFlow/Summary.tsx @@ -1,4 +1,4 @@ -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { formatCurrencyUnit, getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; import { useValidators } from "@ledgerhq/live-common/families/solana/react"; @@ -34,6 +34,7 @@ import ValidatorImage from "../shared/ValidatorImage"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { DelegationAction, SolanaDelegationFlowParamList } from "./types"; import TranslatedError from "../../../components/TranslatedError"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; @@ -440,7 +441,7 @@ function SummaryWords({ const i18nActionKey = delegationAction.kind === "new" ? "iDelegate" : `i${capitalize(delegationAction.stakeAction)}`; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formattedAmount = formatCurrencyUnit(unit, new BigNumber(amount), { disableRounding: true, alwaysShowSign: false, @@ -481,7 +482,7 @@ function SummaryWords({ } const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/solana/Delegations/index.tsx b/apps/ledger-live-mobile/src/families/solana/Delegations/index.tsx index acd97d4b53bf..046ba14f18d8 100644 --- a/apps/ledger-live-mobile/src/families/solana/Delegations/index.tsx +++ b/apps/ledger-live-mobile/src/families/solana/Delegations/index.tsx @@ -1,8 +1,4 @@ -import { - getAccountCurrency, - getAccountUnit, - getMainAccount, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers"; import { stakeActions, stakeActivePercent } from "@ledgerhq/live-common/families/solana/logic"; @@ -42,6 +38,7 @@ import UndelegateIcon from "~/icons/Undelegate"; import ValidatorImage from "../shared/ValidatorImage"; import DelegationLabelRight from "./LabelRight"; import DelegationRow from "./Row"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: SolanaAccount; @@ -63,7 +60,7 @@ function Delegations({ account }: Props) { mainAccount.solanaResources?.stakes ?? [], ); - const unit = getAccountUnit(mainAccount); + const unit = useAccountUnit(mainAccount); const navigation = useNavigation(); const [selectedStakeWithMeta, setSelectedStakeWithMeta] = useState< diff --git a/apps/ledger-live-mobile/src/families/solana/SendRowsFee.tsx b/apps/ledger-live-mobile/src/families/solana/SendRowsFee.tsx index 8813a5f38657..9f4c1761c474 100644 --- a/apps/ledger-live-mobile/src/families/solana/SendRowsFee.tsx +++ b/apps/ledger-live-mobile/src/families/solana/SendRowsFee.tsx @@ -1,4 +1,4 @@ -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; import { TransactionStatus as SolanaTransactionStatus } from "@ledgerhq/live-common/families/solana/types"; import { Account, AccountLike } from "@ledgerhq/types-live"; @@ -18,6 +18,7 @@ import type { SendFundsNavigatorStackParamList } from "~/components/RootNavigato import { ScreenName } from "~/const"; import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -39,7 +40,7 @@ export default function SolanaFeeRow({ account, status }: Props) { const fees = (status as SolanaTransactionStatus).estimatedFees; - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/families/solana/operationDetails.tsx b/apps/ledger-live-mobile/src/families/solana/operationDetails.tsx index 4648b13e597b..88d9c9e96706 100644 --- a/apps/ledger-live-mobile/src/families/solana/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/solana/operationDetails.tsx @@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next"; import { BigNumber } from "bignumber.js"; import { OperationType } from "@ledgerhq/types-live"; import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { CryptoCurrency, Unit } from "@ledgerhq/types-cryptoassets"; import { useSolanaPreloadData } from "@ledgerhq/live-common/families/solana/react"; @@ -13,6 +12,7 @@ import { SolanaAccount, SolanaOperation } from "@ledgerhq/live-common/families/s import Section from "~/screens/OperationDetails/Section"; import { discreetModeSelector } from "~/reducers/settings"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; export const openAddressUrl = (currency: CryptoCurrency, address: string) => () => { const url = getAddressExplorer(getDefaultExplorerView(currency), address); @@ -45,7 +45,7 @@ type WithdrawExtraFieldsProps = { const WithdrawExtraFields = ({ account, fromAddress, amount }: WithdrawExtraFieldsProps) => { const { t } = useTranslation(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formatAmount = useFormatAmount(); return ( @@ -67,7 +67,7 @@ type DelegateExtraFieldsProps = { const DelegateExtraFields = ({ account, voteAddress, amount }: DelegateExtraFieldsProps) => { const { t } = useTranslation(); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const formatAmount = useFormatAmount(); const preloadData = useSolanaPreloadData(account.currency); const validator = preloadData?.validators.find(v => v.voteAccount === voteAddress); diff --git a/apps/ledger-live-mobile/src/families/stellar/ScreenEditCustomFees.tsx b/apps/ledger-live-mobile/src/families/stellar/ScreenEditCustomFees.tsx index e07e4b5dca70..a5bbf7cdc5a0 100644 --- a/apps/ledger-live-mobile/src/families/stellar/ScreenEditCustomFees.tsx +++ b/apps/ledger-live-mobile/src/families/stellar/ScreenEditCustomFees.tsx @@ -17,6 +17,7 @@ import { SendFundsNavigatorStackParamList } from "~/components/RootNavigator/typ import { ScreenName } from "~/const"; import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const options = { title: , @@ -40,6 +41,8 @@ function StellarEditCustomFees({ navigation, route }: NavigationProps) { const { networkCongestionLevel } = transaction?.networkInfo || {}; const [customFee, setCustomFee] = useState(transaction.fees); + const unit = useAccountUnit(mainAccount); + const onChange = (fee: BigNumber) => { setCustomFee(fee); }; @@ -75,11 +78,11 @@ function StellarEditCustomFees({ navigation, route }: NavigationProps) { editable isActive onChange={onChange} - unit={mainAccount.unit} + unit={unit} value={customFee} renderRight={ - {mainAccount.unit.code} + {unit.code} } /> diff --git a/apps/ledger-live-mobile/src/families/stellar/StellarFeeRow.tsx b/apps/ledger-live-mobile/src/families/stellar/StellarFeeRow.tsx index 1f66e7e6a17e..4a8086b82d7d 100644 --- a/apps/ledger-live-mobile/src/families/stellar/StellarFeeRow.tsx +++ b/apps/ledger-live-mobile/src/families/stellar/StellarFeeRow.tsx @@ -21,6 +21,7 @@ import type { StackNavigatorProps } from "~/components/RootNavigator/types/helpe import type { SendFundsNavigatorStackParamList } from "~/components/RootNavigator/types/SendFundsNavigator"; import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -46,12 +47,14 @@ export default function StellarFeeRow({ const extraInfoFees = useCallback(() => { Linking.openURL(urls.feesMoreInfo); }, []); - if (transaction.family !== "stellar") return null; + const mainAccount = getMainAccount(account, parentAccount); + const unit = useMaybeAccountUnit(mainAccount); + if (transaction.family !== "stellar" || !unit) return null; const bridge = getAccountBridge(account, parentAccount); const suggestedFee = transaction.networkInfo?.fees; const fees = transaction.fees; const isCustomFee = fees && suggestedFee ? !fees.eq(suggestedFee) : false; - const mainAccount = getMainAccount(account, parentAccount); + const currency = getAccountCurrency(account); const onFeeModeChange = (isCustom: boolean) => { @@ -102,7 +105,7 @@ export default function StellarFeeRow({ {fee ? ( - + ) : null} diff --git a/apps/ledger-live-mobile/src/families/tezos/AccountBodyHeader.tsx b/apps/ledger-live-mobile/src/families/tezos/AccountBodyHeader.tsx index 9e697224e280..788ba5583d05 100644 --- a/apps/ledger-live-mobile/src/families/tezos/AccountBodyHeader.tsx +++ b/apps/ledger-live-mobile/src/families/tezos/AccountBodyHeader.tsx @@ -3,11 +3,7 @@ import { Trans } from "react-i18next"; import { differenceInCalendarDays } from "date-fns"; import { StyleSheet, Platform, View } from "react-native"; import { AccountLike, Account } from "@ledgerhq/types-live"; -import { - shortAddressPreview, - getAccountCurrency, - getAccountUnit, -} from "@ledgerhq/live-common/account/index"; +import { shortAddressPreview, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers"; import { Flex, Text } from "@ledgerhq/native-ui"; import LText from "~/components/LText"; @@ -16,6 +12,7 @@ import CounterValue from "~/components/CounterValue"; import DelegationDetailsModal from "./DelegationDetailsModal"; import BakerImage from "./BakerImage"; import Button from "~/components/wrappedUi/Button"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const styles = StyleSheet.create({ root: { @@ -102,6 +99,8 @@ export default function TezosAccountBodyHeader({ const delegation = useDelegation(account); + const unit = useAccountUnit(account); + if (!delegation) { return null; } @@ -109,7 +108,6 @@ export default function TezosAccountBodyHeader({ const name = delegation.baker ? delegation.baker.name : shortAddressPreview(delegation.address); const amount = account.balance; const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); const days = differenceInCalendarDays(Date.now(), delegation.operation.date); return ( diff --git a/apps/ledger-live-mobile/src/families/tezos/DelegationDetailsModal.tsx b/apps/ledger-live-mobile/src/families/tezos/DelegationDetailsModal.tsx index 39d55c4f0e49..b9569c6d1d42 100644 --- a/apps/ledger-live-mobile/src/families/tezos/DelegationDetailsModal.tsx +++ b/apps/ledger-live-mobile/src/families/tezos/DelegationDetailsModal.tsx @@ -10,11 +10,7 @@ import { } from "@ledgerhq/live-common/explorers"; import type { AccountLike, Account } from "@ledgerhq/types-live"; import type { Delegation } from "@ledgerhq/live-common/families/tezos/types"; -import { - getMainAccount, - getAccountCurrency, - getAccountUnit, -} from "@ledgerhq/live-common/account/index"; +import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; import Icon from "react-native-vector-icons/Feather"; import getWindowDimensions from "~/logic/getWindowDimensions"; @@ -32,6 +28,7 @@ import { NavigatorName, ScreenName } from "~/const"; import BakerImage from "./BakerImage"; import DelegatingContainer from "./DelegatingContainer"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { isOpened: boolean; @@ -153,7 +150,7 @@ export default function DelegationDetailsModal({ const { colors } = useTheme(); const navigation = useNavigation(); const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const mainAccount = getMainAccount(account, parentAccount); const { baker } = delegation; const amount = account.balance; diff --git a/apps/ledger-live-mobile/src/families/tezos/DelegationFlow/Summary.tsx b/apps/ledger-live-mobile/src/families/tezos/DelegationFlow/Summary.tsx index 04fe9587727a..a9c62061c955 100644 --- a/apps/ledger-live-mobile/src/families/tezos/DelegationFlow/Summary.tsx +++ b/apps/ledger-live-mobile/src/families/tezos/DelegationFlow/Summary.tsx @@ -6,11 +6,7 @@ import { Trans, useTranslation } from "react-i18next"; import invariant from "invariant"; import Icon from "react-native-vector-icons/Feather"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; -import { - getAccountCurrency, - getAccountUnit, - shortAddressPreview, -} from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency, shortAddressPreview } from "@ledgerhq/live-common/account/index"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; import type { Transaction as TezosTransaction } from "@ledgerhq/live-common/families/tezos/types"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; @@ -35,11 +31,12 @@ import BakerImage from "../BakerImage"; import type { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import type { TezosDelegationFlowParamList } from "./types"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; const AccountBalanceTag = ({ account }: { account: AccountLike }) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { colors } = useTheme(); return ( diff --git a/apps/ledger-live-mobile/src/families/tezos/TezosFeeRow.tsx b/apps/ledger-live-mobile/src/families/tezos/TezosFeeRow.tsx index fae8a965a936..f05949ef105a 100644 --- a/apps/ledger-live-mobile/src/families/tezos/TezosFeeRow.tsx +++ b/apps/ledger-live-mobile/src/families/tezos/TezosFeeRow.tsx @@ -3,7 +3,7 @@ import { View, StyleSheet, Linking } from "react-native"; import type { Account, AccountLike } from "@ledgerhq/types-live"; import { Trans } from "react-i18next"; import type { Transaction } from "@ledgerhq/live-common/generated/types"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { useTheme } from "@react-navigation/native"; import SummaryRow from "~/screens/SendFunds/SummaryRow"; import LText from "~/components/LText"; @@ -11,6 +11,7 @@ import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import CounterValue from "~/components/CounterValue"; import ExternalLink from "~/icons/ExternalLink"; import { urls } from "~/utils/urls"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -22,9 +23,12 @@ export default function TezosFeeRow({ account, transaction }: Props) { const extraInfoFees = useCallback(() => { Linking.openURL(urls.feesMoreInfo); }, []); + + const unit = useAccountUnit(account); + if (transaction.family !== "tezos") return null; const fees = transaction.fees; - const unit = getAccountUnit(account); + const currency = getAccountCurrency(account); return ( freeLimit.plus(gainedLimit).minus(gainedUsed).minus(freeUsed), [freeLimit, gainedLimit, gainedUsed, freeUsed], diff --git a/apps/ledger-live-mobile/src/families/tron/Votes/index.tsx b/apps/ledger-live-mobile/src/families/tron/Votes/index.tsx index 71b578e4299f..8923a7d19f05 100644 --- a/apps/ledger-live-mobile/src/families/tron/Votes/index.tsx +++ b/apps/ledger-live-mobile/src/families/tron/Votes/index.tsx @@ -3,7 +3,7 @@ import { View, TouchableOpacity, StyleSheet } from "react-native"; import { ParamListBase, useNavigation, useTheme } from "@react-navigation/native"; import { Trans, useTranslation } from "react-i18next"; import { BigNumber } from "bignumber.js"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import { useTronSuperRepresentatives, formatVotes, @@ -29,6 +29,7 @@ import AccountSectionLabel from "~/components/AccountSectionLabel"; import { useManifest } from "@ledgerhq/live-common/platform/hooks/useManifest"; import { StackNavigationProp } from "@react-navigation/stack"; import { ScreenName } from "../../../const"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: TronAccount; @@ -45,7 +46,7 @@ const Delegation = ({ account }: Props) => { const lastDate = lastVotedDate ? : null; const currency = getAccountCurrency(account); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const explorerView = getDefaultExplorerView(account.currency); const { spendableBalance, tronResources } = account; diff --git a/apps/ledger-live-mobile/src/families/tron/operationDetails.tsx b/apps/ledger-live-mobile/src/families/tron/operationDetails.tsx index 7dcaab4935e9..a3a311780208 100644 --- a/apps/ledger-live-mobile/src/families/tron/operationDetails.tsx +++ b/apps/ledger-live-mobile/src/families/tron/operationDetails.tsx @@ -19,6 +19,7 @@ import DelegationInfo from "~/components/DelegationInfo"; import Section from "~/screens/OperationDetails/Section"; import { discreetModeSelector } from "~/reducers/settings"; import { useSettings } from "~/hooks"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const helpURL = "https://support.ledger.com/hc/en-us/articles/360013062139"; @@ -47,7 +48,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt const { extra: { votes, frozenAmount, unfreezeAmount, unDelegatedAmount, receiverAddress }, } = operation; - + const unit = useAccountUnit(account); switch (type) { case "VOTE": { if (!votes || !votes.length) return null; @@ -55,7 +56,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt } case "FREEZE": { - const value = formatCurrencyUnit(account.unit, frozenAmount || new BigNumber(0), { + const value = formatCurrencyUnit(unit, frozenAmount || new BigNumber(0), { showCode: true, discreet, locale: locale, @@ -64,7 +65,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt } case "UNFREEZE": { - const value = formatCurrencyUnit(account.unit, unfreezeAmount || new BigNumber(0), { + const value = formatCurrencyUnit(unit, unfreezeAmount || new BigNumber(0), { showCode: true, discreet, locale: locale, @@ -73,7 +74,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt } case "UNDELEGATE_RESOURCE": { - const value = formatCurrencyUnit(account.unit, unDelegatedAmount || new BigNumber(0), { + const value = formatCurrencyUnit(unit, unDelegatedAmount || new BigNumber(0), { showCode: true, discreet, locale, @@ -87,7 +88,7 @@ function OperationDetailsExtra({ operation, type, account }: OperationDetailsExt } case "LEGACY_UNFREEZE": { - const value = formatCurrencyUnit(account.unit, unfreezeAmount || new BigNumber(0), { + const value = formatCurrencyUnit(unit, unfreezeAmount || new BigNumber(0), { showCode: true, discreet, locale, diff --git a/apps/ledger-live-mobile/src/helpers/CurrencySettingsDefaults.ts b/apps/ledger-live-mobile/src/helpers/CurrencySettingsDefaults.ts index 1eb22d8e1f74..92fd35f56855 100644 --- a/apps/ledger-live-mobile/src/helpers/CurrencySettingsDefaults.ts +++ b/apps/ledger-live-mobile/src/helpers/CurrencySettingsDefaults.ts @@ -1,7 +1,7 @@ import type { Currency } from "@ledgerhq/types-cryptoassets"; -import type { ConfirmationDefaults } from "../types/common"; +import type { ConfirmationDefaults, UnitDefaults } from "../types/common"; -export const currencySettingsDefaults = (c: Currency): ConfirmationDefaults => { +export const currencySettingsDefaults = (c: Currency): ConfirmationDefaults & UnitDefaults => { let confirmationsNb; if (c.type === "CryptoCurrency") { @@ -20,5 +20,6 @@ export const currencySettingsDefaults = (c: Currency): ConfirmationDefaults => { return { confirmationsNb, + unit: c.units[0], }; }; diff --git a/apps/ledger-live-mobile/src/hooks/useAccountUnit.ts b/apps/ledger-live-mobile/src/hooks/useAccountUnit.ts new file mode 100644 index 000000000000..bf1567e4e3b9 --- /dev/null +++ b/apps/ledger-live-mobile/src/hooks/useAccountUnit.ts @@ -0,0 +1,16 @@ +import { useSelector } from "react-redux"; +import { accountUnitSelector } from "../reducers/settings"; +import { AccountLike } from "@ledgerhq/types-live"; +import { State } from "~/reducers/types"; + +export function useAccountUnit(account: AccountLike) { + const unit = useSelector((state: State) => accountUnitSelector(state, account)); + return unit; +} + +export function useMaybeAccountUnit(account?: AccountLike | null) { + const unit = useSelector((state: State) => + account ? accountUnitSelector(state, account) : undefined, + ); + return unit; +} diff --git a/apps/ledger-live-mobile/src/reducers/settings.ts b/apps/ledger-live-mobile/src/reducers/settings.ts index 0e69ddf521fd..6696570ab2f7 100644 --- a/apps/ledger-live-mobile/src/reducers/settings.ts +++ b/apps/ledger-live-mobile/src/reducers/settings.ts @@ -9,7 +9,7 @@ import { getEnv, setEnvUnsafe } from "@ledgerhq/live-env"; import { createSelector } from "reselect"; import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import type { AccountLike } from "@ledgerhq/types-live"; -import type { CryptoCurrency, Currency } from "@ledgerhq/types-cryptoassets"; +import type { CryptoCurrency, Currency, Unit } from "@ledgerhq/types-cryptoassets"; import { DeviceModelId } from "@ledgerhq/types-devices"; import type { CurrencySettings, SettingsState, State } from "./types"; import { currencySettingsDefaults } from "../helpers/CurrencySettingsDefaults"; @@ -682,22 +682,22 @@ const handlers: ReducerMap = { export default handleActions(handlers, INITIAL_STATE); -const storeSelector = (state: State): SettingsState => state.settings; +export const settingsStoreSelector = (state: State): SettingsState => state.settings; -export const exportSelector = storeSelector; +export const exportSelector = settingsStoreSelector; const counterValueCurrencyLocalSelector = (state: SettingsState): Currency => findCurrencyByTicker(state.counterValue) || getFiatCurrencyByTicker("USD"); export const counterValueCurrencySelector = createSelector( - storeSelector, + settingsStoreSelector, counterValueCurrencyLocalSelector, ); const counterValueExchangeLocalSelector = (s: SettingsState) => s.counterValueExchange; export const counterValueExchangeSelector = createSelector( - storeSelector, + settingsStoreSelector, counterValueExchangeLocalSelector, ); @@ -705,40 +705,72 @@ const defaultCurrencySettingsForCurrency: (_: Currency) => CurrencySettings = cr const defaults = currencySettingsDefaults(crypto); return { confirmationsNb: defaults.confirmationsNb ? defaults.confirmationsNb.def : 0, - exchange: null, + unit: defaults.unit, }; }; export const currencySettingsSelector = ( - state: State, + state: SettingsState, { currency, }: { currency: Currency; }, -) => ({ - ...defaultCurrencySettingsForCurrency(currency), - ...state.settings.currenciesSettings[currency.ticker], -}); -export const privacySelector = createSelector(storeSelector, s => s.privacy); +) => { + const currencySettings = Object.keys(state.currenciesSettings)?.includes(currency.ticker) + ? state.currenciesSettings[currency.ticker] + : {}; + + return { + ...defaultCurrencySettingsForCurrency(currency), + ...currencySettings, + }; +}; + +export const unitForCurrencySelector = ( + state: State, + { + currency, + }: { + currency: CryptoCurrency; + }, +): Unit => { + const obj = state.settings.currenciesSettings[currency.ticker]; + if (obj?.unit) return obj.unit; + const defs = currencySettingsDefaults(currency); + return defs.unit; +}; + +export const accountUnitSelector = (state: State, account: AccountLike): Unit => { + if (account.type === "Account") { + return unitForCurrencySelector(state, account); + } else { + return account.token.units[0]; + } +}; + +export const privacySelector = createSelector(settingsStoreSelector, s => s.privacy); export const reportErrorsEnabledSelector = createSelector( - storeSelector, + settingsStoreSelector, s => s.reportErrorsEnabled, ); -export const analyticsEnabledSelector = createSelector(storeSelector, s => s.analyticsEnabled); +export const analyticsEnabledSelector = createSelector( + settingsStoreSelector, + s => s.analyticsEnabled, +); export const personalizedRecommendationsEnabledSelector = createSelector( - storeSelector, + settingsStoreSelector, s => s.personalizedRecommendationsEnabled, ); export const trackingEnabledSelector = createSelector( - storeSelector, + settingsStoreSelector, s => s.analyticsEnabled || s.personalizedRecommendationsEnabled, ); export const lastSeenCustomImageSelector = createSelector( - storeSelector, + settingsStoreSelector, s => s.lastSeenCustomImage, ); export const currencySettingsForAccountSelector = ( - s: State, + s: SettingsState, { account, }: { diff --git a/apps/ledger-live-mobile/src/reducers/types.ts b/apps/ledger-live-mobile/src/reducers/types.ts index e55e218bb81b..239b2eae615b 100644 --- a/apps/ledger-live-mobile/src/reducers/types.ts +++ b/apps/ledger-live-mobile/src/reducers/types.ts @@ -8,7 +8,7 @@ import type { } from "@ledgerhq/types-live"; import type { Device } from "@ledgerhq/live-common/hw/actions/types"; import type { DeviceModelId } from "@ledgerhq/devices"; -import type { CryptoCurrencyId, Currency } from "@ledgerhq/types-cryptoassets"; +import type { CryptoCurrencyId, Currency, Unit } from "@ledgerhq/types-cryptoassets"; import { MarketListRequestParams } from "@ledgerhq/live-common/market/types"; import { PostOnboardingState } from "@ledgerhq/types-live"; import { AvailableProviderV3, ExchangeRate } from "@ledgerhq/live-common/exchange/swap/types"; @@ -160,8 +160,7 @@ export enum OnboardingType { export type CurrencySettings = { confirmationsNb: number; - // FIXME: SEEMS TO NEVER BE USED - DROPPING ? - // exchange?: any | null; + unit: Unit; }; export type Privacy = { diff --git a/apps/ledger-live-mobile/src/screens/Account/AccountHeader.tsx b/apps/ledger-live-mobile/src/screens/Account/AccountHeader.tsx index 31a2c199105a..7cf73d504c96 100644 --- a/apps/ledger-live-mobile/src/screens/Account/AccountHeader.tsx +++ b/apps/ledger-live-mobile/src/screens/Account/AccountHeader.tsx @@ -1,7 +1,7 @@ import React from "react"; import { Flex, Text } from "@ledgerhq/native-ui"; import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Currency } from "@ledgerhq/types-cryptoassets"; import { AccountLike, Account, BalanceHistoryWithCountervalue } from "@ledgerhq/types-live"; import Animated from "react-native-reanimated"; @@ -12,6 +12,7 @@ import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import Placeholder from "~/components/Placeholder"; import AccountHeaderLeft from "./AccountHeaderLeft"; import { useAccountName, useMaybeAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; function AccountHeader({ currentPositionY, @@ -33,7 +34,7 @@ function AccountHeader({ parentAccount?: Account; }) { const item = history[history.length - 1]; - const cryptoCurrencyUnit = getAccountUnit(account); + const cryptoCurrencyUnit = useAccountUnit(account); const items = [ { unit: cryptoCurrencyUnit, diff --git a/apps/ledger-live-mobile/src/screens/AccountSettings/AccountUnitsRow.tsx b/apps/ledger-live-mobile/src/screens/AccountSettings/AccountUnitsRow.tsx deleted file mode 100644 index 89d2930c44bb..000000000000 --- a/apps/ledger-live-mobile/src/screens/AccountSettings/AccountUnitsRow.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React, { memo } from "react"; -import { Trans } from "react-i18next"; -import type { Account } from "@ledgerhq/types-live"; -import { useTheme } from "@react-navigation/native"; -import { ScreenName } from "~/const"; -import SettingsRow from "~/components/SettingsRow"; -import LText from "~/components/LText"; -import type { NavigationProps } from "./index"; - -type Props = { - navigation: NavigationProps["navigation"]; - account: Account; -}; - -function AccountUnitsRow({ navigation, account }: Props) { - const { colors } = useTheme(); - return ( - } - desc={} - arrowRight - onPress={() => - navigation.navigate(ScreenName.EditAccountUnits, { - accountId: account.id, - }) - } - > - - {account.unit.code} - - - ); -} - -export default memo(AccountUnitsRow); diff --git a/apps/ledger-live-mobile/src/screens/AccountSettings/EditAccountUnits.tsx b/apps/ledger-live-mobile/src/screens/AccountSettings/EditAccountUnits.tsx deleted file mode 100644 index c47992043799..000000000000 --- a/apps/ledger-live-mobile/src/screens/AccountSettings/EditAccountUnits.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import invariant from "invariant"; -import React, { useCallback } from "react"; -import { View, StyleSheet, FlatList } from "react-native"; -import { useDispatch, useSelector } from "react-redux"; -import { Unit } from "@ledgerhq/types-cryptoassets"; -import { accountScreenSelector } from "~/reducers/accounts"; -import { updateAccount } from "~/actions/accounts"; -import SettingsRow from "~/components/SettingsRow"; -import Touchable from "~/components/Touchable"; -import NavigationScrollView from "~/components/NavigationScrollView"; -import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; -import { AccountSettingsNavigatorParamList } from "~/components/RootNavigator/types/AccountSettingsNavigator"; -import { ScreenName } from "~/const"; - -type NavigationProps = StackNavigatorProps< - AccountSettingsNavigatorParamList, - ScreenName.EditAccountUnits ->; - -export default function EditAccountUnits({ navigation, route }: NavigationProps) { - const dispatch = useDispatch(); - const { account } = useSelector(accountScreenSelector(route)); - invariant(account?.type === "Account", "account must be a main account"); - const onPressItem = useCallback( - (item: Unit) => { - const newAccount = { ...account, unit: item }; - dispatch(updateAccount(newAccount)); - navigation.goBack(); - }, - [account, navigation, dispatch], - ); - const accountUnits = account.currency.units; - return ( - - - item.code} - renderItem={({ item }) => ( - { - onPressItem(item); - }} - > - - - )} - > - {account.unit.code} - - - - ); -} -const styles = StyleSheet.create({ - root: { - flex: 1, - paddingTop: 16, - paddingBottom: 64, - }, - body: { - flexDirection: "column", - flex: 1, - padding: 16, - }, -}); diff --git a/apps/ledger-live-mobile/src/screens/AccountSettings/index.tsx b/apps/ledger-live-mobile/src/screens/AccountSettings/index.tsx index ed2718425a99..9fe9f3ef6ad1 100644 --- a/apps/ledger-live-mobile/src/screens/AccountSettings/index.tsx +++ b/apps/ledger-live-mobile/src/screens/AccountSettings/index.tsx @@ -10,7 +10,6 @@ import { TrackScreen } from "~/analytics"; import { NavigatorName, ScreenName } from "~/const"; import AccountNameRow from "./AccountNameRow"; -import AccountUnitsRow from "./AccountUnitsRow"; import DeleteAccountRow from "./DeleteAccountRow"; import DeleteAccountModal from "./DeleteAccountModal"; import AccountAdvancedLogsRow from "./AccountAdvancedLogsRow"; @@ -86,7 +85,6 @@ class AccountSettings extends PureComponent { - (); @@ -205,10 +205,10 @@ export default function FreezeAmount({ navigation, route }: NavigatorProps) { [showAmountRatio, spendableBalance], ); - if (!account || !transaction) return null; + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { amount } = status; - const unit = getAccountUnit(account); const error = amount.eq(0) || bridgePending ? null : status.errors.amount; const warning = status.warnings.amount; diff --git a/apps/ledger-live-mobile/src/screens/OperationDetails/Content.tsx b/apps/ledger-live-mobile/src/screens/OperationDetails/Content.tsx index 0eee141dc415..bfcdfdb0c32d 100644 --- a/apps/ledger-live-mobile/src/screens/OperationDetails/Content.tsx +++ b/apps/ledger-live-mobile/src/screens/OperationDetails/Content.tsx @@ -5,7 +5,7 @@ import { useSelector } from "react-redux"; import { Trans, useTranslation } from "react-i18next"; import { useNavigation, useTheme } from "@react-navigation/native"; import type { Account, Operation, AccountLike, NFTMetadataResponse } from "@ledgerhq/types-live"; -import { getAccountUnit, getFeesCurrency, getFeesUnit } from "@ledgerhq/live-common/account/index"; +import { getFeesCurrency, getFeesUnit } from "@ledgerhq/live-common/account/index"; import { getOperationAmountNumber, isConfirmedOperation, @@ -43,6 +43,7 @@ import type { } from "~/components/RootNavigator/types/helpers"; import type { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type HelpLinkProps = { event: string; @@ -104,14 +105,14 @@ export default function Content({ }, []); const currencySettings = useSelector((s: State) => - currencySettingsForAccountSelector(s, { + currencySettingsForAccountSelector(s.settings, { account: mainAccount, }), ); const isToken = currency.type === "TokenCurrency"; const accountName = useAccountName(account); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const feeCurrency = getFeesCurrency(mainAccount); const feeUnit = getFeesUnit(feeCurrency); const amount = getOperationAmountNumber(operation); diff --git a/apps/ledger-live-mobile/src/screens/RequestAccount/02-SelectAccount.tsx b/apps/ledger-live-mobile/src/screens/RequestAccount/02-SelectAccount.tsx index 692ead8dd688..c39c1cd35a60 100644 --- a/apps/ledger-live-mobile/src/screens/RequestAccount/02-SelectAccount.tsx +++ b/apps/ledger-live-mobile/src/screens/RequestAccount/02-SelectAccount.tsx @@ -26,11 +26,11 @@ import { Flex } from "@ledgerhq/native-ui"; const SEARCH_KEYS = [ "name", - "account.unit.code", + "account.currency.name", + "account.currency.ticker", "account.token.name", "account.token.ticker", "subAccount.name", - "subAccount.unit.code", "subAccount.token.name", "subAccount.token.ticker", ]; diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx index 69daa000f5c0..67c66a7c2fb0 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx @@ -54,7 +54,7 @@ export default function SendSelectRecipient({ navigation, route }: Props) { const mainAccount = getMainAccount(account, parentAccount); const currencySettings = useSelector((s: State) => - currencySettingsForAccountSelector(s, { + currencySettingsForAccountSelector(s.settings, { account: mainAccount, }), ); diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/03a-AmountCoin.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/03a-AmountCoin.tsx index bb309d29348c..ec8a96dbce38 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/03a-AmountCoin.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/03a-AmountCoin.tsx @@ -10,7 +10,6 @@ import { useTheme } from "@react-navigation/native"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import { ScreenName } from "~/const"; import { accountScreenSelector } from "~/reducers/accounts"; @@ -32,6 +31,7 @@ import { GenericInformationBody } from "~/components/GenericInformationBody"; import { ExternalLinkMedium, InformationFill } from "@ledgerhq/native-ui/assets/icons"; import { Flex, Link } from "@ledgerhq/native-ui"; import { urls } from "~/utils/urls"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; @@ -120,10 +120,11 @@ export default function SendAmountCoin({ navigation, route }: Props) { }, [setTransaction, account, parentAccount, transaction]); const blur = useCallback(() => Keyboard.dismiss(), []); const onMaxSpendableLearnMore = useCallback(() => Linking.openURL(urls.maxSpendable), []); - if (!account || !transaction) return null; + + const unit = useMaybeAccountUnit(account); + if (!account || !transaction || !unit) return null; const { useAllAmount } = transaction; const { amount } = status; - const unit = getAccountUnit(account); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryAmountSection.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryAmountSection.tsx index 6a808f1e5f3b..2fc926c3b3f1 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryAmountSection.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryAmountSection.tsx @@ -2,12 +2,13 @@ import React from "react"; import { View, StyleSheet } from "react-native"; import { Trans } from "react-i18next"; import type { Account, AccountLike } from "@ledgerhq/types-live"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import BigNumber from "bignumber.js"; import SummaryRow from "./SummaryRow"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import CounterValue from "~/components/CounterValue"; import LText from "~/components/LText"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const styles = StyleSheet.create({ amountContainer: { @@ -30,7 +31,7 @@ type Props = { }; const SummaryAmountSection = ({ account, amount, overrideAmountLabel }: Props) => { - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const currency = getAccountCurrency(account); return ( diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx index 68a476ff37e9..cf2249172469 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx @@ -1,7 +1,7 @@ -import React, { PureComponent } from "react"; +import React, { useState } from "react"; import { View, StyleSheet } from "react-native"; import type { Account, AccountLike } from "@ledgerhq/types-live"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/index"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/index"; import { Trans } from "react-i18next"; import BigNumber from "bignumber.js"; import SummaryRow from "./SummaryRow"; @@ -14,6 +14,7 @@ import Info from "~/icons/Info"; import { withTheme, Theme } from "~/colors"; import { GenericInformationBody } from "~/components/GenericInformationBody"; import { InformationFill } from "@ledgerhq/native-ui/assets/icons"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -21,65 +22,55 @@ type Props = { amount: number | BigNumber; colors: Theme["colors"]; }; -type State = { - isModalOpened: boolean; -}; -class SummaryTotalSection extends PureComponent { - state = { - isModalOpened: false, - }; - onRequestClose = () => { - this.setState({ - isModalOpened: false, - }); +const SummaryTotalSection = ({ account, amount, colors }: Props) => { + const [isModalOpened, setIsModalOpened] = useState(false); + + const onRequestClose = () => { + setIsModalOpened(false); }; - onPress = () => { - this.setState({ - isModalOpened: true, - }); + + const onPress = () => { + setIsModalOpened(true); }; - render() { - const { account, amount, colors } = this.props; - const { isModalOpened } = this.state; - const unit = getAccountUnit(account); - const currency = getAccountCurrency(account); - return ( - <> - } - additionalInfo={ - - - - } - titleProps={{ - semiBold: true, - style: styles.title, - }} - > - - - - - - - - - - - } - description={} - /> - - - ); - } -} + const unit = useAccountUnit(account); + const currency = getAccountCurrency(account); + + return ( + <> + } + additionalInfo={ + + + + } + titleProps={{ + semiBold: true, + style: styles.title, + }} + > + + + + + + + + + + + } + description={} + /> + + + ); +}; const styles = StyleSheet.create({ summary: { @@ -95,4 +86,5 @@ const styles = StyleSheet.create({ fontSize: 14, }, }); + export default withTheme(SummaryTotalSection); diff --git a/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencySettings.tsx b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencySettings.tsx index 4f19ba740316..d072b0592031 100644 --- a/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencySettings.tsx +++ b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencySettings.tsx @@ -15,10 +15,11 @@ import { currencySettingsDefaults } from "~/helpers/CurrencySettingsDefaults"; import CurrencyIcon from "~/components/CurrencyIcon"; import { ScreenName } from "~/const"; import { SettingsNavigatorStackParamList } from "~/components/RootNavigator/types/SettingsNavigator"; -import { ConfirmationDefaults } from "~/types/common"; +import { ConfirmationDefaults, UnitDefaults } from "~/types/common"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator"; import { AccountSettingsNavigatorParamList } from "~/components/RootNavigator/types/AccountSettingsNavigator"; +import CurrencyUnitsRow from "./CurrencyUnitsRow"; type NavigationProps = | StackNavigatorProps @@ -28,7 +29,7 @@ type NavigationProps = type Props = { confirmationsNb: number; updateCurrencySettings: typeof updateCurrencySettings; - defaults: ConfirmationDefaults; + defaults: ConfirmationDefaults & UnitDefaults; currency: CryptoCurrency; }; @@ -102,6 +103,8 @@ function EachCurrencySettings({ )} + + {defaults.unit && } ); } diff --git a/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencyUnitsRow.tsx b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencyUnitsRow.tsx new file mode 100644 index 000000000000..307f9ca55504 --- /dev/null +++ b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/CurrencyUnitsRow.tsx @@ -0,0 +1,49 @@ +import React, { memo } from "react"; +import { Trans } from "react-i18next"; +import { useNavigation, useTheme } from "@react-navigation/native"; +import { ScreenName } from "~/const"; +import SettingsRow from "~/components/SettingsRow"; +import LText from "~/components/LText"; +import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; +import { useSelector } from "react-redux"; +import { currencySettingsSelector } from "~/reducers/settings"; +import { State } from "~/reducers/types"; + +type Props = { + currency: CryptoCurrency; +}; + +function CurrencyUnitsRow({ currency }: Props) { + const { colors } = useTheme(); + const navigation = useNavigation(); + const currencySettings = useSelector((s: State) => + currencySettingsSelector(s.settings, { + currency, + }), + ); + + return ( + } + desc={} + arrowRight + onPress={() => + navigation.navigate(ScreenName.EditCurrencyUnits, { + currency, + }) + } + > + + {currencySettings.unit.code} + + + ); +} + +export default memo(CurrencyUnitsRow); diff --git a/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/EditCurrencyUnits.tsx b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/EditCurrencyUnits.tsx new file mode 100644 index 000000000000..26ad41939db4 --- /dev/null +++ b/apps/ledger-live-mobile/src/screens/Settings/CryptoAssets/Currencies/EditCurrencyUnits.tsx @@ -0,0 +1,74 @@ +import React from "react"; +import { View, StyleSheet, FlatList } from "react-native"; +import { useDispatch, useSelector } from "react-redux"; +import { Unit } from "@ledgerhq/types-cryptoassets"; +import SettingsRow from "~/components/SettingsRow"; +import NavigationScrollView from "~/components/NavigationScrollView"; +import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; +import { ScreenName } from "~/const"; +import { SettingsNavigatorStackParamList } from "~/components/RootNavigator/types/SettingsNavigator"; +import { updateCurrencySettings } from "~/actions/settings"; +import { State } from "~/reducers/types"; +import { currencySettingsSelector } from "~/reducers/settings"; + +type NavigationProps = StackNavigatorProps< + SettingsNavigatorStackParamList, + ScreenName.EditCurrencyUnits +>; + +export default function EditCurrencyUnits({ navigation, route }: NavigationProps) { + const dispatch = useDispatch(); + const { currency } = route.params; + + const currencySettings = useSelector((s: State) => + currencySettingsSelector(s.settings, { + currency, + }), + ); + + const onPressItem = (item: Unit) => { + dispatch( + updateCurrencySettings({ + ticker: currency.ticker, + patch: { + unit: item, + }, + }), + ); + navigation.goBack(); + }; + + const units = currency.units; + const unit = currencySettings.unit; + + return ( + + + item.code} + renderItem={({ item }) => ( + onPressItem(item)} + /> + )} + /> + + + ); +} +const styles = StyleSheet.create({ + root: { + flex: 1, + paddingTop: 16, + paddingBottom: 64, + }, + body: { + flexDirection: "column", + flex: 1, + padding: 16, + }, +}); diff --git a/apps/ledger-live-mobile/src/screens/Swap/Form/Summary/index.tsx b/apps/ledger-live-mobile/src/screens/Swap/Form/Summary/index.tsx index 96912b16af92..f5892ec42374 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/Form/Summary/index.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/Form/Summary/index.tsx @@ -4,7 +4,7 @@ import { BigNumber } from "bignumber.js"; import { Flex, Icon, Text } from "@ledgerhq/native-ui"; import { getProviderName } from "@ledgerhq/live-common/exchange/swap/utils/index"; import { SwapTransactionType } from "@ledgerhq/live-common/exchange/swap/types"; -import { getAccountUnit, getMainAccount } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { CompositeScreenProps, useNavigation, useRoute } from "@react-navigation/native"; import { useSelector } from "react-redux"; import { useCalculate } from "@ledgerhq/live-countervalues-react"; @@ -28,6 +28,7 @@ import { useAnalytics } from "~/analytics"; import { sharedSwapTracking } from "../../utils"; import { EDITABLE_FEE_FAMILIES } from "@ledgerhq/live-common/exchange/swap/const/blockchain"; import { useMaybeAccountName } from "~/reducers/wallet"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; interface Props { provider?: string; @@ -152,7 +153,7 @@ export function Summary({ provider, swapTx: { swap, status, transaction } }: Pro const fromUnit = from.currency?.units[0]; const mainFromAccount = from.account && getMainAccount(from.account, from.parentAccount); - const mainAccountUnit = mainFromAccount && getAccountUnit(mainFromAccount); + const mainAccountUnit = useMaybeAccountUnit(mainFromAccount); const editableFee = mainFromAccount && EDITABLE_FEE_FAMILIES.includes(mainFromAccount.currency.family); diff --git a/apps/ledger-live-mobile/src/screens/Swap/Form/TxForm/From.tsx b/apps/ledger-live-mobile/src/screens/Swap/Form/TxForm/From.tsx index de2f25d6e3f4..927ecfe5d417 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/Form/TxForm/From.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/Form/TxForm/From.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { useNavigation } from "@react-navigation/native"; import { Flex, Text } from "@ledgerhq/native-ui"; -import { getAccountSpendableBalance, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getAccountSpendableBalance } from "@ledgerhq/live-common/account/index"; import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; import { useFetchCurrencyFrom, @@ -24,6 +24,7 @@ import { useSelector } from "react-redux"; import { AccountLike } from "@ledgerhq/types-live"; import { walletSelector } from "~/reducers/wallet"; import { accountNameWithDefaultSelector } from "@ledgerhq/live-wallet/store"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; interface Props { provider?: string; @@ -53,17 +54,18 @@ export function From({ swapTx, provider, swapError, swapWarning, isSendMaxLoadin [], ); - const { name, balance, unit } = useMemo(() => { + const { name, balance, account } = useMemo(() => { const { currency, account } = swapTx.swap.from; const name = account && accountNameWithDefaultSelector(walletState, account); return { account, name, balance: getAccountBalance({ account, currency }), - unit: account && getAccountUnit(account), }; }, [swapTx.swap.from, walletState, getAccountBalance]); + const unit = useMaybeAccountUnit(account); + usePickDefaultAccount(accounts, swapTx.swap.from.account, swapTx.setFromAccount); const onPress = useCallback(() => { diff --git a/apps/ledger-live-mobile/src/screens/Swap/History/OperationRow.tsx b/apps/ledger-live-mobile/src/screens/Swap/History/OperationRow.tsx index dcac770dca6c..4bf077095a05 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/History/OperationRow.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/History/OperationRow.tsx @@ -3,7 +3,6 @@ import { TouchableOpacity, StyleSheet, View } from "react-native"; import { useNavigation, useTheme } from "@react-navigation/native"; import { Icon } from "@ledgerhq/native-ui"; import type { MappedSwapOperation } from "@ledgerhq/live-common/exchange/swap/types"; -import { getAccountUnit } from "@ledgerhq/live-common/account/helpers"; import LText from "~/components/LText"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; import { SwapStatusIndicator } from "../SwapStatusIndicator"; @@ -11,6 +10,7 @@ import { ScreenName } from "~/const"; import type { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; import type { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers"; import { useAccountName } from "~/reducers/wallet"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; const OperationRow = ({ item }: { item: MappedSwapOperation }) => { const { colors } = useTheme(); @@ -31,6 +31,9 @@ const OperationRow = ({ item }: { item: MappedSwapOperation }) => { const fromAccountName = useAccountName(fromAccount); const toAccountName = useAccountName(toAccount); + const unitFrom = useAccountUnit(fromAccount); + const unitTo = useAccountUnit(toAccount); + return ( { {fromAccountName} - + @@ -53,7 +56,7 @@ const OperationRow = ({ item }: { item: MappedSwapOperation }) => { {toAccountName} - + diff --git a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/OperationDetails.tsx b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/OperationDetails.tsx index 2abcc29ef14d..1ddfdf95a2a9 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/OperationDetails.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/OperationDetails.tsx @@ -6,7 +6,7 @@ import { useTheme } from "@react-navigation/native"; import Config from "react-native-config"; import { ScrollView, StyleSheet, View, Linking, TouchableOpacity } from "react-native"; import { getDefaultExplorerView, getTransactionExplorer } from "@ledgerhq/live-common/explorers"; -import { getAccountUnit, getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers"; import { getProviderName } from "@ledgerhq/live-common/exchange/swap/utils/index"; import { flattenAccountsSelector } from "~/reducers/accounts"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; @@ -21,6 +21,7 @@ import { SwapStatusIndicator, getStatusColor } from "../SwapStatusIndicator"; import Footer from "../../OperationDetails/Footer"; import { OperationDetailsParamList } from "../types"; import { useMaybeAccountName } from "~/reducers/wallet"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; export function OperationDetails({ route }: OperationDetailsParamList) { const { swapOperation } = route.params; @@ -61,16 +62,19 @@ export function OperationDetails({ route }: OperationDetailsParamList) { const fromAccountName = useMaybeAccountName(fromAccount); const toAccountName = useMaybeAccountName(toAccount); + const unitFrom = useMaybeAccountUnit(fromAccount); + const unitTo = useMaybeAccountUnit(toAccount); + return ( {status ? : null} - {fromAccount && ( + {fromAccount && unitFrom && ( @@ -79,13 +83,8 @@ export function OperationDetails({ route }: OperationDetailsParamList) { - {toAccount ? ( - + {toAccount && unitTo ? ( + ) : null} @@ -136,9 +135,9 @@ export function OperationDetails({ route }: OperationDetailsParamList) { - {fromAccount && ( + {fromAccount && unitFrom && ( - + )} @@ -159,8 +158,8 @@ export function OperationDetails({ route }: OperationDetailsParamList) { - {toAccount ? ( - + {toAccount && unitTo ? ( + ) : null} diff --git a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectAccount.tsx b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectAccount.tsx index 0ef984157250..baf8e27d8436 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectAccount.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectAccount.tsx @@ -206,7 +206,13 @@ export function SelectAccount({ navigation, route: { params } }: SelectAccountPa ( diff --git a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectProvider.tsx b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectProvider.tsx index aa14210456f5..12360f3a2e84 100644 --- a/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectProvider.tsx +++ b/apps/ledger-live-mobile/src/screens/Swap/SubScreens/SelectProvider.tsx @@ -1,9 +1,8 @@ -import React, { useMemo, useCallback } from "react"; +import React, { useCallback } from "react"; import { TouchableOpacity } from "react-native"; import { BigNumber } from "bignumber.js"; import { Flex, Text, Icon } from "@ledgerhq/native-ui"; import { getProviderName } from "@ledgerhq/live-common/exchange/swap/utils/index"; -import { getAccountUnit } from "@ledgerhq/live-common/account/index"; import { useTranslation } from "react-i18next"; import { ExchangeRate } from "@ledgerhq/live-common/exchange/swap/types"; import CurrencyUnitValue from "~/components/CurrencyUnitValue"; @@ -13,6 +12,7 @@ import CounterValue from "~/components/CounterValue"; import { TrackScreen, useAnalytics } from "~/analytics"; import { ScreenName } from "~/const"; import { sharedSwapTracking, SWAP_VERSION } from "../utils"; +import { useMaybeAccountUnit } from "~/hooks/useAccountUnit"; export function SelectProvider({ navigation, route }: SelectProviderParamList) { const { @@ -24,7 +24,7 @@ export function SelectProvider({ navigation, route }: SelectProviderParamList) { } = route; const { track } = useAnalytics(); const { t } = useTranslation(); - const fromUnit = useMemo(() => from.account && getAccountUnit(from.account), [from.account]); + const fromUnit = useMaybeAccountUnit(from.account); const onSelect = useCallback( (rate: ExchangeRate) => { diff --git a/apps/ledger-live-mobile/src/screens/UnfreezeFunds/01-Amount.tsx b/apps/ledger-live-mobile/src/screens/UnfreezeFunds/01-Amount.tsx index 86607638429b..71452d015718 100644 --- a/apps/ledger-live-mobile/src/screens/UnfreezeFunds/01-Amount.tsx +++ b/apps/ledger-live-mobile/src/screens/UnfreezeFunds/01-Amount.tsx @@ -6,7 +6,7 @@ import { useSelector } from "react-redux"; import { Trans } from "react-i18next"; import { useNavigation, useTheme } from "@react-navigation/native"; import type { Account } from "@ledgerhq/types-live"; -import { getMainAccount, getAccountUnit } from "@ledgerhq/live-common/account/index"; +import { getMainAccount } from "@ledgerhq/live-common/account/index"; import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import type { @@ -34,6 +34,7 @@ import { } from "~/components/RootNavigator/types/helpers"; import { UnfreezeNavigatorParamList } from "~/components/RootNavigator/types/UnfreezeNavigator"; import { getUnfreezeData } from "@ledgerhq/live-common/families/tron/react"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = StackNavigatorProps; @@ -55,7 +56,7 @@ function UnfreezeAmountInner({ account }: InnerProps) { const { colors } = useTheme(); const navigation = useNavigation>(); const bridge = getAccountBridge(account, undefined); - const unit = getAccountUnit(account); + const unit = useAccountUnit(account); const { tronResources } = account as TronAccount; invariant(tronResources, "tron resources expected"); const { unfreezeBandwidth, unfreezeEnergy, canUnfreezeBandwidth, canUnfreezeEnergy } = useMemo( diff --git a/apps/ledger-live-mobile/src/types/common.ts b/apps/ledger-live-mobile/src/types/common.ts index 5a5c02926b8a..4c4fc10432dc 100644 --- a/apps/ledger-live-mobile/src/types/common.ts +++ b/apps/ledger-live-mobile/src/types/common.ts @@ -1,4 +1,7 @@ // TODO should drop this file!, + +import { Unit } from "@ledgerhq/types-cryptoassets"; + // FIXME then drop it, i'm not here for that. export type T = ( arg0: string | null | undefined, @@ -15,3 +18,7 @@ export type ConfirmationDefaults = { | null | undefined; }; + +export type UnitDefaults = { + unit: Unit; +}; diff --git a/apps/web-tools/pages/logsviewer.tsx b/apps/web-tools/pages/logsviewer.tsx index e9b9e5e3219c..ea4e5a524330 100644 --- a/apps/web-tools/pages/logsviewer.tsx +++ b/apps/web-tools/pages/logsviewer.tsx @@ -142,7 +142,6 @@ const Header = ({ operations: [], pendingOperations: [], swapHistory: [], - unitMagnitude: 0, lastSyncDate: "0", }; return { diff --git a/apps/web-tools/pages/sync.tsx b/apps/web-tools/pages/sync.tsx index 3096b9ded123..cd6f7c70ec41 100644 --- a/apps/web-tools/pages/sync.tsx +++ b/apps/web-tools/pages/sync.tsx @@ -57,7 +57,6 @@ function inferAccount(id: string): Account { id, derivationMode, currency, - unit: currency.units[0], index, freshAddress: xpubOrAddress, freshAddressPath, diff --git a/libs/coin-framework/src/account/helpers.test.ts b/libs/coin-framework/src/account/helpers.test.ts index 1dfb3d2642b3..e5947252dea6 100644 --- a/libs/coin-framework/src/account/helpers.test.ts +++ b/libs/coin-framework/src/account/helpers.test.ts @@ -1,4 +1,4 @@ -import { CryptoCurrency, TokenCurrency, Unit } from "@ledgerhq/types-cryptoassets"; +import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; import { Account, Operation, SubAccount, TokenAccount } from "@ledgerhq/types-live"; import BigNumber from "bignumber.js"; import { @@ -6,7 +6,6 @@ import { emptyHistoryCache, getAccountCurrency, getAccountSpendableBalance, - getAccountUnit, getFeesCurrency, } from "."; import { isAccountEmpty, isAccountBalanceSignificant, clearAccount } from "./helpers"; @@ -41,46 +40,6 @@ describe(getAccountCurrency.name, () => { }); }); -describe(getAccountUnit.name, () => { - describe("given an Account", () => { - beforeEach(() => { - mockAccount.type = "Account"; - }); - it("should return the unit", () => { - const sampleUnit = { name: "unit" } as Unit; - mockAccount.unit = sampleUnit; - expect(getAccountUnit(mockAccount)).toEqual(sampleUnit); - }); - }); - - describe("given a TokenAccount", () => { - it("should return the token unit", () => { - const sampleUnit = { name: "unit" } as Unit; - tokenAccount.token = { units: [sampleUnit] } as TokenCurrency; - expect(getAccountUnit(tokenAccount)).toEqual(sampleUnit); - }); - }); - - describe("given an unknown type Account", () => { - beforeEach(() => { - (mockAccount as any).type = "DefinitelyNotAStandardAccount"; - }); - - it("should throw an error", () => { - expect(() => getAccountUnit(mockAccount)).toThrow(Error); - }); - - it("should display the account type in the error message", () => { - expect.assertions(1); - try { - getAccountUnit(mockAccount); - } catch (e: unknown) { - expect((e as Error).message.includes(mockAccount.type)).toEqual(true); - } - }); - }); -}); - describe(getFeesCurrency.name, () => { describe("given an Account", () => { beforeEach(() => { diff --git a/libs/coin-framework/src/account/helpers.ts b/libs/coin-framework/src/account/helpers.ts index c53865666a78..c9a2a202a325 100644 --- a/libs/coin-framework/src/account/helpers.ts +++ b/libs/coin-framework/src/account/helpers.ts @@ -56,19 +56,6 @@ export const getAccountCurrency = (account?: AccountLike): TokenCurrency | Crypt } }; -export const getAccountUnit = (account: AccountLike): Unit => { - switch (account.type) { - case "Account": - return account.unit; - - case "TokenAccount": - return account.token.units[0]; - - default: - throw new Error("invalid account.type=" + (account as AccountLike).type); - } -}; - export const getAccountSpendableBalance = (account: AccountLike): BigNumber => account.spendableBalance; diff --git a/libs/coin-framework/src/account/pending.test.ts b/libs/coin-framework/src/account/pending.test.ts index b0a5dce3ddd9..f031cd3a6566 100644 --- a/libs/coin-framework/src/account/pending.test.ts +++ b/libs/coin-framework/src/account/pending.test.ts @@ -95,7 +95,6 @@ function createAccount(id: string): Account { creationDate: new Date(), blockHeight: 0, currency, - unit: currency.units[0], operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/coin-framework/src/bridge/jsHelpers.test.ts b/libs/coin-framework/src/bridge/jsHelpers.test.ts index aaa0514b46b0..329223add916 100644 --- a/libs/coin-framework/src/bridge/jsHelpers.test.ts +++ b/libs/coin-framework/src/bridge/jsHelpers.test.ts @@ -122,7 +122,6 @@ function createAccount(id: string): Account { creationDate: new Date(), blockHeight: 0, currency, - unit: currency.units[0], operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/coin-framework/src/bridge/jsHelpers.ts b/libs/coin-framework/src/bridge/jsHelpers.ts index 52373839211a..33de33f9506e 100644 --- a/libs/coin-framework/src/bridge/jsHelpers.ts +++ b/libs/coin-framework/src/bridge/jsHelpers.ts @@ -365,7 +365,6 @@ export const makeScanAccounts = operations: [], swapHistory: [], pendingOperations: [], - unit: currency.units[0], lastSyncDate: new Date(), creationDate, // overrides diff --git a/libs/coin-framework/src/formatters.ts b/libs/coin-framework/src/formatters.ts index 82e18e3551b4..1d991131e26b 100644 --- a/libs/coin-framework/src/formatters.ts +++ b/libs/coin-framework/src/formatters.ts @@ -1,5 +1,5 @@ import type { Account, TransactionCommon, TransactionStatusCommon } from "@ledgerhq/types-live"; -import { getAccountUnit } from "./account"; +import { getAccountCurrency } from "./account"; import { formatCurrencyUnit } from "./currencies"; const formatErrorSmall = (e: Error): string => (e.name === "Error" ? e.message : e.name); @@ -16,19 +16,19 @@ export const formatTransactionStatus = ( str += "\n amount: " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }); str += "\n estimated fees: " + - formatCurrencyUnit(getAccountUnit(mainAccount), estimatedFees, { + formatCurrencyUnit(getAccountCurrency(mainAccount).units[0], estimatedFees, { showCode: true, disableRounding: true, }); str += "\n total spent: " + - formatCurrencyUnit(getAccountUnit(account), totalSpent, { + formatCurrencyUnit(getAccountCurrency(account).units[0], totalSpent, { showCode: true, disableRounding: true, }); diff --git a/libs/coin-framework/src/mocks/account.ts b/libs/coin-framework/src/mocks/account.ts index eb677858a41b..d4c86b55e061 100644 --- a/libs/coin-framework/src/mocks/account.ts +++ b/libs/coin-framework/src/mocks/account.ts @@ -316,9 +316,9 @@ export function genAccount( const outdated = ["ethereum_classic", "dogecoin"].includes(currency.id) && `${id}`.endsWith("_2"); const accountId = `mock:${outdated ? 0 : 1}:${currency.id}:${id}:`; const xpub = genHex(64, rng); - rng.nextString(rng.nextInt(4, 34)); // to not break the determinism, we will still run this code that used to generate fake account names + rng.nextString(rng.nextInt(4, 34)); // to not break the determinism, we will still run this code that used to generate fake account names. remove it when we allow ourself a breaking change. const blockHeight = rng.nextInt(100000, 200000); - const unit = rng.nextArrayItem(currency.units); + rng.nextArrayItem(currency.units); // to not break the determinism, we still run this code. remove it when we allow ourself a breaking change. const account: Account = { type: "Account", id: accountId, @@ -333,7 +333,6 @@ export function genAccount( spendableBalance: new BigNumber(0), blockHeight, currency, - unit, operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/coin-framework/src/serialization/account.ts b/libs/coin-framework/src/serialization/account.ts index e9f4b35a2bbb..472ddfd288c3 100644 --- a/libs/coin-framework/src/serialization/account.ts +++ b/libs/coin-framework/src/serialization/account.ts @@ -45,7 +45,6 @@ export function fromAccountRaw(rawAccount: AccountRaw, fromRaw?: FromFamiliyRaw) blockHeight, currencyId, feesCurrencyId, - unitMagnitude, operations, operationsCount, pendingOperations, @@ -78,7 +77,6 @@ export function fromAccountRaw(rawAccount: AccountRaw, fromRaw?: FromFamiliyRaw) const feesCurrency = (feesCurrencyId && (findCryptoCurrencyById(feesCurrencyId) || findTokenById(feesCurrencyId))) || undefined; - const unit = currency.units.find(u => u.magnitude === unitMagnitude) || currency.units[0]; const res: Account = { type: "Account", @@ -97,7 +95,6 @@ export function fromAccountRaw(rawAccount: AccountRaw, fromRaw?: FromFamiliyRaw) operations: (operations || []).map(convertOperation), operationsCount: operationsCount || (operations && operations.length) || 0, pendingOperations: (pendingOperations || []).map(convertOperation), - unit, currency, feesCurrency, lastSyncDate: new Date(lastSyncDate || 0), @@ -160,7 +157,6 @@ export function toAccountRaw( operationsCount, operations, pendingOperations, - unit, lastSyncDate, balance, balanceHistoryCache, @@ -198,7 +194,6 @@ export function toAccountRaw( operations: (operations || []).map(convertOperation), pendingOperations: (pendingOperations || []).map(convertOperation), currencyId: currency.id, - unitMagnitude: unit.magnitude, lastSyncDate: lastSyncDate.toISOString(), balance: balance.toFixed(), spendableBalance: spendableBalance.toFixed(), diff --git a/libs/coin-modules/coin-algorand/src/bridge.integration.test.ts b/libs/coin-modules/coin-algorand/src/bridge.integration.test.ts index bd6435b64c61..b717d67a1af0 100644 --- a/libs/coin-modules/coin-algorand/src/bridge.integration.test.ts +++ b/libs/coin-modules/coin-algorand/src/bridge.integration.test.ts @@ -46,7 +46,6 @@ const algorand: CurrenciesData = { index: 0, freshAddress: "ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q", freshAddressPath: "44'/283'/0'/0/0", - unitMagnitude: 6, blockHeight: 8518049, operations: [], pendingOperations: [], @@ -214,7 +213,6 @@ const algorand: CurrenciesData = { index: 3, freshAddress: "MECOWMKPKH2NWVZTS5V5RQDGFFYBT25KNLOPHG2KUMMNKU6FOHGJT24WBI", freshAddressPath: "44'/283'/3'/0/0", - unitMagnitude: 6, blockHeight: 8518189, balance: "0", spendableBalance: "0", diff --git a/libs/coin-modules/coin-algorand/src/deviceTransactionConfig.ts b/libs/coin-modules/coin-algorand/src/deviceTransactionConfig.ts index 7db5127a5ea3..b271e850a8b1 100644 --- a/libs/coin-modules/coin-algorand/src/deviceTransactionConfig.ts +++ b/libs/coin-modules/coin-algorand/src/deviceTransactionConfig.ts @@ -1,4 +1,4 @@ -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { findTokenById, formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common"; import { TokenCurrency } from "@ledgerhq/types-cryptoassets"; @@ -60,7 +60,7 @@ const getSendFields = ( fields.push({ type: "text", label: account.type === "TokenAccount" ? "Asset amt" : "Amount", - value: formatCurrencyUnit(getAccountUnit(account), amount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }), diff --git a/libs/coin-modules/coin-algorand/src/formatters.ts b/libs/coin-modules/coin-algorand/src/formatters.ts index d38651ec19a3..a2e4c9761d60 100644 --- a/libs/coin-modules/coin-algorand/src/formatters.ts +++ b/libs/coin-modules/coin-algorand/src/formatters.ts @@ -1,4 +1,4 @@ -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import type { Unit } from "@ledgerhq/types-cryptoassets"; import invariant from "invariant"; @@ -21,7 +21,7 @@ function formatOperationSpecifics(op: AlgorandOperation, unit: Unit | null | und function formatAccountSpecifics(account: AlgorandAccount): string { const { algorandResources } = account; invariant(algorandResources, "algorand account expected"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/coin-modules/coin-algorand/src/transaction.ts b/libs/coin-modules/coin-algorand/src/transaction.ts index 7bd944b997bd..cd901d8e0797 100644 --- a/libs/coin-modules/coin-algorand/src/transaction.ts +++ b/libs/coin-modules/coin-algorand/src/transaction.ts @@ -1,4 +1,4 @@ -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters"; import { @@ -21,7 +21,7 @@ export const formatTransaction = ( ${mode === "claimReward" ? "CLAIM REWARD" : mode === "optIn" ? "OPT_IN" : "SEND"} ${ useAllAmount ? "MAX" - : formatCurrencyUnit(getAccountUnit(account), amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: false, }) @@ -30,7 +30,7 @@ export const formatTransaction = ( with fees=${ !fees ? "?" - : formatCurrencyUnit(getAccountUnit(mainAccount), fees, { + : formatCurrencyUnit(mainAccount.currency.units[0], fees, { showCode: true, disableRounding: false, }) diff --git a/libs/coin-modules/coin-bitcoin/src/datasets/bitcoin.ts b/libs/coin-modules/coin-bitcoin/src/datasets/bitcoin.ts index 0b5746edc483..2642b4ff654e 100644 --- a/libs/coin-modules/coin-bitcoin/src/datasets/bitcoin.ts +++ b/libs/coin-modules/coin-bitcoin/src/datasets/bitcoin.ts @@ -42,7 +42,6 @@ export const bitcoin1: BitcoinAccountRaw = { pendingOperations: [], operations: [], currencyId: "bitcoin", - unitMagnitude: 8, balance: "2757", blockHeight: 0, lastSyncDate: "", @@ -65,7 +64,6 @@ export const bitcoin2: BitcoinAccountRaw = { operations: [], pendingOperations: [], currencyId: "bitcoin", - unitMagnitude: 8, lastSyncDate: "", balance: "2717", xpub: "xpub6DEHKg8fgKcb9at2u9Xhjtx4tXGyWqUPQAx2zNCzr41gQRyCqpCn7onSoJU4VS96GXyCtAhhFxErnG2pGVvVexaqF7DEfqGGnGk7Havn7C2", diff --git a/libs/coin-modules/coin-bitcoin/src/datasets/digibyte.ts b/libs/coin-modules/coin-bitcoin/src/datasets/digibyte.ts index 9a4fc530a2f5..f437cc4eaca1 100644 --- a/libs/coin-modules/coin-bitcoin/src/datasets/digibyte.ts +++ b/libs/coin-modules/coin-bitcoin/src/datasets/digibyte.ts @@ -115,7 +115,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "digibyte", - unitMagnitude: 8, lastSyncDate: "", balance: "2302647120", xpub: "xpub6CV98T6ompjUmKuMaULsw4UP8yfnVCg6831rWdcPjScn6RaGWrt3b7uvTpt9hcq6tLtS1dGNzeJ9x4NpVGzLq7CFscxCdoPZ6zxkqGymx98", @@ -138,7 +137,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "digibyte", - unitMagnitude: 8, lastSyncDate: "", balance: "0", xpub: "xpub6CsavyNsoieEiR5QNsHZ3VQt7UzRcnKcFNXkadn1kaxsysqa2L79m3iNw6bFyJ1Vz8xYNu9ivECVvFTxydqMp4C3njLGA5PFxBid81Jinkh", diff --git a/libs/coin-modules/coin-bitcoin/src/datasets/litecoin.ts b/libs/coin-modules/coin-bitcoin/src/datasets/litecoin.ts index 952ee7cbe881..9f24911e6ec4 100644 --- a/libs/coin-modules/coin-bitcoin/src/datasets/litecoin.ts +++ b/libs/coin-modules/coin-bitcoin/src/datasets/litecoin.ts @@ -137,7 +137,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "litecoin", - unitMagnitude: 8, lastSyncDate: "", balance: "2183515", xpub: "Ltub2ZDyeYFtDj5kHy4w5WaXBDE9217rNDYfmv7u5NV8dk8vKdmkqAfPdwRma5rkPcj5daMU8JiiLXQYPX9rtqEzrK1YrmkofcpADTV7s5FgzLF", @@ -160,7 +159,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "litecoin", - unitMagnitude: 8, lastSyncDate: "", balance: "0", xpub: "Ltub2Yz97oUCaVDo1Ak6FJ1Fvg2EscNzrWvLYxnXeY7rrArUPpdfgUAEWM49MrjVBNrdjwgFnMbqKGh8XkUdQFx3h8y1SDcak4vGSbqKM5PR8Rr", diff --git a/libs/coin-modules/coin-bitcoin/src/formatters.ts b/libs/coin-modules/coin-bitcoin/src/formatters.ts index afee37e3d515..995b223d8391 100644 --- a/libs/coin-modules/coin-bitcoin/src/formatters.ts +++ b/libs/coin-modules/coin-bitcoin/src/formatters.ts @@ -6,7 +6,7 @@ const sortUTXO = (a: BitcoinOutput, b: BitcoinOutput) => b.value.minus(a.value). export function formatInput(account: BitcoinAccount, input: BitcoinInput): string { return `${(input.value - ? formatCurrencyUnit(account.unit, input.value, { + ? formatCurrencyUnit(account.currency.units[0], input.value, { showCode: false, }) : "" @@ -14,7 +14,7 @@ export function formatInput(account: BitcoinAccount, input: BitcoinInput): strin } export function formatOutput(account: BitcoinAccount, o: BitcoinOutput): string { return [ - formatCurrencyUnit(account.unit, o.value, { + formatCurrencyUnit(account.currency.units[0], o.value, { showCode: false, }).padEnd(12), o.address, diff --git a/libs/coin-modules/coin-bitcoin/src/hw-signMessage.test.ts b/libs/coin-modules/coin-bitcoin/src/hw-signMessage.test.ts index d716cc5d7b74..bb4002ea482a 100644 --- a/libs/coin-modules/coin-bitcoin/src/hw-signMessage.test.ts +++ b/libs/coin-modules/coin-bitcoin/src/hw-signMessage.test.ts @@ -69,7 +69,6 @@ function createFixtureAccount(account?: Partial): BitcoinAccount creationDate: new Date(), blockHeight: 100_000, currency, - unit: currency.units[0], operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/coin-modules/coin-bitcoin/src/transaction.ts b/libs/coin-modules/coin-bitcoin/src/transaction.ts index e827734c6d1b..61adc1516566 100644 --- a/libs/coin-modules/coin-bitcoin/src/transaction.ts +++ b/libs/coin-modules/coin-bitcoin/src/transaction.ts @@ -17,7 +17,7 @@ import { toTransactionCommonRaw, toTransactionStatusRawCommon, } from "@ledgerhq/coin-framework/serialization"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import type { Account } from "@ledgerhq/types-live"; import { @@ -152,7 +152,7 @@ export const formatTransaction = (t: Transaction, account: Account): string => { SEND ${ t.useAllAmount ? "MAX" - : formatCurrencyUnit(getAccountUnit(account), t.amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], t.amount, { showCode: true, disableRounding: true, }) diff --git a/libs/coin-modules/coin-evm/src/__tests__/fixtures/common.fixtures.ts b/libs/coin-modules/coin-evm/src/__tests__/fixtures/common.fixtures.ts index 12f6975fa2bf..56d343f77036 100644 --- a/libs/coin-modules/coin-evm/src/__tests__/fixtures/common.fixtures.ts +++ b/libs/coin-modules/coin-evm/src/__tests__/fixtures/common.fixtures.ts @@ -51,7 +51,6 @@ export const makeAccount = ( id, derivationMode, currency, - unit: currency.units[0], index, nfts: [], freshAddress: xpubOrAddress, diff --git a/libs/coin-modules/coin-evm/src/__tests__/unit/editTransaction/getFormattedFeeFields.test.ts b/libs/coin-modules/coin-evm/src/__tests__/unit/editTransaction/getFormattedFeeFields.test.ts index a2ca3c69c04d..80f1caa7c14d 100644 --- a/libs/coin-modules/coin-evm/src/__tests__/unit/editTransaction/getFormattedFeeFields.test.ts +++ b/libs/coin-modules/coin-evm/src/__tests__/unit/editTransaction/getFormattedFeeFields.test.ts @@ -37,7 +37,7 @@ const testCases: { .map(currency => { return { currencyName: currency.name, - account: { type: "Account", currency, unit: currency.units[0] } as Account, + account: { type: "Account", currency } as Account, type2Transaction: dummyType2Transaction, type0Transaction: dummyType0Transaction, }; diff --git a/libs/coin-modules/coin-evm/src/datasets/ethereum1.ts b/libs/coin-modules/coin-evm/src/datasets/ethereum1.ts index c4df0c39495d..73e911dca3bb 100644 --- a/libs/coin-modules/coin-evm/src/datasets/ethereum1.ts +++ b/libs/coin-modules/coin-evm/src/datasets/ethereum1.ts @@ -13,7 +13,6 @@ export const ethereum1: AccountRaw = { pendingOperations: [], operations: [], currencyId: "ethereum", - unitMagnitude: 18, balance: "", blockHeight: 0, lastSyncDate: "", diff --git a/libs/coin-modules/coin-evm/src/editTransaction/getFormattedFeeFields.ts b/libs/coin-modules/coin-evm/src/editTransaction/getFormattedFeeFields.ts index 63a296e49e69..2fb501b0e479 100644 --- a/libs/coin-modules/coin-evm/src/editTransaction/getFormattedFeeFields.ts +++ b/libs/coin-modules/coin-evm/src/editTransaction/getFormattedFeeFields.ts @@ -1,4 +1,3 @@ -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import type { Account } from "@ledgerhq/types-live"; import { BigNumber } from "bignumber.js"; @@ -23,16 +22,16 @@ export const getFormattedFeeFields = ({ formattedMaxFeePerGas: string; formattedGasPrice: string; } => { - const unit = getAccountUnit(mainAccount); + const { currency } = mainAccount; + const unit = currency.units[0]; const feeValue = getEstimatedFees(transaction); const formattedFeeValue = formatCurrencyUnit(unit, feeValue, { showCode: true, locale, }); - const { currency } = mainAccount; // If a lower unit is available, use it to display the fees (e.g. ETH -> GWEI) - // This might not be the case for all currencies, so we fallback to the account unit + // This might not be the case for all currencies, so we fallback to the general unit const feesUnit = currency.units.length > 1 ? currency.units[1] : unit; const maxPriorityFeePerGas = transaction.maxPriorityFeePerGas ?? new BigNumber(0); diff --git a/libs/coin-modules/coin-evm/src/transaction.ts b/libs/coin-modules/coin-evm/src/transaction.ts index 8899efedc794..ee6e92e6538d 100644 --- a/libs/coin-modules/coin-evm/src/transaction.ts +++ b/libs/coin-modules/coin-evm/src/transaction.ts @@ -7,8 +7,8 @@ import { fromTransactionStatusRawCommon as fromTransactionStatusRaw, toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, -} from "@ledgerhq/coin-framework/serialization/index"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +} from "@ledgerhq/coin-framework/serialization"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import { transactionToEthersTransaction } from "./adapters"; import ERC1155ABI from "./abis/erc1155.abi.json"; @@ -43,7 +43,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/coin-modules/coin-near/src/bridge.integration.test.ts b/libs/coin-modules/coin-near/src/bridge.integration.test.ts index 6da11872464c..7036c2195900 100644 --- a/libs/coin-modules/coin-near/src/bridge.integration.test.ts +++ b/libs/coin-modules/coin-near/src/bridge.integration.test.ts @@ -52,7 +52,6 @@ const near: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "near", - unitMagnitude: 24, lastSyncDate: "", balance: "47162281393064900000001", }, diff --git a/libs/coin-modules/coin-near/src/speculos-deviceActions.ts b/libs/coin-modules/coin-near/src/speculos-deviceActions.ts index b59ab8c6ae54..6e1036219c80 100644 --- a/libs/coin-modules/coin-near/src/speculos-deviceActions.ts +++ b/libs/coin-modules/coin-near/src/speculos-deviceActions.ts @@ -1,5 +1,5 @@ import * as nearAPI from "near-api-js"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types"; import type { Transaction } from "./types"; @@ -23,7 +23,7 @@ export const acceptTransaction: DeviceAction = deviceActionFlo button: SpeculosButton.RIGHT, expectedValue: ({ transaction, account }) => { if (transaction.mode === "stake") { - return formatCurrencyUnit(getAccountUnit(account), transaction.amount, { + return formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, { disableRounding: true, }); } @@ -35,7 +35,7 @@ export const acceptTransaction: DeviceAction = deviceActionFlo title: "Amount", button: SpeculosButton.RIGHT, expectedValue: ({ transaction, account }) => - formatCurrencyUnit(getAccountUnit(account), transaction.amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, { disableRounding: true, }), }, @@ -59,7 +59,7 @@ export const acceptTransaction: DeviceAction = deviceActionFlo return JSON.stringify({ amount: nearAPI.utils.format.parseNearAmount( - formatCurrencyUnit(getAccountUnit(account), transaction.amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, { disableRounding: true, }), ), diff --git a/libs/coin-modules/coin-near/src/transaction.ts b/libs/coin-modules/coin-near/src/transaction.ts index c0ae783ad0b6..5e244afdc1e9 100644 --- a/libs/coin-modules/coin-near/src/transaction.ts +++ b/libs/coin-modules/coin-near/src/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; export const formatTransaction = ( @@ -21,7 +21,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/coin-modules/coin-polkadot/src/bridge/formatters.ts b/libs/coin-modules/coin-polkadot/src/bridge/formatters.ts index 001ffef9c596..a07428747923 100644 --- a/libs/coin-modules/coin-polkadot/src/bridge/formatters.ts +++ b/libs/coin-modules/coin-polkadot/src/bridge/formatters.ts @@ -1,6 +1,6 @@ import invariant from "invariant"; import type { Operation } from "@ledgerhq/types-live"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; import { PolkadotAccount, PolkadotOperation, PolkadotResources } from "../types"; import type { Unit } from "@ledgerhq/types-cryptoassets"; @@ -38,7 +38,7 @@ function formatOperationSpecifics(op: Operation, unit: Unit | null | undefined): function formatAccountSpecifics(account: PolkadotAccount): string { const polkadotResources = account.polkadotResources as PolkadotResources; invariant(polkadotResources, "polkadot account expected"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/coin-modules/coin-polkadot/src/bridge/transaction.ts b/libs/coin-modules/coin-polkadot/src/bridge/transaction.ts index 076bf843a7c8..6b6d77fa8643 100644 --- a/libs/coin-modules/coin-polkadot/src/bridge/transaction.ts +++ b/libs/coin-modules/coin-polkadot/src/bridge/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index"; export const formatTransaction = ( @@ -21,7 +21,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/coin-modules/coin-polkadot/src/test/bridgeDatasetTest.ts b/libs/coin-modules/coin-polkadot/src/test/bridgeDatasetTest.ts index 0065ef991bc8..8095f7a0952d 100644 --- a/libs/coin-modules/coin-polkadot/src/test/bridgeDatasetTest.ts +++ b/libs/coin-modules/coin-polkadot/src/test/bridgeDatasetTest.ts @@ -63,7 +63,6 @@ const polkadot: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "polkadot", - unitMagnitude: 10, lastSyncDate: "", balance: "21000310", }, @@ -370,7 +369,6 @@ const polkadot: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "polkadot", - unitMagnitude: 10, lastSyncDate: "", balance: "11000000000", }, @@ -487,7 +485,6 @@ const polkadot: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "polkadot", - unitMagnitude: 10, lastSyncDate: "", balance: "11000000000", }, diff --git a/libs/coin-modules/coin-polkadot/src/types/bridge.fixture.ts b/libs/coin-modules/coin-polkadot/src/types/bridge.fixture.ts index 65a815c68e56..b845cc1977bb 100644 --- a/libs/coin-modules/coin-polkadot/src/types/bridge.fixture.ts +++ b/libs/coin-modules/coin-polkadot/src/types/bridge.fixture.ts @@ -50,7 +50,6 @@ export function createFixtureAccount(account?: Partial): Polkad creationDate: faker.date.past(), blockHeight: faker.number.int({ min: 100_000, max: 200_000 }), currency, - unit: currency.units[0], operationsCount: account?.operationsCount || 0, operations: account?.operations || [], pendingOperations: account?.pendingOperations || [], diff --git a/libs/ledger-live-common/src/__tests__/accounts/groupPerDay.ts b/libs/ledger-live-common/src/__tests__/accounts/groupPerDay.ts index fb7cc84055df..57359e03287c 100644 --- a/libs/ledger-live-common/src/__tests__/accounts/groupPerDay.ts +++ b/libs/ledger-live-common/src/__tests__/accounts/groupPerDay.ts @@ -172,7 +172,6 @@ const account = fromAccountRaw({ }, ], currencyId: "tezos", - unitMagnitude: 6, lastSyncDate: "2019-11-27T15:29:51.673Z", balance: "278000", spendableBalance: "278000", diff --git a/libs/ledger-live-common/src/__tests__/migration/account-migration.ts b/libs/ledger-live-common/src/__tests__/migration/account-migration.ts index ad39666a1831..e5453a8f5ac7 100644 --- a/libs/ledger-live-common/src/__tests__/migration/account-migration.ts +++ b/libs/ledger-live-common/src/__tests__/migration/account-migration.ts @@ -153,7 +153,6 @@ const getMockAccount = (currencyId: string, address: string): Account => { operations: [], currency, creationDate: new Date(0), - unit: currency.units[0], balance: new BigNumber(0), spendableBalance: new BigNumber(0), blockHeight: 0, diff --git a/libs/ledger-live-common/src/account/formatters.ts b/libs/ledger-live-common/src/account/formatters.ts index fc826161312f..17071731a965 100644 --- a/libs/ledger-live-common/src/account/formatters.ts +++ b/libs/ledger-live-common/src/account/formatters.ts @@ -1,7 +1,7 @@ import invariant from "invariant"; import { BigNumber } from "bignumber.js"; import { toAccountRaw } from "./serialization"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/coin-framework/account/index"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; import { getOperationAmountNumberWithInternals } from "../operation"; import { formatCurrencyUnit } from "../currencies"; import { getOperationAmountNumber } from "../operation"; @@ -20,7 +20,8 @@ const styling = { reverse: (str: string) => `\x1b[7m${str}\x1b[27m`, }; -const isSignificantAccount = acc => acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6)); +const isSignificantAccount = acc => + acc.balance.gt(10 ** (getAccountCurrency(acc).units[0].magnitude - 6)); const formatOp = ( unitByAccountId: (arg0: string) => Unit | null | undefined, @@ -77,7 +78,7 @@ const cliFormat = (account, level?: string) => { const { id, name, freshAddress, freshAddressPath, derivationMode, index, operations, nfts } = account; const tag = getTagDerivationMode(account.currency, derivationMode); - const balance = formatCurrencyUnit(account.unit, account.balance, { + const balance = formatCurrencyUnit(getAccountCurrency(account).units[0], account.balance, { showCode: true, }); const opsCount = `${operations.length}ops`; @@ -87,7 +88,11 @@ const cliFormat = (account, level?: string) => { tag ? " [" + tag + "]" : "" }: ${balance} (${opsCount}) (${freshInfo}) ${derivationInfo} ${id || ""}`; if (level === "head") return str; - str += maybeDisplaySumOfOpsIssue(operations, account.balance, getAccountUnit(account)); + str += maybeDisplaySumOfOpsIssue( + operations, + account.balance, + getAccountCurrency(account).units[0], + ); const family = byFamily[account.currency.family]; if (family && family.formatAccountSpecifics) { @@ -104,14 +109,14 @@ const cliFormat = (account, level?: string) => { " " + getDefaultAccountName(ta) + ": " + - formatCurrencyUnit(getAccountUnit(ta), ta.balance, { + formatCurrencyUnit(getAccountCurrency(ta).units[0], ta.balance, { showCode: true, disableRounding: true, }) + " (" + ta.operations.length + " ops)" + - maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountUnit(ta)), + maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountCurrency(ta).units[0]), ) .join("\n"); @@ -149,9 +154,9 @@ const cliFormat = (account, level?: string) => { .map( formatOp( id => { - if (account.id === id) return account.unit; + if (account.id === id) return getAccountCurrency(account).units[0]; const ta = subAccounts.find(a => a.id === id); - if (ta) return getAccountUnit(ta); + if (ta) return getAccountCurrency(ta).units[0]; console.error("unexpected missing token account " + id); }, (operation, unit) => { @@ -173,10 +178,10 @@ const stats = account => { (sum: BigNumber, op) => sum.plus(getOperationAmountNumberWithInternals(op)), new BigNumber(0), ); - const sumOfAllOps = formatCurrencyUnit(account.unit, sumOfAllOpsNumber, { + const sumOfAllOps = formatCurrencyUnit(getAccountCurrency(account).units[0], sumOfAllOpsNumber, { showCode: true, }); - const balance = formatCurrencyUnit(account.unit, account.balance, { + const balance = formatCurrencyUnit(getAccountCurrency(account).units[0], account.balance, { showCode: true, }); return { @@ -241,9 +246,9 @@ export function formatAccount(account: Account, format = "full"): string { export function formatOperation(account: Account | null | undefined): (arg0: Operation) => string { const unitByAccountId = (id: string) => { if (!account) return; - if (account.id === id) return account.unit; + if (account.id === id) return getAccountCurrency(account).units[0]; const ta = (account.subAccounts || []).find(a => a.id === id); - if (ta) return getAccountUnit(ta); + if (ta) return getAccountCurrency(ta).units[0]; }; const familyExtra = (operation, unit) => { diff --git a/libs/ledger-live-common/src/account/helpers.ts b/libs/ledger-live-common/src/account/helpers.ts index d0626d08ea74..dfa6a6be0c8d 100644 --- a/libs/ledger-live-common/src/account/helpers.ts +++ b/libs/ledger-live-common/src/account/helpers.ts @@ -6,7 +6,6 @@ import { CosmosAccount } from "../families/cosmos/types"; import { getMainAccount, getAccountCurrency, - getAccountUnit, getFeesCurrency, getFeesUnit, getAccountSpendableBalance, @@ -35,7 +34,6 @@ import { export { getMainAccount, getAccountCurrency, - getAccountUnit, getFeesCurrency, getFeesUnit, getAccountSpendableBalance, diff --git a/libs/ledger-live-common/src/bot/formatters.ts b/libs/ledger-live-common/src/bot/formatters.ts index 5786dda278c7..34be74a6098e 100644 --- a/libs/ledger-live-common/src/bot/formatters.ts +++ b/libs/ledger-live-common/src/bot/formatters.ts @@ -67,7 +67,7 @@ export function formatReportForConsole({ } if (account && maxSpendable) { - str += `max spendable ~${formatCurrencyUnit(account.unit, maxSpendable)}\n`; + str += `max spendable ~${formatCurrencyUnit(account.currency.units[0], maxSpendable)}\n`; } if (unavailableMutationReasons) { diff --git a/libs/ledger-live-common/src/bridge/mockHelpers.ts b/libs/ledger-live-common/src/bridge/mockHelpers.ts index 0129c0baab21..264235d06ab9 100644 --- a/libs/ledger-live-common/src/bridge/mockHelpers.ts +++ b/libs/ledger-live-common/src/bridge/mockHelpers.ts @@ -132,7 +132,6 @@ export const scanAccounts: CurrencyBridge["scanAccounts"] = ({ currency }) => operationsSize: isLast ? 0 : 100, currency, }); - account.unit = currency.units[0]; account.index = i; account.operations = isLast ? [] diff --git a/libs/ledger-live-common/src/exchange/swap/getExchangeRates.ts b/libs/ledger-live-common/src/exchange/swap/getExchangeRates.ts index bd70c1d6408d..56eb4c391b5b 100644 --- a/libs/ledger-live-common/src/exchange/swap/getExchangeRates.ts +++ b/libs/ledger-live-common/src/exchange/swap/getExchangeRates.ts @@ -1,7 +1,7 @@ import network from "@ledgerhq/live-network/network"; import type { Unit } from "@ledgerhq/types-cryptoassets"; import { BigNumber } from "bignumber.js"; -import { getAccountCurrency, getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { SwapExchangeRateAmountTooHigh, @@ -25,9 +25,10 @@ const getExchangeRates: GetExchangeRates = async ({ if (isIntegrationTestEnv()) return mockGetExchangeRates(exchange, transaction, currencyTo); const from = getAccountCurrency(exchange.fromAccount).id; - const unitFrom = getAccountUnit(exchange.fromAccount); + const unitFrom = getAccountCurrency(exchange.fromAccount).units[0]; const to = (currencyTo ?? getAccountCurrency(exchange.toAccount)).id; - const unitTo = (currencyTo && currencyTo.units[0]) ?? getAccountUnit(exchange.toAccount); + const unitTo = + (currencyTo && currencyTo.units[0]) ?? getAccountCurrency(exchange.toAccount).units[0]; const amountFrom = transaction.amount; const tenPowMagnitude = new BigNumber(10).pow(unitFrom.magnitude); const apiAmount = new BigNumber(amountFrom).div(tenPowMagnitude); diff --git a/libs/ledger-live-common/src/exchange/swap/hooks/v5/useFetchRates.ts b/libs/ledger-live-common/src/exchange/swap/hooks/v5/useFetchRates.ts index aafc9699a773..f567479abcce 100644 --- a/libs/ledger-live-common/src/exchange/swap/hooks/v5/useFetchRates.ts +++ b/libs/ledger-live-common/src/exchange/swap/hooks/v5/useFetchRates.ts @@ -1,6 +1,6 @@ import { getAvailableProviders } from "../.."; import { AccountLike } from "@ledgerhq/types-live"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/coin-framework/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers"; import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets"; import BigNumber from "bignumber.js"; import { fetchRates } from "../../api/v5/fetchRates"; @@ -22,7 +22,9 @@ export function useFetchRates({ onSuccess, }: Props) { const currencyFrom = fromCurrencyAccount ? getAccountCurrency(fromCurrencyAccount).id : undefined; - const unitFrom = fromCurrencyAccount ? getAccountUnit(fromCurrencyAccount) : undefined; + const unitFrom = fromCurrencyAccount + ? getAccountCurrency(fromCurrencyAccount).units[0] + : undefined; const unitTo = toCurrency?.units[0]; const moonpayFF = useFeature("ptxSwapMoonpayProvider"); const formattedCurrencyAmount = diff --git a/libs/ledger-live-common/src/exchange/swap/initSwap.ts b/libs/ledger-live-common/src/exchange/swap/initSwap.ts index 98ad10175314..9637b67b0728 100644 --- a/libs/ledger-live-common/src/exchange/swap/initSwap.ts +++ b/libs/ledger-live-common/src/exchange/swap/initSwap.ts @@ -12,7 +12,7 @@ import invariant from "invariant"; import { Observable, firstValueFrom, from } from "rxjs"; import secp256k1 from "secp256k1"; import { getCurrencyExchangeConfig } from "../"; -import { getAccountCurrency, getAccountUnit, getMainAccount } from "../../account"; +import { getAccountCurrency, getMainAccount } from "../../account"; import { getAccountBridge } from "../../bridge"; import { getEnv } from "@ledgerhq/live-env"; import { @@ -63,7 +63,7 @@ const initSwap = (input: InitSwapInput): Observable => { const { fromParentAccount, fromAccount, toParentAccount, toAccount } = exchange; const { amount } = transaction; const refundCurrency = getAccountCurrency(fromAccount); - const unitFrom = getAccountUnit(exchange.fromAccount); + const unitFrom = getAccountCurrency(exchange.fromAccount).units[0]; const payoutCurrency = getAccountCurrency(toAccount); const refundAccount = getMainAccount(fromAccount, fromParentAccount); const payoutAccount = getMainAccount(toAccount, toParentAccount); diff --git a/libs/ledger-live-common/src/exchange/swap/mock.ts b/libs/ledger-live-common/src/exchange/swap/mock.ts index c7d94bdbfd54..48b90b1d2d3f 100644 --- a/libs/ledger-live-common/src/exchange/swap/mock.ts +++ b/libs/ledger-live-common/src/exchange/swap/mock.ts @@ -1,6 +1,6 @@ import { BigNumber } from "bignumber.js"; import { Observable, of } from "rxjs"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { SwapExchangeRateAmountTooHigh, SwapExchangeRateAmountTooLow } from "../../errors"; import type { @@ -22,8 +22,8 @@ export const mockGetExchangeRates = async ( ): Promise<(ExchangeRate & { expirationDate?: Date })[]> => { const { fromAccount, toAccount } = exchange; const amount = transaction.amount; - const unitFrom = getAccountUnit(fromAccount); - const unitTo = (currencyTo && currencyTo.units[0]) ?? getAccountUnit(toAccount); + const unitFrom = getAccountCurrency(fromAccount).units[0]; + const unitTo = (currencyTo && currencyTo.units[0]) ?? getAccountCurrency(toAccount).units[0]; const tenPowMagnitude = new BigNumber(10).pow(unitFrom.magnitude); const amountFrom = amount.div(tenPowMagnitude); const minAmountFrom = new BigNumber(0.0001); diff --git a/libs/ledger-live-common/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap index a5fd96d75465..f4f3d253ecb0 100644 --- a/libs/ledger-live-common/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap @@ -21,7 +21,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q", }, @@ -110,7 +109,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "EGZQNDFCXGR3BMP4NDM6ZPLBMY7WSV6GRKOHM6VBJKFLWQ3RQDTE3JYNFE", }, @@ -133,7 +131,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "ZQVVJ2S4XWS542KXBBVIINOEHIDOEZKZWK725PWFNN2I5RNCUBI53RT2EY", }, @@ -156,7 +153,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "MECOWMKPKH2NWVZTS5V5RQDGFFYBT25KNLOPHG2KUMMNKU6FOHGJT24WBI", }, @@ -190,7 +186,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "MVE6C3XB4JBKXKORC3NLAWFW4M7EY3MADU6L72DADFP4NZBJIAYXGSLN3Y", }, diff --git a/libs/ledger-live-common/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap index 8ec3582e9167..f05def22c3c2 100644 --- a/libs/ledger-live-common/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap @@ -20,7 +20,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DEHKg8fgKcb5iYGPLtpBYD9gm7nvym3wwhHVnH3TtogvJGTcApj71K8iTpL7CzdZWAxwyjkZEFUrnLK24zKqgj3EVH7Vg1CD1ujibwiHuy", }, @@ -42,7 +41,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DEHKg8fgKcb9at2u9Xhjtx4tXGyWqUPQAx2zNCzr41gQRyCqpCn7onSoJU4VS96GXyCtAhhFxErnG2pGVvVexaqF7DEfqGGnGk7Havn7C2", }, @@ -64,7 +62,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6DEHKg8fgKcbC7ZzoayZKxpDs8PYag9aBvXLhpvZhag3DT2nU5PwLE6xaineM5jciavwNYGUZrdSTcktK6Xu9odBYXN6K2zeou479HUcbsc", }, @@ -86,7 +83,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6BvkrmBTnBQMW1tBLgY2H6itSqFh9xGAYLGtR8PsKi762NghTQVUkv5gJ3osjMzaqqcfpKgHm2ov7N67A6njxLG8RSU8WwLVN4F596cDmp6", }, @@ -108,7 +104,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CKb86o7RHSCxuwP5dnxyDySLbnVWypQUxhWpycFZWFTzXuXy3UgGtG3o51oGER6X2UY6zRqd5AXgzNghb9va1FkfzXz6k1RT6EwTwCKejE", }, @@ -130,7 +125,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CKb86o7RHSD1tDBFKwPgEZ5Q83gnRPG7Bs5HzBRUxcm4dvLEPnSTWP8C7c4P71GgMCk1Fw6xS6Ki4XC6bGAQcxE8gc9KJHXzQnErDtwTa6", }, @@ -152,7 +146,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6CKb86o7RHSD4ZhRxHBtCWgL2J5MJYrVdurKFkdChDPjLpUt7EpvrsoCaBRCD78Qo7ith2DeCqonWinReuXMfs2bqJiLkcoE4VcwvkvUzEJ", }, @@ -174,7 +167,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn", }, @@ -196,7 +188,6 @@ exports[`bitcoin currency bridge scanAccounts bitcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6BuPWhjLqutPY3pENUxwkG3NAQfjLxoHMTAkwzH13rZSzkymZrbKui1MN3KgwiNFsH4AyLM3GkodNo4bTxQXE1kvZiruVUtJLe1bMW1MBBJ", }, @@ -11385,7 +11376,6 @@ exports[`bitcoin_cash currency bridge scanAccounts bitcoin_cash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn", }, @@ -11407,7 +11397,6 @@ exports[`bitcoin_cash currency bridge scanAccounts bitcoin_cash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6D7pqJa4V3SFSigcsRaFL2mpfG7469osrMkk4ieR2uk8y1v3nuQUD8W8v36PLWQtVRSggSQM7jLpGNKH7sqCaoPSJEp9wZCVkRnMWoiUUXa", }, @@ -11429,7 +11418,6 @@ exports[`bitcoin_cash currency bridge scanAccounts bitcoin_cash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6D7pqJa4V3SFVc2TjqQaz1N6gCs5vTjznBSAyEE9es1j5nTb2uKXbihXQuaUURKJ59hEVQZctuCSC8t1MURbeiSmZFDTBsJ9QJCS5crNrBG", }, @@ -13957,7 +13945,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn", }, @@ -13979,7 +13966,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CKb86o7RHSCxuwP5dnxyDySLbnVWypQUxhWpycFZWFTzXuXy3UgGtG3o51oGER6X2UY6zRqd5AXgzNghb9va1FkfzXz6k1RT6EwTwCKejE", }, @@ -14001,7 +13987,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CtTgvCAvB8VFH5iab8qc8GcXAQ3qfBGEJkedBrEH414ND1mpFzp6PhQP5m74Uzqb4o51KnXYK6KEiL51XbrwYa6WE1jxzwuCQa7GV88MHa", }, @@ -14023,7 +14008,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6CtTgvCAvB8VJZVpJsSueoPyDoWwXtQf1P49q3kTaSoCe6ELeGtyJVtQ9qikkuPyTUrm5MpN2yw2Muhyd2tWnazehh6616Gajsp4FqwsisA", }, @@ -14045,7 +14029,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6C5kqm418Wut5RFaiKvcBznC1MC6oHi6G8RZ1xRVbQbNDSkpUTzkgZ9Z43RtC5ptHBV3AMqycVS2tHhmmxmqWorswc3796CMHTSCg5AJXnx", }, @@ -14067,7 +14050,6 @@ exports[`bitcoin_gold currency bridge scanAccounts bitcoin_gold seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6C5kqm418Wut6kFDfmmLTnHvyBCLjJJYyvDmDJW8dzLVZ93Y9rWrjuUp4iecWCFUqLNiLF28awmMngyCQ7c4WywHsWKZ1VEbd66UP5uFTx6", }, @@ -14797,7 +14779,6 @@ exports[`dash currency bridge scanAccounts dash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "drkvjRicQKXd21b4fiTjSfm4SMoVE5q6DhCopUQ4pBYU9WT1dTVSUHoF91sfFkfgR9MdXqiPGgpNV45VrGFrVfVGn8vH7jroquD34qyYuHbj6Dk", }, @@ -14819,7 +14800,6 @@ exports[`dash currency bridge scanAccounts dash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "drkvjRicQKXd21b4iYXbeKjiBPLHQyqeriXcjUL6HxiLnMbLkC6w2teZTgxpjSv4tZ4gq5KrNan9c9aPtrkUhRF3aBQa4vr3WGy6z1WwQh5GB7W", }, @@ -14841,7 +14821,6 @@ exports[`dash currency bridge scanAccounts dash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "drkvjRicQKXd21b4iybA3Ujpe4BxxrvMPEBs5W1vrHeGK4tFU6uZixaCzJ8Jq4C3yXdKmMnW45JvZ6nnuzSBevrtvh9GdRU6soFJhgGHBKtwboC", }, @@ -15841,7 +15820,6 @@ exports[`decred currency bridge scanAccounts decred seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "dpubZFDVCCdFkBeuZXSf8dL49fG3zb6vqnE7wLixKRiHpiCAirvNh53N28DAHmqybRLgCZMgVDgrFBrTqNZZJppZ8QgDqxY6vtD4aJ1nNjUYnhT", }, @@ -15863,7 +15841,6 @@ exports[`decred currency bridge scanAccounts decred seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "dpubZFDVCCdFkBeubksrzFQXDzcn7nVB3uFKUAj17LfCijBm4SyCTPb2mbAbYqtrotmWjiZPigWTEePwzgXLUx1fT2UN6n5NfC2WtBPx7e3pAhN", }, @@ -15885,7 +15862,6 @@ exports[`decred currency bridge scanAccounts decred seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "dpubZFDVCCdFkBeufRYVfDcs6YcRsGkepqD2uyJk8DDxhsjSo1TETDoxjqY9fdoYjBU2W93Sdxyy1vVj4vzJTiKuLBEAUSpPTDU1jVGoq1oX8f1", }, @@ -15907,7 +15883,6 @@ exports[`decred currency bridge scanAccounts decred seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "dpubZFDVCCdFkBeufxc7PWg8o1L6oBJKRk7wUhNMLDDm1Pxg9D9eyCR3EB6kas2Uuqwx6236oauPDLQ5r5AwPS43Byt7UPbgeiZ2oxZ97sGmA6S", }, @@ -20771,7 +20746,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CV98T6ompjUmKuMaULsw4UP8yfnVCg6831rWdcPjScn6RaGWrt3b7uvTpt9hcq6tLtS1dGNzeJ9x4NpVGzLq7CFscxCdoPZ6zxkqGymx98", }, @@ -20793,7 +20767,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6CV98T6ompjUo2YMbNNwkK6t2xQ9ZMihM54xFopW9896ztmAA6haNfNFuFQY3JLrCmKUAdRbYn1sqUUN7aVSVBPRqCdYX9uoroNUWTLFUU1", }, @@ -20815,7 +20788,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CU9cUEYPkHVCSCuHWM9g7TxhmXByzPJGU3k9W588wNearJ1xjPjS5PW3fkYUaYRHgkaFx352YQTyWwZD7qbR8yMaac6K8UeV9XjydgBnkv", }, @@ -20837,7 +20809,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CU9cUEYPkHVFw3jvQ3epUkHpqpN7NS9eFFbS57WynDvmzqcBtdAY5uvaLCS7QakFN7uJiQLWLZz56tPAwqQq8LFXqorVMgK9r4Ev2Sg2Eu", }, @@ -20859,7 +20830,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6CU9cUEYPkHVHnMTPxCWhA59f6GbHCrop6j1RXbZKFZg8ES9eCamW26rWEji2zmXhRBLc2xxTVcD7qxKHKe99XyWwn4udqDBeTzRysURXRR", }, @@ -20881,7 +20851,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DUeEdRmKaQSJnJBJURNcg4ss2fsjQvPFLkgQdmDsJ6aH9FJjurpgt3jxMbs2n3ctHsDYztMWiZ7H27wLRevnkFggwK8HVyKZf5Kij3PjuG", }, @@ -20903,7 +20872,6 @@ exports[`digibyte currency bridge scanAccounts digibyte seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6DUeEdRmKaQSNaZhYGoVZBaP42H4hCNdJTpQzFztxBiqfD1GMCds4v8LENpHYCTU1Am9NDVmswJkNrahKpQ24GTBugvqzCgk9aUNUEYMtFj", }, @@ -22650,7 +22618,6 @@ exports[`dogecoin currency bridge scanAccounts dogecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "dgub8rBqrhN2grbuDNuFBCu9u9KQKgQmkKaa15Yvnf4YznmvqFZByDPJypigogDKanefhrjj129Ek1W13zvtyQSD6HDpzxyskJvU6xmhD29S9eF", }, @@ -22672,7 +22639,6 @@ exports[`dogecoin currency bridge scanAccounts dogecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "dgub8rBqrhN2grbuFeMR47KiFwZWqV6A6kmKQ5F73eKwpLqT8Wmj7P4gmuAUbEHJxVr5qkfaUN2kmYsD4pPTQbkUtTqk7dtpGcWWTLC7F1ACS1u", }, @@ -22694,7 +22660,6 @@ exports[`dogecoin currency bridge scanAccounts dogecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "dgub8rBqrhN2grbuGtVSoWKrKi97gHrA1eV6XQtR9AKFgG2BP3pQ12ncpkTBPmKGSU7xTd28RpYZFkUryG9PBFStcdCuHVCtAfLmi8NhTF8PRGY", }, @@ -23336,7 +23301,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "Ltub2ZDyeYFtDj5kHy4w5WaXBDE9217rNDYfmv7u5NV8dk8vKdmkqAfPdwRma5rkPcj5daMU8JiiLXQYPX9rtqEzrK1YrmkofcpADTV7s5FgzLF", }, @@ -23358,7 +23322,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "Ltub2ZDyeYFtDj5kL5kYEcBGiDwhXQtZNefG3k4XvAtoMfD5cHxa93WMr6zLGnLb11LCgUXpxWTZRVPv2Roh2vdxesTpgFYayeNNVJb7wmCfD3x", }, @@ -23380,7 +23343,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "Ltub2ZoEDG8AmPfD8oGoFEvfsKWjeyiXh6TiKYjgLnoVxfeECfQteY6sDF1AuH1iW6ekue2PSwdbbvG2NpFPzLqcgNgteHZPNo6zGthjcAmwxT3", }, @@ -23402,7 +23364,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "Ltub2ZoEDG8AmPfDAyu3yK2WfA9zE8VgL3E3nNjnS5VRYAo7LfrrEmaCUYqWP8tgo6vNWc7dsr3kDykaX7yDpkAN93RWorZG6tekiyNpBNtFJhc", }, @@ -23424,7 +23385,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "Ltub2ZoEDG8AmPfDCKLYi3GHWexWa26tL5G4QvPkYgdRNKFKLsDe1i3rzjSZiBYDpYnkgQn9T8GRRJTXF8rdG6NXyWR9wTzATChRQbixYxnjKBg", }, @@ -23446,7 +23406,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "Ltub2YRPRjnvZVoBBbfDrEV3jJdGQCTMHgKg1V1mnAZuQbbSY6XPhufcRTpoGB4595dUuW1GSDy6CApUYmCfwA4YjG5JWrAFd4GBR1WRJ8Jm6cM", }, @@ -23468,7 +23427,6 @@ exports[`litecoin currency bridge scanAccounts litecoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "Ltub2YRPRjnvZVoBD5RZpkoyuuiSPJdHS8jeDksZHPtt5RraJFHLDSRdobd1gfBrPKZHx1Nag5nUBuuA95LkNMXbZ6fnFHCotsewEdqccigYadD", }, @@ -25636,7 +25594,6 @@ exports[`peercoin currency bridge scanAccounts peercoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "r29uBq4dqT4ZLPtkuN51ASxXHAuSmY4QEqvYKPjj8kBNvdpcc4wRvhTPDoLmUj1qx1UbwS32DgsKkRPdgjrwNdWrHiSDjH7hBeqiEmGi79xEZNBt", }, @@ -25658,7 +25615,6 @@ exports[`peercoin currency bridge scanAccounts peercoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "r29uBq4dqT4ZLPtkuP4N8ms3jx8ts6zcfHMNNZUJhMqo1DgJpWSfFiwYwZb3uQYaHya6LSWNfALUxQwdFw3ZZEoB2DCKYK2QqBp5VbaZbo9FHbbv", }, @@ -25680,7 +25636,6 @@ exports[`peercoin currency bridge scanAccounts peercoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "r29uBq4dqT4ZLPtkuRYpvqYJ7Uri474wVJSGfCBycWK88JbhoE31jzYQrxa4re5gRRjdK52fYte1wR6Gjo3KsnMGk1JNqELQoema8GaWRcX4Tp3c", }, @@ -25902,7 +25857,6 @@ exports[`pivx currency bridge scanAccounts pivx seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "ToEA6kbZp37Q14yj3MBi989NwAtYpRezRAveGjoQtrBNenh5w5D8AAU3pQFHk3bd7YRXgQ86JoXBZHm8voQeCNJX4ETH7WdGGcfD35CsCEgQjih", }, @@ -25924,7 +25878,6 @@ exports[`pivx currency bridge scanAccounts pivx seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "ToEA6kbZp37Q14yj58Etmammo9PZzJApeRsUnjSqri7fugNHm29Z8XHyhs1qePUKDUkrBD51sAwqD6HjFx3Z81S4djrYPrxKJssLrekhh2j2rpT", }, @@ -25946,7 +25899,6 @@ exports[`pivx currency bridge scanAccounts pivx seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "ToEA6kbZp37Q14yj8uQJcgxNYNLfh77mCkRc5WYNKnFXz9F7ioREkssDvZtYm6haAQc3xEgMhTLT6TMHKzEVX4HLudaACbipsLTvnthw2KUUhTf", }, @@ -26351,7 +26303,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6CcxPiPTCZz31AAqNayf5M4yJWGwe3LCsLASDyDVvVaorfjibtEDaRGA2vRDCr9XwD7zF2KyDuru2MxsbzzqoEHdvQpqGAKQhRY9jCGLu3a", }, @@ -26373,7 +26324,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6C1k89xbMPhSU8SLMTtcf8nbyZ3aEer86VnXNVZLkczoRKvfvLcA2Hp8gBJWZSM8UaDYaEpyxN1hqseTJ99tXt4QPxKPNNpVucgrjWPhMbj", }, @@ -26395,7 +26345,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6Cvus6TFyZpqAXyw3PZchE4e6aotv5DpG2JzSUgrAaWq568T6E68CitHvAoGS7P2ey5n6D92brXCdeMFU6YZyhypZYiMddGFgWe7ovwxNAK", }, @@ -26417,7 +26366,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6Cvus6TFyZpqBdZMUVoDaX8aVh3jok6tNKLmyf9sYg1TByCEHNwWPzRwLmssQ6reLV1aZaKQv9XL3KQ9ery6SBcppNdAvqGh72dF1AdYQso", }, @@ -26439,7 +26387,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6BgVHiD3Go6yH6fBUXQfHHdBsb6Xkm5XswQid7ZF5xhh3udDP7MKUKBpREoLJt7dkwcvpPGo3h5DkCqsjVCZvPTkeRgxJRmab3bpv9k15pc", }, @@ -26461,7 +26408,6 @@ exports[`vertcoin currency bridge scanAccounts vertcoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6BgVHiD3Go6yLzjPsBg2M1VwwK6CTvgGQV1DCWVZ9sCiK63bkaio7EYnEEqyfqEH2uq8V99TWbrc7zXNgy3ju5N6XDN2GHrbHnDhBGpD9hJ", }, @@ -27032,7 +26978,6 @@ exports[`viacoin currency bridge scanAccounts viacoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DXFhSSckkAXA8y3fxCxv6TW7PhTubEk5r9UoXiJJEbzzhDjWaH8qxEDED9nA751pz3iAPc1HVXe8LpiotsqUfDRvf8JiQdEewFtyNyR6Vz", }, @@ -27054,7 +26999,6 @@ exports[`viacoin currency bridge scanAccounts viacoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6DXFhSSckkAXEDj2tdsRZ9hffq6BkcyJM8zCeZ6zA4S71pqnUZCKWFNnzWMuQ7iYNFkDB3aSJnh5CQCRD26iFZfDs8zo1bnU6MVtYxNxSdd", }, @@ -27076,7 +27020,6 @@ exports[`viacoin currency bridge scanAccounts viacoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6BvPb5yXV4aMKokGgameLTA36UzHykjCZo5Vcrmr2PFxutPhvfbzkr6LpD6vXkm5A611mYA2m4TnZYHHSZjxRZsadDCXfwDqxc3d7BZTqwW", }, @@ -27098,7 +27041,6 @@ exports[`viacoin currency bridge scanAccounts viacoin seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6BvPb5yXV4aMNvoWDVF2SNqbhYN3puWm9PCwbEF4XxgnkSnHxfiHTEfy76u8atjEvcGwMxqpTE5rjYw3c3nxF44Nvok8XskpBEJyTfVXxip", }, @@ -27576,7 +27518,6 @@ exports[`zcash currency bridge scanAccounts zcash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DXuLL97nvCs14Ashf3u8N2X9BLBpxN3HKCQWnLzn61o6CqME3Jm1hZ6oBeXcMhkqGDaziTGmw19w5iRstuXJrKLX6khbDt1rEatozTkf97", }, @@ -27598,7 +27539,6 @@ exports[`zcash currency bridge scanAccounts zcash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DXuLL97nvCs4QQNEeUwxH6Y5tSVhSEPcdnQ3K2pa8CfnbZuHcpeZovTSMu6jdj6JV9piQyVsHoNSYuP8MijXdYKHGFYvPoLLy3Ddrv5MPi", }, @@ -27620,7 +27560,6 @@ exports[`zcash currency bridge scanAccounts zcash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6DXuLL97nvCs4gn5uhL5hngT77sZRgrPKE1wDzxtN73mcmTQKFnHb2yAahvnoT3QCeSzxakpFMGxxY9d4ozgAKWzGtK31VP3v2vciXyVtEP", }, @@ -27642,7 +27581,6 @@ exports[`zcash currency bridge scanAccounts zcash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6DXuLL97nvCs84Bu7dzut6oWXsSADKfHtoBvHQqpejzzfEy8TMu5WNuzz6bdhcjY3u8B4noZTkDho8wue49P6HogYitm64dyQpLJti8aEDb", }, @@ -31496,7 +31434,6 @@ exports[`zencash currency bridge scanAccounts zencash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6D5t3ggLE75WLn8cMhJ6V5tdZsT5ixJDjoYrERnYgkjXe5f2qqBBsjCLJ4ktGeorZBrSwQZ6tRqmmu9CM5fpi6S7n1T6VMxitE4LnXBStue", }, @@ -31518,7 +31455,6 @@ exports[`zencash currency bridge scanAccounts zencash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "xpub6D5t3ggLE75WMZywf9sHZtBZcgdQTvVorb4U6YiYBSZrWiPZsB7JjjyMfyM7KiSQMwc87BLZSi8wXgoRvMZHVACMF7CBE3B77NN314ZKWuA", }, @@ -31540,7 +31476,6 @@ exports[`zencash currency bridge scanAccounts zencash seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "xpub6D5t3ggLE75WQGWU8XaFEiYXbgQFJD3u6eyN1Yb7gcRu4Gan7uKEwqaCBoRhFs73nN1Kf51D5W7kx6TRLpDmwWgeDEk6mghh4gPA3BZbNvg", }, diff --git a/libs/ledger-live-common/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap index b206482647e0..f2161cb725a4 100644 --- a/libs/ledger-live-common/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap @@ -766,7 +766,6 @@ exports[`cardano_testnet currency bridge scanAccounts cardano_testnet seed 1 1`] "subAccounts": [], "swapHistory": [], "syncHash": "["ethereum/erc20/ampleforth","ethereum/erc20/steth"]_0", - "unitMagnitude": 6, "used": true, "xpub": "806499588e0c4a58f4119f7e6e096bf42c3f774a528d2acec9e82ceebf87d1ceb3d4f3622dd2c77c65cc89c123f79337db22cf8a69f122e36dab1bf5083bf82d", }, @@ -1415,7 +1414,6 @@ exports[`cardano_testnet currency bridge scanAccounts cardano_testnet seed 1 1`] "subAccounts": [], "swapHistory": [], "syncHash": "["ethereum/erc20/ampleforth","ethereum/erc20/steth"]_0", - "unitMagnitude": 6, "used": false, "xpub": "ed5e0d059cb2eed53ea30b9ba84bb3aaa6c2364c6305a0c9a7e8944aa439884a642cc2f06e601808926e14b6e27417be0b0323d5a5149f1eebab8fc4e1fe14d4", }, diff --git a/libs/ledger-live-common/src/families/cardano/account.ts b/libs/ledger-live-common/src/families/cardano/account.ts index af15571311b3..3d47541e1c57 100644 --- a/libs/ledger-live-common/src/families/cardano/account.ts +++ b/libs/ledger-live-common/src/families/cardano/account.ts @@ -1,5 +1,5 @@ import invariant from "invariant"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { CardanoAccount } from "./types"; @@ -7,7 +7,7 @@ export function formatAccountSpecifics(account: CardanoAccount): string { const { cardanoResources } = account; invariant(cardanoResources, "cardano account expected"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/ledger-live-common/src/families/cardano/datasets/rawAccount.1.ts b/libs/ledger-live-common/src/families/cardano/datasets/rawAccount.1.ts index b44e84f790ea..4b86cc077f56 100644 --- a/libs/ledger-live-common/src/families/cardano/datasets/rawAccount.1.ts +++ b/libs/ledger-live-common/src/families/cardano/datasets/rawAccount.1.ts @@ -13,7 +13,6 @@ export const cardanoRawAccount1: AccountRaw = { operations: [], pendingOperations: [], currencyId: "cardano_testnet", - unitMagnitude: 6, lastSyncDate: "", balance: "10098829375", xpub: "806499588e0c4a58f4119f7e6e096bf42c3f774a528d2acec9e82ceebf87d1ceb3d4f3622dd2c77c65cc89c123f79337db22cf8a69f122e36dab1bf5083bf82d", diff --git a/libs/ledger-live-common/src/families/cardano/deviceTransactionConfig.ts b/libs/ledger-live-common/src/families/cardano/deviceTransactionConfig.ts index 90ff9dff4272..f12a40470cc2 100644 --- a/libs/ledger-live-common/src/families/cardano/deviceTransactionConfig.ts +++ b/libs/ledger-live-common/src/families/cardano/deviceTransactionConfig.ts @@ -1,5 +1,5 @@ import BigNumber from "bignumber.js"; -import { getAccountUnit, getMainAccount } from "../../account"; +import { getAccountCurrency, getMainAccount } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { DeviceTransactionField } from "../../transaction"; import { Account, AccountLike } from "@ledgerhq/types-live"; @@ -33,7 +33,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Transaction Fee", - value: formatCurrencyUnit(getAccountUnit(account), fees, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], fees, { showCode: true, disableRounding: true, }), @@ -61,10 +61,14 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "ADA", - value: formatCurrencyUnit(getAccountUnit(mainAccount), requiredMinAdaForTokens, { - showCode: true, - disableRounding: true, - }), + value: formatCurrencyUnit( + getAccountCurrency(mainAccount).units[0], + requiredMinAdaForTokens, + { + showCode: true, + disableRounding: true, + }, + ), }); fields.push({ type: "text", @@ -74,7 +78,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), transactionAmount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], transactionAmount, { showCode: true, disableRounding: true, }), @@ -83,7 +87,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), transaction.amount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, { showCode: true, disableRounding: true, }), diff --git a/libs/ledger-live-common/src/families/cardano/transaction.ts b/libs/ledger-live-common/src/families/cardano/transaction.ts index 562ba0dfbe7d..1de02c277f3a 100644 --- a/libs/ledger-live-common/src/families/cardano/transaction.ts +++ b/libs/ledger-live-common/src/families/cardano/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import type { Account } from "@ledgerhq/types-live"; @@ -25,7 +25,7 @@ export const formatTransaction = ( : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/casper/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/casper/__snapshots__/bridge.integration.test.ts.snap index b6f9f1d9d1d2..9f3e2c645be6 100644 --- a/libs/ledger-live-common/src/families/casper/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/casper/__snapshots__/bridge.integration.test.ts.snap @@ -19,7 +19,6 @@ exports[`casper currency bridge scanAccounts casper seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 9, "used": true, }, { @@ -39,7 +38,6 @@ exports[`casper currency bridge scanAccounts casper seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 9, "used": true, }, { @@ -59,7 +57,6 @@ exports[`casper currency bridge scanAccounts casper seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 9, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/casper/bridge.integration.test.ts b/libs/ledger-live-common/src/families/casper/bridge.integration.test.ts index ef7798449764..3a2668387d8d 100644 --- a/libs/ledger-live-common/src/families/casper/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/casper/bridge.integration.test.ts @@ -43,7 +43,6 @@ const casper: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "casper", - unitMagnitude: 9, lastSyncDate: "", balance: "1000", }, diff --git a/libs/ledger-live-common/src/families/casper/transaction.ts b/libs/ledger-live-common/src/families/casper/transaction.ts index 85c389660968..67a71108235e 100644 --- a/libs/ledger-live-common/src/families/casper/transaction.ts +++ b/libs/ledger-live-common/src/families/casper/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import BigNumber from "bignumber.js"; @@ -21,7 +21,7 @@ SEND ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/celo/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/celo/__snapshots__/bridge.integration.test.ts.snap index 94436feaceaa..d9e4f77b7831 100644 --- a/libs/ledger-live-common/src/families/celo/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/celo/__snapshots__/bridge.integration.test.ts.snap @@ -46,7 +46,6 @@ exports[`celo currency bridge scanAccounts Celo 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, }, { @@ -76,7 +75,6 @@ exports[`celo currency bridge scanAccounts Celo 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/celo/datasets/celo.scanAccounts.1.ts b/libs/ledger-live-common/src/families/celo/datasets/celo.scanAccounts.1.ts index 739356408f12..c2221dde773d 100644 --- a/libs/ledger-live-common/src/families/celo/datasets/celo.scanAccounts.1.ts +++ b/libs/ledger-live-common/src/families/celo/datasets/celo.scanAccounts.1.ts @@ -50,7 +50,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "celo", - unitMagnitude: 18, lastSyncDate: "", balance: "399893159500000000", celoResources: { @@ -340,7 +339,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "celo", - unitMagnitude: 18, lastSyncDate: "", balance: "399893159500000000", celoResources: { diff --git a/libs/ledger-live-common/src/families/celo/transaction.ts b/libs/ledger-live-common/src/families/celo/transaction.ts index 995a3e70dbd9..ff5c9234d988 100644 --- a/libs/ledger-live-common/src/families/celo/transaction.ts +++ b/libs/ledger-live-common/src/families/celo/transaction.ts @@ -7,14 +7,14 @@ import { toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { Account } from "@ledgerhq/types-live"; export const formatTransaction = (t: Transaction, account: Account): string => ` SEND ${ t.useAllAmount ? "MAX CELO" - : formatCurrencyUnit(getAccountUnit(account), t.amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], t.amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/cosmos/banner.test.ts b/libs/ledger-live-common/src/families/cosmos/banner.test.ts index 70dc4a783f08..23f7215a84d9 100644 --- a/libs/ledger-live-common/src/families/cosmos/banner.test.ts +++ b/libs/ledger-live-common/src/families/cosmos/banner.test.ts @@ -42,7 +42,6 @@ const account: CosmosAccount = { operations: [], operationsCount: 1, pendingOperations: [], - unit: { name: "Atom", code: "ATOM", magnitude: 6 }, currency: { type: "CryptoCurrency", id: "cosmos", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/axelar.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/axelar.integration.test.ts.snap index 11bb8ee5f3c8..28e52a1ab2d8 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/axelar.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/axelar.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`axelar currency bridge scanAccounts axelar seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "axelar1gyauvl44q2apn3u3aujm36q8zrj74vry3kglyg", }, @@ -38,7 +37,6 @@ exports[`axelar currency bridge scanAccounts axelar seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "axelar1v2mp0m7k96dm9qv60fkspcqlzpkzrwnext9980", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap index 91f55a3dd34f..015a82d0abb5 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`coreum currency bridge scanAccounts coreum seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "core10l6h3qw05u7qduqgafj8wlrx3fjhr852z7r5l2", }, @@ -38,7 +37,6 @@ exports[`coreum currency bridge scanAccounts coreum seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "core1sel9ys8a7jlsmrxp9692zfjncnmhxkws0qr3g9", }, @@ -58,7 +56,6 @@ exports[`coreum currency bridge scanAccounts coreum seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "core1mdj6j89ev4yfelv3kqn7prj4h92er5zlxssxwk", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap index e1bf6c7f212d..16355052676d 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl", }, @@ -38,7 +37,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "cosmos108uy5q9jt59gwugq5yrdhkzcd9jryslmpcstk5", }, @@ -58,7 +56,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "cosmos1cgc696ay2pg6d4gcejek2y8la66j7e5y3c7kyw", }, @@ -78,7 +75,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "cosmos14tg4vsd0q745fxhzn329pkx0krqtszcxyzl5ku", }, @@ -98,7 +94,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "cosmos18q6ad294dw5wf7nueq7ctleehxh9fgt8dcecr9", }, @@ -118,7 +113,6 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "cosmos1uh39jx0dva8upvqqqh690rht2vn68zt9wmmhq4", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/desmos.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/desmos.integration.test.ts.snap index 5e1ee33ca03e..e1bbcdde491a 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/desmos.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/desmos.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`desmos currency bridge scanAccounts desmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "desmos1gyauvl44q2apn3u3aujm36q8zrj74vrypqn8c3", }, @@ -38,7 +37,6 @@ exports[`desmos currency bridge scanAccounts desmos seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "desmos1v2mp0m7k96dm9qv60fkspcqlzpkzrwneka7amk", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/injective.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/injective.integration.test.ts.snap index 1d8fea784904..3cf687ad97e9 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/injective.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/injective.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`injective currency bridge scanAccounts injective seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, "xpub": "inj1hn46zvx43mxq47vsecvw84k5chjhuhwp6d62dt", }, @@ -38,7 +37,6 @@ exports[`injective currency bridge scanAccounts injective seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": false, "xpub": "inj1604wce9t0u8vne0zrj4t2rspjsg28dymyljzrm", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/onomy.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/onomy.integration.test.ts.snap index b6d5028a2030..3f9e94ca9ee9 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/onomy.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/onomy.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`onomy currency bridge scanAccounts onomy seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, "xpub": "onomy1gyauvl44q2apn3u3aujm36q8zrj74vry0e2p7v", }, @@ -38,7 +37,6 @@ exports[`onomy currency bridge scanAccounts onomy seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": false, "xpub": "onomy1v2mp0m7k96dm9qv60fkspcqlzpkzrwnecy8mat", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/osmosis.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/osmosis.integration.test.ts.snap index 9762466f9025..68cb0cd28eab 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/osmosis.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/osmosis.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`osmo currency bridge scanAccounts osmo seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "osmo17gmcxyc5ccd5kwqqatpgfdgh380w2hc77zm0zw", }, @@ -38,7 +37,6 @@ exports[`osmo currency bridge scanAccounts osmo seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "osmo19h8cennrkf09sjxqt36lmk93fzyrcwrfxw784y", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/persistence.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/persistence.integration.test.ts.snap index 3ff311eacd31..501535fbc542 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/persistence.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/persistence.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`persistence currency bridge scanAccounts persistence seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "persistence1gyauvl44q2apn3u3aujm36q8zrj74vrym5cypd", }, @@ -38,7 +37,6 @@ exports[`persistence currency bridge scanAccounts persistence seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "persistence1v2mp0m7k96dm9qv60fkspcqlzpkzrwnevf47z2", }, @@ -58,7 +56,6 @@ exports[`persistence currency bridge scanAccounts persistence seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "persistence17r56udl09ssv88x85cxftx7su0rgv4v27ej3p0", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/quicksilver.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/quicksilver.integration.test.ts.snap index 6f32e106ebf9..b71198725703 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/quicksilver.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/quicksilver.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`quicksilver currency bridge scanAccounts quicksilver seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "quick1gyauvl44q2apn3u3aujm36q8zrj74vry7uw9km", }, @@ -38,7 +37,6 @@ exports[`quicksilver currency bridge scanAccounts quicksilver seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "quick1v2mp0m7k96dm9qv60fkspcqlzpkzrwnefprl4u", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/seiNetwork.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/seiNetwork.integration.test.ts.snap index ea3319ea5427..7a3bcd14b5e6 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/seiNetwork.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/seiNetwork.integration.test.ts.snap @@ -17,7 +17,6 @@ exports[`sei_network currency bridge scanAccounts sei_network seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "sei1gyauvl44q2apn3u3aujm36q8zrj74vryc50pfg", }, @@ -36,7 +35,6 @@ exports[`sei_network currency bridge scanAccounts sei_network seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "sei1v2mp0m7k96dm9qv60fkspcqlzpkzrwne0fzm20", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/stargaze.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/stargaze.integration.test.ts.snap index 17d126235d4c..863837e5f6df 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/stargaze.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/stargaze.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`stargaze currency bridge scanAccounts stargaze seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "stars1gyauvl44q2apn3u3aujm36q8zrj74vrypyf2yc", }, @@ -38,7 +37,6 @@ exports[`stargaze currency bridge scanAccounts stargaze seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "stars1v2mp0m7k96dm9qv60fkspcqlzpkzrwnekeys8l", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/umee.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/umee.integration.test.ts.snap index 3f9f3d8412f3..a4afdffa0f6e 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/umee.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/umee.integration.test.ts.snap @@ -18,7 +18,6 @@ exports[`umee currency bridge scanAccounts umee seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "umee1gyauvl44q2apn3u3aujm36q8zrj74vry8wrgtm", }, @@ -38,7 +37,6 @@ exports[`umee currency bridge scanAccounts umee seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "umee1v2mp0m7k96dm9qv60fkspcqlzpkzrwnesnwjgu", }, diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/axelar.ts b/libs/ledger-live-common/src/families/cosmos/datasets/axelar.ts index 777f71f0b194..7296d366e43c 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/axelar.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/axelar.ts @@ -35,7 +35,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "axelar", - unitMagnitude: 6, lastSyncDate: "2023-04-17T14:48:22.102Z", balance: "978792", spendableBalance: "628791", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/coreum.ts b/libs/ledger-live-common/src/families/cosmos/datasets/coreum.ts index 12d0c129886f..cfb6c52c9282 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/coreum.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/coreum.ts @@ -56,7 +56,6 @@ const dataset: CurrenciesData = { ], pendingOperations: [], currencyId: "coreum", - unitMagnitude: 6, lastSyncDate: "2023-07-26T05:46:40.684Z", balance: "1000000", spendableBalance: "1000000", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/cosmos.ts b/libs/ledger-live-common/src/families/cosmos/datasets/cosmos.ts index f06656cc00c3..53f9dac61c3c 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/cosmos.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/cosmos.ts @@ -50,7 +50,6 @@ const dataset: CurrenciesData = { spendableBalance: "2180673", blockHeight: 1615299, currencyId: "cosmos", - unitMagnitude: 6, operationsCount: 85, operations: [], pendingOperations: [], @@ -374,7 +373,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "cosmos", - unitMagnitude: 6, lastSyncDate: "2020-06-11T07:44:10.266Z", balance: "1000000", spendableBalance: "0", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/desmos.ts b/libs/ledger-live-common/src/families/cosmos/datasets/desmos.ts index e34bd383763f..654c000f90de 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/desmos.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/desmos.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "desmos", - unitMagnitude: 6, lastSyncDate: "2023-04-19T08:50:37.675Z", balance: "9998421", spendableBalance: "9898421", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/dydx.ts b/libs/ledger-live-common/src/families/cosmos/datasets/dydx.ts index 3a5462e2786c..d851ef59aa38 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/dydx.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/dydx.ts @@ -39,7 +39,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "dydx", - unitMagnitude: 18, lastSyncDate: "2023-11-02T08:01:16.412Z", balance: "7620812500000000", spendableBalance: "7520812500000000", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/injective.ts b/libs/ledger-live-common/src/families/cosmos/datasets/injective.ts index 086380c1e09c..14f8cf21dcda 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/injective.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/injective.ts @@ -35,7 +35,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "injective", - unitMagnitude: 18, lastSyncDate: "2023-09-18T06:38:17.652Z", balance: "607564000000000", spendableBalance: "506564000000000", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/onomy.ts b/libs/ledger-live-common/src/families/cosmos/datasets/onomy.ts index 9546e8c57ae8..39a87851da44 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/onomy.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/onomy.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "onomy", - unitMagnitude: 18, lastSyncDate: "2023-04-26T14:37:50.539Z", balance: "5006237953263518010", spendableBalance: "3806237953263518010", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/osmosis.ts b/libs/ledger-live-common/src/families/cosmos/datasets/osmosis.ts index deedbc0048b1..9983f5b49135 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/osmosis.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/osmosis.ts @@ -42,7 +42,6 @@ const dataset: CurrenciesData = { spendableBalance: "500250", blockHeight: 5417468, currencyId: "osmo", - unitMagnitude: 6, operationsCount: 2, operations: [], pendingOperations: [], @@ -365,7 +364,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "osmo", - unitMagnitude: 6, lastSyncDate: "2022-08-02T16:11:47.343Z", balance: "200250", spendableBalance: "200250", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/persistence.ts b/libs/ledger-live-common/src/families/cosmos/datasets/persistence.ts index 77312ba35d30..5cdcd8ee6a65 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/persistence.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/persistence.ts @@ -38,7 +38,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "persistence", - unitMagnitude: 6, lastSyncDate: "2023-04-26T14:01:03.106Z", balance: "4776304", spendableBalance: "4176304", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/quicksilver.ts b/libs/ledger-live-common/src/families/cosmos/datasets/quicksilver.ts index 86632b49d4c6..26b66025245f 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/quicksilver.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/quicksilver.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "quicksilver", - unitMagnitude: 6, lastSyncDate: "2023-04-25T15:22:47.450Z", balance: "9998269", spendableBalance: "8998269", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/secretNetwork.ts b/libs/ledger-live-common/src/families/cosmos/datasets/secretNetwork.ts index 32e486d4f4b8..215eaf6ca9dd 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/secretNetwork.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/secretNetwork.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "secret_network", - unitMagnitude: 6, lastSyncDate: "2023-06-12T12:45:06.797Z", balance: "1964000", spendableBalance: "1232751", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/seiNetwork.ts b/libs/ledger-live-common/src/families/cosmos/datasets/seiNetwork.ts index 3b86bb6e0efd..161fe6ceedee 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/seiNetwork.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/seiNetwork.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { blockHeight: 30141265, creationDate: "2023-10-05T07:51:50.000Z", currencyId: "sei_network", - unitMagnitude: 6, lastSyncDate: "2023-10-05T07:57:42.286Z", balance: "278991", spendableBalance: "128991", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/stargaze.ts b/libs/ledger-live-common/src/families/cosmos/datasets/stargaze.ts index f836b7810e48..54552d0eecfc 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/stargaze.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/stargaze.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "stargaze", - unitMagnitude: 6, lastSyncDate: "2023-06-12T13:27:26.351Z", balance: "2000000", spendableBalance: "2000000", diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/umee.ts b/libs/ledger-live-common/src/families/cosmos/datasets/umee.ts index 406b909bb3ab..7bfc3a430140 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/umee.ts +++ b/libs/ledger-live-common/src/families/cosmos/datasets/umee.ts @@ -36,7 +36,6 @@ const dataset: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "umee", - unitMagnitude: 6, lastSyncDate: "2023-04-19T09:37:58.369Z", balance: "9899013", spendableBalance: "9799013", diff --git a/libs/ledger-live-common/src/families/cosmos/deviceTransactionConfig.ts b/libs/ledger-live-common/src/families/cosmos/deviceTransactionConfig.ts index 1a32d7490f6d..b33f6b7e5b0e 100644 --- a/libs/ledger-live-common/src/families/cosmos/deviceTransactionConfig.ts +++ b/libs/ledger-live-common/src/families/cosmos/deviceTransactionConfig.ts @@ -2,7 +2,7 @@ import type { AccountLike, Account } from "@ledgerhq/types-live"; import type { Transaction, TransactionStatus } from "./types"; import type { DeviceTransactionField } from "../../transaction"; import { getMainAccount } from "../../account"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export type ExtraDeviceTransactionField = | { @@ -47,7 +47,7 @@ const getSendFields = ({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), amount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }), @@ -111,7 +111,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), validators[0].amount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], validators[0].amount, { showCode: true, disableRounding: true, }), @@ -131,7 +131,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), validators[0].amount, { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], validators[0].amount, { showCode: true, disableRounding: true, }), diff --git a/libs/ledger-live-common/src/families/cosmos/formatters.ts b/libs/ledger-live-common/src/families/cosmos/formatters.ts index 1b13d4262dc1..27ebb2c3176d 100644 --- a/libs/ledger-live-common/src/families/cosmos/formatters.ts +++ b/libs/ledger-live-common/src/families/cosmos/formatters.ts @@ -1,7 +1,7 @@ import invariant from "invariant"; import { BigNumber } from "bignumber.js"; import { getCurrentCosmosPreloadData } from "./preloadedData"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { CosmosOperation, CosmosAccount } from "./types"; import { mapDelegations, mapUnbondings, mapRedelegations } from "./logic"; @@ -30,7 +30,7 @@ export function formatAccountSpecifics(account: CosmosAccount): string { const { validators } = getCurrentCosmosPreloadData()[account.currency.id] ?? { validators: [], }; - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/ledger-live-common/src/families/cosmos/react.test.ts b/libs/ledger-live-common/src/families/cosmos/react.test.ts index 411f0c508851..73284e88212a 100644 --- a/libs/ledger-live-common/src/families/cosmos/react.test.ts +++ b/libs/ledger-live-common/src/families/cosmos/react.test.ts @@ -4,7 +4,7 @@ import "../../__tests__/test-helpers/dom-polyfill"; import invariant from "invariant"; import { renderHook, act } from "@testing-library/react"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { getAccountBridge, getCurrencyBridge } from "../../bridge"; import { getCryptoCurrencyById } from "../../currencies"; import { setEnv } from "@ledgerhq/live-env"; @@ -68,7 +68,7 @@ describe("cosmos/react", () => { expect(account.cosmosResources?.delegations?.some(d => d.amount[0] === 0)).toBe(false); expect(Array.isArray(result.current)).toBe(true); expect(result.current.length).toBe((delegations as CosmosDelegation[]).length); - const { code } = getAccountUnit(account); + const { code } = getAccountCurrency(account).units[0]; expect(result.current[0].formattedAmount.split(" ")[1]).toBe(code); expect(result.current[0].formattedPendingRewards.split(" ")[1]).toBe(code); expect(typeof result.current[0].rank).toBe("number"); diff --git a/libs/ledger-live-common/src/families/cosmos/react.ts b/libs/ledger-live-common/src/families/cosmos/react.ts index 6016712cc40c..245db5a08bf0 100644 --- a/libs/ledger-live-common/src/families/cosmos/react.ts +++ b/libs/ledger-live-common/src/families/cosmos/react.ts @@ -13,7 +13,7 @@ import type { CosmosAccount, } from "./types"; import { mapDelegations, searchFilter as defaultSearchFilter } from "./logic"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import useMemoOnce from "../../hooks/useMemoOnce"; import cryptoFactory from "./chain/chain"; @@ -44,7 +44,7 @@ export function useCosmosFamilyMappedDelegations( const delegations = account.cosmosResources?.delegations; invariant(delegations, "cosmos: delegations is required"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; return useMemo(() => { const mappedDelegations = mapDelegations(delegations || [], validators, unit); return mode === "claimReward" diff --git a/libs/ledger-live-common/src/families/cosmos/transaction.ts b/libs/ledger-live-common/src/families/cosmos/transaction.ts index 9fc638312c8d..fce25f554a00 100644 --- a/libs/ledger-live-common/src/families/cosmos/transaction.ts +++ b/libs/ledger-live-common/src/families/cosmos/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import { Account } from "@ledgerhq/types-live"; @@ -21,7 +21,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) @@ -34,7 +34,7 @@ ${ .map( v => " " + - formatCurrencyUnit(getAccountUnit(account), v.amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], v.amount, { disableRounding: true, }) + " -> " + @@ -42,7 +42,7 @@ ${ ) .join("\n") }${!sourceValidator ? "" : "\n source validator=" + sourceValidator} -with fees=${fees ? formatCurrencyUnit(getAccountUnit(account), fees) : "?"}${ +with fees=${fees ? formatCurrencyUnit(getAccountCurrency(account).units[0], fees) : "?"}${ !memo ? "" : `\n memo=${memo}` }`; diff --git a/libs/ledger-live-common/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap index 879182d336c7..355bc77d978d 100644 --- a/libs/ledger-live-common/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap @@ -25,7 +25,6 @@ exports[`crypto_org_croeseid currency bridge scanAccounts crypto_org_croeseid se "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, }, { @@ -51,7 +50,6 @@ exports[`crypto_org_croeseid currency bridge scanAccounts crypto_org_croeseid se "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, }, { @@ -77,7 +75,6 @@ exports[`crypto_org_croeseid currency bridge scanAccounts crypto_org_croeseid se "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/crypto_org/account.ts b/libs/ledger-live-common/src/families/crypto_org/account.ts index f2d2e4a76f4a..ca15ecfe1080 100644 --- a/libs/ledger-live-common/src/families/crypto_org/account.ts +++ b/libs/ledger-live-common/src/families/crypto_org/account.ts @@ -1,5 +1,5 @@ import invariant from "invariant"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import type { CryptoOrgAccount } from "./types"; @@ -8,7 +8,7 @@ function formatAccountSpecifics(account: CryptoOrgAccount): string { invariant(cryptoOrgResources, "Cronos POS Chain (formerly Crypto.org) account expected"); if (!cryptoOrgResources) throw new Error("Cronos POS Chain (formerly Crypto.org) account expected"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/ledger-live-common/src/families/crypto_org/transaction.ts b/libs/ledger-live-common/src/families/crypto_org/transaction.ts index 9021297bf501..4537db062f73 100644 --- a/libs/ledger-live-common/src/families/crypto_org/transaction.ts +++ b/libs/ledger-live-common/src/families/crypto_org/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( { mode, amount, recipient, useAllAmount, memo }: Transaction, @@ -20,7 +20,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap index 9cf2adbfcfd2..19ffb5c09351 100644 --- a/libs/ledger-live-common/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap @@ -25,7 +25,6 @@ exports[`elrond currency bridge scanAccounts elrond seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, }, { @@ -51,7 +50,6 @@ exports[`elrond currency bridge scanAccounts elrond seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/elrond/bridge.integration.test.ts b/libs/ledger-live-common/src/families/elrond/bridge.integration.test.ts index 6499dfd764bf..909e50148ba4 100644 --- a/libs/ledger-live-common/src/families/elrond/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/elrond/bridge.integration.test.ts @@ -41,7 +41,6 @@ const elrond: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "elrond", - unitMagnitude: 18, lastSyncDate: "", balance: "299569965", subAccounts: [ diff --git a/libs/ledger-live-common/src/families/elrond/datasets/elrond1.ts b/libs/ledger-live-common/src/families/elrond/datasets/elrond1.ts index d43143d4d30d..190982826e3a 100644 --- a/libs/ledger-live-common/src/families/elrond/datasets/elrond1.ts +++ b/libs/ledger-live-common/src/families/elrond/datasets/elrond1.ts @@ -11,7 +11,6 @@ export const elrond1: AccountRaw = { pendingOperations: [], operations: [], currencyId: "elrond", - unitMagnitude: 18, balance: "", blockHeight: 0, lastSyncDate: "", diff --git a/libs/ledger-live-common/src/families/elrond/deviceTransactionConfig.ts b/libs/ledger-live-common/src/families/elrond/deviceTransactionConfig.ts index 10670c15ecd5..77b83badd424 100644 --- a/libs/ledger-live-common/src/families/elrond/deviceTransactionConfig.ts +++ b/libs/ledger-live-common/src/families/elrond/deviceTransactionConfig.ts @@ -2,7 +2,7 @@ import type { DeviceTransactionField } from "../../transaction"; import type { TransactionStatus, Transaction } from "./types"; import BigNumber from "bignumber.js"; import { formatCurrencyUnit } from "../../currencies"; -import { decodeTokenAccountId, getAccountUnit } from "../../account"; +import { decodeTokenAccountId, getAccountCurrency } from "../../account"; import { Account } from "@ledgerhq/types-live"; import { isAmountSpentFromBalance } from "./logic"; @@ -48,7 +48,7 @@ function getDeviceTransactionConfig({ fields.push({ type: "text", label: "Amount", - value: formatCurrencyUnit(getAccountUnit(account), new BigNumber(0), { + value: formatCurrencyUnit(getAccountCurrency(account).units[0], new BigNumber(0), { showCode: true, disableRounding: true, }), diff --git a/libs/ledger-live-common/src/families/elrond/formatters.ts b/libs/ledger-live-common/src/families/elrond/formatters.ts index 510611c72662..b0588752ce97 100644 --- a/libs/ledger-live-common/src/families/elrond/formatters.ts +++ b/libs/ledger-live-common/src/families/elrond/formatters.ts @@ -1,6 +1,6 @@ import invariant from "invariant"; import type { Operation } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import type { Unit } from "@ledgerhq/types-cryptoassets"; import type { ElrondAccount, ElrondOperation } from "./types"; @@ -9,7 +9,7 @@ import BigNumber from "bignumber.js"; function formatAccountSpecifics(account: ElrondAccount): string { const { elrondResources } = account; invariant(elrondResources, "elrond account expected"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/ledger-live-common/src/families/elrond/js-getTransactionStatus.ts b/libs/ledger-live-common/src/families/elrond/js-getTransactionStatus.ts index bc75d31c7d5f..c99081a2b05e 100644 --- a/libs/ledger-live-common/src/families/elrond/js-getTransactionStatus.ts +++ b/libs/ledger-live-common/src/families/elrond/js-getTransactionStatus.ts @@ -9,7 +9,7 @@ import { AmountRequired, } from "@ledgerhq/errors"; import { formatCurrencyUnit } from "../../currencies"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { DECIMALS_LIMIT, MIN_DELEGATION_AMOUNT } from "./constants"; import type { ElrondAccount, Transaction, TransactionStatus } from "./types"; import { isValidAddress, isSelfTransaction, isAmountSpentFromBalance } from "./logic"; @@ -79,9 +79,13 @@ const getTransactionStatus = async ( // All delegate and undelegate transactions must have an amount >= 1 EGLD if (!errors.amount && t.amount.lt(MIN_DELEGATION_AMOUNT)) { - const formattedAmount = formatCurrencyUnit(getAccountUnit(a), MIN_DELEGATION_AMOUNT, { - showCode: true, - }); + const formattedAmount = formatCurrencyUnit( + getAccountCurrency(a).units[0], + MIN_DELEGATION_AMOUNT, + { + showCode: true, + }, + ); if (t.mode === "delegate") { errors.amount = new ElrondMinDelegatedAmountError("", { formattedAmount, @@ -103,9 +107,13 @@ const getTransactionStatus = async ( delegationRemainingBalance.gt(0) && delegationRemainingBalance.lt(MIN_DELEGATION_AMOUNT); if (!errors.amount && t.mode === "unDelegate" && delegationBalanceForbidden) { - const formattedAmount = formatCurrencyUnit(getAccountUnit(a), MIN_DELEGATION_AMOUNT, { - showCode: true, - }); + const formattedAmount = formatCurrencyUnit( + getAccountCurrency(a).units[0], + MIN_DELEGATION_AMOUNT, + { + showCode: true, + }, + ); errors.amount = new ElrondDelegationBelowMinimumError("", { formattedAmount, }); diff --git a/libs/ledger-live-common/src/families/elrond/speculos-deviceActions.ts b/libs/ledger-live-common/src/families/elrond/speculos-deviceActions.ts index 63a85a77bc23..9390ffb433ff 100644 --- a/libs/ledger-live-common/src/families/elrond/speculos-deviceActions.ts +++ b/libs/ledger-live-common/src/families/elrond/speculos-deviceActions.ts @@ -25,7 +25,7 @@ export const acceptMoveBalanceTransaction: DeviceAction = devi title: "Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.fees || new BigNumber(50000), { + formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -59,7 +59,7 @@ export const acceptDelegateTransaction: DeviceAction = deviceA title: "Amount", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.amount, { + formatCurrencyUnit(account.currency.units[0], transaction.amount, { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -69,7 +69,7 @@ export const acceptDelegateTransaction: DeviceAction = deviceA title: "Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.fees || new BigNumber(50000), { + formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -104,7 +104,7 @@ export const acceptUndelegateTransaction: DeviceAction = devic title: "Amount", button: SpeculosButton.RIGHT, expectedValue: ({ account }) => - formatCurrencyUnit(account.unit, new BigNumber(0), { + formatCurrencyUnit(account.currency.units[0], new BigNumber(0), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -114,7 +114,7 @@ export const acceptUndelegateTransaction: DeviceAction = devic title: "Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.fees || new BigNumber(50000), { + formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -148,7 +148,7 @@ export const acceptWithdrawTransaction: DeviceAction = deviceA title: "Amount", button: SpeculosButton.RIGHT, expectedValue: ({ account }) => - formatCurrencyUnit(account.unit, new BigNumber(0), { + formatCurrencyUnit(account.currency.units[0], new BigNumber(0), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -158,7 +158,7 @@ export const acceptWithdrawTransaction: DeviceAction = deviceA title: "Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.fees || new BigNumber(50000), { + formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", @@ -237,7 +237,7 @@ export const acceptEsdtTransferTransaction: DeviceAction = dev title: "Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => - formatCurrencyUnit(account.unit, transaction.fees || new BigNumber(50000), { + formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), { showCode: true, disableRounding: true, joinFragmentsSeparator: " ", diff --git a/libs/ledger-live-common/src/families/elrond/transaction.ts b/libs/ledger-live-common/src/families/elrond/transaction.ts index 3690a2180839..27e89e7f7583 100644 --- a/libs/ledger-live-common/src/families/elrond/transaction.ts +++ b/libs/ledger-live-common/src/families/elrond/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( { mode, amount, recipient, useAllAmount, subAccountId }: Transaction, @@ -24,7 +24,7 @@ ${mode.toUpperCase()} ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/filecoin/bridge.integration.test.ts b/libs/ledger-live-common/src/families/filecoin/bridge.integration.test.ts index a11e1d8c8866..2261474cb29a 100644 --- a/libs/ledger-live-common/src/families/filecoin/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/filecoin/bridge.integration.test.ts @@ -31,7 +31,6 @@ const filecoin: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "filecoin", - unitMagnitude: 18, lastSyncDate: "", balance: "1000", }, diff --git a/libs/ledger-live-common/src/families/filecoin/transaction.ts b/libs/ledger-live-common/src/families/filecoin/transaction.ts index 0ffa0ccc09ce..3b4883595ef1 100644 --- a/libs/ledger-live-common/src/families/filecoin/transaction.ts +++ b/libs/ledger-live-common/src/families/filecoin/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import BigNumber from "bignumber.js"; @@ -21,7 +21,7 @@ SEND ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap index 953431262d31..aa6ae8302880 100644 --- a/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap @@ -19,7 +19,6 @@ exports[`hedera currency bridge scanAccounts hedera seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, }, ] diff --git a/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts b/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts index c07e534058ab..3275811b32e1 100644 --- a/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/hedera/bridge.integration.test.ts @@ -35,7 +35,6 @@ const hedera: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "hedera", - unitMagnitude: 8, lastSyncDate: "", balance: "0", }, diff --git a/libs/ledger-live-common/src/families/hedera/speculos-deviceActions.ts b/libs/ledger-live-common/src/families/hedera/speculos-deviceActions.ts index e04ff5f2f42a..469c07c9b4d7 100644 --- a/libs/ledger-live-common/src/families/hedera/speculos-deviceActions.ts +++ b/libs/ledger-live-common/src/families/hedera/speculos-deviceActions.ts @@ -2,6 +2,7 @@ import type { DeviceAction } from "../../bot/types"; import type { Transaction } from "./types"; import { formatCurrencyUnit } from "../../currencies"; import { deviceActionFlow, SpeculosButton } from "../../bot/specs"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; export const acceptTransaction: DeviceAction = deviceActionFlow({ steps: [ @@ -30,9 +31,9 @@ export const acceptTransaction: DeviceAction = deviceActionFlo { title: "Amount", button: SpeculosButton.RIGHT, - expectedValue: ({ account: { unit }, status: { amount } }) => { + expectedValue: ({ account, status: { amount } }) => { return ( - formatCurrencyUnit(unit, amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { disableRounding: true, showAllDigits: true, }) + " hbar" @@ -42,8 +43,8 @@ export const acceptTransaction: DeviceAction = deviceActionFlo { title: "Fee", button: SpeculosButton.RIGHT, - expectedValue: ({ account: { unit }, status: { estimatedFees } }) => - formatCurrencyUnit(unit, estimatedFees, { + expectedValue: ({ account, status: { estimatedFees } }) => + formatCurrencyUnit(getAccountCurrency(account).units[0], estimatedFees, { disableRounding: true, showAllDigits: true, }) + " hbar", diff --git a/libs/ledger-live-common/src/families/hedera/tests/js-estimateMaxSpendable.integration.test.ts b/libs/ledger-live-common/src/families/hedera/tests/js-estimateMaxSpendable.integration.test.ts index 643c103f8e7d..bc4b076aecaa 100644 --- a/libs/ledger-live-common/src/families/hedera/tests/js-estimateMaxSpendable.integration.test.ts +++ b/libs/ledger-live-common/src/families/hedera/tests/js-estimateMaxSpendable.integration.test.ts @@ -40,13 +40,6 @@ const account: Account = { WEEK: { latestDate: null, balances: [] }, }, swapHistory: [], - unit: { - name: "", - code: "", - magnitude: 0, - showAllDigits: undefined, - prefixCode: undefined, - }, }; describe("js-estimateMaxSpendable", () => { diff --git a/libs/ledger-live-common/src/families/hedera/tests/js-transaction.test.ts b/libs/ledger-live-common/src/families/hedera/tests/js-transaction.test.ts index 5292157c3499..daa503e99bb7 100644 --- a/libs/ledger-live-common/src/families/hedera/tests/js-transaction.test.ts +++ b/libs/ledger-live-common/src/families/hedera/tests/js-transaction.test.ts @@ -40,13 +40,6 @@ const account: Account = { WEEK: { latestDate: null, balances: [] }, }, swapHistory: [], - unit: { - name: "", - code: "", - magnitude: 0, - showAllDigits: undefined, - prefixCode: undefined, - }, }; const transaction: Transaction = { diff --git a/libs/ledger-live-common/src/families/hedera/tests/transaction.test.ts b/libs/ledger-live-common/src/families/hedera/tests/transaction.test.ts index b9627c910bcc..64e8e76c14bf 100644 --- a/libs/ledger-live-common/src/families/hedera/tests/transaction.test.ts +++ b/libs/ledger-live-common/src/families/hedera/tests/transaction.test.ts @@ -27,7 +27,13 @@ const account: Account = { explorerViews: [], name: "", ticker: "", - units: [], + units: [ + { + name: "", + code: "", + magnitude: 0, + }, + ], }, operationsCount: 0, operations: [], @@ -39,13 +45,6 @@ const account: Account = { WEEK: { latestDate: null, balances: [] }, }, swapHistory: [], - unit: { - name: "", - code: "", - magnitude: 0, - showAllDigits: undefined, - prefixCode: undefined, - }, }; const transaction: Transaction = { diff --git a/libs/ledger-live-common/src/families/hedera/tests/utils.integration.test.ts b/libs/ledger-live-common/src/families/hedera/tests/utils.integration.test.ts index e208a3e04610..a2a51ba3629b 100644 --- a/libs/ledger-live-common/src/families/hedera/tests/utils.integration.test.ts +++ b/libs/ledger-live-common/src/families/hedera/tests/utils.integration.test.ts @@ -40,13 +40,6 @@ const account: Account = { WEEK: { latestDate: null, balances: [] }, }, swapHistory: [], - unit: { - name: "", - code: "", - magnitude: 0, - showAllDigits: undefined, - prefixCode: undefined, - }, }; const transaction: Transaction = { diff --git a/libs/ledger-live-common/src/families/hedera/transaction.ts b/libs/ledger-live-common/src/families/hedera/transaction.ts index 1285ad7f4041..fd072b473fcd 100644 --- a/libs/ledger-live-common/src/families/hedera/transaction.ts +++ b/libs/ledger-live-common/src/families/hedera/transaction.ts @@ -7,11 +7,11 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export function formatTransaction(transaction: Transaction, account: Account): string { - const amount = formatCurrencyUnit(getAccountUnit(account), transaction.amount, { + const amount = formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, { showCode: true, disableRounding: true, }); diff --git a/libs/ledger-live-common/src/families/internet_computer/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/internet_computer/__snapshots__/bridge.integration.test.ts.snap index 890e9de28b52..082a22dc11d3 100644 --- a/libs/ledger-live-common/src/families/internet_computer/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/internet_computer/__snapshots__/bridge.integration.test.ts.snap @@ -19,7 +19,6 @@ exports[`internet_computer currency bridge scanAccounts internet_computer seed 1 "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": true, "xpub": "046f08828871028b6e3cb5c13b2e2a8fa6e93f0b3ca7379171f6b7b45877955a2430925f76ec69ccb3cd8738859a8e29dcd0f9a357f1d009d2b497c6c8f63aa7cf", }, @@ -40,7 +39,6 @@ exports[`internet_computer currency bridge scanAccounts internet_computer seed 1 "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 8, "used": false, "xpub": "043ad9dda46b25cbcf98b2d91f8aa289d08078fa960d13e7d77a571c625eedcb62b6c26a86408d30a6bbdea5ecad6f7603bc1ba11fbb62caa315789f333ece2c8c", }, diff --git a/libs/ledger-live-common/src/families/internet_computer/bridge.integration.test.ts b/libs/ledger-live-common/src/families/internet_computer/bridge.integration.test.ts index 7f5646afadfc..6541dff7aecd 100644 --- a/libs/ledger-live-common/src/families/internet_computer/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/internet_computer/bridge.integration.test.ts @@ -52,7 +52,6 @@ const internet_computer: CurrenciesData = { spendableBalance: "1000000", swapHistory: [], syncHash: undefined, - unitMagnitude: 8, used: true, xpub: SEED_IDENTIFIER, }, diff --git a/libs/ledger-live-common/src/families/internet_computer/transaction.ts b/libs/ledger-live-common/src/families/internet_computer/transaction.ts index 2c2007d6a984..deed07b34b23 100644 --- a/libs/ledger-live-common/src/families/internet_computer/transaction.ts +++ b/libs/ledger-live-common/src/families/internet_computer/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; import BigNumber from "bignumber.js"; @@ -21,7 +21,7 @@ SEND ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/near/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/near/__snapshots__/bridge.integration.test.ts.snap index 9e391db8b716..aa2d02f47431 100644 --- a/libs/ledger-live-common/src/families/near/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/near/__snapshots__/bridge.integration.test.ts.snap @@ -34,7 +34,6 @@ exports[`near currency bridge scanAccounts near seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 24, "used": true, }, { @@ -61,7 +60,6 @@ exports[`near currency bridge scanAccounts near seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 24, "used": false, }, { @@ -88,7 +86,6 @@ exports[`near currency bridge scanAccounts near seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 24, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/near/banner.test.ts b/libs/ledger-live-common/src/families/near/banner.test.ts index 1819b1511cab..78852671f140 100644 --- a/libs/ledger-live-common/src/families/near/banner.test.ts +++ b/libs/ledger-live-common/src/families/near/banner.test.ts @@ -40,7 +40,6 @@ const account: NearAccount = { operations: [], operationsCount: 3, pendingOperations: [], - unit: { name: "NEAR", code: "NEAR", magnitude: 24 }, currency: { type: "CryptoCurrency", id: "near", diff --git a/libs/ledger-live-common/src/families/near/react.ts b/libs/ledger-live-common/src/families/near/react.ts index 7e975334f5f4..840baad4ca94 100644 --- a/libs/ledger-live-common/src/families/near/react.ts +++ b/libs/ledger-live-common/src/families/near/react.ts @@ -10,7 +10,7 @@ import { NearAccount, } from "@ledgerhq/coin-near/types"; import { getCurrentNearPreloadData } from "@ledgerhq/coin-near/preload"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; export function useNearMappedStakingPositions(account: NearAccount): NearMappedStakingPosition[] { const { validators } = getCurrentNearPreloadData(); @@ -18,7 +18,7 @@ export function useNearMappedStakingPositions(account: NearAccount): NearMappedS invariant(stakingPositions, "near: stakingPositions is required"); - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; return useMemo(() => { const mappedStakingPositions = mapStakingPositions(stakingPositions || [], validators, unit); diff --git a/libs/ledger-live-common/src/families/polkadot/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/polkadot/__snapshots__/bridge.integration.test.ts.snap index 8e28913f85cc..fcd0ff459543 100644 --- a/libs/ledger-live-common/src/families/polkadot/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/polkadot/__snapshots__/bridge.integration.test.ts.snap @@ -27,7 +27,6 @@ exports[`polkadot currency bridge scanAccounts polkadot seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 10, "used": true, }, { @@ -55,7 +54,6 @@ exports[`polkadot currency bridge scanAccounts polkadot seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 10, "used": true, }, { @@ -83,7 +81,6 @@ exports[`polkadot currency bridge scanAccounts polkadot seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 10, "used": true, }, { @@ -111,7 +108,6 @@ exports[`polkadot currency bridge scanAccounts polkadot seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 10, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/ripple/bridge.integration.test.ts b/libs/ledger-live-common/src/families/ripple/bridge.integration.test.ts index e169540652e0..b4a841239436 100644 --- a/libs/ledger-live-common/src/families/ripple/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/ripple/bridge.integration.test.ts @@ -153,7 +153,6 @@ const dataset: DatasetTest = { operations: [], pendingOperations: [], currencyId: "ripple", - unitMagnitude: 6, lastSyncDate: "", balance: "21000310", }, diff --git a/libs/ledger-live-common/src/families/ripple/transaction.ts b/libs/ledger-live-common/src/families/ripple/transaction.ts index 0ecdaba4be73..5150102e38ea 100644 --- a/libs/ledger-live-common/src/families/ripple/transaction.ts +++ b/libs/ledger-live-common/src/families/ripple/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( { amount, recipient, fee, tag, useAllAmount }: Transaction, @@ -17,7 +17,7 @@ export const formatTransaction = ( SEND ${ useAllAmount ? "MAX" - : formatCurrencyUnit(getAccountUnit(account), amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) @@ -26,7 +26,7 @@ TO ${recipient} with fee=${ !fee ? "?" - : formatCurrencyUnit(getAccountUnit(account), fee, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], fee, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/solana/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/solana/__snapshots__/bridge.integration.test.ts.snap index 2b066b335992..78146c3b0056 100644 --- a/libs/ledger-live-common/src/families/solana/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/solana/__snapshots__/bridge.integration.test.ts.snap @@ -23,7 +23,6 @@ exports[`solana currency bridge scanAccounts solana seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 9, "used": true, }, { @@ -47,7 +46,6 @@ exports[`solana currency bridge scanAccounts solana seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 9, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/solana/banner.test.ts b/libs/ledger-live-common/src/families/solana/banner.test.ts index 932bd2a77d06..2e72fdc9ed22 100644 --- a/libs/ledger-live-common/src/families/solana/banner.test.ts +++ b/libs/ledger-live-common/src/families/solana/banner.test.ts @@ -55,7 +55,6 @@ const account: SolanaAccount = { operations: [], operationsCount: 2, pendingOperations: [], - unit: { name: "SOL", code: "SOL", magnitude: 9 }, currency: { type: "CryptoCurrency", id: "solana", diff --git a/libs/ledger-live-common/src/families/solana/bridge.integration.test.ts b/libs/ledger-live-common/src/families/solana/bridge.integration.test.ts index 524c68eef117..77adc0eec544 100644 --- a/libs/ledger-live-common/src/families/solana/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/solana/bridge.integration.test.ts @@ -156,7 +156,6 @@ function makeAccount(freshAddress: string) { operations: [], pendingOperations: [], currencyId: "solana", - unitMagnitude: 9, lastSyncDate: "", balance: "0", }; diff --git a/libs/ledger-live-common/src/families/solana/transaction.ts b/libs/ledger-live-common/src/families/solana/transaction.ts index 5db57033fc4e..b1e2b94dd732 100644 --- a/libs/ledger-live-common/src/families/solana/transaction.ts +++ b/libs/ledger-live-common/src/families/solana/transaction.ts @@ -20,7 +20,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { findSubAccountById, getAccountUnit } from "../../account"; +import { findSubAccountById, getAccountCurrency } from "../../account"; import { formatCurrencyUnit, getTokenById } from "../../currencies"; import { assertUnreachable } from "./utils"; import { toTokenId } from "./logic"; @@ -46,7 +46,7 @@ export const toTransactionRaw = (t: Transaction): TransactionRaw => { }; const lamportsToSOL = (account: Account, amount: number) => { - return formatCurrencyUnit(getAccountUnit(account), new BigNumber(amount), { + return formatCurrencyUnit(getAccountCurrency(account).units[0], new BigNumber(amount), { showCode: true, disableRounding: true, }); @@ -127,10 +127,14 @@ function formatTokenTransfer(mainAccount: Account, tx: Transaction, command: Tok if (!subAccount || subAccount.type !== "TokenAccount") { throw new Error("token subaccount expected"); } - const amount = formatCurrencyUnit(getAccountUnit(subAccount), new BigNumber(command.amount), { - showCode: true, - disableRounding: true, - }); + const amount = formatCurrencyUnit( + getAccountCurrency(subAccount).units[0], + new BigNumber(command.amount), + { + showCode: true, + disableRounding: true, + }, + ); const recipient = command.recipientDescriptor.walletAddress; const str = [ ` SEND: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`, diff --git a/libs/ledger-live-common/src/families/stacks/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/stacks/__snapshots__/bridge.integration.test.ts.snap index 767fdc01c560..df7655a8f91e 100644 --- a/libs/ledger-live-common/src/families/stacks/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/stacks/__snapshots__/bridge.integration.test.ts.snap @@ -19,7 +19,6 @@ exports[`stacks currency bridge scanAccounts stacks seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "022a460decc9dba8c452927fecb33d7ae25a8d79dc5442b84feaf8f3aa0e2b575d", }, @@ -40,7 +39,6 @@ exports[`stacks currency bridge scanAccounts stacks seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "034bbb21911e9d4502ac170162c5c05cbba65cbb79e5b46adf95152af2d0e78a45", }, @@ -61,7 +59,6 @@ exports[`stacks currency bridge scanAccounts stacks seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "020637c4d824458f6a11551f51df9e5be9e96c2e3a2e5bdb25d2916cc1dd5ba2d7", }, @@ -82,7 +79,6 @@ exports[`stacks currency bridge scanAccounts stacks seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": true, "xpub": "02e57bb8c28c4c768cf65f8e28935482e40afbb33168d26810199f39a719cc05f0", }, @@ -103,7 +99,6 @@ exports[`stacks currency bridge scanAccounts stacks seed 1 1`] = ` "starred": undefined, "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 6, "used": false, "xpub": "0264b6d44f720fa50055dc294276bf15ce22e4f3dec48510b317ab8c07419c1b77", }, diff --git a/libs/ledger-live-common/src/families/stacks/bridge.integration.test.ts b/libs/ledger-live-common/src/families/stacks/bridge.integration.test.ts index c6849c8a43fa..9d37ee7d8a08 100644 --- a/libs/ledger-live-common/src/families/stacks/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/stacks/bridge.integration.test.ts @@ -54,7 +54,6 @@ const stacks: CurrenciesData = { xpub: SEED_IDENTIFIER_PUBKEY, pendingOperations: [], currencyId: "stacks", - unitMagnitude: 6, lastSyncDate: "", balance: "1000", }, diff --git a/libs/ledger-live-common/src/families/stacks/transaction.ts b/libs/ledger-live-common/src/families/stacks/transaction.ts index c3cf2ffa818f..9cbe61fb81bf 100644 --- a/libs/ledger-live-common/src/families/stacks/transaction.ts +++ b/libs/ledger-live-common/src/families/stacks/transaction.ts @@ -10,7 +10,7 @@ import { toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( @@ -23,7 +23,7 @@ SEND ${ : amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap index 25121d3232a4..fa7564d28ca4 100644 --- a/libs/ledger-live-common/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap @@ -20,7 +20,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": true, }, { @@ -41,7 +40,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": true, }, { @@ -62,7 +60,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": true, }, { @@ -83,7 +80,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": true, }, { @@ -104,7 +100,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": true, }, { @@ -125,7 +120,6 @@ exports[`stellar currency bridge scanAccounts stellar seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 7, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/stellar/bridge.integration.test.ts b/libs/ledger-live-common/src/families/stellar/bridge.integration.test.ts index 6c905c8c359e..d84e8eb4e498 100644 --- a/libs/ledger-live-common/src/families/stellar/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/stellar/bridge.integration.test.ts @@ -64,7 +64,6 @@ const dataset: DatasetTest = { operations: [], pendingOperations: [], currencyId: "stellar", - unitMagnitude: 7, lastSyncDate: "", balance: "371210662", spendableBalance: "371210662", @@ -274,7 +273,6 @@ const dataset: DatasetTest = { operations: [], pendingOperations: [], currencyId: "stellar", - unitMagnitude: 7, lastSyncDate: "", balance: "59999500", spendableBalance: "59999500", @@ -315,7 +313,6 @@ const dataset: DatasetTest = { lastSyncDate: "", operations: [], pendingOperations: [], - unitMagnitude: 7, }, }, { @@ -335,7 +332,6 @@ const dataset: DatasetTest = { lastSyncDate: "", operations: [], pendingOperations: [], - unitMagnitude: 7, }, }, { @@ -355,7 +351,6 @@ const dataset: DatasetTest = { lastSyncDate: "", operations: [], pendingOperations: [], - unitMagnitude: 7, }, transactions: [ { diff --git a/libs/ledger-live-common/src/families/stellar/speculos-deviceActions.ts b/libs/ledger-live-common/src/families/stellar/speculos-deviceActions.ts index 694a21a1392c..13d1d3b821fa 100644 --- a/libs/ledger-live-common/src/families/stellar/speculos-deviceActions.ts +++ b/libs/ledger-live-common/src/families/stellar/speculos-deviceActions.ts @@ -2,6 +2,7 @@ import type { DeviceAction } from "../../bot/types"; import type { Transaction } from "./types"; import { formatCurrencyUnit } from "../../currencies"; import { deviceActionFlow, formatDeviceAmount, SpeculosButton } from "../../bot/specs"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index"; const expectedAmount = ({ account, status, transaction }) => { if (transaction.assetCode && transaction.assetIssuer) { @@ -35,7 +36,7 @@ export const acceptTransaction: DeviceAction = deviceActionFlo title: "Max Fee", button: SpeculosButton.RIGHT, expectedValue: ({ account, status }) => - formatCurrencyUnit(account.unit, status.estimatedFees, { + formatCurrencyUnit(getAccountCurrency(account).units[0], status.estimatedFees, { disableRounding: true, }) + " XLM", }, diff --git a/libs/ledger-live-common/src/families/stellar/transaction.ts b/libs/ledger-live-common/src/families/stellar/transaction.ts index 9c636c6a998d..f9be235d0c89 100644 --- a/libs/ledger-live-common/src/families/stellar/transaction.ts +++ b/libs/ledger-live-common/src/families/stellar/transaction.ts @@ -9,7 +9,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( @@ -24,7 +24,7 @@ export const formatTransaction = ( SEND ${ useAllAmount ? "MAX" - : formatCurrencyUnit(getAccountUnit(account), amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) @@ -33,7 +33,7 @@ export const formatTransaction = ( with fees=${ !fees ? "?" - : formatCurrencyUnit(getAccountUnit(account), fees, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], fees, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/tezos/bridge.integration.test.ts b/libs/ledger-live-common/src/families/tezos/bridge.integration.test.ts index b7699f97bec2..dde12271bdbf 100644 --- a/libs/ledger-live-common/src/families/tezos/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/tezos/bridge.integration.test.ts @@ -23,7 +23,6 @@ function makeAccountRaw(name, pubkey, address, derivationMode): TezosAccountRaw operations: [], pendingOperations: [], currencyId: "tezos", - unitMagnitude: 6, lastSyncDate: "", balance: "0", xpub: pubkey, diff --git a/libs/ledger-live-common/src/families/tezos/fixtures/makeAccount.ts b/libs/ledger-live-common/src/families/tezos/fixtures/makeAccount.ts index ffec67871a0f..1e4d8be86289 100644 --- a/libs/ledger-live-common/src/families/tezos/fixtures/makeAccount.ts +++ b/libs/ledger-live-common/src/families/tezos/fixtures/makeAccount.ts @@ -27,7 +27,6 @@ export function makeAccount( spendableBalance: new BigNumber(100), creationDate: new Date(), currency: getCryptoCurrencyById("tezos"), - unit: { name: "xtz", code: "xtz", magnitude: 6 }, operationsCount: 0, swapHistory: [], balanceHistoryCache: { diff --git a/libs/ledger-live-common/src/families/tezos/transaction.ts b/libs/ledger-live-common/src/families/tezos/transaction.ts index ea670d3df144..cb18d0fb00c7 100644 --- a/libs/ledger-live-common/src/families/tezos/transaction.ts +++ b/libs/ledger-live-common/src/families/tezos/transaction.ts @@ -8,7 +8,7 @@ import { toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = ( { @@ -31,16 +31,18 @@ export const formatTransaction = ( ${mode.toUpperCase()} ${ useAllAmount ? "MAX" - : formatCurrencyUnit(getAccountUnit(account), amount, { + : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }) } TO ${recipient} -with fees=${!fees ? "?" : formatCurrencyUnit(mainAccount.unit, fees)} +with fees=${!fees ? "?" : formatCurrencyUnit(mainAccount.currency.units[0], fees)} with gasLimit=${!gasLimit ? "?" : gasLimit.toString()} with storageLimit=${!storageLimit ? "?" : storageLimit.toString()} -(estimatedFees ${!estimatedFees ? "?" : formatCurrencyUnit(mainAccount.unit, estimatedFees)})`; +(estimatedFees ${ + !estimatedFees ? "?" : formatCurrencyUnit(mainAccount.currency.units[0], estimatedFees) + })`; }; export const fromTransactionRaw = (tr: TransactionRaw): Transaction => { const common = fromTransactionCommonRaw(tr); diff --git a/libs/ledger-live-common/src/families/tron/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/tron/__snapshots__/bridge.integration.test.ts.snap index 6557ac23fee6..1f971cab2713 100644 --- a/libs/ledger-live-common/src/families/tron/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/tron/__snapshots__/bridge.integration.test.ts.snap @@ -58,7 +58,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, ], }, - "unitMagnitude": 6, "used": true, }, { @@ -224,7 +223,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -462,7 +460,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -531,7 +528,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -587,7 +583,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -656,7 +651,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -712,7 +706,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": true, }, { @@ -767,7 +760,6 @@ exports[`tron currency bridge scanAccounts tron seed 1 1`] = ` }, "votes": [], }, - "unitMagnitude": 6, "used": false, }, ] diff --git a/libs/ledger-live-common/src/families/tron/bridge.integration.test.ts b/libs/ledger-live-common/src/families/tron/bridge.integration.test.ts index bd6631acb649..01a814450b6d 100644 --- a/libs/ledger-live-common/src/families/tron/bridge.integration.test.ts +++ b/libs/ledger-live-common/src/families/tron/bridge.integration.test.ts @@ -751,7 +751,6 @@ const tron: CurrenciesData = { freshAddressPath: "44'/195'/0'/0/0", pendingOperations: [], currencyId: "tron", - unitMagnitude: 18, balance: "10006000", spendableBalance: "1606000", subAccounts: [], @@ -830,7 +829,6 @@ const tron: CurrenciesData = { freshAddressPath: "44'/195'/0'/0/0", pendingOperations: [], currencyId: "tron", - unitMagnitude: 18, balance: "26000197", spendableBalance: "197", subAccounts: [], @@ -1189,7 +1187,6 @@ const tron: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "tron", - unitMagnitude: 6, lastSyncDate: "2023-12-21T12:28:03.177Z", balance: "859005207", spendableBalance: "252128207", @@ -1237,7 +1234,6 @@ const tron: CurrenciesData = { operations: [], pendingOperations: [], currencyId: "tron", - unitMagnitude: 6, lastSyncDate: "2024-02-15T17:11:40.339Z", balance: "15000004", spendableBalance: "10000004", diff --git a/libs/ledger-live-common/src/families/tron/bridge/js.ts b/libs/ledger-live-common/src/families/tron/bridge/js.ts index 1775a4894ae3..bd57ecfc6795 100644 --- a/libs/ledger-live-common/src/families/tron/bridge/js.ts +++ b/libs/ledger-live-common/src/families/tron/bridge/js.ts @@ -37,11 +37,11 @@ import { makeSync, makeScanAccounts } from "../../../bridge/jsHelpers"; import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers"; import { formatCurrencyUnit } from "../../../currencies"; import { - getAccountUnit, getMainAccount, encodeTokenAccountId, emptyHistoryCache, encodeAccountId, + getAccountCurrency, } from "../../../account"; import { getOperationsPageSize } from "../../../pagination"; import { @@ -819,7 +819,7 @@ const getTransactionStatus = async (a: TronAccount, t: Transaction): Promise { @@ -66,7 +66,7 @@ ${t.mode.toUpperCase()}${t.resource ? " " + t.resource : ""} ${ : t.amount.isZero() ? "" : " " + - formatCurrencyUnit(getAccountUnit(account), t.amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], t.amount, { showCode: true, disableRounding: true, }) diff --git a/libs/ledger-live-common/src/families/vechain/__snapshots__/bridge.integration.test.ts.snap b/libs/ledger-live-common/src/families/vechain/__snapshots__/bridge.integration.test.ts.snap index 13bcc19ee43a..7b0088ec0619 100644 --- a/libs/ledger-live-common/src/families/vechain/__snapshots__/bridge.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/vechain/__snapshots__/bridge.integration.test.ts.snap @@ -19,7 +19,6 @@ exports[`vechain currency bridge scanAccounts vechain seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, }, { @@ -50,7 +49,6 @@ exports[`vechain currency bridge scanAccounts vechain seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": true, }, { @@ -81,7 +79,6 @@ exports[`vechain currency bridge scanAccounts vechain seed 1 1`] = ` "subAccounts": [], "swapHistory": [], "syncHash": undefined, - "unitMagnitude": 18, "used": false, }, { diff --git a/libs/ledger-live-common/src/families/vechain/account.ts b/libs/ledger-live-common/src/families/vechain/account.ts index 0ec938283637..6ce5b5dbc58e 100644 --- a/libs/ledger-live-common/src/families/vechain/account.ts +++ b/libs/ledger-live-common/src/families/vechain/account.ts @@ -1,9 +1,9 @@ import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; function formatAccountSpecifics(account: Account): string { - const unit = getAccountUnit(account); + const unit = getAccountCurrency(account).units[0]; const formatConfig = { disableRounding: true, alwaysShowSign: false, diff --git a/libs/ledger-live-common/src/families/vechain/datasets/vechain.ts b/libs/ledger-live-common/src/families/vechain/datasets/vechain.ts index 804a5414a5ee..0fbe9cec88ec 100644 --- a/libs/ledger-live-common/src/families/vechain/datasets/vechain.ts +++ b/libs/ledger-live-common/src/families/vechain/datasets/vechain.ts @@ -16,7 +16,6 @@ export const vechain1: AccountRaw = { pendingOperations: [], currencyId: "vechain", feesCurrencyId: "vechain/vip180/vtho", - unitMagnitude: 18, lastSyncDate: "2023-04-21T14:22:48.395Z", balance: "10000000000000000000", subAccounts: [ @@ -46,7 +45,6 @@ export const vechain2: AccountRaw = { pendingOperations: [], currencyId: "vechain", feesCurrencyId: "vechain/vip180/vtho", - unitMagnitude: 18, lastSyncDate: "2023-04-21T14:22:48.395Z", balance: "10000000000000000000", subAccounts: [ @@ -77,7 +75,6 @@ export const vechain3: AccountRaw = { pendingOperations: [], currencyId: "vechain", feesCurrencyId: "vechain/vip180/vtho", - unitMagnitude: 18, lastSyncDate: "2023-11-13T13:55:32.004Z", balance: "0", subAccounts: [ diff --git a/libs/ledger-live-common/src/families/vechain/transaction.ts b/libs/ledger-live-common/src/families/vechain/transaction.ts index a713c0b9fe69..834fa18c142b 100644 --- a/libs/ledger-live-common/src/families/vechain/transaction.ts +++ b/libs/ledger-live-common/src/families/vechain/transaction.ts @@ -7,7 +7,7 @@ import { toTransactionStatusRawCommon, } from "@ledgerhq/coin-framework/serialization"; import type { Account } from "@ledgerhq/types-live"; -import { getAccountUnit } from "../../account"; +import { getAccountCurrency } from "../../account"; import { formatCurrencyUnit } from "../../currencies"; export const formatTransaction = (t: Transaction, account: Account): string => { @@ -20,7 +20,7 @@ export const formatTransaction = (t: Transaction, account: Account): string => { } else { displayedAmount = " " + - formatCurrencyUnit(getAccountUnit(account), amount, { + formatCurrencyUnit(getAccountCurrency(account).units[0], amount, { showCode: true, disableRounding: true, }); diff --git a/libs/ledger-live-common/src/hooks/useAccountsWithFundsListener.test.tsx b/libs/ledger-live-common/src/hooks/useAccountsWithFundsListener.test.tsx index eb790bcc1f95..98362063e267 100644 --- a/libs/ledger-live-common/src/hooks/useAccountsWithFundsListener.test.tsx +++ b/libs/ledger-live-common/src/hooks/useAccountsWithFundsListener.test.tsx @@ -27,11 +27,6 @@ const ethMockAccount: Account = { operations: [], operationsCount: 0, pendingOperations: [], - unit: { - name: "ether", - code: "ETH", - magnitude: 18, - }, currency: eth, lastSyncDate: new Date("2023-02-14T11:01:19.252Z"), swapHistory: [], @@ -60,11 +55,6 @@ const polygonMockAccount: Account = { operations: [], operationsCount: 0, pendingOperations: [], - unit: { - name: "matic", - code: "MATIC", - magnitude: 18, - }, currency: polygon, lastSyncDate: new Date("2023-02-14T11:01:19.252Z"), swapHistory: [], diff --git a/libs/ledger-live-common/src/hw/signMessage/index.test.ts b/libs/ledger-live-common/src/hw/signMessage/index.test.ts index d92109a26fb4..b62aed8ef377 100644 --- a/libs/ledger-live-common/src/hw/signMessage/index.test.ts +++ b/libs/ledger-live-common/src/hw/signMessage/index.test.ts @@ -94,11 +94,6 @@ const createAccount = (crypto: CryptoCurrency): Account => ({ creationDate: new Date(), blockHeight: 8168983, currency: crypto, - unit: { - name: "satoshi", - code: "BTC", - magnitude: 5, - }, operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/ledger-live-common/src/mock/fixtures/cryptoCurrencies.ts b/libs/ledger-live-common/src/mock/fixtures/cryptoCurrencies.ts index 2d617bcc76d6..605bd3288fc2 100644 --- a/libs/ledger-live-common/src/mock/fixtures/cryptoCurrencies.ts +++ b/libs/ledger-live-common/src/mock/fixtures/cryptoCurrencies.ts @@ -92,11 +92,6 @@ export function createFixtureAccount( blockHeight: 8168983, currency, xpub: currency.family === "bitcoin" ? "testxpub" : undefined, - unit: { - name: "satoshi", - code: "BTC", - magnitude: 5, - }, operationsCount: 0, operations: [], pendingOperations: [], diff --git a/libs/ledgerjs/packages/types-live/README.md b/libs/ledgerjs/packages/types-live/README.md index 2a3b52a11558..d34e88738ad8 100644 --- a/libs/ledgerjs/packages/types-live/README.md +++ b/libs/ledgerjs/packages/types-live/README.md @@ -235,7 +235,7 @@ const bitcoinAccount = account as BitcoinAccount; and that BitcoinAccount type would be part of a coin integration family specific indeed. -Type: {type: `"Account"`, id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), seedIdentifier: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpub: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, derivationMode: [DerivationMode](#derivationmode), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), freshAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), freshAddressPath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), used: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), balance: BigNumber, spendableBalance: BigNumber, creationDate: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date), blockHeight: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), currency: CryptoCurrency, feesCurrency: (CryptoCurrency | TokenCurrency)?, unit: Unit, operationsCount: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), operations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>, pendingOperations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>, lastSyncDate: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date), subAccounts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TokenAccount](#tokenaccount)>?, balanceHistoryCache: BalanceHistoryCache, swapHistory: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[SwapOperation](#swapoperation)>, syncHash: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, nfts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[ProtoNFT](#protonft)>?} +Type: {type: `"Account"`, id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), seedIdentifier: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpub: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, derivationMode: [DerivationMode](#derivationmode), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), freshAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), freshAddressPath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), used: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), balance: BigNumber, spendableBalance: BigNumber, creationDate: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date), blockHeight: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), currency: CryptoCurrency, feesCurrency: (CryptoCurrency | TokenCurrency)?, operationsCount: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), operations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>, pendingOperations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>, lastSyncDate: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date), subAccounts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TokenAccount](#tokenaccount)>?, balanceHistoryCache: BalanceHistoryCache, swapHistory: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[SwapOperation](#swapoperation)>, syncHash: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, nfts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[ProtoNFT](#protonft)>?} #### Properties @@ -254,7 +254,6 @@ Type: {type: `"Account"`, id: [string](https://developer.mozilla.org/docs/Web/Ja * `blockHeight` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** * `currency` **CryptoCurrency** * `feesCurrency` **(CryptoCurrency | TokenCurrency)?** -* `unit` **Unit** * `operationsCount` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** * `operations` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>** * `pendingOperations` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Operation](#operation)>** @@ -306,7 +305,7 @@ Type: {type: `"TokenAccountRaw"`, id: [string](https://developer.mozilla.org/doc ### AccountRaw -Type: {id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), seedIdentifier: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpub: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, derivationMode: [DerivationMode](#derivationmode), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), freshAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), freshAddressPath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), name: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), starred: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, used: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, balance: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), spendableBalance: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, blockHeight: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), creationDate: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, operationsCount: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, currencyId: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), feesCurrencyId: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, operations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\, pendingOperations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\, unitMagnitude: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lastSyncDate: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), subAccounts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TokenAccountRaw](#tokenaccountraw)>?, balanceHistoryCache: BalanceHistoryCache?, swapHistory: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[SwapOperationRaw](#swapoperationraw)>?, syncHash: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, nfts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[ProtoNFTRaw](#protonftraw)>?} +Type: {id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), seedIdentifier: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpub: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, derivationMode: [DerivationMode](#derivationmode), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), freshAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), freshAddressPath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), name: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), starred: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, used: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, balance: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), spendableBalance: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, blockHeight: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), creationDate: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, operationsCount: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, currencyId: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), feesCurrencyId: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, operations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\, pendingOperations: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\, lastSyncDate: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), subAccounts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TokenAccountRaw](#tokenaccountraw)>?, balanceHistoryCache: BalanceHistoryCache?, swapHistory: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[SwapOperationRaw](#swapoperationraw)>?, syncHash: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, nfts: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[ProtoNFTRaw](#protonftraw)>?} #### Properties @@ -329,7 +328,6 @@ Type: {id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/ * `feesCurrencyId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** * `operations` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\** * `pendingOperations` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\** -* `unitMagnitude` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** * `lastSyncDate` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** * `subAccounts` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TokenAccountRaw](#tokenaccountraw)>?** * `balanceHistoryCache` **BalanceHistoryCache?** diff --git a/libs/ledgerjs/packages/types-live/src/account.ts b/libs/ledgerjs/packages/types-live/src/account.ts index 240d48a61dbb..e2dcd34c30a8 100644 --- a/libs/ledgerjs/packages/types-live/src/account.ts +++ b/libs/ledgerjs/packages/types-live/src/account.ts @@ -1,5 +1,5 @@ import type { BigNumber } from "bignumber.js"; -import type { CryptoCurrency, TokenCurrency, Unit } from "@ledgerhq/types-cryptoassets"; +import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; import type { OperationRaw, Operation } from "./operation"; import type { DerivationMode } from "./derivation"; import type { SwapOperation, SwapOperationRaw } from "./swap"; @@ -106,8 +106,6 @@ export type Account = { currency: CryptoCurrency; // Some blockchains may use a different currency than the main one to pay fees feesCurrency?: CryptoCurrency | TokenCurrency; - // user preferred unit to use. unit is coming from currency.units. You can assume currency.units.indexOf(unit) will work. (make sure to preserve reference) - unit: Unit; // The total number of operations (operations[] can be partial) operationsCount: number; // lazy list of operations that exists on the blockchain. @@ -204,7 +202,6 @@ export type AccountRaw = { feesCurrencyId?: string; operations: OperationRaw[]; pendingOperations: OperationRaw[]; - unitMagnitude: number; lastSyncDate: string; subAccounts?: TokenAccountRaw[]; balanceHistoryCache?: BalanceHistoryCache; diff --git a/libs/live-countervalues-react/src/index.tsx b/libs/live-countervalues-react/src/index.tsx index 037b8fa9adb8..c4485c102395 100644 --- a/libs/live-countervalues-react/src/index.tsx +++ b/libs/live-countervalues-react/src/index.tsx @@ -9,7 +9,7 @@ import React, { useCallback, ReactElement, } from "react"; -import { getAccountCurrency, getAccountUnit } from "@ledgerhq/coin-framework/account/helpers"; +import { getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers"; import { initialState, calculate, @@ -394,7 +394,7 @@ export function useSendAmount({ }); const fiatAmount = new BigNumber(fiatCountervalue ?? 0); const fiatUnit = fiatCurrency.units[0]; - const cryptoUnit = getAccountUnit(account); + const cryptoUnit = getAccountCurrency(account).units[0]; const state = useCountervaluesState(); const calculateCryptoAmount = useCallback( (fiatAmount: BigNumber) => { diff --git a/libs/live-wallet/src/liveqr/cross.ts b/libs/live-wallet/src/liveqr/cross.ts index 3ffc011954fd..b29b15869305 100644 --- a/libs/live-wallet/src/liveqr/cross.ts +++ b/libs/live-wallet/src/liveqr/cross.ts @@ -377,7 +377,6 @@ export const accountDataToAccount = ({ operationsCount: 0, operations: [], pendingOperations: [], - unit: currency.units[0], lastSyncDate: new Date(0), creationDate: new Date(), balanceHistoryCache: emptyHistoryCache, diff --git a/libs/live-wallet/src/liveqr/importAccounts.test.ts b/libs/live-wallet/src/liveqr/importAccounts.test.ts index f8f6e9afa298..f552d852ef54 100644 --- a/libs/live-wallet/src/liveqr/importAccounts.test.ts +++ b/libs/live-wallet/src/liveqr/importAccounts.test.ts @@ -90,7 +90,6 @@ describe("importAccountsMakeItems", () => { operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:30.318Z", balance: "51281813126095910", }, @@ -107,7 +106,6 @@ describe("importAccountsMakeItems", () => { operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "1081392000000000", }, @@ -124,7 +122,6 @@ describe("importAccountsMakeItems", () => { operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "1081392000000000", }, diff --git a/libs/live-wallet/src/ordering.test.ts b/libs/live-wallet/src/ordering.test.ts index 49b0599d5632..d4215ccc142f 100644 --- a/libs/live-wallet/src/ordering.test.ts +++ b/libs/live-wallet/src/ordering.test.ts @@ -21,7 +21,6 @@ const raws: AccountRaw[] = [ operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:30.318Z", balance: "1000000000000000000", }, @@ -37,7 +36,6 @@ const raws: AccountRaw[] = [ operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "2000000000000000000", }, @@ -53,7 +51,6 @@ const raws: AccountRaw[] = [ operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "3000000000000000000", }, @@ -69,7 +66,6 @@ const raws: AccountRaw[] = [ operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "3000000000000000000", }, @@ -85,7 +81,6 @@ const raws: AccountRaw[] = [ operations: [], pendingOperations: [], currencyId: "ethereum", - unitMagnitude: 18, lastSyncDate: "2019-07-17T15:13:29.306Z", balance: "4000000000000000000", }, From 3363885f49b813eba3d2514931ffb8e1796e1f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 2 May 2024 09:52:12 +0200 Subject: [PATCH 2/3] chore(llm): React.memo on SendFunds/SummaryTotalSection --- .../src/screens/SendFunds/SummaryTotalSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx index cf2249172469..8593c323a38a 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/SummaryTotalSection.tsx @@ -87,4 +87,4 @@ const styles = StyleSheet.create({ }, }); -export default withTheme(SummaryTotalSection); +export default withTheme(React.memo(SummaryTotalSection)); From 6928ae3e143eb9942bc7711ca3aaf4b2721b362c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 2 May 2024 10:16:54 +0200 Subject: [PATCH 3/3] fix: support of unit in send flow --- .../src/renderer/components/RequestAmount.tsx | 4 +++- apps/ledger-live-mobile/src/screens/SendFunds/AmountInput.tsx | 4 +++- libs/live-countervalues-react/src/index.tsx | 3 --- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/RequestAmount.tsx b/apps/ledger-live-desktop/src/renderer/components/RequestAmount.tsx index 2a82835adfc3..b6e3f3388675 100644 --- a/apps/ledger-live-desktop/src/renderer/components/RequestAmount.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/RequestAmount.tsx @@ -9,6 +9,7 @@ import InputCurrency from "~/renderer/components/InputCurrency"; import IconTransfer from "~/renderer/icons/Transfer"; import { counterValueCurrencySelector } from "~/renderer/reducers/settings"; import TranslatedError from "./TranslatedError"; +import { useAccountUnit } from "../hooks/useAccountUnit"; const ErrorContainer = styled(Box)<{ hasError: unknown; @@ -71,7 +72,8 @@ export default function RequestAmount({ validTransactionWarning, }: Props) { const fiatCurrency = useSelector(counterValueCurrencySelector); - const { cryptoUnit, fiatAmount, fiatUnit, calculateCryptoAmount } = useSendAmount({ + const cryptoUnit = useAccountUnit(account); + const { fiatAmount, fiatUnit, calculateCryptoAmount } = useSendAmount({ account, fiatCurrency, cryptoAmount, diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/AmountInput.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/AmountInput.tsx index cc56866020f9..6d6dd61491c2 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/AmountInput.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/AmountInput.tsx @@ -11,6 +11,7 @@ import LText from "~/components/LText/index"; import CounterValuesSeparator from "./CounterValuesSeparator"; import CurrencyInput from "~/components/CurrencyInput"; import TranslatedError from "~/components/TranslatedError"; +import { useAccountUnit } from "~/hooks/useAccountUnit"; type Props = { account: AccountLike; @@ -34,7 +35,8 @@ export default function AmountInput({ }: Props) { const { t } = useTranslation(); const fiatCurrency = useSelector(counterValueCurrencySelector); - const { cryptoUnit, fiatAmount, fiatUnit, calculateCryptoAmount } = useSendAmount({ + const cryptoUnit = useAccountUnit(account); + const { fiatAmount, fiatUnit, calculateCryptoAmount } = useSendAmount({ account, fiatCurrency, cryptoAmount, diff --git a/libs/live-countervalues-react/src/index.tsx b/libs/live-countervalues-react/src/index.tsx index c4485c102395..0b106c4cd7c8 100644 --- a/libs/live-countervalues-react/src/index.tsx +++ b/libs/live-countervalues-react/src/index.tsx @@ -380,7 +380,6 @@ export function useSendAmount({ fiatCurrency: Currency; cryptoAmount: BigNumber; }): { - cryptoUnit: Unit; fiatAmount: BigNumber; fiatUnit: Unit; calculateCryptoAmount: (fiatAmount: BigNumber) => BigNumber; @@ -394,7 +393,6 @@ export function useSendAmount({ }); const fiatAmount = new BigNumber(fiatCountervalue ?? 0); const fiatUnit = fiatCurrency.units[0]; - const cryptoUnit = getAccountCurrency(account).units[0]; const state = useCountervaluesState(); const calculateCryptoAmount = useCallback( (fiatAmount: BigNumber) => { @@ -411,7 +409,6 @@ export function useSendAmount({ [state, cryptoCurrency, fiatCurrency], ); return { - cryptoUnit, fiatAmount, fiatUnit, calculateCryptoAmount,