@ledgerhq/live-common 34.51.0-nightly.3 → 34.51.0-nightly.5
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/crypto-assets/index.d.ts.map +1 -1
- package/lib/bridge/crypto-assets/index.js +2 -30
- package/lib/bridge/crypto-assets/index.js.map +1 -1
- package/lib/bridge/crypto-assets/index.test.js +5 -34
- package/lib/bridge/crypto-assets/index.test.js.map +1 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.js +2 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/utils.js +1 -1
- package/lib/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib/currencies/cryptoIcons.test.js +4 -1
- package/lib/currencies/cryptoIcons.test.js.map +1 -1
- package/lib/currencies/index.d.ts +1 -1
- package/lib/currencies/index.d.ts.map +1 -1
- package/lib/currencies/index.js +1 -3
- package/lib/currencies/index.js.map +1 -1
- package/lib/deposit/deposit.test.js +29 -12
- package/lib/deposit/deposit.test.js.map +1 -1
- package/lib/deposit/helper.d.ts.map +1 -1
- package/lib/deposit/helper.js +5 -1
- package/lib/deposit/helper.js.map +1 -1
- package/lib/e2e/index.d.ts +2 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useFromState.test.js +4 -1
- package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js +4 -1
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useToState.test.js +4 -1
- package/lib/exchange/swap/hooks/useToState.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +4 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
- package/lib/exchange/swap/utils/index.test.js +4 -1
- package/lib/exchange/swap/utils/index.test.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -0
- 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/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts +5 -0
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts.map +1 -0
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.js +266 -0
- package/lib/modularDrawer/modules/__test__/createNetworkConfiguration.test.js.map +1 -0
- package/lib/notifications/ServiceStatusProvider/index.d.ts +1 -1
- package/lib/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib/notifications/ServiceStatusProvider/index.js +1 -1
- package/lib/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js +4 -1
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -1
- package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -1
- package/lib-es/bridge/crypto-assets/index.js +2 -7
- package/lib-es/bridge/crypto-assets/index.js.map +1 -1
- package/lib-es/bridge/crypto-assets/index.test.js +5 -11
- package/lib-es/bridge/crypto-assets/index.test.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.js +2 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.d.ts.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/currencies/cryptoIcons.test.js +5 -2
- package/lib-es/currencies/cryptoIcons.test.js.map +1 -1
- package/lib-es/currencies/index.d.ts +1 -1
- package/lib-es/currencies/index.d.ts.map +1 -1
- package/lib-es/currencies/index.js +1 -1
- package/lib-es/currencies/index.js.map +1 -1
- package/lib-es/deposit/deposit.test.js +30 -13
- package/lib-es/deposit/deposit.test.js.map +1 -1
- package/lib-es/deposit/helper.d.ts.map +1 -1
- package/lib-es/deposit/helper.js +6 -2
- package/lib-es/deposit/helper.js.map +1 -1
- package/lib-es/e2e/index.d.ts +2 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/exchange/swap/hooks/useFromState.test.js +5 -2
- package/lib-es/exchange/swap/hooks/useFromState.test.js.map +1 -1
- package/lib-es/exchange/swap/hooks/useReverseAccounts.test.js +5 -2
- package/lib-es/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -1
- package/lib-es/exchange/swap/hooks/useToState.test.js +5 -2
- package/lib-es/exchange/swap/hooks/useToState.test.js.map +1 -1
- package/lib-es/exchange/swap/hooks/useUpdateMaxAmount.test.js +5 -2
- package/lib-es/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
- package/lib-es/exchange/swap/utils/index.test.js +5 -2
- package/lib-es/exchange/swap/utils/index.test.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +1 -0
- 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/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts +5 -0
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.js +264 -0
- package/lib-es/modularDrawer/modules/__test__/createNetworkConfiguration.test.js.map +1 -0
- package/lib-es/notifications/ServiceStatusProvider/index.d.ts +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.js +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js +5 -2
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -1
- package/package.json +49 -49
- package/src/bridge/crypto-assets/index.test.ts +9 -11
- package/src/bridge/crypto-assets/index.ts +2 -8
- package/src/bridge/generic-alpaca/getTransactionStatus.ts +6 -4
- package/src/bridge/generic-alpaca/utils.ts +1 -2
- package/src/currencies/cryptoIcons.test.ts +4 -4
- package/src/currencies/index.ts +0 -2
- package/src/deposit/deposit.test.ts +29 -14
- package/src/deposit/helper.ts +6 -2
- package/src/exchange/swap/hooks/useFromState.test.ts +4 -2
- package/src/exchange/swap/hooks/useReverseAccounts.test.ts +4 -2
- package/src/exchange/swap/hooks/useToState.test.ts +4 -2
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +4 -2
- package/src/exchange/swap/utils/index.test.ts +4 -2
- package/src/featureFlags/defaultFeatures.ts +1 -0
- package/src/modularDrawer/modules/__test__/createNetworkConfiguration.test.ts +383 -0
- package/src/notifications/ServiceStatusProvider/index.tsx +1 -1
- package/src/utils/__tests__/getAccountTuplesForCurrency.test.ts +4 -2
|
@@ -0,0 +1,383 @@
|
|
|
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
|
+
|
|
13
|
+
const makeUsdcToken = (
|
|
14
|
+
parentCurrency: CryptoCurrency,
|
|
15
|
+
contractAddress: string,
|
|
16
|
+
tokenType: string = "erc20",
|
|
17
|
+
magnitude: number = 6,
|
|
18
|
+
name: string = "USD Coin",
|
|
19
|
+
unitName: string = "USD Coin",
|
|
20
|
+
explicitId?: string,
|
|
21
|
+
) => {
|
|
22
|
+
const id = explicitId ?? `${parentCurrency.id}/${tokenType}/usdc`;
|
|
23
|
+
return {
|
|
24
|
+
type: "TokenCurrency" as const,
|
|
25
|
+
parentCurrency,
|
|
26
|
+
tokenType,
|
|
27
|
+
id,
|
|
28
|
+
contractAddress,
|
|
29
|
+
ticker: "USDC",
|
|
30
|
+
name,
|
|
31
|
+
units: [
|
|
32
|
+
{
|
|
33
|
+
name: unitName,
|
|
34
|
+
code: "USDC",
|
|
35
|
+
magnitude,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const bscCurrency = createFixtureCryptoCurrency("bsc");
|
|
42
|
+
const bscAccount = genAccount("bsc-account", { currency: bscCurrency });
|
|
43
|
+
const bscUsdcToken: TokenCurrency = makeUsdcToken(
|
|
44
|
+
bscCurrency,
|
|
45
|
+
"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
46
|
+
"bep20",
|
|
47
|
+
18,
|
|
48
|
+
"USD Coin",
|
|
49
|
+
"Binance-Peg USD Coin",
|
|
50
|
+
"bsc/erc20/usdc",
|
|
51
|
+
);
|
|
52
|
+
const bscUsdcTokenAccount = genTokenAccount(0, bscAccount, bscUsdcToken);
|
|
53
|
+
bscAccount.subAccounts = [bscUsdcTokenAccount];
|
|
54
|
+
|
|
55
|
+
const baseCurrency = createFixtureCryptoCurrency("base");
|
|
56
|
+
const baseAccount = genAccount("base-account", { currency: baseCurrency });
|
|
57
|
+
const baseUsdcToken: TokenCurrency = makeUsdcToken(
|
|
58
|
+
baseCurrency,
|
|
59
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
60
|
+
"erc20",
|
|
61
|
+
6,
|
|
62
|
+
"USD Coin",
|
|
63
|
+
"USD Coin",
|
|
64
|
+
"base/erc20/usd_coin",
|
|
65
|
+
);
|
|
66
|
+
const baseUsdcTokenAccount = genTokenAccount(0, baseAccount, baseUsdcToken);
|
|
67
|
+
baseAccount.subAccounts = [baseUsdcTokenAccount];
|
|
68
|
+
|
|
69
|
+
const ethereumCurrency = createFixtureCryptoCurrency("ethereum");
|
|
70
|
+
const ethereumAccountHigh = genAccount("ethereum-account-high", {
|
|
71
|
+
currency: ethereumCurrency,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
ethereumAccountHigh.balance = new BigNumber("1000000000000000000000");
|
|
75
|
+
ethereumAccountHigh.spendableBalance = ethereumAccountHigh.balance;
|
|
76
|
+
|
|
77
|
+
const ethereumUsdcToken: TokenCurrency = makeUsdcToken(
|
|
78
|
+
ethereumCurrency,
|
|
79
|
+
"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
80
|
+
"erc20",
|
|
81
|
+
6,
|
|
82
|
+
"USD Coin",
|
|
83
|
+
"USD Coin",
|
|
84
|
+
);
|
|
85
|
+
const ethereumUsdcTokenAccount = genTokenAccount(0, ethereumAccountHigh, ethereumUsdcToken);
|
|
86
|
+
ethereumAccountHigh.subAccounts = [ethereumUsdcTokenAccount];
|
|
87
|
+
|
|
88
|
+
const ethereumAccountLow = genAccount("ethereum-account-low", {
|
|
89
|
+
currency: ethereumCurrency,
|
|
90
|
+
});
|
|
91
|
+
ethereumAccountLow.balance = new BigNumber("100000000000000000");
|
|
92
|
+
ethereumAccountLow.spendableBalance = ethereumAccountLow.balance;
|
|
93
|
+
|
|
94
|
+
const ethereumAccountZero = genAccount("ethereum-account-zero", {
|
|
95
|
+
currency: ethereumCurrency,
|
|
96
|
+
});
|
|
97
|
+
ethereumAccountZero.balance = new BigNumber("0");
|
|
98
|
+
ethereumAccountZero.spendableBalance = ethereumAccountZero.balance;
|
|
99
|
+
|
|
100
|
+
const polygonCurrency = createFixtureCryptoCurrency("polygon");
|
|
101
|
+
const polygonAccountMedium = genAccount("polygon-account-medium", {
|
|
102
|
+
currency: polygonCurrency,
|
|
103
|
+
});
|
|
104
|
+
polygonAccountMedium.balance = new BigNumber("500000000000000000000");
|
|
105
|
+
polygonAccountMedium.spendableBalance = polygonAccountMedium.balance;
|
|
106
|
+
|
|
107
|
+
const polygonUsdcToken: TokenCurrency = makeUsdcToken(
|
|
108
|
+
polygonCurrency,
|
|
109
|
+
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
110
|
+
"erc20",
|
|
111
|
+
6,
|
|
112
|
+
"USD Coin",
|
|
113
|
+
"USD Coin",
|
|
114
|
+
);
|
|
115
|
+
const polygonUsdcTokenAccount = genTokenAccount(0, polygonAccountMedium, polygonUsdcToken);
|
|
116
|
+
polygonAccountMedium.subAccounts = [polygonUsdcTokenAccount];
|
|
117
|
+
|
|
118
|
+
const makeAccountData = (asset, count) => ({
|
|
119
|
+
asset,
|
|
120
|
+
label: `${count} account`,
|
|
121
|
+
count,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const useAccountData = () => {
|
|
125
|
+
return [
|
|
126
|
+
makeAccountData(createFixtureCryptoCurrency("ethereum"), 3),
|
|
127
|
+
makeAccountData(createFixtureCryptoCurrency("polygon"), 1),
|
|
128
|
+
makeAccountData(createFixtureCryptoCurrency("bsc"), 2),
|
|
129
|
+
makeAccountData(createFixtureCryptoCurrency("base"), 1),
|
|
130
|
+
makeAccountData(createFixtureCryptoCurrency("avalanche_c_chain"), 0),
|
|
131
|
+
];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const mockFiatCurrency: FiatCurrency = {
|
|
135
|
+
type: "FiatCurrency",
|
|
136
|
+
ticker: "USD",
|
|
137
|
+
name: "US Dollar",
|
|
138
|
+
symbol: "$",
|
|
139
|
+
units: [
|
|
140
|
+
{
|
|
141
|
+
code: "$",
|
|
142
|
+
name: "US Dollar",
|
|
143
|
+
magnitude: 2,
|
|
144
|
+
showAllDigits: true,
|
|
145
|
+
prefixCode: true,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const accountsCount = jest.fn(() => null);
|
|
151
|
+
const accountsCountAndApy = () => null;
|
|
152
|
+
const useBalanceDeps = () => {
|
|
153
|
+
const mockCounterValuesState: CounterValuesState = {
|
|
154
|
+
cache: {
|
|
155
|
+
"USD testCoinId": {
|
|
156
|
+
fallback: 2354.213,
|
|
157
|
+
map: new Map(),
|
|
158
|
+
stats: {
|
|
159
|
+
oldest: "2024-09-12",
|
|
160
|
+
earliest: "2025-10-02T13",
|
|
161
|
+
oldestDate: new Date(),
|
|
162
|
+
earliestDate: new Date(),
|
|
163
|
+
earliestStableDate: new Date(),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
data: {},
|
|
168
|
+
status: {},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
counterValueCurrency: mockFiatCurrency,
|
|
173
|
+
flattenedAccounts: [
|
|
174
|
+
bscAccount,
|
|
175
|
+
bscUsdcTokenAccount,
|
|
176
|
+
baseAccount,
|
|
177
|
+
baseUsdcTokenAccount,
|
|
178
|
+
ethereumAccountHigh,
|
|
179
|
+
ethereumUsdcTokenAccount,
|
|
180
|
+
ethereumAccountLow,
|
|
181
|
+
ethereumAccountZero,
|
|
182
|
+
polygonAccountMedium,
|
|
183
|
+
polygonUsdcTokenAccount,
|
|
184
|
+
],
|
|
185
|
+
state: mockCounterValuesState,
|
|
186
|
+
locale: "en-US",
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const balanceItem = jest.fn(() => null);
|
|
190
|
+
|
|
191
|
+
const networkConfigurationDeps = {
|
|
192
|
+
useAccountData,
|
|
193
|
+
accountsCount,
|
|
194
|
+
accountsCountAndApy,
|
|
195
|
+
useBalanceDeps,
|
|
196
|
+
balanceItem,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
describe("createNetworkConfiguration", () => {
|
|
200
|
+
beforeEach(() => {
|
|
201
|
+
jest.clearAllMocks();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should call balanceItem with correct BalanceUI objects for each network", () => {
|
|
205
|
+
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
206
|
+
const res = result.current({ networksConfig: { rightElement: "balance" } });
|
|
207
|
+
res([baseCurrency, bscCurrency], [baseUsdcToken, bscUsdcToken]);
|
|
208
|
+
|
|
209
|
+
expect(balanceItem).toHaveBeenCalledTimes(2);
|
|
210
|
+
expect(balanceItem).toHaveBeenNthCalledWith(
|
|
211
|
+
1,
|
|
212
|
+
expect.objectContaining({ balance: baseUsdcTokenAccount.balance }),
|
|
213
|
+
);
|
|
214
|
+
expect(balanceItem).toHaveBeenNthCalledWith(
|
|
215
|
+
2,
|
|
216
|
+
expect.objectContaining({ balance: bscUsdcTokenAccount.balance }),
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("account count", () => {
|
|
221
|
+
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
222
|
+
const res = result.current({ networksConfig: { leftElement: "numberOfAccounts" } });
|
|
223
|
+
res([baseCurrency, bscCurrency], [baseUsdcToken, bscUsdcToken]);
|
|
224
|
+
|
|
225
|
+
expect(accountsCount).toHaveBeenCalledTimes(4);
|
|
226
|
+
expect(accountsCount).toHaveBeenNthCalledWith(1, { label: "3 account" });
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should order by balance (highest first) when only balance element is present", () => {
|
|
230
|
+
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
231
|
+
const res = result.current({
|
|
232
|
+
networksConfig: { rightElement: "balance" },
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const orderedResult = res(
|
|
236
|
+
[ethereumCurrency, polygonCurrency, bscCurrency],
|
|
237
|
+
[ethereumUsdcToken, polygonUsdcToken, bscUsdcToken],
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
expect(orderedResult).toHaveLength(3);
|
|
241
|
+
|
|
242
|
+
// Should be ordered by balance amount (highest first)
|
|
243
|
+
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 1000 ETH
|
|
244
|
+
expect(orderedResult[1].id).toBe(polygonCurrency.id); // 500 MATIC
|
|
245
|
+
expect(orderedResult[2].id).toBe(bscCurrency.id); // Lower balance
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("should order by account count (highest first) when only account count element is present", () => {
|
|
249
|
+
const { result } = renderHook(() => createNetworkConfigurationHook(networkConfigurationDeps));
|
|
250
|
+
const res = result.current({
|
|
251
|
+
networksConfig: { leftElement: "numberOfAccounts" },
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const orderedResult = res(
|
|
255
|
+
[ethereumCurrency, polygonCurrency, bscCurrency],
|
|
256
|
+
[ethereumUsdcToken, polygonUsdcToken, bscUsdcToken],
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect(orderedResult).toHaveLength(3);
|
|
260
|
+
|
|
261
|
+
// Should be ordered by account count (highest first)
|
|
262
|
+
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 3 accounts
|
|
263
|
+
expect(orderedResult[1].id).toBe(bscCurrency.id); // 2 accounts
|
|
264
|
+
expect(orderedResult[2].id).toBe(polygonCurrency.id); // 1 account
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("should handle networks with zero balances by ordering them by account count", () => {
|
|
268
|
+
const zeroBalanceEth = { ...ethereumAccountZero };
|
|
269
|
+
const zeroBalancePoly = {
|
|
270
|
+
...polygonAccountMedium,
|
|
271
|
+
balance: new BigNumber("0"),
|
|
272
|
+
spendableBalance: new BigNumber("0"),
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const mockUseBalanceDepsZero = () => ({
|
|
276
|
+
counterValueCurrency: {
|
|
277
|
+
type: "FiatCurrency" as const,
|
|
278
|
+
ticker: "USD",
|
|
279
|
+
name: "US Dollar",
|
|
280
|
+
symbol: "$",
|
|
281
|
+
units: [
|
|
282
|
+
{ code: "$", name: "US Dollar", magnitude: 2, showAllDigits: true, prefixCode: true },
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
flattenedAccounts: [zeroBalanceEth, zeroBalancePoly],
|
|
286
|
+
state: { cache: {}, data: {}, status: {} },
|
|
287
|
+
locale: "en-US",
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const { result } = renderHook(() =>
|
|
291
|
+
createNetworkConfigurationHook({
|
|
292
|
+
...networkConfigurationDeps,
|
|
293
|
+
useBalanceDeps: mockUseBalanceDepsZero,
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
const res = result.current({
|
|
297
|
+
networksConfig: { leftElement: "numberOfAccounts", rightElement: "balance" },
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const orderedResult = res(
|
|
301
|
+
[ethereumCurrency, polygonCurrency],
|
|
302
|
+
[ethereumUsdcToken, polygonUsdcToken],
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
expect(orderedResult).toHaveLength(2);
|
|
306
|
+
|
|
307
|
+
// When both have zero balance, should order by account count
|
|
308
|
+
expect(orderedResult[0].id).toBe(ethereumCurrency.id); // 3 accounts
|
|
309
|
+
expect(orderedResult[1].id).toBe(polygonCurrency.id); // 1 account
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("should prioritise non-zero balances over account count", () => {
|
|
313
|
+
const testEthereumCurrency: CryptoCurrency = createFixtureCryptoCurrency("ethereum");
|
|
314
|
+
const testPolygonCurrency: CryptoCurrency = createFixtureCryptoCurrency("polygon");
|
|
315
|
+
const testAvalancheCurrency: CryptoCurrency = createFixtureCryptoCurrency("avalanche_c_chain");
|
|
316
|
+
const testArbitrumCurrency: CryptoCurrency = createFixtureCryptoCurrency("arbitrum");
|
|
317
|
+
|
|
318
|
+
const testEthereumAccount = genAccount("test-ethereum-account", {
|
|
319
|
+
currency: testEthereumCurrency,
|
|
320
|
+
});
|
|
321
|
+
testEthereumAccount.balance = new BigNumber("1000000000000000000000");
|
|
322
|
+
testEthereumAccount.spendableBalance = testEthereumAccount.balance;
|
|
323
|
+
|
|
324
|
+
const testPolygonAccount = genAccount("test-polygon-account", {
|
|
325
|
+
currency: testPolygonCurrency,
|
|
326
|
+
});
|
|
327
|
+
testPolygonAccount.balance = new BigNumber("500000000000000000000");
|
|
328
|
+
testPolygonAccount.spendableBalance = testPolygonAccount.balance;
|
|
329
|
+
|
|
330
|
+
const testEthereumUsdcToken = makeUsdcToken(
|
|
331
|
+
testEthereumCurrency,
|
|
332
|
+
"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
333
|
+
);
|
|
334
|
+
const testPolygonUsdcToken = makeUsdcToken(
|
|
335
|
+
testPolygonCurrency,
|
|
336
|
+
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
337
|
+
);
|
|
338
|
+
const testAvalancheUsdcToken = makeUsdcToken(
|
|
339
|
+
testAvalancheCurrency,
|
|
340
|
+
"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
341
|
+
);
|
|
342
|
+
const testArbitrumUsdcToken = makeUsdcToken(
|
|
343
|
+
testArbitrumCurrency,
|
|
344
|
+
"0xFF970A61A04b1cA14834A43f5de4533eBDDB5CC8",
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
const testUseBalanceDeps = () => ({
|
|
348
|
+
counterValueCurrency: mockFiatCurrency,
|
|
349
|
+
flattenedAccounts: [testEthereumAccount, testPolygonAccount],
|
|
350
|
+
state: { cache: {}, data: {}, status: {} },
|
|
351
|
+
locale: "en-US",
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const testUseAccountData = () => [
|
|
355
|
+
makeAccountData(testEthereumCurrency, 3),
|
|
356
|
+
makeAccountData(testPolygonCurrency, 1),
|
|
357
|
+
makeAccountData(testAvalancheCurrency, 1),
|
|
358
|
+
makeAccountData(testArbitrumCurrency, 2),
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
const { result } = renderHook(() =>
|
|
362
|
+
createNetworkConfigurationHook({
|
|
363
|
+
...networkConfigurationDeps,
|
|
364
|
+
useAccountData: testUseAccountData,
|
|
365
|
+
useBalanceDeps: testUseBalanceDeps,
|
|
366
|
+
}),
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
const res = result.current({
|
|
370
|
+
networksConfig: { leftElement: "numberOfAccounts", rightElement: "balance" },
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const orderedResult = res(
|
|
374
|
+
[testEthereumCurrency, testPolygonCurrency, testAvalancheCurrency, testArbitrumCurrency],
|
|
375
|
+
[testEthereumUsdcToken, testPolygonUsdcToken, testAvalancheUsdcToken, testArbitrumUsdcToken],
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
expect(orderedResult[0].id).toBe(testEthereumCurrency.id); // 1000 ETH balance, 3 accounts
|
|
379
|
+
expect(orderedResult[1].id).toBe(testPolygonCurrency.id); // 500 MATIC balance, 1 account
|
|
380
|
+
expect(orderedResult[2].id).toBe(testArbitrumCurrency.id); // (0 balance, 2 accounts)
|
|
381
|
+
expect(orderedResult[3].id).toBe(testAvalancheCurrency.id); // (0 balance, 1 account)
|
|
382
|
+
});
|
|
383
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCryptoCurrencyById,
|
|
1
|
+
import { getCryptoCurrencyById, findTokenById } from "@ledgerhq/cryptoassets";
|
|
2
2
|
import { genAccount } from "../../mock/account";
|
|
3
3
|
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
4
|
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
@@ -66,7 +66,9 @@ describe("getAccountTuplesForCurrency", () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
describe("TokenCurrency", () => {
|
|
69
|
-
const
|
|
69
|
+
const token = findTokenById("ethereum/erc20/aave");
|
|
70
|
+
if (!token) throw new Error("AAVE token not found");
|
|
71
|
+
const aaveToken = token;
|
|
70
72
|
|
|
71
73
|
test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
|
|
72
74
|
const ethAccounts = [
|