@ledgerhq/live-common 34.51.0-nightly.8 → 34.51.0
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/bridge/generic-alpaca/estimateMaxSpendable.js +1 -1
- package/lib/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/prepareTransaction.js +45 -37
- package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
- package/lib/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/signOperation.js +20 -0
- package/lib/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +88 -186
- package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.js +1 -1
- package/lib/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.test.js +2 -2
- package/lib/bridge/generic-alpaca/utils.test.js.map +1 -1
- package/lib/dada-client/state-manager/api.d.ts.map +1 -1
- package/lib/dada-client/state-manager/api.js +5 -10
- package/lib/dada-client/state-manager/api.js.map +1 -1
- package/lib/dada-client/state-manager/types.d.ts +0 -1
- package/lib/dada-client/state-manager/types.d.ts.map +1 -1
- package/lib/device/use-cases/getAppsCatalogForDevice.d.ts +1 -1
- package/lib/device/use-cases/getAppsCatalogForDevice.d.ts.map +1 -1
- package/lib/e2e/data/deviceLabelsData.d.ts.map +1 -1
- package/lib/e2e/data/deviceLabelsData.js +4 -2
- package/lib/e2e/data/deviceLabelsData.js.map +1 -1
- package/lib/e2e/enum/Device.d.ts +4 -5
- package/lib/e2e/enum/Device.d.ts.map +1 -1
- package/lib/e2e/enum/Device.js +4 -6
- package/lib/e2e/enum/Device.js.map +1 -1
- package/lib/e2e/families/bitcoin.d.ts.map +1 -1
- package/lib/e2e/families/bitcoin.js +3 -4
- package/lib/e2e/families/bitcoin.js.map +1 -1
- package/lib/e2e/families/cardano.js +2 -2
- package/lib/e2e/families/cardano.js.map +1 -1
- package/lib/e2e/families/evm.d.ts.map +1 -1
- package/lib/e2e/families/evm.js +2 -3
- package/lib/e2e/families/evm.js.map +1 -1
- package/lib/e2e/families/solana.d.ts.map +1 -1
- package/lib/e2e/families/solana.js +5 -2
- package/lib/e2e/families/solana.js.map +1 -1
- package/lib/e2e/families/tezos.d.ts.map +1 -1
- package/lib/e2e/families/tezos.js +1 -2
- package/lib/e2e/families/tezos.js.map +1 -1
- package/lib/e2e/index.d.ts +2 -7
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/speculos.d.ts +1 -1
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +60 -53
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +2 -3
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.js +9 -14
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
- package/lib/exchange/swap/transactionStrategies.d.ts +1 -2
- package/lib/exchange/swap/transactionStrategies.d.ts.map +1 -1
- package/lib/exchange/swap/transactionStrategies.js +1 -3
- package/lib/exchange/swap/transactionStrategies.js.map +1 -1
- package/lib/exchange/swap/types.d.ts +0 -1
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/families/evm/walletApiAdapter.d.ts.map +1 -1
- package/lib/families/evm/walletApiAdapter.js +0 -5
- package/lib/families/evm/walletApiAdapter.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts +3 -0
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -10
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/load/speculos.d.ts.map +1 -1
- package/lib/load/speculos.js +0 -1
- package/lib/load/speculos.js.map +1 -1
- package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts.map +1 -0
- package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js.map +1 -0
- package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
- package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +3 -0
- package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
- package/lib/wallet-api/Exchange/server.d.ts +0 -1
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +2 -5
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib/wallet-api/react.d.ts.map +1 -1
- package/lib/wallet-api/react.js +1 -5
- package/lib/wallet-api/react.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js +1 -1
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/prepareTransaction.js +45 -37
- package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.js +17 -0
- package/lib-es/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +88 -163
- package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.js +1 -1
- package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.test.js +2 -2
- package/lib-es/bridge/generic-alpaca/utils.test.js.map +1 -1
- package/lib-es/dada-client/state-manager/api.d.ts.map +1 -1
- package/lib-es/dada-client/state-manager/api.js +5 -10
- package/lib-es/dada-client/state-manager/api.js.map +1 -1
- package/lib-es/dada-client/state-manager/types.d.ts +0 -1
- package/lib-es/dada-client/state-manager/types.d.ts.map +1 -1
- package/lib-es/device/use-cases/getAppsCatalogForDevice.d.ts +1 -1
- package/lib-es/device/use-cases/getAppsCatalogForDevice.d.ts.map +1 -1
- package/lib-es/e2e/data/deviceLabelsData.d.ts.map +1 -1
- package/lib-es/e2e/data/deviceLabelsData.js +4 -2
- package/lib-es/e2e/data/deviceLabelsData.js.map +1 -1
- package/lib-es/e2e/enum/Device.d.ts +4 -5
- package/lib-es/e2e/enum/Device.d.ts.map +1 -1
- package/lib-es/e2e/enum/Device.js +4 -6
- package/lib-es/e2e/enum/Device.js.map +1 -1
- package/lib-es/e2e/families/bitcoin.d.ts.map +1 -1
- package/lib-es/e2e/families/bitcoin.js +3 -4
- package/lib-es/e2e/families/bitcoin.js.map +1 -1
- package/lib-es/e2e/families/cardano.js +2 -2
- package/lib-es/e2e/families/cardano.js.map +1 -1
- package/lib-es/e2e/families/evm.d.ts.map +1 -1
- package/lib-es/e2e/families/evm.js +2 -3
- package/lib-es/e2e/families/evm.js.map +1 -1
- package/lib-es/e2e/families/solana.d.ts.map +1 -1
- package/lib-es/e2e/families/solana.js +6 -3
- package/lib-es/e2e/families/solana.js.map +1 -1
- package/lib-es/e2e/families/tezos.d.ts.map +1 -1
- package/lib-es/e2e/families/tezos.js +1 -2
- package/lib-es/e2e/families/tezos.js.map +1 -1
- package/lib-es/e2e/index.d.ts +2 -7
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/speculos.d.ts +1 -1
- package/lib-es/e2e/speculos.d.ts.map +1 -1
- package/lib-es/e2e/speculos.js +25 -19
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/exchange/swap/hooks/usePickDefaultAccount.js +2 -2
- package/lib-es/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -1
- package/lib-es/exchange/swap/hooks/useSwapTransaction.d.ts +2 -3
- package/lib-es/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
- package/lib-es/exchange/swap/hooks/useSwapTransaction.js +9 -14
- package/lib-es/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
- package/lib-es/exchange/swap/transactionStrategies.d.ts +1 -2
- package/lib-es/exchange/swap/transactionStrategies.d.ts.map +1 -1
- package/lib-es/exchange/swap/transactionStrategies.js +1 -3
- package/lib-es/exchange/swap/transactionStrategies.js.map +1 -1
- package/lib-es/exchange/swap/types.d.ts +0 -1
- package/lib-es/exchange/swap/types.d.ts.map +1 -1
- package/lib-es/families/evm/walletApiAdapter.d.ts.map +1 -1
- package/lib-es/families/evm/walletApiAdapter.js +0 -5
- package/lib-es/families/evm/walletApiAdapter.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts +3 -0
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +1 -10
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/load/speculos.d.ts.map +1 -1
- package/lib-es/load/speculos.js +0 -1
- package/lib-es/load/speculos.js.map +1 -1
- package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js.map +1 -0
- package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
- package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +3 -0
- package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.d.ts +0 -1
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +2 -5
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/wallet-api/react.d.ts.map +1 -1
- package/lib-es/wallet-api/react.js +1 -5
- package/lib-es/wallet-api/react.js.map +1 -1
- package/package.json +78 -78
- package/src/bridge/generic-alpaca/estimateMaxSpendable.ts +1 -1
- package/src/bridge/generic-alpaca/prepareTransaction.ts +69 -46
- package/src/bridge/generic-alpaca/signOperation.ts +20 -0
- package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +109 -191
- package/src/bridge/generic-alpaca/utils.test.ts +15 -12
- package/src/bridge/generic-alpaca/utils.ts +1 -1
- package/src/dada-client/state-manager/api.ts +5 -10
- package/src/dada-client/state-manager/types.ts +0 -1
- package/src/e2e/data/deviceLabelsData.ts +4 -2
- package/src/e2e/enum/Device.ts +4 -7
- package/src/e2e/families/bitcoin.ts +9 -4
- package/src/e2e/families/cardano.ts +2 -2
- package/src/e2e/families/evm.ts +8 -3
- package/src/e2e/families/solana.ts +7 -2
- package/src/e2e/families/tezos.ts +7 -2
- package/src/e2e/speculos.ts +27 -22
- package/src/exchange/swap/hooks/usePickDefaultAccount.ts +2 -2
- package/src/exchange/swap/hooks/useSwapTransaction.ts +7 -20
- package/src/exchange/swap/transactionStrategies.ts +0 -4
- package/src/exchange/swap/types.ts +0 -1
- package/src/families/evm/walletApiAdapter.ts +0 -6
- package/src/featureFlags/defaultFeatures.ts +1 -10
- package/src/load/speculos.ts +0 -1
- package/src/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.ts +3 -0
- package/src/wallet-api/Exchange/server.ts +3 -12
- package/src/wallet-api/react.ts +1 -7
- package/lib/e2e/speculosAppVersion.d.ts +0 -7
- package/lib/e2e/speculosAppVersion.d.ts.map +0 -1
- package/lib/e2e/speculosAppVersion.js +0 -104
- package/lib/e2e/speculosAppVersion.js.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useAssetAccountCounts.test.d.ts +0 -2
- package/lib/modularDrawer/hooks/__test__/useAssetAccountCounts.test.d.ts.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useAssetAccountCounts.test.js +0 -38
- package/lib/modularDrawer/hooks/__test__/useAssetAccountCounts.test.js.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.d.ts +0 -2
- package/lib/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.d.ts.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.js +0 -50
- package/lib/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.js.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useDetailedAccountsCore.test.d.ts.map +0 -1
- package/lib/modularDrawer/hooks/__test__/useDetailedAccountsCore.test.js.map +0 -1
- package/lib/modularDrawer/modules/__test__/createAssetConfiguration.test.d.ts +0 -19
- package/lib/modularDrawer/modules/__test__/createAssetConfiguration.test.d.ts.map +0 -1
- package/lib/modularDrawer/modules/__test__/createAssetConfiguration.test.js +0 -209
- package/lib/modularDrawer/modules/__test__/createAssetConfiguration.test.js.map +0 -1
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts +0 -5
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts.map +0 -1
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.js +0 -248
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.js.map +0 -1
- package/lib-es/e2e/speculosAppVersion.d.ts +0 -7
- package/lib-es/e2e/speculosAppVersion.d.ts.map +0 -1
- package/lib-es/e2e/speculosAppVersion.js +0 -74
- package/lib-es/e2e/speculosAppVersion.js.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useAssetAccountCounts.test.d.ts +0 -2
- package/lib-es/modularDrawer/hooks/__test__/useAssetAccountCounts.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useAssetAccountCounts.test.js +0 -36
- package/lib-es/modularDrawer/hooks/__test__/useAssetAccountCounts.test.js.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.d.ts +0 -2
- package/lib-es/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.js +0 -45
- package/lib-es/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.js.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useDetailedAccountsCore.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/hooks/__test__/useDetailedAccountsCore.test.js.map +0 -1
- package/lib-es/modularDrawer/modules/__test__/createAssetConfiguration.test.d.ts +0 -19
- package/lib-es/modularDrawer/modules/__test__/createAssetConfiguration.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/modules/__test__/createAssetConfiguration.test.js +0 -202
- package/lib-es/modularDrawer/modules/__test__/createAssetConfiguration.test.js.map +0 -1
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts +0 -5
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.js +0 -246
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.js.map +0 -1
- package/src/e2e/speculosAppVersion.ts +0 -86
- package/src/modularDrawer/hooks/__test__/useAssetAccountCounts.test.ts +0 -40
- package/src/modularDrawer/hooks/__test__/useCurrenciesUnderFeatureFlag.test.ts +0 -59
- package/src/modularDrawer/modules/__test__/createAssetConfiguration.test.tsx +0 -250
- package/src/modularDrawer/modules/__test__/createNetworkConfiguration.test.ts +0 -349
- /package/lib/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.d.ts +0 -0
- /package/lib/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.js +0 -0
- /package/lib-es/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.d.ts +0 -0
- /package/lib-es/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.js +0 -0
- /package/src/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.ts +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
import { renderHook } from "@testing-library/react";
|
|
5
|
-
import { useCurrenciesUnderFeatureFlag } from "../useCurrenciesUnderFeatureFlag";
|
|
6
|
-
import { useFeature } from "../../../featureFlags";
|
|
7
|
-
import useEnv from "../../../hooks/useEnv";
|
|
8
|
-
|
|
9
|
-
jest.mock("../../../featureFlags", () => ({ useFeature: jest.fn() }));
|
|
10
|
-
jest.mock("../../../hooks/useEnv", () => jest.fn());
|
|
11
|
-
|
|
12
|
-
const mockUseFeature = jest.mocked(useFeature);
|
|
13
|
-
const mockedEnvironment = jest.mocked(useEnv);
|
|
14
|
-
|
|
15
|
-
describe("useCurrenciesUnderFeatureFlag", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should return empty deactivatedCurrencyIds when all features are enabled", () => {
|
|
21
|
-
mockedEnvironment.mockReturnValue(false);
|
|
22
|
-
mockUseFeature.mockReturnValue({ enabled: true });
|
|
23
|
-
|
|
24
|
-
const { result } = renderHook(() => useCurrenciesUnderFeatureFlag());
|
|
25
|
-
|
|
26
|
-
expect(result.current.deactivatedCurrencyIds.size).toEqual(0);
|
|
27
|
-
expect(result.current.featureFlaggedCurrencies).toBeDefined();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should include disabled currencies in deactivatedCurrencyIds", () => {
|
|
31
|
-
mockedEnvironment.mockReturnValue(false);
|
|
32
|
-
mockUseFeature.mockReturnValue({ enabled: false });
|
|
33
|
-
|
|
34
|
-
const { result } = renderHook(() => useCurrenciesUnderFeatureFlag());
|
|
35
|
-
|
|
36
|
-
expect(result.current.deactivatedCurrencyIds.size).toBeGreaterThan(0);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should return empty deactivatedCurrencyIds when MOCK is true", () => {
|
|
40
|
-
mockedEnvironment.mockReturnValue(true);
|
|
41
|
-
mockUseFeature.mockReturnValue({ enabled: false });
|
|
42
|
-
|
|
43
|
-
const { result } = renderHook(() => useCurrenciesUnderFeatureFlag());
|
|
44
|
-
|
|
45
|
-
expect(result.current.deactivatedCurrencyIds.size).toBe(0);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should contain currency mappings", () => {
|
|
49
|
-
mockedEnvironment.mockReturnValue(false);
|
|
50
|
-
mockUseFeature.mockReturnValue({ enabled: true });
|
|
51
|
-
|
|
52
|
-
const { result } = renderHook(() => useCurrenciesUnderFeatureFlag());
|
|
53
|
-
|
|
54
|
-
const currencies = result.current.featureFlaggedCurrencies;
|
|
55
|
-
expect(currencies).toHaveProperty("aptos");
|
|
56
|
-
expect(currencies).toHaveProperty("stacks");
|
|
57
|
-
expect(currencies).toHaveProperty("optimism");
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import React from "react";
|
|
6
|
-
import { renderHook } from "@testing-library/react";
|
|
7
|
-
import { mockEthCryptoCurrency } from "../../__mocks__/currencies.mock";
|
|
8
|
-
import { groupCurrenciesByProvider } from "../../utils";
|
|
9
|
-
import createAssetConfigurationHook from "../createAssetConfiguration";
|
|
10
|
-
import { BigNumber } from "bignumber.js";
|
|
11
|
-
import { genAccount, genTokenAccount } from "@ledgerhq/coin-framework/lib/mocks/account";
|
|
12
|
-
import { createFixtureCryptoCurrency } from "../../../mock/fixtures/cryptoCurrencies";
|
|
13
|
-
import { CounterValuesState } from "@ledgerhq/live-countervalues/lib/types";
|
|
14
|
-
import { CryptoCurrency, FiatCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
15
|
-
import { Provider } from "react-redux";
|
|
16
|
-
import { configureStore } from "@reduxjs/toolkit";
|
|
17
|
-
|
|
18
|
-
export const makeUsdcToken = (
|
|
19
|
-
parentCurrency: CryptoCurrency,
|
|
20
|
-
contractAddress: string,
|
|
21
|
-
tokenType: string = "erc20",
|
|
22
|
-
name: string = "USD Coin",
|
|
23
|
-
explicitId?: string,
|
|
24
|
-
) => {
|
|
25
|
-
const id = explicitId ?? `${parentCurrency.id}/${tokenType}/usdc`;
|
|
26
|
-
return {
|
|
27
|
-
type: "TokenCurrency" as const,
|
|
28
|
-
parentCurrency,
|
|
29
|
-
tokenType,
|
|
30
|
-
id,
|
|
31
|
-
contractAddress,
|
|
32
|
-
ticker: "USDC",
|
|
33
|
-
name,
|
|
34
|
-
units: [
|
|
35
|
-
{
|
|
36
|
-
name: "USD Coin",
|
|
37
|
-
code: "USDC",
|
|
38
|
-
magnitude: 6,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const ApyIndicator = () => null;
|
|
45
|
-
const MarketPercentIndicator = () => null;
|
|
46
|
-
const MarketPriceIndicator = jest.fn(() => null);
|
|
47
|
-
|
|
48
|
-
const ethereumCurrencyMagnitude = 18;
|
|
49
|
-
const fiatCurrencyMagnitude = 2;
|
|
50
|
-
const fiatConversion = 4589;
|
|
51
|
-
|
|
52
|
-
const ethereumCurrency = createFixtureCryptoCurrency("ethereum");
|
|
53
|
-
ethereumCurrency.id = "ethereum";
|
|
54
|
-
ethereumCurrency.units[0].magnitude = ethereumCurrencyMagnitude;
|
|
55
|
-
const ethereumAccountHigh = genAccount("ethereum-account-high", {
|
|
56
|
-
currency: ethereumCurrency,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
ethereumAccountHigh.balance = new BigNumber("1000000000000000000000");
|
|
60
|
-
ethereumAccountHigh.spendableBalance = ethereumAccountHigh.balance;
|
|
61
|
-
|
|
62
|
-
const ethereumUsdcToken: TokenCurrency = makeUsdcToken(ethereumCurrency, "erc20", "USD Coin");
|
|
63
|
-
const ethereumUsdcTokenAccount = genTokenAccount(0, ethereumAccountHigh, ethereumUsdcToken);
|
|
64
|
-
ethereumUsdcTokenAccount.balance = new BigNumber("1000000000");
|
|
65
|
-
ethereumAccountHigh.subAccounts = [ethereumUsdcTokenAccount];
|
|
66
|
-
|
|
67
|
-
const mockFiatCurrency: FiatCurrency = {
|
|
68
|
-
type: "FiatCurrency",
|
|
69
|
-
ticker: "USD",
|
|
70
|
-
name: "US Dollar",
|
|
71
|
-
symbol: "$",
|
|
72
|
-
units: [
|
|
73
|
-
{
|
|
74
|
-
code: "$",
|
|
75
|
-
name: "US Dollar",
|
|
76
|
-
magnitude: fiatCurrencyMagnitude,
|
|
77
|
-
showAllDigits: true,
|
|
78
|
-
prefixCode: true,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const useBalanceDeps = () => {
|
|
84
|
-
const mockCounterValuesState: CounterValuesState = {
|
|
85
|
-
cache: {
|
|
86
|
-
"USD ethereum": {
|
|
87
|
-
map: new Map([["latest", fiatConversion]]),
|
|
88
|
-
stats: {
|
|
89
|
-
oldest: "2024-09-12",
|
|
90
|
-
earliest: "2025-10-02T13",
|
|
91
|
-
oldestDate: new Date(),
|
|
92
|
-
earliestDate: new Date(),
|
|
93
|
-
earliestStableDate: new Date(),
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
data: {},
|
|
98
|
-
status: {},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
counterValueCurrency: mockFiatCurrency,
|
|
103
|
-
flattenedAccounts: [ethereumAccountHigh],
|
|
104
|
-
state: mockCounterValuesState,
|
|
105
|
-
locale: "en-US",
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const balanceItem = jest.fn(() => null);
|
|
110
|
-
|
|
111
|
-
const assetConfigurationDeps = {
|
|
112
|
-
useBalanceDeps,
|
|
113
|
-
balanceItem,
|
|
114
|
-
ApyIndicator,
|
|
115
|
-
MarketPercentIndicator,
|
|
116
|
-
MarketPriceIndicator,
|
|
117
|
-
assetsMap: groupCurrenciesByProvider([
|
|
118
|
-
{
|
|
119
|
-
asset: {
|
|
120
|
-
id: "ethereum",
|
|
121
|
-
ticker: "ETH",
|
|
122
|
-
name: "Ethereum",
|
|
123
|
-
assetsIds: {
|
|
124
|
-
ethereum: "ethereum",
|
|
125
|
-
arbitrum: "arbitrum",
|
|
126
|
-
},
|
|
127
|
-
metaCurrencyId: "ethereum",
|
|
128
|
-
},
|
|
129
|
-
networks: [mockEthCryptoCurrency],
|
|
130
|
-
},
|
|
131
|
-
]),
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
describe("createAssetConfiguration", () => {
|
|
135
|
-
it("should call balanceItem with correct BalanceUI objects for each asset", () => {
|
|
136
|
-
renderHook(() =>
|
|
137
|
-
createAssetConfigurationHook(assetConfigurationDeps)({
|
|
138
|
-
assetsConfiguration: { rightElement: "balance" },
|
|
139
|
-
})([ethereumCurrency]),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
expect(balanceItem).toHaveBeenCalledTimes(1);
|
|
143
|
-
expect(balanceItem).toHaveBeenNthCalledWith(1, {
|
|
144
|
-
currency: ethereumCurrency,
|
|
145
|
-
balance: ethereumAccountHigh.balance,
|
|
146
|
-
fiatValue: ethereumAccountHigh.balance
|
|
147
|
-
.shiftedBy(fiatCurrencyMagnitude - ethereumCurrencyMagnitude)
|
|
148
|
-
.multipliedBy(fiatConversion)
|
|
149
|
-
.toNumber(),
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const store = configureStore({
|
|
154
|
-
reducer: {
|
|
155
|
-
assetsDataApi: (state = {}, _action) => state,
|
|
156
|
-
},
|
|
157
|
-
preloadedState: {
|
|
158
|
-
assetsDataApi: {
|
|
159
|
-
queries: {
|
|
160
|
-
mockMarketsQuery: {
|
|
161
|
-
data: {
|
|
162
|
-
pages: [
|
|
163
|
-
{
|
|
164
|
-
markets: {
|
|
165
|
-
ethereum: {
|
|
166
|
-
price: 2500.5,
|
|
167
|
-
priceChangePercentage24h: 5.25,
|
|
168
|
-
marketCap: 300000000000,
|
|
169
|
-
ticker: "ETH",
|
|
170
|
-
name: "Ethereum",
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
interestRates: {
|
|
174
|
-
ethereum: {
|
|
175
|
-
currencyId: "ethereum",
|
|
176
|
-
rate: 0.045,
|
|
177
|
-
type: "APY",
|
|
178
|
-
fetchAt: "2024-10-13T10:00:00Z",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should generate market trend right element with correct market trend data", () => {
|
|
191
|
-
const {
|
|
192
|
-
result: { current },
|
|
193
|
-
} = renderHook(
|
|
194
|
-
() =>
|
|
195
|
-
createAssetConfigurationHook(assetConfigurationDeps)({
|
|
196
|
-
assetsConfiguration: { rightElement: "marketTrend" },
|
|
197
|
-
})([ethereumCurrency]),
|
|
198
|
-
{
|
|
199
|
-
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
const rightElement = current[0]?.rightElement;
|
|
204
|
-
expect(rightElement).toBeDefined();
|
|
205
|
-
expect(React.isValidElement(rightElement)).toBe(true);
|
|
206
|
-
if (React.isValidElement(rightElement)) {
|
|
207
|
-
expect(rightElement.props).toEqual({
|
|
208
|
-
percent: 5.25,
|
|
209
|
-
price: "$2,500.50",
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("should generate apy left element when leftElement is 'apy'", () => {
|
|
215
|
-
const {
|
|
216
|
-
result: { current },
|
|
217
|
-
} = renderHook(
|
|
218
|
-
() =>
|
|
219
|
-
createAssetConfigurationHook(assetConfigurationDeps)({
|
|
220
|
-
assetsConfiguration: { leftElement: "apy" },
|
|
221
|
-
})([ethereumCurrency]),
|
|
222
|
-
{
|
|
223
|
-
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
|
|
224
|
-
},
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
expect((current[0]?.leftElement as React.ReactElement).props).toEqual({
|
|
228
|
-
value: 4.5,
|
|
229
|
-
type: "APY",
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("should generate market trend left element when leftElement is 'marketTrend'", () => {
|
|
234
|
-
const {
|
|
235
|
-
result: { current },
|
|
236
|
-
} = renderHook(
|
|
237
|
-
() =>
|
|
238
|
-
createAssetConfigurationHook(assetConfigurationDeps)({
|
|
239
|
-
assetsConfiguration: { leftElement: "marketTrend" },
|
|
240
|
-
})([ethereumCurrency]),
|
|
241
|
-
{
|
|
242
|
-
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
|
|
243
|
-
},
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
expect((current[0]?.leftElement as React.ReactElement).props).toEqual({
|
|
247
|
-
percent: 5.25,
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { BigNumber } from "bignumber.js";
|
|
6
|
-
import { genAccount, genTokenAccount } from "@ledgerhq/coin-framework/lib/mocks/account";
|
|
7
|
-
import { createFixtureCryptoCurrency } from "../../../mock/fixtures/cryptoCurrencies";
|
|
8
|
-
import { createNetworkConfigurationHook } from "../createNetworkConfiguration";
|
|
9
|
-
import { renderHook } from "@testing-library/react";
|
|
10
|
-
import { CounterValuesState } from "@ledgerhq/live-countervalues/lib/types";
|
|
11
|
-
import { FiatCurrency, TokenCurrency, CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
12
|
-
import { makeUsdcToken } from "./createAssetConfiguration.test";
|
|
13
|
-
|
|
14
|
-
const bscCurrency = createFixtureCryptoCurrency("bsc");
|
|
15
|
-
const bscAccount = genAccount("bsc-account", { currency: bscCurrency });
|
|
16
|
-
const bscUsdcToken: TokenCurrency = makeUsdcToken(
|
|
17
|
-
bscCurrency,
|
|
18
|
-
"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
19
|
-
"bep20",
|
|
20
|
-
"USD Coin",
|
|
21
|
-
"bsc/erc20/usdc",
|
|
22
|
-
);
|
|
23
|
-
const bscUsdcTokenAccount = genTokenAccount(0, bscAccount, bscUsdcToken);
|
|
24
|
-
bscAccount.subAccounts = [bscUsdcTokenAccount];
|
|
25
|
-
|
|
26
|
-
const baseCurrency = createFixtureCryptoCurrency("base");
|
|
27
|
-
const baseAccount = genAccount("base-account", { currency: baseCurrency });
|
|
28
|
-
const baseUsdcToken: TokenCurrency = makeUsdcToken(
|
|
29
|
-
baseCurrency,
|
|
30
|
-
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
31
|
-
"erc20",
|
|
32
|
-
"USD Coin",
|
|
33
|
-
"base/erc20/usd_coin",
|
|
34
|
-
);
|
|
35
|
-
const baseUsdcTokenAccount = genTokenAccount(0, baseAccount, baseUsdcToken);
|
|
36
|
-
baseAccount.subAccounts = [baseUsdcTokenAccount];
|
|
37
|
-
|
|
38
|
-
const ethereumCurrency = createFixtureCryptoCurrency("ethereum");
|
|
39
|
-
const ethereumAccountHigh = genAccount("ethereum-account-high", {
|
|
40
|
-
currency: ethereumCurrency,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
ethereumAccountHigh.balance = new BigNumber("1000000000000000000000");
|
|
44
|
-
ethereumAccountHigh.spendableBalance = ethereumAccountHigh.balance;
|
|
45
|
-
|
|
46
|
-
const ethereumUsdcToken: TokenCurrency = makeUsdcToken(
|
|
47
|
-
ethereumCurrency,
|
|
48
|
-
"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
49
|
-
"erc20",
|
|
50
|
-
|
|
51
|
-
"USD Coin",
|
|
52
|
-
);
|
|
53
|
-
const ethereumUsdcTokenAccount = genTokenAccount(0, ethereumAccountHigh, ethereumUsdcToken);
|
|
54
|
-
ethereumAccountHigh.subAccounts = [ethereumUsdcTokenAccount];
|
|
55
|
-
|
|
56
|
-
const ethereumAccountLow = genAccount("ethereum-account-low", {
|
|
57
|
-
currency: ethereumCurrency,
|
|
58
|
-
});
|
|
59
|
-
ethereumAccountLow.balance = new BigNumber("100000000000000000");
|
|
60
|
-
ethereumAccountLow.spendableBalance = ethereumAccountLow.balance;
|
|
61
|
-
|
|
62
|
-
const ethereumAccountZero = genAccount("ethereum-account-zero", {
|
|
63
|
-
currency: ethereumCurrency,
|
|
64
|
-
});
|
|
65
|
-
ethereumAccountZero.balance = new BigNumber("0");
|
|
66
|
-
ethereumAccountZero.spendableBalance = ethereumAccountZero.balance;
|
|
67
|
-
|
|
68
|
-
const polygonCurrency = createFixtureCryptoCurrency("polygon");
|
|
69
|
-
const polygonAccountMedium = genAccount("polygon-account-medium", {
|
|
70
|
-
currency: polygonCurrency,
|
|
71
|
-
});
|
|
72
|
-
polygonAccountMedium.balance = new BigNumber("500000000000000000000");
|
|
73
|
-
polygonAccountMedium.spendableBalance = polygonAccountMedium.balance;
|
|
74
|
-
|
|
75
|
-
const polygonUsdcToken: TokenCurrency = makeUsdcToken(
|
|
76
|
-
polygonCurrency,
|
|
77
|
-
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
78
|
-
"erc20",
|
|
79
|
-
"USD Coin",
|
|
80
|
-
);
|
|
81
|
-
const polygonUsdcTokenAccount = genTokenAccount(0, polygonAccountMedium, polygonUsdcToken);
|
|
82
|
-
polygonAccountMedium.subAccounts = [polygonUsdcTokenAccount];
|
|
83
|
-
|
|
84
|
-
const makeAccountData = (asset, count) => ({
|
|
85
|
-
asset,
|
|
86
|
-
label: `${count} account`,
|
|
87
|
-
count,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const useAccountData = () => {
|
|
91
|
-
return [
|
|
92
|
-
makeAccountData(createFixtureCryptoCurrency("ethereum"), 3),
|
|
93
|
-
makeAccountData(createFixtureCryptoCurrency("polygon"), 1),
|
|
94
|
-
makeAccountData(createFixtureCryptoCurrency("bsc"), 2),
|
|
95
|
-
makeAccountData(createFixtureCryptoCurrency("base"), 1),
|
|
96
|
-
makeAccountData(createFixtureCryptoCurrency("avalanche_c_chain"), 0),
|
|
97
|
-
];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const mockFiatCurrency: FiatCurrency = {
|
|
101
|
-
type: "FiatCurrency",
|
|
102
|
-
ticker: "USD",
|
|
103
|
-
name: "US Dollar",
|
|
104
|
-
symbol: "$",
|
|
105
|
-
units: [
|
|
106
|
-
{
|
|
107
|
-
code: "$",
|
|
108
|
-
name: "US Dollar",
|
|
109
|
-
magnitude: 2,
|
|
110
|
-
showAllDigits: true,
|
|
111
|
-
prefixCode: true,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const accountsCount = jest.fn(() => null);
|
|
117
|
-
const accountsCountAndApy = () => null;
|
|
118
|
-
const useBalanceDeps = () => {
|
|
119
|
-
const mockCounterValuesState: CounterValuesState = {
|
|
120
|
-
cache: {
|
|
121
|
-
"USD testCoinId": {
|
|
122
|
-
fallback: 2354.213,
|
|
123
|
-
map: new Map(),
|
|
124
|
-
stats: {
|
|
125
|
-
oldest: "2024-09-12",
|
|
126
|
-
earliest: "2025-10-02T13",
|
|
127
|
-
oldestDate: new Date(),
|
|
128
|
-
earliestDate: new Date(),
|
|
129
|
-
earliestStableDate: new Date(),
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
data: {},
|
|
134
|
-
status: {},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
counterValueCurrency: mockFiatCurrency,
|
|
139
|
-
flattenedAccounts: [
|
|
140
|
-
bscAccount,
|
|
141
|
-
bscUsdcTokenAccount,
|
|
142
|
-
baseAccount,
|
|
143
|
-
baseUsdcTokenAccount,
|
|
144
|
-
ethereumAccountHigh,
|
|
145
|
-
ethereumUsdcTokenAccount,
|
|
146
|
-
ethereumAccountLow,
|
|
147
|
-
ethereumAccountZero,
|
|
148
|
-
polygonAccountMedium,
|
|
149
|
-
polygonUsdcTokenAccount,
|
|
150
|
-
],
|
|
151
|
-
state: mockCounterValuesState,
|
|
152
|
-
locale: "en-US",
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
const balanceItem = jest.fn(() => null);
|
|
156
|
-
|
|
157
|
-
const networkConfigurationDeps = {
|
|
158
|
-
useAccountData,
|
|
159
|
-
accountsCount,
|
|
160
|
-
accountsCountAndApy,
|
|
161
|
-
useBalanceDeps,
|
|
162
|
-
balanceItem,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
describe("createNetworkConfiguration", () => {
|
|
166
|
-
beforeEach(() => {
|
|
167
|
-
jest.clearAllMocks();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("should call balanceItem with correct BalanceUI objects for each network", () => {
|
|
171
|
-
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
172
|
-
const res = result.current({ networksConfig: { rightElement: "balance" } });
|
|
173
|
-
res([baseCurrency, bscCurrency], [baseUsdcToken, bscUsdcToken]);
|
|
174
|
-
|
|
175
|
-
expect(balanceItem).toHaveBeenCalledTimes(2);
|
|
176
|
-
expect(balanceItem).toHaveBeenNthCalledWith(
|
|
177
|
-
1,
|
|
178
|
-
expect.objectContaining({ balance: baseUsdcTokenAccount.balance }),
|
|
179
|
-
);
|
|
180
|
-
expect(balanceItem).toHaveBeenNthCalledWith(
|
|
181
|
-
2,
|
|
182
|
-
expect.objectContaining({ balance: bscUsdcTokenAccount.balance }),
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("account count", () => {
|
|
187
|
-
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
188
|
-
const res = result.current({ networksConfig: { leftElement: "numberOfAccounts" } });
|
|
189
|
-
res([baseCurrency, bscCurrency], [baseUsdcToken, bscUsdcToken]);
|
|
190
|
-
|
|
191
|
-
expect(accountsCount).toHaveBeenCalledTimes(4);
|
|
192
|
-
expect(accountsCount).toHaveBeenNthCalledWith(1, { label: "3 account" });
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("should order by balance (highest first) when only balance element is present", () => {
|
|
196
|
-
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
197
|
-
const res = result.current({
|
|
198
|
-
networksConfig: { rightElement: "balance" },
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const orderedResult = res(
|
|
202
|
-
[ethereumCurrency, polygonCurrency, bscCurrency],
|
|
203
|
-
[ethereumUsdcToken, polygonUsdcToken, bscUsdcToken],
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
expect(orderedResult).toHaveLength(3);
|
|
207
|
-
|
|
208
|
-
// Should be ordered by balance amount (highest first)
|
|
209
|
-
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 1000 ETH
|
|
210
|
-
expect(orderedResult[1].id).toBe(polygonCurrency.id); // 500 MATIC
|
|
211
|
-
expect(orderedResult[2].id).toBe(bscCurrency.id); // Lower balance
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("should order by account count (highest first) when only account count element is present", () => {
|
|
215
|
-
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
216
|
-
const res = result.current({
|
|
217
|
-
networksConfig: { leftElement: "numberOfAccounts" },
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const orderedResult = res(
|
|
221
|
-
[ethereumCurrency, polygonCurrency, bscCurrency],
|
|
222
|
-
[ethereumUsdcToken, polygonUsdcToken, bscUsdcToken],
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
expect(orderedResult).toHaveLength(3);
|
|
226
|
-
|
|
227
|
-
// Should be ordered by account count (highest first)
|
|
228
|
-
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 3 accounts
|
|
229
|
-
expect(orderedResult[1].id).toBe(bscCurrency.id); // 2 accounts
|
|
230
|
-
expect(orderedResult[2].id).toBe(polygonCurrency.id); // 1 account
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("should handle networks with zero balances by ordering them by account count", () => {
|
|
234
|
-
const zeroBalanceEth = { ...ethereumAccountZero };
|
|
235
|
-
const zeroBalancePoly = {
|
|
236
|
-
...polygonAccountMedium,
|
|
237
|
-
balance: new BigNumber("0"),
|
|
238
|
-
spendableBalance: new BigNumber("0"),
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const mockUseBalanceDepsZero = () => ({
|
|
242
|
-
counterValueCurrency: {
|
|
243
|
-
type: "FiatCurrency" as const,
|
|
244
|
-
ticker: "USD",
|
|
245
|
-
name: "US Dollar",
|
|
246
|
-
symbol: "$",
|
|
247
|
-
units: [
|
|
248
|
-
{ code: "$", name: "US Dollar", magnitude: 2, showAllDigits: true, prefixCode: true },
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
flattenedAccounts: [zeroBalanceEth, zeroBalancePoly],
|
|
252
|
-
state: { cache: {}, data: {}, status: {} },
|
|
253
|
-
locale: "en-US",
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const { result } = renderHook(() =>
|
|
257
|
-
createNetworkConfigurationHook({
|
|
258
|
-
...networkConfigurationDeps,
|
|
259
|
-
useBalanceDeps: mockUseBalanceDepsZero,
|
|
260
|
-
}),
|
|
261
|
-
);
|
|
262
|
-
const res = result.current({
|
|
263
|
-
networksConfig: { leftElement: "numberOfAccounts", rightElement: "balance" },
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const orderedResult = res(
|
|
267
|
-
[ethereumCurrency, polygonCurrency],
|
|
268
|
-
[ethereumUsdcToken, polygonUsdcToken],
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
expect(orderedResult).toHaveLength(2);
|
|
272
|
-
|
|
273
|
-
// When both have zero balance, should order by account count
|
|
274
|
-
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 3 accounts
|
|
275
|
-
expect(orderedResult[1].id).toBe(polygonCurrency.id); // 1 account
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("should prioritise non-zero balances over account count", () => {
|
|
279
|
-
const testEthereumCurrency: CryptoCurrency = createFixtureCryptoCurrency("ethereum");
|
|
280
|
-
const testPolygonCurrency: CryptoCurrency = createFixtureCryptoCurrency("polygon");
|
|
281
|
-
const testAvalancheCurrency: CryptoCurrency = createFixtureCryptoCurrency("avalanche_c_chain");
|
|
282
|
-
const testArbitrumCurrency: CryptoCurrency = createFixtureCryptoCurrency("arbitrum");
|
|
283
|
-
|
|
284
|
-
const testEthereumAccount = genAccount("test-ethereum-account", {
|
|
285
|
-
currency: testEthereumCurrency,
|
|
286
|
-
});
|
|
287
|
-
testEthereumAccount.balance = new BigNumber("1000000000000000000000");
|
|
288
|
-
testEthereumAccount.spendableBalance = testEthereumAccount.balance;
|
|
289
|
-
|
|
290
|
-
const testPolygonAccount = genAccount("test-polygon-account", {
|
|
291
|
-
currency: testPolygonCurrency,
|
|
292
|
-
});
|
|
293
|
-
testPolygonAccount.balance = new BigNumber("500000000000000000000");
|
|
294
|
-
testPolygonAccount.spendableBalance = testPolygonAccount.balance;
|
|
295
|
-
|
|
296
|
-
const testEthereumUsdcToken = makeUsdcToken(
|
|
297
|
-
testEthereumCurrency,
|
|
298
|
-
"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
299
|
-
);
|
|
300
|
-
const testPolygonUsdcToken = makeUsdcToken(
|
|
301
|
-
testPolygonCurrency,
|
|
302
|
-
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
303
|
-
);
|
|
304
|
-
const testAvalancheUsdcToken = makeUsdcToken(
|
|
305
|
-
testAvalancheCurrency,
|
|
306
|
-
"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
307
|
-
);
|
|
308
|
-
const testArbitrumUsdcToken = makeUsdcToken(
|
|
309
|
-
testArbitrumCurrency,
|
|
310
|
-
"0xFF970A61A04b1cA14834A43f5de4533eBDDB5CC8",
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
const testUseBalanceDeps = () => ({
|
|
314
|
-
counterValueCurrency: mockFiatCurrency,
|
|
315
|
-
flattenedAccounts: [testEthereumAccount, testPolygonAccount],
|
|
316
|
-
state: { cache: {}, data: {}, status: {} },
|
|
317
|
-
locale: "en-US",
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const testUseAccountData = () => [
|
|
321
|
-
makeAccountData(testEthereumCurrency, 3),
|
|
322
|
-
makeAccountData(testPolygonCurrency, 1),
|
|
323
|
-
makeAccountData(testAvalancheCurrency, 1),
|
|
324
|
-
makeAccountData(testArbitrumCurrency, 2),
|
|
325
|
-
];
|
|
326
|
-
|
|
327
|
-
const { result } = renderHook(() =>
|
|
328
|
-
createNetworkConfigurationHook({
|
|
329
|
-
...networkConfigurationDeps,
|
|
330
|
-
useAccountData: testUseAccountData,
|
|
331
|
-
useBalanceDeps: testUseBalanceDeps,
|
|
332
|
-
}),
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
const res = result.current({
|
|
336
|
-
networksConfig: { leftElement: "numberOfAccounts", rightElement: "balance" },
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
const orderedResult = res(
|
|
340
|
-
[testEthereumCurrency, testPolygonCurrency, testAvalancheCurrency, testArbitrumCurrency],
|
|
341
|
-
[testEthereumUsdcToken, testPolygonUsdcToken, testAvalancheUsdcToken, testArbitrumUsdcToken],
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
expect(orderedResult[0].id).toBe(testEthereumCurrency.id); // 1000 ETH balance, 3 accounts
|
|
345
|
-
expect(orderedResult[1].id).toBe(testPolygonCurrency.id); // 500 MATIC balance, 1 account
|
|
346
|
-
expect(orderedResult[2].id).toBe(testArbitrumCurrency.id); // (0 balance, 2 accounts)
|
|
347
|
-
expect(orderedResult[3].id).toBe(testAvalancheCurrency.id); // (0 balance, 1 account)
|
|
348
|
-
});
|
|
349
|
-
});
|
|
File without changes
|
|
File without changes
|
/package/lib-es/modularDrawer/hooks/{__test__ → __tests__}/useDetailedAccountsCore.test.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|