@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/portfolio/index.ts
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import memoize from "lodash/memoize";
|
|
3
|
-
import last from "lodash/last";
|
|
4
|
-
import find from "lodash/find";
|
|
5
|
-
import type {
|
|
6
|
-
AccountLikeArray,
|
|
7
|
-
AccountLike,
|
|
8
|
-
Account,
|
|
9
|
-
BalanceHistory,
|
|
10
|
-
AccountPortfolio,
|
|
11
|
-
CurrencyPortfolio,
|
|
12
|
-
PortfolioRange,
|
|
13
|
-
BalanceHistoryWithCountervalue,
|
|
14
|
-
Portfolio,
|
|
15
|
-
AssetsDistribution,
|
|
16
|
-
TokenCurrency,
|
|
17
|
-
CryptoCurrency,
|
|
18
|
-
} from "../types";
|
|
19
|
-
import { getOperationAmountNumberWithInternals } from "../operation";
|
|
20
|
-
import { flattenAccounts, getAccountCurrency } from "../account/helpers";
|
|
21
|
-
import { getEnv } from "../env";
|
|
22
|
-
import { getPortfolioRangeConfig, getDates } from "./range";
|
|
23
|
-
|
|
24
|
-
export * from "./range";
|
|
25
|
-
|
|
26
|
-
type GetBalanceHistory = (
|
|
27
|
-
account: AccountLike,
|
|
28
|
-
r: PortfolioRange
|
|
29
|
-
) => BalanceHistory;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* generate an array of {daysCount} datapoints, one per day,
|
|
33
|
-
* for the balance history of an account.
|
|
34
|
-
* The last item of the array is the balance available right now.
|
|
35
|
-
* @memberof account
|
|
36
|
-
*/
|
|
37
|
-
const getBalanceHistoryImpl: GetBalanceHistory = (account, r) => {
|
|
38
|
-
const conf = getPortfolioRangeConfig(r);
|
|
39
|
-
const history: Array<{ date: Date; value: BigNumber }> = [];
|
|
40
|
-
let { balance } = account;
|
|
41
|
-
const operationsLength = account.operations.length;
|
|
42
|
-
let i = 0; // index of operation
|
|
43
|
-
|
|
44
|
-
let t = new Date();
|
|
45
|
-
history.unshift({
|
|
46
|
-
date: t,
|
|
47
|
-
value: balance,
|
|
48
|
-
});
|
|
49
|
-
t = new Date((conf.startOf(t) as any) - 1); // end of yesterday
|
|
50
|
-
|
|
51
|
-
for (let d = conf.count - 1; d > 0; d--) {
|
|
52
|
-
// accumulate operations after time t
|
|
53
|
-
while (i < operationsLength && account.operations[i].date > t) {
|
|
54
|
-
balance = balance.minus(
|
|
55
|
-
getOperationAmountNumberWithInternals(account.operations[i])
|
|
56
|
-
);
|
|
57
|
-
i++;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (i === operationsLength) {
|
|
61
|
-
// When there is no more operation, we consider we reached ZERO to avoid invalid assumption that balance was already available.
|
|
62
|
-
balance = new BigNumber(0);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
history.unshift({
|
|
66
|
-
date: t,
|
|
67
|
-
value: BigNumber.max(balance, 0),
|
|
68
|
-
});
|
|
69
|
-
t = new Date((t as any) - conf.increment);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return history;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const accountRateHash = (account, r) =>
|
|
76
|
-
`${r}_${account.id}_${account.balance.toString()}_${
|
|
77
|
-
account.operations[0] ? account.operations[0].id : ""
|
|
78
|
-
}`;
|
|
79
|
-
|
|
80
|
-
export const getBalanceHistoryJS: GetBalanceHistory = memoize(
|
|
81
|
-
getBalanceHistoryImpl,
|
|
82
|
-
accountRateHash
|
|
83
|
-
);
|
|
84
|
-
export const getBalanceHistory: GetBalanceHistory = (account, r) => {
|
|
85
|
-
// try to find it in the account object
|
|
86
|
-
const balanceHistory = account.balanceHistory;
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
balanceHistory &&
|
|
90
|
-
balanceHistory[r] &&
|
|
91
|
-
(<BalanceHistory>balanceHistory[r]).length > 1
|
|
92
|
-
) {
|
|
93
|
-
return <BalanceHistory>balanceHistory[r];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// fallback on JS implementation
|
|
97
|
-
return getBalanceHistoryJS(account, r);
|
|
98
|
-
};
|
|
99
|
-
type GetBalanceHistoryWithCountervalue = (
|
|
100
|
-
account: AccountLike,
|
|
101
|
-
r: PortfolioRange,
|
|
102
|
-
calculateAccountCounterValue: (
|
|
103
|
-
arg0: TokenCurrency | CryptoCurrency,
|
|
104
|
-
arg1: BigNumber,
|
|
105
|
-
arg2: Date
|
|
106
|
-
) => BigNumber | null | undefined,
|
|
107
|
-
useEffectiveFrom?: boolean
|
|
108
|
-
) => AccountPortfolio;
|
|
109
|
-
|
|
110
|
-
// hash the "stable" part of the histo
|
|
111
|
-
// only the latest datapoint is "unstable" meaning it always changes because it's the current date.
|
|
112
|
-
const accountRateHashCVStable = (account, r, cvRef, useEffectiveFrom) =>
|
|
113
|
-
`${accountRateHash(account, r)}_${cvRef ? cvRef.toString() : "none"}_${
|
|
114
|
-
useEffectiveFrom ? "withEffectiveFrom" : ""
|
|
115
|
-
}`;
|
|
116
|
-
|
|
117
|
-
const accountCVstableCache = {};
|
|
118
|
-
const ZERO = new BigNumber(0);
|
|
119
|
-
const percentageHighThreshold = 100000;
|
|
120
|
-
|
|
121
|
-
const meaningfulPercentage = (
|
|
122
|
-
deltaChange: BigNumber | null | undefined,
|
|
123
|
-
balanceDivider: BigNumber | null | undefined
|
|
124
|
-
): BigNumber | null | undefined => {
|
|
125
|
-
if (deltaChange && balanceDivider && !balanceDivider.isZero()) {
|
|
126
|
-
const percent = deltaChange.div(balanceDivider);
|
|
127
|
-
|
|
128
|
-
if (percent.lt(percentageHighThreshold)) {
|
|
129
|
-
return percent;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const getBalanceHistoryWithCountervalue: GetBalanceHistoryWithCountervalue =
|
|
135
|
-
(account, r, calc, useEffectiveFrom = true) => {
|
|
136
|
-
const history = getBalanceHistory(account, r);
|
|
137
|
-
const cur = getAccountCurrency(account);
|
|
138
|
-
// a high enough value so we can compare if something changes
|
|
139
|
-
const cacheReferenceValue = new BigNumber("10").pow(
|
|
140
|
-
3 + cur.units[0].magnitude
|
|
141
|
-
);
|
|
142
|
-
// pick a stable countervalue point in time to hash for the cache
|
|
143
|
-
const cvRef = calc(cur, cacheReferenceValue, history[0].date);
|
|
144
|
-
|
|
145
|
-
const mapFn = (p) => ({
|
|
146
|
-
...p,
|
|
147
|
-
countervalue: (cvRef && calc(cur, p.value, p.date)) || ZERO,
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const stableHash = accountRateHashCVStable(
|
|
151
|
-
account,
|
|
152
|
-
r,
|
|
153
|
-
cvRef,
|
|
154
|
-
useEffectiveFrom
|
|
155
|
-
);
|
|
156
|
-
let stable = accountCVstableCache[stableHash];
|
|
157
|
-
const lastPoint = mapFn(history[history.length - 1]);
|
|
158
|
-
|
|
159
|
-
const calcChanges = (h: BalanceHistoryWithCountervalue) => {
|
|
160
|
-
// previous existing implementation here
|
|
161
|
-
const from = h[0];
|
|
162
|
-
const to = h[h.length - 1];
|
|
163
|
-
const fromEffective = useEffectiveFrom
|
|
164
|
-
? find(h, (record) => record.value.isGreaterThan(0)) || from
|
|
165
|
-
: from;
|
|
166
|
-
return {
|
|
167
|
-
countervalueReceiveSum: new BigNumber(0),
|
|
168
|
-
// not available here
|
|
169
|
-
countervalueSendSum: new BigNumber(0),
|
|
170
|
-
cryptoChange: {
|
|
171
|
-
value: to.value.minus(fromEffective.value),
|
|
172
|
-
percentage: null,
|
|
173
|
-
},
|
|
174
|
-
countervalueChange: {
|
|
175
|
-
value: (to.countervalue || ZERO).minus(
|
|
176
|
-
fromEffective.countervalue || ZERO
|
|
177
|
-
),
|
|
178
|
-
percentage: meaningfulPercentage(
|
|
179
|
-
(to.countervalue || ZERO).minus(fromEffective.countervalue || ZERO),
|
|
180
|
-
fromEffective.countervalue
|
|
181
|
-
),
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
if (!stable) {
|
|
187
|
-
const h = history.map(mapFn);
|
|
188
|
-
stable = {
|
|
189
|
-
history: h,
|
|
190
|
-
countervalueAvailable: !!cvRef,
|
|
191
|
-
...calcChanges(h),
|
|
192
|
-
};
|
|
193
|
-
accountCVstableCache[stableHash] = stable;
|
|
194
|
-
return stable;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const lastStable: any = last(stable.history);
|
|
198
|
-
|
|
199
|
-
if (lastPoint.countervalue.eq(lastStable.countervalue)) {
|
|
200
|
-
return stable;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const h = stable.history.slice(0, -1).concat(lastPoint);
|
|
204
|
-
const copy = { ...stable, history: h, ...calcChanges(h) };
|
|
205
|
-
accountCVstableCache[stableHash] = copy;
|
|
206
|
-
return copy;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* calculate the total balance history for all accounts in a reference fiat unit
|
|
211
|
-
* and using a CalculateCounterValue function (see countervalue helper)
|
|
212
|
-
* NB the last item of the array is actually the current total balance.
|
|
213
|
-
* @memberof account
|
|
214
|
-
*/
|
|
215
|
-
export function getPortfolio(
|
|
216
|
-
topAccounts: Account[],
|
|
217
|
-
range: PortfolioRange,
|
|
218
|
-
calc: (
|
|
219
|
-
arg0: TokenCurrency | CryptoCurrency,
|
|
220
|
-
arg1: BigNumber,
|
|
221
|
-
arg2: Date
|
|
222
|
-
) => BigNumber | null | undefined
|
|
223
|
-
): Portfolio {
|
|
224
|
-
const accounts: AccountLike[] = flattenAccounts(topAccounts);
|
|
225
|
-
const availableAccounts: AccountLike[] = [];
|
|
226
|
-
const unavailableAccounts: AccountLike[] = [];
|
|
227
|
-
const histories: BalanceHistoryWithCountervalue[] = [];
|
|
228
|
-
const changes: BigNumber[] = [];
|
|
229
|
-
const countervalueReceiveSums: BigNumber[] = [];
|
|
230
|
-
const countervalueSendSums: BigNumber[] = [];
|
|
231
|
-
|
|
232
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
233
|
-
const account = accounts[i];
|
|
234
|
-
const r = getBalanceHistoryWithCountervalue(account, range, calc, false);
|
|
235
|
-
|
|
236
|
-
if (r.countervalueAvailable) {
|
|
237
|
-
availableAccounts.push(account);
|
|
238
|
-
histories.push(r.history);
|
|
239
|
-
changes.push(r.countervalueChange.value);
|
|
240
|
-
countervalueReceiveSums.push(r.countervalueReceiveSum);
|
|
241
|
-
countervalueSendSums.push(r.countervalueSendSum);
|
|
242
|
-
} else {
|
|
243
|
-
unavailableAccounts.push(account);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const unavailableCurrencies: any[] = [
|
|
248
|
-
...new Set(unavailableAccounts.map(getAccountCurrency)),
|
|
249
|
-
];
|
|
250
|
-
const balanceAvailable =
|
|
251
|
-
accounts.length === 0 || availableAccounts.length > 0;
|
|
252
|
-
const balanceHistory = getDates(range).map((date) => ({
|
|
253
|
-
date,
|
|
254
|
-
value: ZERO,
|
|
255
|
-
}));
|
|
256
|
-
|
|
257
|
-
for (let i = 0; i < histories.length; i++) {
|
|
258
|
-
const history = histories[i];
|
|
259
|
-
|
|
260
|
-
for (let j = 0; j < history.length; j++) {
|
|
261
|
-
const res = balanceHistory[j];
|
|
262
|
-
|
|
263
|
-
if (res) {
|
|
264
|
-
res.value = res.value.plus(history[j].countervalue);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const countervalueChangeValue: BigNumber = changes.reduce(
|
|
270
|
-
(sum, v) => sum.plus(v),
|
|
271
|
-
new BigNumber(0)
|
|
272
|
-
);
|
|
273
|
-
const countervalueReceiveSum: BigNumber = countervalueReceiveSums.reduce(
|
|
274
|
-
(sum, v) => sum.plus(v),
|
|
275
|
-
new BigNumber(0)
|
|
276
|
-
);
|
|
277
|
-
const countervalueSendSum: BigNumber = countervalueSendSums.reduce(
|
|
278
|
-
(sum, v) => sum.plus(v),
|
|
279
|
-
new BigNumber(0)
|
|
280
|
-
);
|
|
281
|
-
// in case there were no receive, we just track the market change
|
|
282
|
-
// weighted by the current balances
|
|
283
|
-
let countervalueChangePercentage;
|
|
284
|
-
|
|
285
|
-
if (getEnv("EXPERIMENTAL_ROI_CALCULATION")) {
|
|
286
|
-
if (countervalueReceiveSum.isZero()) {
|
|
287
|
-
countervalueChangePercentage = meaningfulPercentage(
|
|
288
|
-
countervalueChangeValue,
|
|
289
|
-
balanceHistory[0].value.plus(countervalueSendSum)
|
|
290
|
-
);
|
|
291
|
-
} else {
|
|
292
|
-
countervalueChangePercentage = meaningfulPercentage(
|
|
293
|
-
countervalueChangeValue,
|
|
294
|
-
countervalueReceiveSum
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
} else {
|
|
298
|
-
countervalueChangePercentage = meaningfulPercentage(
|
|
299
|
-
countervalueChangeValue, // in non experimental mode, we were dividing by first point
|
|
300
|
-
balanceHistory[0].value
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const ret = {
|
|
305
|
-
balanceHistory,
|
|
306
|
-
balanceAvailable,
|
|
307
|
-
availableAccounts,
|
|
308
|
-
unavailableCurrencies,
|
|
309
|
-
accounts,
|
|
310
|
-
range,
|
|
311
|
-
histories,
|
|
312
|
-
countervalueReceiveSum,
|
|
313
|
-
countervalueSendSum,
|
|
314
|
-
countervalueChange: {
|
|
315
|
-
percentage: countervalueChangePercentage,
|
|
316
|
-
value: countervalueChangeValue,
|
|
317
|
-
},
|
|
318
|
-
};
|
|
319
|
-
return ret;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* calculate the total balance history for all accounts in a reference fiat unit
|
|
324
|
-
* and using a CalculateCounterValue function (see countervalue helper)
|
|
325
|
-
* NB the last item of the array is actually the current total balance.
|
|
326
|
-
* @memberof account
|
|
327
|
-
*/
|
|
328
|
-
export function getCurrencyPortfolio(
|
|
329
|
-
accounts: AccountLikeArray,
|
|
330
|
-
range: PortfolioRange,
|
|
331
|
-
calc: (
|
|
332
|
-
arg0: TokenCurrency | CryptoCurrency,
|
|
333
|
-
arg1: BigNumber,
|
|
334
|
-
arg2: Date
|
|
335
|
-
) => BigNumber | null | undefined
|
|
336
|
-
): CurrencyPortfolio {
|
|
337
|
-
const histories: BalanceHistoryWithCountervalue[] = [];
|
|
338
|
-
let countervalueAvailable = false;
|
|
339
|
-
|
|
340
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
341
|
-
const account = accounts[i];
|
|
342
|
-
const r = getBalanceHistoryWithCountervalue(account, range, calc);
|
|
343
|
-
histories.push(r.history);
|
|
344
|
-
countervalueAvailable = r.countervalueAvailable;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const history = getDates(range).map((date) => ({
|
|
348
|
-
date,
|
|
349
|
-
value: ZERO,
|
|
350
|
-
countervalue: ZERO,
|
|
351
|
-
}));
|
|
352
|
-
|
|
353
|
-
for (let i = 0; i < histories.length; i++) {
|
|
354
|
-
const h = histories[i];
|
|
355
|
-
|
|
356
|
-
for (let j = 0; j < h.length; j++) {
|
|
357
|
-
const res = history[j];
|
|
358
|
-
res.value = res.value.plus(h[j].value);
|
|
359
|
-
res.countervalue = res.countervalue.plus(h[j].countervalue);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// previous existing implementation here
|
|
364
|
-
const from = history[0];
|
|
365
|
-
const to = history[history.length - 1];
|
|
366
|
-
const fromEffective =
|
|
367
|
-
(find(history, (record) => record.value.isGreaterThan(0)) as {
|
|
368
|
-
date: Date;
|
|
369
|
-
value: any;
|
|
370
|
-
countervalue: any;
|
|
371
|
-
}) || from;
|
|
372
|
-
const cryptoChange = {
|
|
373
|
-
value: to.value.minus(from.value),
|
|
374
|
-
percentage: null,
|
|
375
|
-
};
|
|
376
|
-
const countervalueChange = {
|
|
377
|
-
value: (to.countervalue || ZERO).minus(fromEffective.countervalue || ZERO),
|
|
378
|
-
percentage: meaningfulPercentage(
|
|
379
|
-
(to.countervalue || ZERO).minus(fromEffective.countervalue || ZERO),
|
|
380
|
-
fromEffective.countervalue
|
|
381
|
-
),
|
|
382
|
-
};
|
|
383
|
-
const ret = {
|
|
384
|
-
history,
|
|
385
|
-
countervalueAvailable,
|
|
386
|
-
accounts,
|
|
387
|
-
range,
|
|
388
|
-
histories,
|
|
389
|
-
cryptoChange,
|
|
390
|
-
countervalueChange,
|
|
391
|
-
};
|
|
392
|
-
return ret;
|
|
393
|
-
}
|
|
394
|
-
export const defaultAssetsDistribution = {
|
|
395
|
-
minShowFirst: 1,
|
|
396
|
-
maxShowFirst: 6,
|
|
397
|
-
showFirstThreshold: 0.95,
|
|
398
|
-
};
|
|
399
|
-
export type AssetsDistributionOpts = typeof defaultAssetsDistribution;
|
|
400
|
-
const assetsDistributionNotAvailable: AssetsDistribution = {
|
|
401
|
-
isAvailable: false,
|
|
402
|
-
list: [],
|
|
403
|
-
showFirst: 0,
|
|
404
|
-
sum: new BigNumber(0),
|
|
405
|
-
};
|
|
406
|
-
const previousDistributionCache = {
|
|
407
|
-
hash: "",
|
|
408
|
-
data: assetsDistributionNotAvailable,
|
|
409
|
-
};
|
|
410
|
-
export function getAssetsDistribution(
|
|
411
|
-
topAccounts: Account[],
|
|
412
|
-
calculateCountervalue: (
|
|
413
|
-
currency: TokenCurrency | CryptoCurrency,
|
|
414
|
-
value: BigNumber
|
|
415
|
-
) => BigNumber | null | undefined,
|
|
416
|
-
opts?: AssetsDistributionOpts
|
|
417
|
-
): AssetsDistribution {
|
|
418
|
-
const { minShowFirst, maxShowFirst, showFirstThreshold } = {
|
|
419
|
-
...defaultAssetsDistribution,
|
|
420
|
-
...opts,
|
|
421
|
-
};
|
|
422
|
-
let sum = new BigNumber(0);
|
|
423
|
-
const idBalances = {};
|
|
424
|
-
const idCurrencies = {};
|
|
425
|
-
const accounts = flattenAccounts(topAccounts);
|
|
426
|
-
|
|
427
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
428
|
-
const account = accounts[i];
|
|
429
|
-
const cur = getAccountCurrency(account);
|
|
430
|
-
const id = cur.id;
|
|
431
|
-
|
|
432
|
-
if (account.balance.isGreaterThan(0)) {
|
|
433
|
-
idCurrencies[id] = cur;
|
|
434
|
-
idBalances[id] = (idBalances[id] || new BigNumber(0)).plus(
|
|
435
|
-
account.balance
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const idCountervalues = {};
|
|
441
|
-
|
|
442
|
-
for (const id in idBalances) {
|
|
443
|
-
const countervalue = calculateCountervalue(
|
|
444
|
-
idCurrencies[id],
|
|
445
|
-
idBalances[id]
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
if (countervalue) {
|
|
449
|
-
idCountervalues[id] = countervalue;
|
|
450
|
-
sum = sum.plus(countervalue);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const idCurrenciesKeys = Object.keys(idCurrencies);
|
|
455
|
-
|
|
456
|
-
if (idCurrenciesKeys.length === 0) {
|
|
457
|
-
return assetsDistributionNotAvailable;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
const isAvailable = !sum.isZero();
|
|
461
|
-
const hash = `${idCurrenciesKeys.length}_${sum.toString()}`;
|
|
462
|
-
|
|
463
|
-
if (hash === previousDistributionCache.hash) {
|
|
464
|
-
return previousDistributionCache.data;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const list = idCurrenciesKeys
|
|
468
|
-
.map((id) => {
|
|
469
|
-
const currency = idCurrencies[id];
|
|
470
|
-
const amount = idBalances[id];
|
|
471
|
-
const countervalue = idCountervalues[id] || new BigNumber(0);
|
|
472
|
-
return {
|
|
473
|
-
currency,
|
|
474
|
-
countervalue,
|
|
475
|
-
amount,
|
|
476
|
-
distribution: isAvailable ? countervalue.div(sum).toNumber() : 0,
|
|
477
|
-
};
|
|
478
|
-
})
|
|
479
|
-
.sort((a, b) => {
|
|
480
|
-
const diff = b.countervalue.minus(a.countervalue).toNumber();
|
|
481
|
-
if (diff === 0) return a.currency.name.localeCompare(b.currency.name);
|
|
482
|
-
return diff;
|
|
483
|
-
});
|
|
484
|
-
let i;
|
|
485
|
-
let acc = 0;
|
|
486
|
-
|
|
487
|
-
for (i = 0; i < maxShowFirst && i < list.length; i++) {
|
|
488
|
-
if (acc > showFirstThreshold) {
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
acc += list[i].distribution;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
const showFirst = Math.max(minShowFirst, i);
|
|
496
|
-
const data = {
|
|
497
|
-
isAvailable,
|
|
498
|
-
list,
|
|
499
|
-
showFirst,
|
|
500
|
-
sum,
|
|
501
|
-
};
|
|
502
|
-
previousDistributionCache.hash = hash;
|
|
503
|
-
previousDistributionCache.data = data;
|
|
504
|
-
return data;
|
|
505
|
-
}
|
package/src/portfolio/range.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { PortfolioRange, PortfolioRangeConfig } from "../types";
|
|
2
|
-
export const hourIncrement = 60 * 60 * 1000;
|
|
3
|
-
export const dayIncrement = 24 * hourIncrement;
|
|
4
|
-
export const weekIncrement = 7 * dayIncrement;
|
|
5
|
-
export function startOfHour(t: Date) {
|
|
6
|
-
return new Date(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours());
|
|
7
|
-
}
|
|
8
|
-
export function startOfMonth(t: Date) {
|
|
9
|
-
return new Date(t.getFullYear(), t.getMonth(), 1);
|
|
10
|
-
}
|
|
11
|
-
export function startOfDay(t: Date) {
|
|
12
|
-
return new Date(t.getFullYear(), t.getMonth(), t.getDate());
|
|
13
|
-
}
|
|
14
|
-
export function startOfWeek(t: Date) {
|
|
15
|
-
const d = startOfDay(t);
|
|
16
|
-
return new Date(d.getTime() - d.getDay() * dayIncrement);
|
|
17
|
-
}
|
|
18
|
-
const ranges: Record<PortfolioRange, PortfolioRangeConfig> = {
|
|
19
|
-
year: {
|
|
20
|
-
count: 52,
|
|
21
|
-
increment: weekIncrement,
|
|
22
|
-
startOf: startOfWeek,
|
|
23
|
-
granularityId: "WEEK",
|
|
24
|
-
},
|
|
25
|
-
month: {
|
|
26
|
-
count: 30,
|
|
27
|
-
increment: dayIncrement,
|
|
28
|
-
startOf: startOfDay,
|
|
29
|
-
granularityId: "DAY",
|
|
30
|
-
},
|
|
31
|
-
week: {
|
|
32
|
-
count: 7 * 24,
|
|
33
|
-
increment: hourIncrement,
|
|
34
|
-
startOf: startOfHour,
|
|
35
|
-
granularityId: "HOUR",
|
|
36
|
-
},
|
|
37
|
-
day: {
|
|
38
|
-
count: 24,
|
|
39
|
-
increment: hourIncrement,
|
|
40
|
-
startOf: startOfHour,
|
|
41
|
-
granularityId: "HOUR",
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const getPerPortfolioRanges = (): Record<
|
|
46
|
-
PortfolioRange,
|
|
47
|
-
PortfolioRangeConfig
|
|
48
|
-
> => {
|
|
49
|
-
return ranges;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export function getPortfolioRangeConfig(
|
|
53
|
-
r: PortfolioRange
|
|
54
|
-
): PortfolioRangeConfig {
|
|
55
|
-
return getPerPortfolioRanges()[r];
|
|
56
|
-
}
|
|
57
|
-
export const getRanges = (): PortfolioRange[] =>
|
|
58
|
-
Object.keys(getPerPortfolioRanges()) as PortfolioRange[];
|
|
59
|
-
export function getDates(r: PortfolioRange): Date[] {
|
|
60
|
-
const conf = getPortfolioRangeConfig(r);
|
|
61
|
-
let t = new Date();
|
|
62
|
-
const array = [t];
|
|
63
|
-
t = new Date(conf.startOf(t).valueOf() - 1); // end of yesterday
|
|
64
|
-
|
|
65
|
-
for (let d = conf.count - 1; d > 0; d--) {
|
|
66
|
-
array.unshift(t);
|
|
67
|
-
t = new Date(t.valueOf() - conf.increment);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return array;
|
|
71
|
-
}
|