@ledgerhq/live-common 23.1.0 → 24.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/mocks/account.js +3 -3
- package/lib/__tests__/mocks/account.js.map +1 -1
- package/lib/__tests__/test-helpers/bridge.d.ts +1 -4
- package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/bridge.js +1 -28
- package/lib/__tests__/test-helpers/bridge.js.map +1 -1
- package/lib/__tests__/test-helpers/setup.js +51 -0
- package/lib/__tests__/test-helpers/setup.js.map +1 -1
- package/lib/api/Ripple.d.ts.map +1 -1
- package/lib/api/Ripple.js +113 -68
- package/lib/api/Ripple.js.map +1 -1
- package/lib/apps/support.d.ts.map +1 -1
- package/lib/apps/support.js +6 -2
- package/lib/apps/support.js.map +1 -1
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +13 -19
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/test.bot.d.ts +1 -1
- package/lib/bot/test.bot.d.ts.map +1 -1
- package/lib/bot/test.bot.js +1 -2
- package/lib/bot/test.bot.js.map +1 -1
- package/lib/countervalues/logic.integration.test.d.ts +2 -0
- package/lib/countervalues/logic.integration.test.d.ts.map +1 -0
- package/lib/countervalues/{logic.test.js → logic.integration.test.js} +1 -1
- package/lib/countervalues/logic.integration.test.js.map +1 -0
- package/lib/countervalues/react.d.ts +1 -21
- package/lib/countervalues/react.d.ts.map +1 -1
- package/lib/countervalues/react.js +1 -77
- package/lib/countervalues/react.js.map +1 -1
- package/lib/derivation.d.ts +1 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +3 -2
- package/lib/derivation.js.map +1 -1
- package/lib/env.d.ts +16 -6
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +11 -1
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/errors.d.ts +0 -3
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -3
- package/lib/errors.js.map +1 -1
- package/lib/exchange/index.d.ts +5 -0
- package/lib/exchange/index.d.ts.map +1 -1
- package/lib/exchange/index.js.map +1 -1
- package/lib/exchange/swap/checkQuote.d.ts +4 -0
- package/lib/exchange/swap/checkQuote.d.ts.map +1 -0
- package/lib/{families/tezos/bridge.test.js → exchange/swap/checkQuote.js} +35 -36
- package/lib/exchange/swap/checkQuote.js.map +1 -0
- package/lib/exchange/swap/checkQuote.test.d.ts +2 -0
- package/lib/exchange/swap/checkQuote.test.d.ts.map +1 -0
- package/lib/{families/filecoin/bridge.test.js → exchange/swap/checkQuote.test.js} +53 -42
- package/lib/exchange/swap/checkQuote.test.js.map +1 -0
- package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +9 -9
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
- package/lib/exchange/swap/getExchangeRates.js +3 -1
- package/lib/exchange/swap/getExchangeRates.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.test.js +1 -2
- package/lib/exchange/swap/getExchangeRates.test.js.map +1 -1
- package/lib/exchange/swap/getProviders.d.ts.map +1 -1
- package/lib/exchange/swap/getProviders.js +10 -4
- package/lib/exchange/swap/getProviders.js.map +1 -1
- package/lib/exchange/swap/getStatus.d.ts +1 -3
- package/lib/exchange/swap/getStatus.d.ts.map +1 -1
- package/lib/exchange/swap/getStatus.js +2 -30
- package/lib/exchange/swap/getStatus.js.map +1 -1
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +4 -5
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.d.ts +3 -4
- package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.js +35 -5
- package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.test.js +107 -3
- package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useSwapProviders.test.js +1 -2
- package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +5 -4
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.js +6 -6
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +4 -3
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +8 -5
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +37 -7
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
- package/lib/exchange/swap/index.d.ts +10 -8
- package/lib/exchange/swap/index.d.ts.map +1 -1
- package/lib/exchange/swap/index.js +43 -18
- package/lib/exchange/swap/index.js.map +1 -1
- package/lib/exchange/swap/index.test.d.ts +2 -0
- package/lib/exchange/swap/index.test.d.ts.map +1 -0
- package/lib/exchange/swap/index.test.js +30 -0
- package/lib/exchange/swap/index.test.js.map +1 -0
- package/lib/exchange/swap/initSwap.d.ts +1 -1
- package/lib/exchange/swap/initSwap.d.ts.map +1 -1
- package/lib/exchange/swap/initSwap.js +30 -25
- package/lib/exchange/swap/initSwap.js.map +1 -1
- package/lib/exchange/swap/mock.d.ts +5 -2
- package/lib/exchange/swap/mock.d.ts.map +1 -1
- package/lib/exchange/swap/mock.js +127 -6
- package/lib/exchange/swap/mock.js.map +1 -1
- package/lib/exchange/swap/postSwapState.d.ts +4 -0
- package/lib/exchange/swap/postSwapState.d.ts.map +1 -0
- package/lib/exchange/swap/postSwapState.js +121 -0
- package/lib/exchange/swap/postSwapState.js.map +1 -0
- package/lib/exchange/swap/types.d.ts +30 -2
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/exchange/swap/updateAccountSwapStatus.d.ts.map +1 -1
- package/lib/exchange/swap/updateAccountSwapStatus.js +2 -2
- package/lib/exchange/swap/updateAccountSwapStatus.js.map +1 -1
- package/lib/exchange/swap/utils/index.d.ts +19 -2
- package/lib/exchange/swap/utils/index.d.ts.map +1 -1
- package/lib/exchange/swap/utils/index.js +96 -20
- package/lib/exchange/swap/utils/index.js.map +1 -1
- package/lib/exchange/swap/utils/index.test.js +95 -48
- package/lib/exchange/swap/utils/index.test.js.map +1 -1
- package/lib/families/algorand/bridge.integration.test.d.ts +2 -0
- package/lib/families/algorand/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/algorand/{test-dataset.js → bridge.integration.test.js} +12 -11
- package/lib/families/algorand/bridge.integration.test.js.map +1 -0
- package/lib/families/bitcoin/bridge.integration.test.d.ts +2 -0
- package/lib/families/bitcoin/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/bitcoin/{test-dataset.js → bridge.integration.test.js} +17 -14
- package/lib/families/bitcoin/bridge.integration.test.js.map +1 -0
- package/lib/families/bitcoin/descriptor.d.ts.map +1 -1
- package/lib/families/bitcoin/descriptor.js +2 -1
- package/lib/families/bitcoin/descriptor.js.map +1 -1
- package/lib/families/bitcoin/satstack.d.ts.map +1 -1
- package/lib/families/bitcoin/satstack.js +5 -6
- package/lib/families/bitcoin/satstack.js.map +1 -1
- package/lib/families/bitcoin/satstack.test.js +4 -1
- package/lib/families/bitcoin/satstack.test.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +1 -2
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/cardano/bridge.integration.test.d.ts +2 -0
- package/lib/families/cardano/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/cardano/{test-dataset.js → bridge.integration.test.js} +4 -2
- package/lib/families/cardano/bridge.integration.test.js.map +1 -0
- package/lib/families/celo/bridge.integration.test.d.ts +2 -0
- package/lib/families/celo/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/celo/bridge.integration.test.js +16 -0
- package/lib/families/celo/bridge.integration.test.js.map +1 -0
- package/lib/families/cosmos/bridge.integration.test.d.ts +2 -0
- package/lib/families/cosmos/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/cosmos/{test-dataset.js → bridge.integration.test.js} +5 -4
- package/lib/families/cosmos/bridge.integration.test.js.map +1 -0
- package/lib/families/cosmos/speculos-deviceActions.js +2 -2
- package/lib/families/crypto_org/bridge.integration.test.d.ts +2 -0
- package/lib/families/crypto_org/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/crypto_org/bridge.integration.test.js +16 -0
- package/lib/families/crypto_org/bridge.integration.test.js.map +1 -0
- package/lib/families/elrond/bridge.integration.test.d.ts +2 -0
- package/lib/families/elrond/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/elrond/{test-dataset.js → bridge.integration.test.js} +5 -5
- package/lib/families/elrond/bridge.integration.test.js.map +1 -0
- package/lib/families/ethereum/bridge.integration.test.d.ts +2 -0
- package/lib/families/ethereum/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/ethereum/{test-dataset.js → bridge.integration.test.js} +8 -24
- package/lib/families/ethereum/bridge.integration.test.js.map +1 -0
- package/lib/families/ethereum/datasets/ethereum1.d.ts +3 -0
- package/lib/families/ethereum/datasets/ethereum1.d.ts.map +1 -0
- package/lib/families/ethereum/datasets/ethereum1.js +22 -0
- package/lib/families/ethereum/datasets/ethereum1.js.map +1 -0
- package/lib/families/ethereum/modules/compound.resilience.integration.test.d.ts +2 -0
- package/lib/families/ethereum/modules/compound.resilience.integration.test.d.ts.map +1 -0
- package/lib/families/ethereum/modules/{compound.resilience.test.js → compound.resilience.integration.test.js} +3 -3
- package/lib/families/ethereum/modules/compound.resilience.integration.test.js.map +1 -0
- package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc1155.js +5 -1
- package/lib/families/ethereum/modules/erc1155.js.map +1 -1
- package/lib/families/ethereum/modules/erc721.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc721.js +5 -0
- package/lib/families/ethereum/modules/erc721.js.map +1 -1
- package/lib/families/ethereum/nft.unit.test.js +35 -15
- package/lib/families/ethereum/nft.unit.test.js.map +1 -1
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.integration.test.d.ts +2 -0
- package/lib/families/ethereum/synchronisation.integration.test.d.ts.map +1 -0
- package/lib/families/ethereum/{synchronisation.test.js → synchronisation.integration.test.js} +4 -4
- package/lib/families/ethereum/synchronisation.integration.test.js.map +1 -0
- package/lib/families/ethereum/synchronisation.js +17 -13
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/filecoin/bridge.integration.test.d.ts +2 -0
- package/lib/families/filecoin/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/filecoin/{test-dataset.js → bridge.integration.test.js} +84 -3
- package/lib/families/filecoin/bridge.integration.test.js.map +1 -0
- package/lib/families/hedera/bridge.integration.test.d.ts +2 -0
- package/lib/families/hedera/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/hedera/{test-dataset.js → bridge.integration.test.js} +5 -3
- package/lib/families/hedera/bridge.integration.test.js.map +1 -0
- package/lib/families/polkadot/bridge.integration.test.d.ts +2 -0
- package/lib/families/polkadot/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/polkadot/{test-dataset.js → bridge.integration.test.js} +138 -4
- package/lib/families/polkadot/bridge.integration.test.js.map +1 -0
- package/lib/families/ripple/bridge.integration.test.d.ts +2 -0
- package/lib/families/ripple/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/ripple/{test-dataset.js → bridge.integration.test.js} +4 -2
- package/lib/families/ripple/bridge.integration.test.js.map +1 -0
- package/lib/families/solana/api/chain/account/token.d.ts +1 -1
- package/lib/families/solana/api/chain/account/vote.d.ts +12 -12
- package/lib/families/solana/api/chain/instruction/system/types.d.ts +4 -4
- package/lib/families/solana/bridge.integration.test.d.ts +2 -0
- package/lib/families/solana/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/solana/{test-dataset.js → bridge.integration.test.js} +289 -73
- package/lib/families/solana/bridge.integration.test.js.map +1 -0
- package/lib/families/stellar/bridge.integration.test.d.ts +2 -0
- package/lib/families/stellar/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/stellar/{test-dataset.js → bridge.integration.test.js} +9 -8
- package/lib/families/stellar/bridge.integration.test.js.map +1 -0
- package/lib/families/stellar/js-estimateMaxSpendable.d.ts.map +1 -1
- package/lib/families/stellar/js-estimateMaxSpendable.js +2 -2
- package/lib/families/stellar/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/tezos/{test-dataset.d.ts → bridge.integration.test.d.ts} +2 -5
- package/lib/families/tezos/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/tezos/{test-dataset.js → bridge.integration.test.js} +73 -2
- package/lib/families/tezos/bridge.integration.test.js.map +1 -0
- package/lib/families/tezos/synchronisation.js +2 -2
- package/lib/families/tezos/synchronisation.js.map +1 -1
- package/lib/families/tron/bridge.integration.test.d.ts +2 -0
- package/lib/families/tron/bridge.integration.test.d.ts.map +1 -0
- package/lib/families/tron/{test-dataset.js → bridge.integration.test.js} +5 -4
- package/lib/families/tron/bridge.integration.test.js.map +1 -0
- package/lib/hw/actions/initSwap.d.ts +4 -3
- package/lib/hw/actions/initSwap.d.ts.map +1 -1
- package/lib/hw/actions/initSwap.js +7 -5
- package/lib/hw/actions/initSwap.js.map +1 -1
- package/lib/load/speculos.d.ts.map +1 -1
- package/lib/load/speculos.js +5 -2
- package/lib/load/speculos.js.map +1 -1
- package/lib/nft/nftOperationId.d.ts +15 -0
- package/lib/nft/nftOperationId.d.ts.map +1 -0
- package/lib/nft/nftOperationId.js +50 -0
- package/lib/nft/nftOperationId.js.map +1 -0
- package/lib/operation.d.ts +1 -1
- package/lib/operation.d.ts.map +1 -1
- package/lib/operation.js +23 -1
- package/lib/operation.js.map +1 -1
- package/lib/portfolio/v2/index.d.ts +6 -1
- package/lib/portfolio/v2/index.d.ts.map +1 -1
- package/lib/portfolio/v2/index.js +7 -3
- package/lib/portfolio/v2/index.js.map +1 -1
- package/lib/portfolio/v2/range.d.ts +7 -1
- package/lib/portfolio/v2/range.d.ts.map +1 -1
- package/lib/portfolio/v2/range.js +37 -18
- package/lib/portfolio/v2/range.js.map +1 -1
- package/lib/portfolio/v2/range.test.d.ts +2 -0
- package/lib/portfolio/v2/range.test.d.ts.map +1 -0
- package/lib/portfolio/v2/range.test.js +51 -0
- package/lib/portfolio/v2/range.test.js.map +1 -0
- package/package.json +14 -10
- package/src/__tests__/mocks/account.ts +3 -3
- package/src/__tests__/test-helpers/bridge.ts +2 -35
- package/src/__tests__/test-helpers/setup.ts +39 -0
- package/src/api/Ripple.ts +97 -52
- package/src/apps/support.ts +6 -2
- package/src/bot/index.ts +26 -24
- package/src/bot/test.bot.ts +2 -2
- package/src/countervalues/{logic.test.ts → logic.integration.test.ts} +0 -0
- package/src/countervalues/react.tsx +2 -131
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +15 -1
- package/src/derivation.ts +2 -1
- package/src/env.ts +12 -2
- package/src/errors.ts +0 -1
- package/src/exchange/index.ts +7 -0
- package/src/exchange/swap/checkQuote.test.ts +53 -0
- package/src/exchange/swap/checkQuote.ts +34 -0
- package/src/exchange/swap/completeExchange.ts +9 -11
- package/src/exchange/swap/getExchangeRates.test.ts +1 -2
- package/src/exchange/swap/getExchangeRates.ts +5 -3
- package/src/exchange/swap/getProviders.ts +12 -4
- package/src/exchange/swap/getStatus.ts +2 -12
- package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +1 -3
- package/src/exchange/swap/hooks/useProviderRates.test.ts +104 -3
- package/src/exchange/swap/hooks/useProviderRates.ts +57 -9
- package/src/exchange/swap/hooks/useSwapProviders.test.ts +1 -3
- package/src/exchange/swap/hooks/useSwapTransaction.ts +14 -13
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +33 -7
- package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +13 -7
- package/src/exchange/swap/index.test.ts +36 -0
- package/src/exchange/swap/index.ts +51 -30
- package/src/exchange/swap/initSwap.ts +54 -40
- package/src/exchange/swap/mock.ts +128 -13
- package/src/exchange/swap/postSwapState.ts +61 -0
- package/src/exchange/swap/types.ts +68 -5
- package/src/exchange/swap/updateAccountSwapStatus.ts +4 -4
- package/src/exchange/swap/utils/index.test.ts +127 -63
- package/src/exchange/swap/utils/index.ts +128 -23
- package/src/families/algorand/{test-dataset.ts → bridge.integration.test.ts} +13 -10
- package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +27607 -0
- package/src/families/bitcoin/{test-dataset.ts → bridge.integration.test.ts} +18 -13
- package/src/families/bitcoin/descriptor.ts +1 -0
- package/src/families/bitcoin/satstack.test.ts +4 -1
- package/src/families/bitcoin/satstack.ts +9 -5
- package/src/families/bitcoin/specs.ts +0 -1
- package/src/families/cardano/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
- package/src/families/cardano/{test-dataset.ts → bridge.integration.test.ts} +3 -1
- package/src/families/celo/bridge.integration.test.ts +14 -0
- package/src/families/cosmos/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
- package/src/families/cosmos/{test-dataset.ts → bridge.integration.test.ts} +17 -15
- package/src/families/cosmos/speculos-deviceActions.ts +2 -2
- package/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap +2968 -0
- package/src/families/crypto_org/bridge.integration.test.ts +14 -0
- package/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap +207 -0
- package/src/families/elrond/{test-dataset.ts → bridge.integration.test.ts} +6 -4
- package/src/families/ethereum/__snapshots__/bridge.integration.test.ts.snap +3263 -0
- package/src/families/ethereum/{test-dataset.ts → bridge.integration.test.ts} +6 -19
- package/src/families/ethereum/datasets/ethereum1.ts +20 -0
- package/src/families/ethereum/modules/{compound.resilience.test.ts → compound.resilience.integration.test.ts} +1 -1
- package/src/families/ethereum/modules/erc1155.ts +12 -5
- package/src/families/ethereum/modules/erc721.ts +11 -0
- package/src/families/ethereum/nft.unit.test.ts +24 -17
- package/src/families/ethereum/{synchronisation.test.ts → synchronisation.integration.test.ts} +1 -1
- package/src/families/ethereum/synchronisation.ts +22 -18
- package/src/families/filecoin/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
- package/src/families/filecoin/{test-dataset.ts → bridge.integration.test.ts} +35 -3
- package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +5 -0
- package/src/families/hedera/{test-dataset.ts → bridge.integration.test.ts} +5 -2
- package/src/families/polkadot/{test-dataset.ts → bridge.integration.test.ts} +81 -5
- package/src/families/ripple/{test-dataset.ts → bridge.integration.test.ts} +5 -1
- package/src/families/solana/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
- package/src/families/solana/{test-dataset.ts → bridge.integration.test.ts} +170 -5
- package/src/families/stellar/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
- package/src/families/stellar/{test-dataset.ts → bridge.integration.test.ts} +5 -3
- package/src/families/stellar/js-estimateMaxSpendable.ts +3 -1
- package/src/families/tezos/{test-dataset.ts → bridge.integration.test.ts} +22 -1
- package/src/families/tezos/synchronisation.ts +1 -1
- package/src/families/tron/{test-dataset.ts → bridge.integration.test.ts} +6 -5
- package/src/hw/actions/initSwap.ts +20 -9
- package/src/load/speculos.ts +5 -2
- package/src/nft/nftOperationId.ts +47 -0
- package/src/operation.ts +50 -1
- package/src/portfolio/v2/index.ts +7 -2
- package/src/portfolio/v2/range.test.ts +66 -0
- package/src/portfolio/v2/range.ts +22 -8
- package/lib/__tests__/portfolio.d.ts +0 -2
- package/lib/__tests__/portfolio.d.ts.map +0 -1
- package/lib/__tests__/portfolio.js +0 -297
- package/lib/__tests__/portfolio.js.map +0 -1
- package/lib/__tests__/test-helpers/libcore-setup.d.ts +0 -3
- package/lib/__tests__/test-helpers/libcore-setup.d.ts.map +0 -1
- package/lib/__tests__/test-helpers/libcore-setup.js +0 -68
- package/lib/__tests__/test-helpers/libcore-setup.js.map +0 -1
- package/lib/__tests__/test-helpers/libcore-setup.native.d.ts +0 -10
- package/lib/__tests__/test-helpers/libcore-setup.native.d.ts.map +0 -1
- package/lib/__tests__/test-helpers/libcore-setup.native.js +0 -16
- package/lib/__tests__/test-helpers/libcore-setup.native.js.map +0 -1
- package/lib/countervalues/logic.test.d.ts +0 -2
- package/lib/countervalues/logic.test.d.ts.map +0 -1
- package/lib/countervalues/logic.test.js.map +0 -1
- package/lib/families/algorand/test-dataset.d.ts +0 -5
- package/lib/families/algorand/test-dataset.d.ts.map +0 -1
- package/lib/families/algorand/test-dataset.js.map +0 -1
- package/lib/families/bitcoin/test-dataset.d.ts +0 -5
- package/lib/families/bitcoin/test-dataset.d.ts.map +0 -1
- package/lib/families/bitcoin/test-dataset.js.map +0 -1
- package/lib/families/cardano/bridge.test.d.ts +0 -2
- package/lib/families/cardano/bridge.test.d.ts.map +0 -1
- package/lib/families/cardano/bridge.test.js +0 -11
- package/lib/families/cardano/bridge.test.js.map +0 -1
- package/lib/families/cardano/test-dataset.d.ts +0 -5
- package/lib/families/cardano/test-dataset.d.ts.map +0 -1
- package/lib/families/cardano/test-dataset.js.map +0 -1
- package/lib/families/cosmos/bridge.test.d.ts +0 -2
- package/lib/families/cosmos/bridge.test.d.ts.map +0 -1
- package/lib/families/cosmos/bridge.test.js +0 -11
- package/lib/families/cosmos/bridge.test.js.map +0 -1
- package/lib/families/cosmos/test-dataset.d.ts +0 -5
- package/lib/families/cosmos/test-dataset.d.ts.map +0 -1
- package/lib/families/cosmos/test-dataset.js.map +0 -1
- package/lib/families/crypto_org/test-dataset.d.ts +0 -5
- package/lib/families/crypto_org/test-dataset.d.ts.map +0 -1
- package/lib/families/crypto_org/test-dataset.js +0 -12
- package/lib/families/crypto_org/test-dataset.js.map +0 -1
- package/lib/families/elrond/test-dataset.d.ts +0 -5
- package/lib/families/elrond/test-dataset.d.ts.map +0 -1
- package/lib/families/elrond/test-dataset.js.map +0 -1
- package/lib/families/ethereum/modules/compound.resilience.test.d.ts +0 -2
- package/lib/families/ethereum/modules/compound.resilience.test.d.ts.map +0 -1
- package/lib/families/ethereum/modules/compound.resilience.test.js.map +0 -1
- package/lib/families/ethereum/synchronisation.test.d.ts +0 -2
- package/lib/families/ethereum/synchronisation.test.d.ts.map +0 -1
- package/lib/families/ethereum/synchronisation.test.js.map +0 -1
- package/lib/families/ethereum/test-dataset.d.ts +0 -6
- package/lib/families/ethereum/test-dataset.d.ts.map +0 -1
- package/lib/families/ethereum/test-dataset.js.map +0 -1
- package/lib/families/filecoin/bridge.test.d.ts +0 -2
- package/lib/families/filecoin/bridge.test.d.ts.map +0 -1
- package/lib/families/filecoin/bridge.test.js.map +0 -1
- package/lib/families/filecoin/test-dataset.d.ts +0 -5
- package/lib/families/filecoin/test-dataset.d.ts.map +0 -1
- package/lib/families/filecoin/test-dataset.js.map +0 -1
- package/lib/families/hedera/test-dataset.d.ts +0 -5
- package/lib/families/hedera/test-dataset.d.ts.map +0 -1
- package/lib/families/hedera/test-dataset.js.map +0 -1
- package/lib/families/polkadot/bridge.test.d.ts +0 -2
- package/lib/families/polkadot/bridge.test.d.ts.map +0 -1
- package/lib/families/polkadot/bridge.test.js +0 -145
- package/lib/families/polkadot/bridge.test.js.map +0 -1
- package/lib/families/polkadot/test-dataset.d.ts +0 -5
- package/lib/families/polkadot/test-dataset.d.ts.map +0 -1
- package/lib/families/polkadot/test-dataset.js.map +0 -1
- package/lib/families/ripple/bridge.test.d.ts +0 -2
- package/lib/families/ripple/bridge.test.d.ts.map +0 -1
- package/lib/families/ripple/bridge.test.js +0 -11
- package/lib/families/ripple/bridge.test.js.map +0 -1
- package/lib/families/ripple/test-dataset.d.ts +0 -5
- package/lib/families/ripple/test-dataset.d.ts.map +0 -1
- package/lib/families/ripple/test-dataset.js.map +0 -1
- package/lib/families/solana/bridge.test.d.ts +0 -2
- package/lib/families/solana/bridge.test.d.ts.map +0 -1
- package/lib/families/solana/bridge.test.js +0 -11
- package/lib/families/solana/bridge.test.js.map +0 -1
- package/lib/families/solana/test-dataset.d.ts +0 -23
- package/lib/families/solana/test-dataset.d.ts.map +0 -1
- package/lib/families/solana/test-dataset.js.map +0 -1
- package/lib/families/solana/test-specifics.d.ts +0 -9
- package/lib/families/solana/test-specifics.d.ts.map +0 -1
- package/lib/families/solana/test-specifics.js +0 -237
- package/lib/families/solana/test-specifics.js.map +0 -1
- package/lib/families/stellar/bridge.test.d.ts +0 -2
- package/lib/families/stellar/bridge.test.d.ts.map +0 -1
- package/lib/families/stellar/bridge.test.js +0 -11
- package/lib/families/stellar/bridge.test.js.map +0 -1
- package/lib/families/stellar/test-dataset.d.ts +0 -7
- package/lib/families/stellar/test-dataset.d.ts.map +0 -1
- package/lib/families/stellar/test-dataset.js.map +0 -1
- package/lib/families/tezos/bridge.test.d.ts +0 -2
- package/lib/families/tezos/bridge.test.d.ts.map +0 -1
- package/lib/families/tezos/bridge.test.js.map +0 -1
- package/lib/families/tezos/test-dataset.d.ts.map +0 -1
- package/lib/families/tezos/test-dataset.js.map +0 -1
- package/lib/families/tron/test-dataset.d.ts +0 -5
- package/lib/families/tron/test-dataset.d.ts.map +0 -1
- package/lib/families/tron/test-dataset.js.map +0 -1
- package/lib/generated/test-dataset.d.ts +0 -19
- package/lib/generated/test-dataset.d.ts.map +0 -1
- package/lib/generated/test-dataset.js +0 -38
- package/lib/generated/test-dataset.js.map +0 -1
- package/lib/portfolio/index.d.ts +0 -30
- package/lib/portfolio/index.d.ts.map +0 -1
- package/lib/portfolio/index.js +0 -399
- package/lib/portfolio/index.js.map +0 -1
- package/lib/portfolio/range.d.ts +0 -12
- package/lib/portfolio/range.d.ts.map +0 -1
- package/lib/portfolio/range.js +0 -73
- package/lib/portfolio/range.js.map +0 -1
- package/src/__tests__/__snapshots__/portfolio.ts.snap +0 -2770
- package/src/__tests__/portfolio.ts +0 -360
- package/src/__tests__/test-helpers/libcore-setup.native.ts +0 -19
- package/src/__tests__/test-helpers/libcore-setup.ts +0 -51
- package/src/families/bitcoin/bridge.test.ts.bak +0 -6
- package/src/families/cardano/bridge.test.ts +0 -6
- package/src/families/cosmos/bridge.test.ts +0 -6
- package/src/families/crypto_org/test-dataset.ts +0 -13
- package/src/families/ethereum/bridge.test.ts.bak +0 -8
- package/src/families/filecoin/bridge.test.ts +0 -39
- package/src/families/polkadot/bridge.test.ts +0 -81
- package/src/families/ripple/bridge.test.ts +0 -6
- package/src/families/solana/bridge.test.ts +0 -6
- package/src/families/solana/test-specifics.ts +0 -170
- package/src/families/stellar/bridge.test.ts +0 -6
- package/src/families/tezos/bridge.test.ts +0 -24
- package/src/generated/test-dataset.ts +0 -48
- package/src/portfolio/index.ts +0 -505
- package/src/portfolio/range.ts +0 -71
package/src/derivation.ts
CHANGED
|
@@ -157,12 +157,13 @@ const modes = Object.freeze({
|
|
|
157
157
|
// glif legacy derivation
|
|
158
158
|
gliflegacy: {
|
|
159
159
|
overridesDerivation: "44'/1'/0'/0/<account>",
|
|
160
|
-
tag: "legacy",
|
|
160
|
+
tag: "glif-legacy",
|
|
161
161
|
},
|
|
162
162
|
// glif normal derivation
|
|
163
163
|
glif: {
|
|
164
164
|
overridesDerivation: "44'/461'/0'/0/<account>",
|
|
165
165
|
startsAt: 1,
|
|
166
|
+
tag: "glif",
|
|
166
167
|
},
|
|
167
168
|
solanaMain: {
|
|
168
169
|
isNonIterable: true,
|
package/src/env.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import mapValues from "lodash/mapValues";
|
|
2
2
|
// set and get environment & config variables
|
|
3
3
|
import { Subject } from "rxjs";
|
|
4
|
-
import
|
|
4
|
+
import { $ElementType } from "utility-types";
|
|
5
5
|
type EnvDef<V> = {
|
|
6
6
|
desc: string;
|
|
7
7
|
def: V;
|
|
@@ -400,6 +400,16 @@ const envDefinitions = {
|
|
|
400
400
|
parser: stringParser,
|
|
401
401
|
desc: "mock the server response for the exchange KYC check, options are 'open', 'pending', 'closed' or 'approved'.",
|
|
402
402
|
},
|
|
403
|
+
MOCK_SWAP_CHECK_QUOTE: {
|
|
404
|
+
def: "",
|
|
405
|
+
parser: stringParser,
|
|
406
|
+
desc: "mock the server response for the exchange check quote, options are 'RATE_VALID', 'KYC_FAILED', 'KYC_PENDING', 'KYC_UNDEFINED', 'KYC_UPGRADE_REQUIRED', 'MFA_REQUIRED', 'OVER_TRADE_LIMIT', 'UNKNOW_USER' or 'UNKNOWN_ERROR'.",
|
|
407
|
+
},
|
|
408
|
+
MOCK_SWAP_WIDGET_BASE_URL: {
|
|
409
|
+
def: "",
|
|
410
|
+
parser: stringParser,
|
|
411
|
+
desc: "mock the FTX swap widget base url",
|
|
412
|
+
},
|
|
403
413
|
/**
|
|
404
414
|
* Note: the mocked cryptoassets config and test partner are signed with the
|
|
405
415
|
* Ledger test private key
|
package/src/errors.ts
CHANGED
|
@@ -160,7 +160,6 @@ export const SwapSubmitKYCFailed = createCustomErrorClass(
|
|
|
160
160
|
"SwapSubmitKYCFailed"
|
|
161
161
|
);
|
|
162
162
|
|
|
163
|
-
export const SwapUnknownSwapId = createCustomErrorClass("SwapUnknownSwapId");
|
|
164
163
|
export const SwapGenericAPIError = createCustomErrorClass(
|
|
165
164
|
"SwapGenericAPIError"
|
|
166
165
|
);
|
package/src/exchange/index.ts
CHANGED
|
@@ -46,6 +46,13 @@ export type ExchangeProviderNameAndSignature = {
|
|
|
46
46
|
nameAndPubkey: Buffer;
|
|
47
47
|
signature: Buffer;
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
export type SwapProviderConfig = ExchangeProviderNameAndSignature & {
|
|
51
|
+
curve: string;
|
|
52
|
+
needsKYC: boolean;
|
|
53
|
+
needsBearerToken: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
49
56
|
export const isExchangeSupportedByApp = (
|
|
50
57
|
appName: string,
|
|
51
58
|
appVersion: string
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import checkQuote from "./checkQuote";
|
|
3
|
+
|
|
4
|
+
jest.mock("axios");
|
|
5
|
+
const mockedAxios = jest.mocked(axios);
|
|
6
|
+
|
|
7
|
+
const provider = "changelly";
|
|
8
|
+
const quoteId = "RATE_ID";
|
|
9
|
+
const bearerToken = "BEARER_TOKEN";
|
|
10
|
+
|
|
11
|
+
describe("swap/checkQuote", () => {
|
|
12
|
+
test("should return response in case of valid rate", async () => {
|
|
13
|
+
const data = {
|
|
14
|
+
code: 1,
|
|
15
|
+
codeName: "RATE_VALID",
|
|
16
|
+
description: "KYC check passed",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const resp = {
|
|
20
|
+
data,
|
|
21
|
+
status: 200,
|
|
22
|
+
statusText: "",
|
|
23
|
+
headers: {},
|
|
24
|
+
config: {},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
mockedAxios.mockResolvedValue(Promise.resolve(resp));
|
|
28
|
+
const res = await checkQuote({ provider, quoteId, bearerToken });
|
|
29
|
+
|
|
30
|
+
expect(res).toEqual(data);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("should return response in case of invalid rate", async () => {
|
|
34
|
+
const data = {
|
|
35
|
+
code: 204,
|
|
36
|
+
codeName: "MFA_REQUIRED",
|
|
37
|
+
description: "MFA Required",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const resp = {
|
|
41
|
+
data,
|
|
42
|
+
status: 200,
|
|
43
|
+
statusText: "",
|
|
44
|
+
headers: {},
|
|
45
|
+
config: {},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
mockedAxios.mockResolvedValue(Promise.resolve(resp));
|
|
49
|
+
const res = await checkQuote({ provider, quoteId, bearerToken });
|
|
50
|
+
|
|
51
|
+
expect(res).toEqual(data);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getEnv } from "../../env";
|
|
2
|
+
import network from "../../network";
|
|
3
|
+
import { getSwapAPIBaseURL } from "./";
|
|
4
|
+
import { mockCheckQuote } from "./mock";
|
|
5
|
+
import type { CheckQuote } from "./types";
|
|
6
|
+
|
|
7
|
+
const checkQuote: CheckQuote = async ({ provider, quoteId, bearerToken }) => {
|
|
8
|
+
if (getEnv("MOCK") || getEnv("MOCK_SWAP_CHECK_QUOTE")) {
|
|
9
|
+
return mockCheckQuote({ provider, quoteId, bearerToken });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const request = {
|
|
13
|
+
provider,
|
|
14
|
+
rateId: quoteId,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const { data } = await network({
|
|
18
|
+
method: "POST",
|
|
19
|
+
url: `${getSwapAPIBaseURL()}/rate/check`,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
22
|
+
},
|
|
23
|
+
data: request,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* TODO: we might want to handle various status and error here
|
|
28
|
+
* cf. https://github.com/LedgerHQ/swap/blob/master/modules/model/src/main/scala/co/ledger/swap/model/RateStatus.scala
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default checkQuote;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
+
import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";
|
|
1
2
|
import { log } from "@ledgerhq/logs";
|
|
2
3
|
import { from, Observable } from "rxjs";
|
|
3
4
|
import secp256k1 from "secp256k1";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { delay } from "../../promise";
|
|
7
|
-
import ExchangeTransport from "../hw-app-exchange/Exchange";
|
|
8
|
-
import perFamily from "../../generated/exchange";
|
|
5
|
+
import { getCurrencyExchangeConfig } from "../";
|
|
9
6
|
import { getAccountCurrency, getMainAccount } from "../../account";
|
|
10
7
|
import { getAccountBridge } from "../../bridge";
|
|
11
8
|
import { TransactionRefusedOnDevice } from "../../errors";
|
|
9
|
+
import perFamily from "../../generated/exchange";
|
|
12
10
|
import { withDevice } from "../../hw/deviceAccess";
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
11
|
+
import { delay } from "../../promise";
|
|
12
|
+
import ExchangeTransport from "../hw-app-exchange/Exchange";
|
|
16
13
|
import type {
|
|
17
14
|
CompleteExchangeInputSwap,
|
|
18
15
|
CompleteExchangeRequestEvent,
|
|
19
16
|
} from "../platform/types";
|
|
17
|
+
import { getProviderConfig } from "./";
|
|
20
18
|
|
|
21
19
|
const withDevicePromise = (deviceId, fn) =>
|
|
22
20
|
withDevice(deviceId)((transport) => from(fn(transport))).toPromise();
|
|
@@ -45,7 +43,7 @@ const completeExchange = (
|
|
|
45
43
|
|
|
46
44
|
const confirmExchange = async () => {
|
|
47
45
|
await withDevicePromise(deviceId, async (transport) => {
|
|
48
|
-
const
|
|
46
|
+
const providerConfig = getProviderConfig(provider);
|
|
49
47
|
const exchange = new ExchangeTransport(
|
|
50
48
|
transport,
|
|
51
49
|
exchangeType,
|
|
@@ -75,10 +73,10 @@ const completeExchange = (
|
|
|
75
73
|
const errorsKeys = Object.keys(errors);
|
|
76
74
|
if (errorsKeys.length > 0) throw errors[errorsKeys[0]]; // throw the first error
|
|
77
75
|
|
|
78
|
-
await exchange.setPartnerKey(
|
|
76
|
+
await exchange.setPartnerKey(providerConfig.nameAndPubkey);
|
|
79
77
|
if (unsubscribed) return;
|
|
80
78
|
|
|
81
|
-
await exchange.checkPartner(
|
|
79
|
+
await exchange.checkPartner(providerConfig.signature);
|
|
82
80
|
if (unsubscribed) return;
|
|
83
81
|
|
|
84
82
|
await exchange.processTransaction(
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import BigNumber from "bignumber.js";
|
|
4
|
-
import { mocked } from "ts-jest/utils";
|
|
5
4
|
import { Account, Transaction } from "../../types";
|
|
6
5
|
import getExchangeRates from "./getExchangeRates";
|
|
7
6
|
import { Exchange, ExchangeRate } from "./types";
|
|
8
7
|
|
|
9
8
|
jest.mock("axios");
|
|
10
|
-
const mockedAxios = mocked(axios);
|
|
9
|
+
const mockedAxios = jest.mocked(axios);
|
|
11
10
|
|
|
12
11
|
const bitcoinCurrency = getCryptoCurrencyById("bitcoin");
|
|
13
12
|
const ethereumCurrency = getCryptoCurrencyById("ethereum");
|
|
@@ -13,9 +13,9 @@ import type {
|
|
|
13
13
|
Transaction,
|
|
14
14
|
Unit,
|
|
15
15
|
} from "../../types";
|
|
16
|
-
import { getSwapAPIBaseURL, getSwapAPIError } from "./";
|
|
16
|
+
import { getAvailableProviders, getSwapAPIBaseURL, getSwapAPIError } from "./";
|
|
17
17
|
import { mockGetExchangeRates } from "./mock";
|
|
18
|
-
import type { Exchange, GetExchangeRates } from "./types";
|
|
18
|
+
import type { CustomMinOrMaxError, Exchange, GetExchangeRates } from "./types";
|
|
19
19
|
|
|
20
20
|
const getExchangeRates: GetExchangeRates = async (
|
|
21
21
|
exchange: Exchange,
|
|
@@ -40,6 +40,7 @@ const getExchangeRates: GetExchangeRates = async (
|
|
|
40
40
|
from,
|
|
41
41
|
to,
|
|
42
42
|
amountFrom: apiAmount.toString(),
|
|
43
|
+
providers: usesV3 ? getAvailableProviders() : undefined,
|
|
43
44
|
};
|
|
44
45
|
const res = await network({
|
|
45
46
|
method: "POST",
|
|
@@ -122,7 +123,7 @@ const inferError = (
|
|
|
122
123
|
errorCode?: number;
|
|
123
124
|
errorMessage?: string;
|
|
124
125
|
}
|
|
125
|
-
): Error | undefined => {
|
|
126
|
+
): Error | CustomMinOrMaxError | undefined => {
|
|
126
127
|
const tenPowMagnitude = new BigNumber(10).pow(unitFrom.magnitude);
|
|
127
128
|
const { amountTo, minAmountFrom, maxAmountFrom, errorCode, errorMessage } =
|
|
128
129
|
responseData;
|
|
@@ -157,6 +158,7 @@ const inferError = (
|
|
|
157
158
|
showCode: true,
|
|
158
159
|
}
|
|
159
160
|
),
|
|
161
|
+
amount: new BigNumber(amount),
|
|
160
162
|
});
|
|
161
163
|
}
|
|
162
164
|
}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import network from "../../network";
|
|
3
|
-
import { getSwapAPIBaseURL } from "./";
|
|
1
|
+
import qs from "qs";
|
|
4
2
|
import { getEnv } from "../../env";
|
|
5
|
-
import { mockGetProviders } from "./mock";
|
|
6
3
|
import { SwapNoAvailableProviders } from "../../errors";
|
|
4
|
+
import network from "../../network";
|
|
5
|
+
import { getAvailableProviders, getSwapAPIBaseURL } from "./";
|
|
6
|
+
import { mockGetProviders } from "./mock";
|
|
7
|
+
import type { GetProviders } from "./types";
|
|
7
8
|
|
|
8
9
|
const getProviders: GetProviders = async () => {
|
|
9
10
|
if (getEnv("MOCK")) return mockGetProviders();
|
|
11
|
+
|
|
12
|
+
// Rely on the api base to determine the version logic
|
|
13
|
+
const usesV3 = getSwapAPIBaseURL().endsWith("v3");
|
|
14
|
+
|
|
10
15
|
const res = await network({
|
|
11
16
|
method: "GET",
|
|
12
17
|
url: `${getSwapAPIBaseURL()}/providers`,
|
|
18
|
+
params: usesV3 ? { whitelist: getAvailableProviders() } : undefined,
|
|
19
|
+
paramsSerializer: (params) =>
|
|
20
|
+
qs.stringify(params, { arrayFormat: "comma" }),
|
|
13
21
|
});
|
|
14
22
|
|
|
15
23
|
if (!res.data.length) {
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
+
import { getEnv } from "../../env";
|
|
1
2
|
import network from "../../network";
|
|
2
3
|
import { getSwapAPIBaseURL } from "./";
|
|
3
|
-
import type { GetMultipleStatus, GetStatus } from "./types";
|
|
4
|
-
import { getEnv } from "../../env";
|
|
5
4
|
import { mockGetStatus } from "./mock";
|
|
6
|
-
import {
|
|
7
|
-
export const getStatus: GetStatus = async (status) => {
|
|
8
|
-
const updatedStatus = await getMultipleStatus([status]);
|
|
5
|
+
import type { GetMultipleStatus } from "./types";
|
|
9
6
|
|
|
10
|
-
if (updatedStatus && updatedStatus.length) {
|
|
11
|
-
return updatedStatus[0];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
throw new SwapUnknownSwapId(undefined, { ...status });
|
|
15
|
-
};
|
|
16
7
|
export const getMultipleStatus: GetMultipleStatus = async (statusList) => {
|
|
17
8
|
if (getEnv("MOCK")) return mockGetStatus(statusList);
|
|
18
9
|
const res = await network({
|
|
@@ -22,4 +13,3 @@ export const getMultipleStatus: GetMultipleStatus = async (statusList) => {
|
|
|
22
13
|
});
|
|
23
14
|
return res.data;
|
|
24
15
|
};
|
|
25
|
-
export default getStatus;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import { mocked } from "ts-jest/utils";
|
|
3
|
-
|
|
4
2
|
import {
|
|
5
3
|
usePollKYCStatus,
|
|
6
4
|
KYC_STATUS_POLLING_INTERVAL,
|
|
@@ -12,7 +10,7 @@ import { KYCStatus } from "../types";
|
|
|
12
10
|
|
|
13
11
|
// mock getKYCStatus
|
|
14
12
|
jest.mock("..");
|
|
15
|
-
const mockedGetKYCStatus = mocked(getKYCStatus, true);
|
|
13
|
+
const mockedGetKYCStatus = jest.mocked(getKYCStatus, true);
|
|
16
14
|
|
|
17
15
|
describe("usePollKYCStatus", () => {
|
|
18
16
|
const defaultInput: UsePollKYCStatusProps = {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { renderHook, act } from "@testing-library/react-hooks";
|
|
2
1
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { act, renderHook } from "@testing-library/react-hooks";
|
|
3
3
|
import BigNumber from "bignumber.js";
|
|
4
|
-
import { mocked } from "ts-jest/utils";
|
|
5
4
|
import { useProviderRates } from ".";
|
|
6
5
|
import { getExchangeRates } from "..";
|
|
6
|
+
import {
|
|
7
|
+
SwapExchangeRateAmountTooHigh,
|
|
8
|
+
SwapExchangeRateAmountTooLow,
|
|
9
|
+
} from "../../../errors";
|
|
7
10
|
import { genAccount } from "../../../mock/account";
|
|
8
11
|
import { mockGetExchangeRates } from "../mock";
|
|
9
12
|
|
|
@@ -15,7 +18,7 @@ const fromAccount = genAccount("from-account", {
|
|
|
15
18
|
currency: ETH,
|
|
16
19
|
});
|
|
17
20
|
|
|
18
|
-
const mockedGetExchangeRates = mocked(getExchangeRates, true);
|
|
21
|
+
const mockedGetExchangeRates = jest.mocked(getExchangeRates, true);
|
|
19
22
|
const mockedRatesPromise = mockGetExchangeRates(
|
|
20
23
|
{ fromAccount } as any,
|
|
21
24
|
{ amount: new BigNumber(1) } as any,
|
|
@@ -185,6 +188,104 @@ describe("useProviderRates", () => {
|
|
|
185
188
|
expect(result.current.rates.value).toBeUndefined();
|
|
186
189
|
});
|
|
187
190
|
|
|
191
|
+
it("should sort SwapExchangeRateAmountTooLow based on amount", async () => {
|
|
192
|
+
const swapExchangeRateAmountTooLowError1 = new SwapExchangeRateAmountTooLow(
|
|
193
|
+
undefined,
|
|
194
|
+
{
|
|
195
|
+
amount: new BigNumber(1),
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const swapExchangeRateAmountTooLowError2 = new SwapExchangeRateAmountTooLow(
|
|
200
|
+
undefined,
|
|
201
|
+
{
|
|
202
|
+
amount: new BigNumber(2),
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
mockedRates[0].error = swapExchangeRateAmountTooLowError2;
|
|
207
|
+
mockedRates[1].error = swapExchangeRateAmountTooLowError1;
|
|
208
|
+
|
|
209
|
+
mockedGetExchangeRates.mockResolvedValue(mockedRates);
|
|
210
|
+
const { result, waitForNextUpdate } = renderHook(useProviderRates, {
|
|
211
|
+
initialProps: baseInitalProps,
|
|
212
|
+
});
|
|
213
|
+
await waitForNextUpdate({ timeout: 1000 });
|
|
214
|
+
expect(result.current.rates.status).toBe("error");
|
|
215
|
+
expect(result.current.rates.error).toBe(swapExchangeRateAmountTooLowError1);
|
|
216
|
+
expect(result.current.rates.value).toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should sort SwapExchangeRateAmountTooHigh based on amount", async () => {
|
|
220
|
+
const swapExchangeRateAmountTooHighError1 =
|
|
221
|
+
new SwapExchangeRateAmountTooHigh(undefined, {
|
|
222
|
+
amount: new BigNumber(1),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const swapExchangeRateAmountTooHighError2 =
|
|
226
|
+
new SwapExchangeRateAmountTooHigh(undefined, {
|
|
227
|
+
amount: new BigNumber(2),
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
mockedRates[0].error = swapExchangeRateAmountTooHighError1;
|
|
231
|
+
mockedRates[1].error = swapExchangeRateAmountTooHighError2;
|
|
232
|
+
|
|
233
|
+
mockedGetExchangeRates.mockResolvedValue(mockedRates);
|
|
234
|
+
const { result, waitForNextUpdate } = renderHook(useProviderRates, {
|
|
235
|
+
initialProps: baseInitalProps,
|
|
236
|
+
});
|
|
237
|
+
await waitForNextUpdate({ timeout: 1000 });
|
|
238
|
+
expect(result.current.rates.status).toBe("error");
|
|
239
|
+
expect(result.current.rates.error).toBe(
|
|
240
|
+
swapExchangeRateAmountTooHighError2
|
|
241
|
+
);
|
|
242
|
+
expect(result.current.rates.value).toBeUndefined();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("SwapExchangeRateAmountTooLow should take precedence over standard errors", async () => {
|
|
246
|
+
const swapExchangeRateAmountTooLowError = new SwapExchangeRateAmountTooLow(
|
|
247
|
+
undefined,
|
|
248
|
+
{
|
|
249
|
+
amount: new BigNumber(1),
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const standardError = new Error("Error");
|
|
254
|
+
|
|
255
|
+
mockedRates[0].error = standardError;
|
|
256
|
+
mockedRates[1].error = swapExchangeRateAmountTooLowError;
|
|
257
|
+
|
|
258
|
+
mockedGetExchangeRates.mockResolvedValue(mockedRates);
|
|
259
|
+
const { result, waitForNextUpdate } = renderHook(useProviderRates, {
|
|
260
|
+
initialProps: baseInitalProps,
|
|
261
|
+
});
|
|
262
|
+
await waitForNextUpdate({ timeout: 1000 });
|
|
263
|
+
expect(result.current.rates.status).toBe("error");
|
|
264
|
+
expect(result.current.rates.error).toBe(swapExchangeRateAmountTooLowError);
|
|
265
|
+
expect(result.current.rates.value).toBeUndefined();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("SwapExchangeRateAmountTooHigh should take precedence over standard errors", async () => {
|
|
269
|
+
const SwapExchangeRateAmountTooHighError =
|
|
270
|
+
new SwapExchangeRateAmountTooHigh(undefined, {
|
|
271
|
+
amount: new BigNumber(1),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const standardError = new Error("Error");
|
|
275
|
+
|
|
276
|
+
mockedRates[0].error = standardError;
|
|
277
|
+
mockedRates[1].error = SwapExchangeRateAmountTooHighError;
|
|
278
|
+
|
|
279
|
+
mockedGetExchangeRates.mockResolvedValue(mockedRates);
|
|
280
|
+
const { result, waitForNextUpdate } = renderHook(useProviderRates, {
|
|
281
|
+
initialProps: baseInitalProps,
|
|
282
|
+
});
|
|
283
|
+
await waitForNextUpdate({ timeout: 1000 });
|
|
284
|
+
expect(result.current.rates.status).toBe("error");
|
|
285
|
+
expect(result.current.rates.error).toBe(SwapExchangeRateAmountTooHighError);
|
|
286
|
+
expect(result.current.rates.value).toBeUndefined();
|
|
287
|
+
});
|
|
288
|
+
|
|
188
289
|
it("should call 'onNoRates' if there are no rates returned by the server", async () => {
|
|
189
290
|
const onNoRates = jest.fn(() => {});
|
|
190
291
|
mockedGetExchangeRates.mockResolvedValue([]);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useCallback, useEffect, useReducer, useState } from "react";
|
|
2
|
+
import { getExchangeRates } from "..";
|
|
3
|
+
import { Transaction } from "../../../generated/types";
|
|
4
|
+
import type { CustomMinOrMaxError, Exchange, ExchangeRate } from "../types";
|
|
2
5
|
import {
|
|
3
6
|
OnNoRatesCallback,
|
|
4
7
|
SetExchangeRateCallback,
|
|
5
8
|
SwapSelectorStateType,
|
|
6
9
|
} from "./useSwapTransaction";
|
|
7
|
-
import { getExchangeRates } from "..";
|
|
8
|
-
import { Exchange, ExchangeRate } from "../types";
|
|
9
|
-
import { pickExchangeRate } from "../utils";
|
|
10
|
-
import { Transaction } from "../../../generated/types";
|
|
11
10
|
|
|
12
11
|
export type RatesReducerState = {
|
|
13
12
|
status?: string | null;
|
|
@@ -34,14 +33,12 @@ const ratesReducer = (state: RatesReducerState, action): RatesReducerState => {
|
|
|
34
33
|
export const useProviderRates = ({
|
|
35
34
|
fromState,
|
|
36
35
|
toState,
|
|
37
|
-
exchangeRate,
|
|
38
36
|
transaction,
|
|
39
37
|
onNoRates,
|
|
40
38
|
setExchangeRate,
|
|
41
39
|
}: {
|
|
42
40
|
fromState: SwapSelectorStateType;
|
|
43
41
|
toState: SwapSelectorStateType;
|
|
44
|
-
exchangeRate?: ExchangeRate | null | undefined;
|
|
45
42
|
transaction?: Transaction | null | undefined;
|
|
46
43
|
onNoRates?: OnNoRatesCallback | null | undefined;
|
|
47
44
|
setExchangeRate?: SetExchangeRateCallback | null | undefined;
|
|
@@ -82,23 +79,74 @@ export const useProviderRates = ({
|
|
|
82
79
|
undefined,
|
|
83
80
|
toCurrency
|
|
84
81
|
);
|
|
82
|
+
|
|
85
83
|
if (abort) return;
|
|
86
84
|
if (rates.length === 0) {
|
|
87
85
|
onNoRates && onNoRates({ fromState, toState });
|
|
88
86
|
}
|
|
87
|
+
|
|
89
88
|
// Discard bad provider rates
|
|
90
|
-
let rateError: Error | null | undefined = null;
|
|
89
|
+
let rateError: Error | CustomMinOrMaxError | null | undefined = null;
|
|
91
90
|
rates = rates.reduce<ExchangeRate[]>((acc, rate) => {
|
|
92
91
|
rateError = rateError ?? rate.error;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* If we have an error linked to the ammount, this error takes
|
|
95
|
+
* precedence over the other (like a "CurrencyNotSupportedError" one
|
|
96
|
+
* for example)
|
|
97
|
+
*/
|
|
98
|
+
if (
|
|
99
|
+
rateError?.name !== rate.error?.name &&
|
|
100
|
+
(rate.error?.name === "SwapExchangeRateAmountTooLow" ||
|
|
101
|
+
rate.error?.name === "SwapExchangeRateAmountTooHigh")
|
|
102
|
+
) {
|
|
103
|
+
rateError = rate.error;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
rateError?.name === rate.error?.name &&
|
|
108
|
+
(rate.error?.name === "SwapExchangeRateAmountTooLow" ||
|
|
109
|
+
rate.error?.name === "SwapExchangeRateAmountTooHigh")
|
|
110
|
+
) {
|
|
111
|
+
/**
|
|
112
|
+
* Comparison pivot, depending on the order in which we want to sort errors
|
|
113
|
+
* If the order is ascending, the pivot is -1, otherwise it's 1
|
|
114
|
+
* Based on returns from https://mikemcl.github.io/bignumber.js/#cmp
|
|
115
|
+
*/
|
|
116
|
+
const cmp =
|
|
117
|
+
rateError?.name === "SwapExchangeRateAmountTooLow" ? -1 : 1;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* If the amount is too low, the user should put at least the
|
|
121
|
+
* minimum amount possible
|
|
122
|
+
* If the amount is too high, the user should put at most the
|
|
123
|
+
* maximum amount possible
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
rateError =
|
|
127
|
+
(rateError as CustomMinOrMaxError).amount.comparedTo(
|
|
128
|
+
(rate.error as CustomMinOrMaxError)?.amount
|
|
129
|
+
) === cmp
|
|
130
|
+
? rateError
|
|
131
|
+
: rate.error;
|
|
132
|
+
}
|
|
133
|
+
|
|
93
134
|
return rate.error ? acc : [...acc, rate];
|
|
94
135
|
}, []);
|
|
136
|
+
|
|
95
137
|
if (rates.length === 0 && rateError) {
|
|
96
138
|
// If all the rates are in error
|
|
97
139
|
dispatchRates({ type: "error", payload: rateError });
|
|
98
140
|
} else {
|
|
99
141
|
dispatchRates({ type: "set", payload: rates });
|
|
100
|
-
|
|
101
|
-
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Select the first rate returned by the API. Should be the prefered
|
|
145
|
+
* rate for the user. Rate ordering logic is handeled on backend side
|
|
146
|
+
*/
|
|
147
|
+
const rate = rates?.length > 0 ? rates[0] : null;
|
|
148
|
+
|
|
149
|
+
setExchangeRate && setExchangeRate(rate);
|
|
102
150
|
}
|
|
103
151
|
} catch (error) {
|
|
104
152
|
!abort && dispatchRates({ type: "error", payload: error });
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import { mocked } from "ts-jest/utils";
|
|
3
|
-
|
|
4
2
|
import { useSwapProviders } from "./useSwapProviders";
|
|
5
3
|
import { getProviders } from "..";
|
|
6
4
|
|
|
7
5
|
jest.mock("..");
|
|
8
6
|
|
|
9
|
-
const mockedGetProviders = mocked(getProviders);
|
|
7
|
+
const mockedGetProviders = jest.mocked(getProviders);
|
|
10
8
|
|
|
11
9
|
describe("useSwapProviders", () => {
|
|
12
10
|
const OLD_ENV = process.env;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AmountRequired } from "@ledgerhq/errors";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import {
|
|
5
|
+
RatesReducerState,
|
|
6
|
+
useFromState,
|
|
7
|
+
useProviderRates,
|
|
8
|
+
useToState,
|
|
9
|
+
} from ".";
|
|
3
10
|
import useBridgeTransaction, {
|
|
4
11
|
Result as UseBridgeTransactionReturnType,
|
|
5
12
|
} from "../../../bridge/useBridgeTransaction";
|
|
6
13
|
import type {
|
|
7
14
|
Account,
|
|
15
|
+
CryptoCurrency,
|
|
8
16
|
TokenAccount,
|
|
9
17
|
TokenCurrency,
|
|
10
|
-
CryptoCurrency,
|
|
11
18
|
} from "../../../types";
|
|
12
19
|
import { ExchangeRate } from "../types";
|
|
13
|
-
import { AmountRequired } from "@ledgerhq/errors";
|
|
14
|
-
import { useUpdateMaxAmount } from "./useUpdateMaxAmount";
|
|
15
|
-
import {
|
|
16
|
-
RatesReducerState,
|
|
17
|
-
useFromState,
|
|
18
|
-
useProviderRates,
|
|
19
|
-
useToState,
|
|
20
|
-
} from ".";
|
|
21
20
|
import { useReverseAccounts } from "./useReverseAccounts";
|
|
21
|
+
import { useUpdateMaxAmount } from "./useUpdateMaxAmount";
|
|
22
22
|
|
|
23
23
|
export type SwapSelectorStateType = {
|
|
24
24
|
currency: null | undefined | TokenCurrency | CryptoCurrency;
|
|
@@ -65,6 +65,7 @@ export type OnNoRatesCallback = (arg: {
|
|
|
65
65
|
export type SetExchangeRateCallback = (
|
|
66
66
|
exchangeRate?: ExchangeRate | null
|
|
67
67
|
) => void;
|
|
68
|
+
export type SetIsSendMaxLoading = (boolean) => void;
|
|
68
69
|
|
|
69
70
|
export const useFromAmountError = (
|
|
70
71
|
errors: Record<string, Error | undefined>
|
|
@@ -82,16 +83,16 @@ export const useFromAmountError = (
|
|
|
82
83
|
|
|
83
84
|
export const useSwapTransaction = ({
|
|
84
85
|
accounts,
|
|
85
|
-
exchangeRate,
|
|
86
86
|
setExchangeRate,
|
|
87
|
+
setIsSendMaxLoading,
|
|
87
88
|
defaultCurrency = selectorStateDefaultValues.currency,
|
|
88
89
|
defaultAccount = selectorStateDefaultValues.account,
|
|
89
90
|
defaultParentAccount = selectorStateDefaultValues.parentAccount,
|
|
90
91
|
onNoRates,
|
|
91
92
|
}: {
|
|
92
93
|
accounts?: Account[];
|
|
93
|
-
exchangeRate?: ExchangeRate;
|
|
94
94
|
setExchangeRate?: SetExchangeRateCallback;
|
|
95
|
+
setIsSendMaxLoading?: SetIsSendMaxLoading;
|
|
95
96
|
defaultCurrency?: SwapSelectorStateType["currency"];
|
|
96
97
|
defaultAccount?: SwapSelectorStateType["account"];
|
|
97
98
|
defaultParentAccount?: SwapSelectorStateType["parentAccount"];
|
|
@@ -136,12 +137,12 @@ export const useSwapTransaction = ({
|
|
|
136
137
|
parentAccount: fromParentAccount,
|
|
137
138
|
transaction,
|
|
138
139
|
feesStrategy: transaction?.feesStrategy,
|
|
140
|
+
setIsSendMaxLoading,
|
|
139
141
|
});
|
|
140
142
|
|
|
141
143
|
const { rates, refetchRates } = useProviderRates({
|
|
142
144
|
fromState,
|
|
143
145
|
toState,
|
|
144
|
-
exchangeRate,
|
|
145
146
|
transaction,
|
|
146
147
|
onNoRates,
|
|
147
148
|
setExchangeRate,
|