@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
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { renderHook, act } from "@testing-library/react-hooks";
|
|
2
1
|
import { getCryptoCurrencyById, getTokenById } from "@ledgerhq/cryptoassets";
|
|
3
|
-
import {
|
|
4
|
-
import { useUpdateMaxAmount, ZERO } from "./useUpdateMaxAmount";
|
|
5
|
-
import { genAccount, genTokenAccount } from "../../../mock/account";
|
|
2
|
+
import { act, renderHook } from "@testing-library/react-hooks";
|
|
6
3
|
import BigNumber from "bignumber.js";
|
|
7
|
-
import ethBridge from "../../../families/ethereum/bridge/mock";
|
|
8
4
|
import { checkAccountSupported } from "../../../account/support";
|
|
5
|
+
import ethBridge from "../../../families/ethereum/bridge/mock";
|
|
6
|
+
import { genAccount, genTokenAccount } from "../../../mock/account";
|
|
7
|
+
import { useUpdateMaxAmount, ZERO } from "./useUpdateMaxAmount";
|
|
9
8
|
|
|
10
9
|
// Needs to be mocked since userSupportedCurrencies is initially empty.
|
|
11
10
|
jest.mock("../../../account/support");
|
|
12
|
-
const mockedCheckAccount = mocked(checkAccountSupported);
|
|
11
|
+
const mockedCheckAccount = jest.mocked(checkAccountSupported);
|
|
13
12
|
// Mock to use a custom estimate value and test the result.
|
|
14
13
|
jest.mock("../../../families/ethereum/bridge/mock");
|
|
15
|
-
const mockedEstimateMaxSpendable = mocked(
|
|
14
|
+
const mockedEstimateMaxSpendable = jest.mocked(
|
|
16
15
|
ethBridge.accountBridge.estimateMaxSpendable,
|
|
17
16
|
true
|
|
18
17
|
);
|
|
@@ -78,6 +77,33 @@ describe("updateAmountUsingMax", () => {
|
|
|
78
77
|
expect(setFromAmount.mock.calls[0][0]).toBe(ZERO);
|
|
79
78
|
});
|
|
80
79
|
|
|
80
|
+
it("should toggle setIsSendMaxLoading", async () => {
|
|
81
|
+
const setIsSendMaxLoading = jest.fn();
|
|
82
|
+
|
|
83
|
+
const amount = new BigNumber(0.5);
|
|
84
|
+
mockedEstimateMaxSpendable.mockResolvedValue(amount);
|
|
85
|
+
const { result } = renderHook(useUpdateMaxAmount, {
|
|
86
|
+
initialProps: { ...defaultProps, setIsSendMaxLoading },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
act(() => result.current.toggleMax());
|
|
90
|
+
expect(setIsSendMaxLoading).toBeCalledTimes(1);
|
|
91
|
+
expect(setIsSendMaxLoading).toBeCalledWith(true);
|
|
92
|
+
setIsSendMaxLoading.mockClear();
|
|
93
|
+
|
|
94
|
+
// Lest resort solution, since waitFor and other helpers will not work here.
|
|
95
|
+
await wait();
|
|
96
|
+
|
|
97
|
+
expect(setIsSendMaxLoading).toBeCalledTimes(1);
|
|
98
|
+
expect(setIsSendMaxLoading).toBeCalledWith(false);
|
|
99
|
+
setIsSendMaxLoading.mockClear();
|
|
100
|
+
|
|
101
|
+
act(() => result.current.toggleMax());
|
|
102
|
+
expect(setIsSendMaxLoading).toBeCalledTimes(1);
|
|
103
|
+
expect(setIsSendMaxLoading).toBeCalledWith(false);
|
|
104
|
+
setIsSendMaxLoading.mockClear();
|
|
105
|
+
});
|
|
106
|
+
|
|
81
107
|
it("should update the max amount whenever the dependencies change", async () => {
|
|
82
108
|
const { result, rerender } = renderHook(useUpdateMaxAmount, {
|
|
83
109
|
initialProps: defaultProps,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
1
2
|
import { useCallback, useEffect, useState } from "react";
|
|
2
3
|
import { getAccountBridge } from "../../../bridge";
|
|
3
|
-
|
|
4
|
+
import { Transaction } from "../../../generated/types";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
+
SetIsSendMaxLoading,
|
|
6
7
|
SwapDataType,
|
|
7
8
|
SwapSelectorStateType,
|
|
9
|
+
SwapTransactionType,
|
|
8
10
|
} from "./useSwapTransaction";
|
|
9
|
-
import { Transaction } from "../../../generated/types";
|
|
10
|
-
import BigNumber from "bignumber.js";
|
|
11
11
|
|
|
12
12
|
export const ZERO = new BigNumber(0);
|
|
13
13
|
|
|
@@ -17,27 +17,31 @@ export const useUpdateMaxAmount = ({
|
|
|
17
17
|
parentAccount,
|
|
18
18
|
transaction,
|
|
19
19
|
feesStrategy,
|
|
20
|
+
setIsSendMaxLoading,
|
|
20
21
|
}: {
|
|
21
22
|
setFromAmount: SwapTransactionType["setFromAmount"];
|
|
22
23
|
account: SwapSelectorStateType["account"];
|
|
23
24
|
parentAccount: SwapSelectorStateType["parentAccount"];
|
|
24
25
|
transaction: SwapTransactionType["transaction"];
|
|
25
26
|
feesStrategy: Transaction["feesStrategy"];
|
|
27
|
+
setIsSendMaxLoading?: SetIsSendMaxLoading;
|
|
26
28
|
}): {
|
|
27
29
|
isMaxEnabled: SwapDataType["isMaxEnabled"];
|
|
28
30
|
toggleMax: SwapTransactionType["toggleMax"];
|
|
29
31
|
} => {
|
|
30
|
-
const [isMaxEnabled,
|
|
32
|
+
const [isMaxEnabled, setIsMaxEnabled] =
|
|
33
|
+
useState<SwapDataType["isMaxEnabled"]>(false);
|
|
31
34
|
|
|
32
35
|
const toggleMax: SwapTransactionType["toggleMax"] = useCallback(
|
|
33
36
|
() =>
|
|
34
|
-
|
|
37
|
+
setIsMaxEnabled((previous) => {
|
|
35
38
|
if (previous) {
|
|
36
39
|
setFromAmount(ZERO);
|
|
40
|
+
setIsSendMaxLoading?.(false);
|
|
37
41
|
}
|
|
38
42
|
return !previous;
|
|
39
43
|
}),
|
|
40
|
-
[setFromAmount]
|
|
44
|
+
[setFromAmount, setIsSendMaxLoading]
|
|
41
45
|
);
|
|
42
46
|
|
|
43
47
|
/* UPDATE from amount to the estimate max spendable on account
|
|
@@ -47,11 +51,13 @@ export const useUpdateMaxAmount = ({
|
|
|
47
51
|
const updateAmountUsingMax = async () => {
|
|
48
52
|
if (!account) return;
|
|
49
53
|
const bridge = getAccountBridge(account, parentAccount);
|
|
54
|
+
setIsSendMaxLoading?.(true);
|
|
50
55
|
const amount = await bridge.estimateMaxSpendable({
|
|
51
56
|
account,
|
|
52
57
|
parentAccount,
|
|
53
58
|
transaction,
|
|
54
59
|
});
|
|
60
|
+
setIsSendMaxLoading?.(false);
|
|
55
61
|
setFromAmount(amount);
|
|
56
62
|
};
|
|
57
63
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isSwapOperationPending } from ".";
|
|
2
|
+
|
|
3
|
+
describe("swap/index", () => {
|
|
4
|
+
describe("isSwapOperationPending", () => {
|
|
5
|
+
test("should return false for ok status", () => {
|
|
6
|
+
const result = isSwapOperationPending("finished");
|
|
7
|
+
|
|
8
|
+
expect(result).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("should return false for ko status", () => {
|
|
12
|
+
const result = isSwapOperationPending("refunded");
|
|
13
|
+
|
|
14
|
+
expect(result).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("should return true for other status", () => {
|
|
18
|
+
const result = isSwapOperationPending("RANDOM_STATUS");
|
|
19
|
+
|
|
20
|
+
expect(result).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("should return true if not status provided", () => {
|
|
24
|
+
/**
|
|
25
|
+
* Since this TS function can be used in loosly typed JS code, we need
|
|
26
|
+
* to test the case of the parameter not being provided
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const result = isSwapOperationPending();
|
|
32
|
+
|
|
33
|
+
expect(result).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -1,45 +1,60 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import getExchangeRates from "./getExchangeRates";
|
|
3
|
-
import getStatus from "./getStatus";
|
|
4
|
-
import getProviders from "./getProviders";
|
|
5
|
-
import getCompleteSwapHistory from "./getCompleteSwapHistory";
|
|
6
|
-
import getKYCStatus from "./getKYCStatus";
|
|
7
|
-
import submitKYC from "./submitKYC";
|
|
8
|
-
import initSwap from "./initSwap";
|
|
1
|
+
import type { SwapProviderConfig } from "../";
|
|
9
2
|
import { getEnv } from "../../env";
|
|
10
3
|
import {
|
|
11
|
-
|
|
12
|
-
JSONDecodeError,
|
|
13
|
-
NoIPHeaderError,
|
|
14
|
-
CurrencyNotSupportedError,
|
|
15
|
-
CurrencyDisabledError,
|
|
4
|
+
AccessDeniedError,
|
|
16
5
|
CurrencyDisabledAsInputError,
|
|
17
6
|
CurrencyDisabledAsOutputError,
|
|
7
|
+
CurrencyDisabledError,
|
|
18
8
|
CurrencyNotSupportedByProviderError,
|
|
9
|
+
CurrencyNotSupportedError,
|
|
10
|
+
JSONDecodeError,
|
|
11
|
+
JSONRPCResponseError,
|
|
12
|
+
NoIPHeaderError,
|
|
13
|
+
NotImplementedError,
|
|
19
14
|
TradeMethodNotSupportedError,
|
|
20
15
|
UnexpectedError,
|
|
21
|
-
NotImplementedError,
|
|
22
16
|
ValidationError,
|
|
23
|
-
AccessDeniedError,
|
|
24
17
|
} from "../../errors";
|
|
18
|
+
import checkQuote from "./checkQuote";
|
|
19
|
+
import getCompleteSwapHistory from "./getCompleteSwapHistory";
|
|
20
|
+
import getExchangeRates from "./getExchangeRates";
|
|
21
|
+
import getKYCStatus from "./getKYCStatus";
|
|
22
|
+
import getProviders from "./getProviders";
|
|
23
|
+
import initSwap from "./initSwap";
|
|
24
|
+
import { postSwapAccepted, postSwapCancelled } from "./postSwapState";
|
|
25
|
+
import submitKYC from "./submitKYC";
|
|
25
26
|
|
|
26
27
|
export const operationStatusList = {
|
|
27
28
|
finishedOK: ["finished"],
|
|
28
29
|
finishedKO: ["refunded"],
|
|
29
|
-
pending: ["pending", "onhold", "expired"],
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// A swap operation is considered pending if it is not in a finishedOK or finishedKO state
|
|
33
|
+
export const isSwapOperationPending: (status: string) => boolean = (status) =>
|
|
34
|
+
!operationStatusList.finishedOK.includes(status) &&
|
|
35
|
+
!operationStatusList.finishedKO.includes(status);
|
|
36
|
+
|
|
32
37
|
const getSwapAPIBaseURL: () => string = () => getEnv("SWAP_API_BASE");
|
|
33
38
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const ftx = {
|
|
40
|
+
nameAndPubkey: Buffer.concat([
|
|
41
|
+
Buffer.from([3]),
|
|
42
|
+
Buffer.from("FTX", "ascii"),
|
|
43
|
+
Buffer.from(
|
|
44
|
+
"04c89f3e48cde252f6cd6fcccc47c2f6ca6cf05f9f921703d31b7a7dddbf0bd6a690744662fe599f8761612021ba1fc0e8a5a4b7d5910c625b6dd09aa40762e5cd",
|
|
45
|
+
"hex"
|
|
46
|
+
),
|
|
47
|
+
]),
|
|
48
|
+
signature: Buffer.from(
|
|
49
|
+
"3044022029c0fb80d6e524f811f30cc04a349fa7f8896ce1ba84010da55f7be5eb9d528802202727985361cab969ad9b4f56570f3f6120c1d77d04ba10e5d99366d8eecee8e2",
|
|
50
|
+
"hex"
|
|
51
|
+
),
|
|
52
|
+
curve: "secp256k1",
|
|
53
|
+
needsKYC: true,
|
|
54
|
+
needsBearerToken: true,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const swapProviders: Record<string, SwapProviderConfig> = {
|
|
43
58
|
changelly: {
|
|
44
59
|
nameAndPubkey: Buffer.from(
|
|
45
60
|
"094368616e67656c6c790480d7c0d3a9183597395f58dda05999328da6f18fabd5cda0aff8e8e3fc633436a2dbf48ecb23d40df7c3c7d3e774b77b4b5df0e9f7e08cf1cdf2dba788eb085b",
|
|
@@ -51,6 +66,7 @@ const swapProviders: Record<
|
|
|
51
66
|
),
|
|
52
67
|
curve: "secpk256k1",
|
|
53
68
|
needsKYC: false,
|
|
69
|
+
needsBearerToken: false,
|
|
54
70
|
},
|
|
55
71
|
wyre: {
|
|
56
72
|
nameAndPubkey: Buffer.from(
|
|
@@ -63,12 +79,13 @@ const swapProviders: Record<
|
|
|
63
79
|
),
|
|
64
80
|
curve: "secpk256k1",
|
|
65
81
|
needsKYC: true,
|
|
82
|
+
needsBearerToken: false,
|
|
66
83
|
},
|
|
84
|
+
ftx,
|
|
85
|
+
ftxus: ftx,
|
|
67
86
|
};
|
|
68
87
|
|
|
69
|
-
const
|
|
70
|
-
providerName: string
|
|
71
|
-
): ExchangeProviderNameAndSignature => {
|
|
88
|
+
const getProviderConfig = (providerName: string): SwapProviderConfig => {
|
|
72
89
|
const res = swapProviders[providerName.toLowerCase()];
|
|
73
90
|
|
|
74
91
|
if (!res) {
|
|
@@ -78,6 +95,8 @@ const getProviderNameAndSignature = (
|
|
|
78
95
|
return res;
|
|
79
96
|
};
|
|
80
97
|
|
|
98
|
+
export const getAvailableProviders = (): string[] => Object.keys(swapProviders);
|
|
99
|
+
|
|
81
100
|
const USStates = {
|
|
82
101
|
AL: "Alabama",
|
|
83
102
|
AK: "Alaska",
|
|
@@ -160,14 +179,16 @@ export const getSwapAPIError = (errorCode: number, errorMessage?: string) => {
|
|
|
160
179
|
|
|
161
180
|
export {
|
|
162
181
|
getSwapAPIBaseURL,
|
|
163
|
-
|
|
182
|
+
getProviderConfig,
|
|
164
183
|
getProviders,
|
|
165
|
-
getStatus,
|
|
166
184
|
getExchangeRates,
|
|
167
185
|
getCompleteSwapHistory,
|
|
186
|
+
postSwapAccepted,
|
|
187
|
+
postSwapCancelled,
|
|
168
188
|
initSwap,
|
|
169
189
|
getKYCStatus,
|
|
170
190
|
submitKYC,
|
|
191
|
+
checkQuote,
|
|
171
192
|
USStates,
|
|
172
193
|
countries,
|
|
173
194
|
};
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";
|
|
2
3
|
import { log } from "@ledgerhq/logs";
|
|
3
|
-
import {
|
|
4
|
-
import secp256k1 from "secp256k1";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
5
|
import invariant from "invariant";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { mockInitSwap } from "./mock";
|
|
10
|
-
import perFamily from "../../generated/exchange";
|
|
6
|
+
import { from, Observable } from "rxjs";
|
|
7
|
+
import secp256k1 from "secp256k1";
|
|
8
|
+
import { getCurrencyExchangeConfig } from "../";
|
|
11
9
|
import {
|
|
12
10
|
getAccountCurrency,
|
|
13
|
-
getMainAccount,
|
|
14
11
|
getAccountUnit,
|
|
12
|
+
getMainAccount,
|
|
15
13
|
} from "../../account";
|
|
16
|
-
import network from "../../network";
|
|
17
14
|
import { getAccountBridge } from "../../bridge";
|
|
18
|
-
import {
|
|
15
|
+
import { getEnv } from "../../env";
|
|
19
16
|
import { SwapGenericAPIError, TransactionRefusedOnDevice } from "../../errors";
|
|
20
|
-
import
|
|
21
|
-
import { Observable } from "rxjs";
|
|
17
|
+
import perFamily from "../../generated/exchange";
|
|
22
18
|
import { withDevice } from "../../hw/deviceAccess";
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
19
|
+
import network from "../../network";
|
|
20
|
+
import { delay } from "../../promise";
|
|
21
|
+
import Exchange, {
|
|
22
|
+
ExchangeTypes,
|
|
23
|
+
RateTypes,
|
|
24
|
+
} from "../hw-app-exchange/Exchange";
|
|
25
|
+
import { getProviderConfig, getSwapAPIBaseURL } from "./";
|
|
26
|
+
import { mockInitSwap } from "./mock";
|
|
27
|
+
import type { InitSwapInput, SwapRequestEvent } from "./types";
|
|
27
28
|
|
|
28
29
|
const withDevicePromise = (deviceId, fn) =>
|
|
29
30
|
withDevice(deviceId)((transport) => from(fn(transport))).toPromise();
|
|
@@ -32,14 +33,15 @@ const withDevicePromise = (deviceId, fn) =>
|
|
|
32
33
|
// throw if TransactionStatus have errors
|
|
33
34
|
// you get at the end a final Transaction to be done (it's not yet signed, nor broadcasted!) and a swapId
|
|
34
35
|
const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
36
|
+
let swapId;
|
|
35
37
|
let { transaction } = input;
|
|
36
38
|
const { exchange, exchangeRate, deviceId, userId } = input;
|
|
39
|
+
|
|
37
40
|
if (getEnv("MOCK")) return mockInitSwap(exchange, exchangeRate, transaction);
|
|
38
41
|
return new Observable((o) => {
|
|
39
42
|
let unsubscribed = false;
|
|
40
43
|
|
|
41
44
|
const confirmSwap = async () => {
|
|
42
|
-
let swapId;
|
|
43
45
|
let ignoreTransportError;
|
|
44
46
|
log("swap", `attempt to connect to ${deviceId}`);
|
|
45
47
|
await withDevicePromise(deviceId, async (transport) => {
|
|
@@ -70,34 +72,45 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
70
72
|
// NB Added the try/catch because of the API stability issues.
|
|
71
73
|
let res;
|
|
72
74
|
|
|
75
|
+
const swapProviderConfig = getProviderConfig(provider);
|
|
76
|
+
|
|
77
|
+
const { needsBearerToken } = swapProviderConfig;
|
|
78
|
+
|
|
79
|
+
const headers = {
|
|
80
|
+
EquipmentId: getEnv("USER_ID"),
|
|
81
|
+
...(needsBearerToken ? { Authorization: `Bearer ${userId}` } : {}),
|
|
82
|
+
...(userId ? { userId } : {}), // NB: only for Wyre AFAIK
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const data = {
|
|
86
|
+
provider,
|
|
87
|
+
amountFrom: apiAmount.toString(),
|
|
88
|
+
from: refundCurrency.id,
|
|
89
|
+
to: payoutCurrency.id,
|
|
90
|
+
address: payoutAccount.freshAddress,
|
|
91
|
+
refundAddress: refundAccount.freshAddress,
|
|
92
|
+
deviceTransactionId,
|
|
93
|
+
...(rateId && ratesFlag === RateTypes.Fixed
|
|
94
|
+
? {
|
|
95
|
+
rateId,
|
|
96
|
+
}
|
|
97
|
+
: {}), // NB float rates dont need rate ids.
|
|
98
|
+
};
|
|
99
|
+
|
|
73
100
|
try {
|
|
74
101
|
res = await network({
|
|
75
102
|
method: "POST",
|
|
76
103
|
url: `${getSwapAPIBaseURL()}/swap`,
|
|
77
|
-
headers
|
|
78
|
-
|
|
79
|
-
...(userId ? { userId } : {}),
|
|
80
|
-
},
|
|
81
|
-
data: {
|
|
82
|
-
provider,
|
|
83
|
-
amountFrom: apiAmount,
|
|
84
|
-
from: refundCurrency.id,
|
|
85
|
-
to: payoutCurrency.id,
|
|
86
|
-
address: payoutAccount.freshAddress,
|
|
87
|
-
refundAddress: refundAccount.freshAddress,
|
|
88
|
-
deviceTransactionId,
|
|
89
|
-
...(rateId
|
|
90
|
-
? {
|
|
91
|
-
rateId,
|
|
92
|
-
}
|
|
93
|
-
: {}), // NB float rates dont need rate ids.
|
|
94
|
-
},
|
|
104
|
+
headers,
|
|
105
|
+
data,
|
|
95
106
|
});
|
|
107
|
+
|
|
96
108
|
if (unsubscribed || !res || !res.data) return;
|
|
97
109
|
} catch (e) {
|
|
98
110
|
o.next({
|
|
99
111
|
type: "init-swap-error",
|
|
100
112
|
error: new SwapGenericAPIError(),
|
|
113
|
+
swapId,
|
|
101
114
|
});
|
|
102
115
|
o.complete();
|
|
103
116
|
return;
|
|
@@ -105,9 +118,7 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
105
118
|
|
|
106
119
|
const swapResult = res.data;
|
|
107
120
|
swapId = swapResult.swapId;
|
|
108
|
-
|
|
109
|
-
swapResult.provider
|
|
110
|
-
);
|
|
121
|
+
|
|
111
122
|
const accountBridge = getAccountBridge(refundAccount);
|
|
112
123
|
transaction = accountBridge.updateTransaction(transaction, {
|
|
113
124
|
recipient: swapResult.payinAddress,
|
|
@@ -157,10 +168,12 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
// Prepare swap app to receive the tx to forward.
|
|
160
|
-
await swap.setPartnerKey(
|
|
171
|
+
await swap.setPartnerKey(swapProviderConfig.nameAndPubkey);
|
|
161
172
|
if (unsubscribed) return;
|
|
162
|
-
|
|
173
|
+
|
|
174
|
+
await swap.checkPartner(swapProviderConfig.signature);
|
|
163
175
|
if (unsubscribed) return;
|
|
176
|
+
|
|
164
177
|
await swap.processTransaction(
|
|
165
178
|
Buffer.from(swapResult.binaryPayload, "hex"),
|
|
166
179
|
estimatedFees
|
|
@@ -304,6 +317,7 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
304
317
|
o.next({
|
|
305
318
|
type: "init-swap-error",
|
|
306
319
|
error: e,
|
|
320
|
+
swapId,
|
|
307
321
|
});
|
|
308
322
|
o.complete();
|
|
309
323
|
unsubscribed = true;
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable, of } from "rxjs";
|
|
3
|
+
import { getAccountUnit } from "../../account";
|
|
4
|
+
import { formatCurrencyUnit } from "../../currencies";
|
|
5
|
+
import { getEnv } from "../../env";
|
|
6
|
+
import {
|
|
7
|
+
SwapExchangeRateAmountTooHigh,
|
|
8
|
+
SwapExchangeRateAmountTooLow,
|
|
9
|
+
} from "../../errors";
|
|
10
|
+
import type { CryptoCurrency, TokenCurrency, Transaction } from "../../types";
|
|
11
|
+
import { getSwapAPIBaseURL } from "./";
|
|
2
12
|
import type {
|
|
13
|
+
CheckQuote,
|
|
3
14
|
Exchange,
|
|
4
15
|
ExchangeRate,
|
|
5
16
|
GetMultipleStatus,
|
|
6
17
|
GetProviders,
|
|
7
18
|
KYCStatus,
|
|
19
|
+
PostSwapAccepted,
|
|
20
|
+
PostSwapCancelled,
|
|
8
21
|
SwapRequestEvent,
|
|
9
22
|
ValidKYCStatus,
|
|
10
23
|
} from "./types";
|
|
11
|
-
import { getAccountUnit } from "../../account";
|
|
12
|
-
import type { Transaction, TokenCurrency, CryptoCurrency } from "../../types";
|
|
13
|
-
import { formatCurrencyUnit } from "../../currencies";
|
|
14
|
-
import {
|
|
15
|
-
SwapExchangeRateAmountTooLow,
|
|
16
|
-
SwapExchangeRateAmountTooHigh,
|
|
17
|
-
} from "../../errors";
|
|
18
|
-
import { Observable, of } from "rxjs";
|
|
19
|
-
import { getSwapAPIBaseURL } from "./";
|
|
20
24
|
|
|
21
25
|
export const getMockExchangeRate = ({
|
|
22
|
-
provider = "
|
|
26
|
+
provider = "ftx",
|
|
23
27
|
tradeMethod = "fixed",
|
|
24
28
|
}: {
|
|
25
29
|
provider?: string;
|
|
@@ -90,7 +94,7 @@ export const mockGetExchangeRates = async (
|
|
|
90
94
|
toAmount: amount.times(magnitudeAwareRate),
|
|
91
95
|
magnitudeAwareRate,
|
|
92
96
|
rateId: "mockedRateId",
|
|
93
|
-
provider: "
|
|
97
|
+
provider: "ftx",
|
|
94
98
|
expirationDate: new Date(),
|
|
95
99
|
tradeMethod: "fixed",
|
|
96
100
|
},
|
|
@@ -99,7 +103,7 @@ export const mockGetExchangeRates = async (
|
|
|
99
103
|
toAmount: amount.times(magnitudeAwareRate),
|
|
100
104
|
magnitudeAwareRate,
|
|
101
105
|
rateId: "mockedRateId",
|
|
102
|
-
provider: "
|
|
106
|
+
provider: "ftx",
|
|
103
107
|
expirationDate: new Date(),
|
|
104
108
|
tradeMethod: "float",
|
|
105
109
|
},
|
|
@@ -126,7 +130,7 @@ export const mockGetProviders: GetProviders = async () => {
|
|
|
126
130
|
return usesV3
|
|
127
131
|
? [
|
|
128
132
|
{
|
|
129
|
-
provider: "
|
|
133
|
+
provider: "ftx",
|
|
130
134
|
pairs: [
|
|
131
135
|
{ from: "bitcoin", to: "ethereum", tradeMethod: "float" },
|
|
132
136
|
{ from: "bitcoin", to: "ethereum", tradeMethod: "fixed" },
|
|
@@ -187,3 +191,114 @@ export const mockGetKYCStatus = async (
|
|
|
187
191
|
await new Promise((r) => setTimeout(r, 2000));
|
|
188
192
|
return { id, status };
|
|
189
193
|
};
|
|
194
|
+
|
|
195
|
+
const mockedCheckQuoteStatusCode = getEnv("MOCK_SWAP_CHECK_QUOTE");
|
|
196
|
+
|
|
197
|
+
export const mockCheckQuote: CheckQuote = async ({
|
|
198
|
+
provider: _provider,
|
|
199
|
+
quoteId: _quoteId,
|
|
200
|
+
bearerToken: _bearerToken,
|
|
201
|
+
}) => {
|
|
202
|
+
//Fake delay to show the pending state in the UI
|
|
203
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
204
|
+
|
|
205
|
+
switch (mockedCheckQuoteStatusCode) {
|
|
206
|
+
case "RATE_VALID":
|
|
207
|
+
return { codeName: mockedCheckQuoteStatusCode };
|
|
208
|
+
|
|
209
|
+
case "KYC_FAILED":
|
|
210
|
+
return {
|
|
211
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
212
|
+
error: "KYC Failed",
|
|
213
|
+
description: "The KYC verification failed",
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
case "KYC_PENDING":
|
|
217
|
+
return {
|
|
218
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
219
|
+
error: "KYC Pending",
|
|
220
|
+
description: "The KYC is pending",
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
case "KYC_UNDEFINED":
|
|
224
|
+
return {
|
|
225
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
226
|
+
error: "KYC undifined",
|
|
227
|
+
description: "The KYC is undifined",
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
case "KYC_UPGRADE_REQUIRED":
|
|
231
|
+
return {
|
|
232
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
233
|
+
error: "KYC upgrade requierd",
|
|
234
|
+
description: "Need to upgrade KYC level",
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
case "MFA_REQUIRED":
|
|
238
|
+
return {
|
|
239
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
240
|
+
error: "MFA requierd",
|
|
241
|
+
description: "Need to enable MFA",
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
case "OVER_TRADE_LIMIT":
|
|
245
|
+
return {
|
|
246
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
247
|
+
error: "Trade over the limit",
|
|
248
|
+
description: "You have reached your trade limit",
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
case "UNKNOW_USER":
|
|
252
|
+
return {
|
|
253
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
254
|
+
error: "Unknown user",
|
|
255
|
+
description: "Provided bearerToken does not match any known user",
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
case "RATE_NOT_FOUND":
|
|
259
|
+
return {
|
|
260
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
261
|
+
error: "Rate not found",
|
|
262
|
+
description: "Rate not found",
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
case "WITHDRAWALS_BLOCKED":
|
|
266
|
+
return {
|
|
267
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
268
|
+
error: "Withdrawals blocked",
|
|
269
|
+
description: "Withdrawals blocked",
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
default:
|
|
273
|
+
return {
|
|
274
|
+
codeName: "UNKNOWN_ERROR",
|
|
275
|
+
error: "Unknown error",
|
|
276
|
+
description: "Something unexpected happened",
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export const mockPostSwapAccepted: PostSwapAccepted = async ({
|
|
282
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
283
|
+
provider,
|
|
284
|
+
swapId,
|
|
285
|
+
transactionId,
|
|
286
|
+
/* eslint-enable */
|
|
287
|
+
}) => {
|
|
288
|
+
//Fake delay to simulate network
|
|
289
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
290
|
+
|
|
291
|
+
return null;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const mockPostSwapCancelled: PostSwapCancelled = async ({
|
|
295
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
296
|
+
provider,
|
|
297
|
+
swapId,
|
|
298
|
+
/* eslint-enable */
|
|
299
|
+
}) => {
|
|
300
|
+
//Fake delay to simulate network
|
|
301
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
302
|
+
|
|
303
|
+
return null;
|
|
304
|
+
};
|