@ledgerhq/live-common 34.42.1 → 34.43.0-nightly.1
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__/migration/account-migration.js +3 -0
- package/lib/__tests__/migration/account-migration.js.map +1 -1
- package/lib/__tests__/test-helpers/environment.js +3 -0
- package/lib/__tests__/test-helpers/environment.js.map +1 -1
- package/lib/bridge/crypto-assets/index.d.ts +4 -0
- package/lib/bridge/crypto-assets/index.d.ts.map +1 -0
- package/lib/bridge/crypto-assets/index.js +52 -0
- package/lib/bridge/crypto-assets/index.js.map +1 -0
- package/lib/bridge/crypto-assets/index.test.d.ts +2 -0
- package/lib/bridge/crypto-assets/index.test.d.ts.map +1 -0
- package/lib/bridge/crypto-assets/index.test.js +85 -0
- package/lib/bridge/crypto-assets/index.test.js.map +1 -0
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib/bridge/impl.d.ts +2 -0
- package/lib/bridge/impl.d.ts.map +1 -1
- package/lib/bridge/impl.js +8 -1
- package/lib/bridge/impl.js.map +1 -1
- package/lib/bridge/useBridgeTransaction.test.js +1 -1
- package/lib/bridge/useBridgeTransaction.test.js.map +1 -1
- package/lib/e2e/families/osmosis.d.ts +3 -0
- package/lib/e2e/families/osmosis.d.ts.map +1 -0
- package/lib/e2e/families/osmosis.js +19 -0
- package/lib/e2e/families/osmosis.js.map +1 -0
- package/lib/e2e/index.d.ts +9 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +50 -17
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/e2e/speculosCI.d.ts.map +1 -1
- package/lib/e2e/speculosCI.js +22 -4
- package/lib/e2e/speculosCI.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/exchange/error.d.ts +2 -1
- package/lib/exchange/error.d.ts.map +1 -1
- package/lib/exchange/error.js +5 -3
- package/lib/exchange/error.js.map +1 -1
- package/lib/exchange/swap/completeExchange.js +2 -2
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/families/evm/config.d.ts.map +1 -1
- package/lib/families/evm/config.js +51 -0
- package/lib/families/evm/config.js.map +1 -1
- package/lib/families/evm/walletApiAdapter.js +1 -1
- package/lib/families/solana/bridge/mock-data.d.ts.map +1 -1
- package/lib/families/solana/bridge/mock-data.js +46 -316
- package/lib/families/solana/bridge/mock-data.js.map +1 -1
- package/lib/families/solana/bridge/mock.js +2 -2
- package/lib/families/solana/bridge/mock.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 +4 -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/__mocks__/accounts.mock.d.ts +18 -0
- package/lib/modularDrawer/__mocks__/accounts.mock.d.ts.map +1 -0
- package/lib/modularDrawer/__mocks__/accounts.mock.js +48 -0
- package/lib/modularDrawer/__mocks__/accounts.mock.js.map +1 -0
- package/lib/modularDrawer/__mocks__/currencies.mock.d.ts +17 -0
- package/lib/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -0
- package/lib/modularDrawer/__mocks__/currencies.mock.js +60 -0
- package/lib/modularDrawer/__mocks__/currencies.mock.js.map +1 -0
- package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts +22 -0
- package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts.map +1 -0
- package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +41 -0
- package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +2 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +1 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +28 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -0
- package/lib/modularDrawer/utils/haveOneCommonProvider.d.ts +11 -0
- package/lib/modularDrawer/utils/haveOneCommonProvider.d.ts.map +1 -0
- package/lib/modularDrawer/utils/haveOneCommonProvider.js +29 -0
- package/lib/modularDrawer/utils/haveOneCommonProvider.js.map +1 -0
- package/lib/modularDrawer/utils/index.d.ts +2 -1
- package/lib/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib/modularDrawer/utils/index.js +3 -1
- package/lib/modularDrawer/utils/index.js.map +1 -1
- package/lib/utils/__tests__/composeHooks.test.d.ts +2 -0
- package/lib/utils/__tests__/composeHooks.test.d.ts.map +1 -0
- package/lib/utils/__tests__/composeHooks.test.js +35 -0
- package/lib/utils/__tests__/composeHooks.test.js.map +1 -0
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.d.ts +2 -0
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.d.ts.map +1 -0
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js +104 -0
- package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -0
- package/lib/utils/composeHooks.d.ts +11 -0
- package/lib/utils/composeHooks.d.ts.map +1 -0
- package/lib/utils/composeHooks.js +25 -0
- package/lib/utils/composeHooks.js.map +1 -0
- package/lib/utils/getAccountTuplesForCurrency.d.ts +8 -0
- package/lib/utils/getAccountTuplesForCurrency.d.ts.map +1 -0
- package/lib/utils/getAccountTuplesForCurrency.js +19 -0
- package/lib/utils/getAccountTuplesForCurrency.js.map +1 -0
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +6 -6
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/__tests__/migration/account-migration.js +3 -0
- package/lib-es/__tests__/migration/account-migration.js.map +1 -1
- package/lib-es/__tests__/test-helpers/environment.js +3 -0
- package/lib-es/__tests__/test-helpers/environment.js.map +1 -1
- package/lib-es/bridge/crypto-assets/index.d.ts +4 -0
- package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -0
- package/lib-es/bridge/crypto-assets/index.js +24 -0
- package/lib-es/bridge/crypto-assets/index.js.map +1 -0
- package/lib-es/bridge/crypto-assets/index.test.d.ts +2 -0
- package/lib-es/bridge/crypto-assets/index.test.d.ts.map +1 -0
- package/lib-es/bridge/crypto-assets/index.test.js +60 -0
- package/lib-es/bridge/crypto-assets/index.test.js.map +1 -0
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib-es/bridge/impl.d.ts +2 -0
- package/lib-es/bridge/impl.d.ts.map +1 -1
- package/lib-es/bridge/impl.js +6 -0
- package/lib-es/bridge/impl.js.map +1 -1
- package/lib-es/bridge/useBridgeTransaction.test.js +1 -1
- package/lib-es/bridge/useBridgeTransaction.test.js.map +1 -1
- package/lib-es/e2e/families/osmosis.d.ts +3 -0
- package/lib-es/e2e/families/osmosis.d.ts.map +1 -0
- package/lib-es/e2e/families/osmosis.js +12 -0
- package/lib-es/e2e/families/osmosis.js.map +1 -0
- package/lib-es/e2e/index.d.ts +9 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/speculos.d.ts.map +1 -1
- package/lib-es/e2e/speculos.js +50 -17
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/e2e/speculosCI.d.ts.map +1 -1
- package/lib-es/e2e/speculosCI.js +22 -4
- package/lib-es/e2e/speculosCI.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/error.d.ts +2 -1
- package/lib-es/exchange/error.d.ts.map +1 -1
- package/lib-es/exchange/error.js +5 -3
- package/lib-es/exchange/error.js.map +1 -1
- package/lib-es/exchange/swap/completeExchange.js +2 -2
- package/lib-es/exchange/swap/completeExchange.js.map +1 -1
- package/lib-es/families/evm/config.d.ts.map +1 -1
- package/lib-es/families/evm/config.js +51 -0
- package/lib-es/families/evm/config.js.map +1 -1
- package/lib-es/families/evm/walletApiAdapter.js +1 -1
- package/lib-es/families/solana/bridge/mock-data.d.ts.map +1 -1
- package/lib-es/families/solana/bridge/mock-data.js +46 -316
- package/lib-es/families/solana/bridge/mock-data.js.map +1 -1
- package/lib-es/families/solana/bridge/mock.js +3 -3
- package/lib-es/families/solana/bridge/mock.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 +4 -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/__mocks__/accounts.mock.d.ts +18 -0
- package/lib-es/modularDrawer/__mocks__/accounts.mock.d.ts.map +1 -0
- package/lib-es/modularDrawer/__mocks__/accounts.mock.js +42 -0
- package/lib-es/modularDrawer/__mocks__/accounts.mock.js.map +1 -0
- package/lib-es/modularDrawer/__mocks__/currencies.mock.d.ts +17 -0
- package/lib-es/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -0
- package/lib-es/modularDrawer/__mocks__/currencies.mock.js +55 -0
- package/lib-es/modularDrawer/__mocks__/currencies.mock.js.map +1 -0
- package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts +22 -0
- package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts.map +1 -0
- package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +38 -0
- package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +2 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +26 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -0
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.d.ts +11 -0
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.js +25 -0
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.js.map +1 -0
- package/lib-es/modularDrawer/utils/index.d.ts +2 -1
- package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib-es/modularDrawer/utils/index.js +2 -1
- package/lib-es/modularDrawer/utils/index.js.map +1 -1
- package/lib-es/utils/__tests__/composeHooks.test.d.ts +2 -0
- package/lib-es/utils/__tests__/composeHooks.test.d.ts.map +1 -0
- package/lib-es/utils/__tests__/composeHooks.test.js +33 -0
- package/lib-es/utils/__tests__/composeHooks.test.js.map +1 -0
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.d.ts +2 -0
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.d.ts.map +1 -0
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js +102 -0
- package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -0
- package/lib-es/utils/composeHooks.d.ts +11 -0
- package/lib-es/utils/composeHooks.d.ts.map +1 -0
- package/lib-es/utils/composeHooks.js +21 -0
- package/lib-es/utils/composeHooks.js.map +1 -0
- package/lib-es/utils/getAccountTuplesForCurrency.d.ts +8 -0
- package/lib-es/utils/getAccountTuplesForCurrency.d.ts.map +1 -0
- package/lib-es/utils/getAccountTuplesForCurrency.js +15 -0
- package/lib-es/utils/getAccountTuplesForCurrency.js.map +1 -0
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +6 -6
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/package.json +50 -50
- package/src/__tests__/migration/account-migration.ts +3 -0
- package/src/__tests__/test-helpers/environment.ts +3 -0
- package/src/bridge/crypto-assets/index.test.ts +71 -0
- package/src/bridge/crypto-assets/index.ts +30 -0
- package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +8 -1
- package/src/bridge/impl.ts +8 -0
- package/src/bridge/useBridgeTransaction.test.ts +1 -1
- package/src/e2e/families/osmosis.ts +13 -0
- package/src/e2e/speculos.ts +82 -23
- package/src/e2e/speculosCI.ts +32 -10
- package/src/exchange/error.ts +5 -3
- package/src/exchange/swap/completeExchange.ts +2 -2
- package/src/families/evm/config.ts +51 -0
- package/src/families/evm/walletApiAdapter.ts +1 -1
- package/src/families/solana/bridge/mock-data.ts +52 -316
- package/src/families/solana/bridge/mock.ts +3 -3
- package/src/featureFlags/defaultFeatures.ts +4 -0
- package/src/modularDrawer/__mocks__/accounts.mock.ts +43 -0
- package/src/modularDrawer/__mocks__/currencies.mock.ts +62 -0
- package/src/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.ts +49 -0
- package/src/modularDrawer/utils/__tests__/haveOneCommonProvider.test.ts +34 -0
- package/src/modularDrawer/utils/haveOneCommonProvider.ts +31 -0
- package/src/modularDrawer/utils/index.ts +2 -1
- package/src/utils/__tests__/composeHooks.test.ts +46 -0
- package/src/utils/__tests__/getAccountTuplesForCurrency.test.ts +138 -0
- package/src/utils/composeHooks.ts +26 -0
- package/src/utils/getAccountTuplesForCurrency.ts +34 -0
- package/src/wallet-api/Exchange/server.ts +7 -6
@@ -0,0 +1,46 @@
|
|
1
|
+
import { composeHooks } from "../composeHooks";
|
2
|
+
|
3
|
+
describe("composeHooks", () => {
|
4
|
+
it("should compose hooks and merge their results", () => {
|
5
|
+
const hook1 = (items: Array<{ id: number }>) =>
|
6
|
+
items.map(item => ({ id: item.id, extra: item.id * 2 }));
|
7
|
+
const hook2 = (items: Array<{ id: number; extra: number }>) =>
|
8
|
+
items.map(item => ({ ...item, final: item.extra + 1 }));
|
9
|
+
|
10
|
+
const composed = composeHooks(hook1, hook2);
|
11
|
+
|
12
|
+
const input: Array<{ id: number }> = [{ id: 1 }, { id: 2 }];
|
13
|
+
const processedInput = input.map(item => ({ id: item.id, extra: item.id * 2 }));
|
14
|
+
const result = composed(processedInput);
|
15
|
+
|
16
|
+
expect(result).toEqual([
|
17
|
+
{ id: 1, extra: 2, final: 3 },
|
18
|
+
{ id: 2, extra: 4, final: 5 },
|
19
|
+
]);
|
20
|
+
});
|
21
|
+
|
22
|
+
it("should handle hooks that return undefined", () => {
|
23
|
+
const hook1 = (items: Array<{ id: number }>) =>
|
24
|
+
items.map(item => ({ id: item.id, extra: item.id * 2 }));
|
25
|
+
const hook2 = () => undefined;
|
26
|
+
|
27
|
+
const composed = composeHooks(hook1, hook2);
|
28
|
+
|
29
|
+
const input = [{ id: 1 }, { id: 2 }];
|
30
|
+
const result = composed(input);
|
31
|
+
|
32
|
+
expect(result).toEqual([
|
33
|
+
{ id: 1, extra: 2 },
|
34
|
+
{ id: 2, extra: 4 },
|
35
|
+
]);
|
36
|
+
});
|
37
|
+
|
38
|
+
it("should return the original items if no hooks are provided", () => {
|
39
|
+
const composed = composeHooks();
|
40
|
+
|
41
|
+
const input = [{ id: 1 }, { id: 2 }];
|
42
|
+
const result = composed(input);
|
43
|
+
|
44
|
+
expect(result).toEqual(input);
|
45
|
+
});
|
46
|
+
});
|
@@ -0,0 +1,138 @@
|
|
1
|
+
import { getCryptoCurrencyById, getTokenById } from "@ledgerhq/cryptoassets";
|
2
|
+
import { genAccount } from "@ledgerhq/live-common/mock/account";
|
3
|
+
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
4
|
+
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
5
|
+
import { getAccountTuplesForCurrency } from "../getAccountTuplesForCurrency";
|
6
|
+
|
7
|
+
function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
|
8
|
+
let id = 0;
|
9
|
+
while (true) {
|
10
|
+
id += 1;
|
11
|
+
yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
|
12
|
+
}
|
13
|
+
}
|
14
|
+
const getAccountCreator = (currencyId: string) => {
|
15
|
+
const generator = accountGenerator(getCryptoCurrencyById(currencyId));
|
16
|
+
return () => generator.next().value;
|
17
|
+
};
|
18
|
+
|
19
|
+
describe("getAccountTuplesForCurrency", () => {
|
20
|
+
const getEthAccount = getAccountCreator("ethereum");
|
21
|
+
const getBtcAccount = getAccountCreator("bitcoin");
|
22
|
+
const getPolkadotAccount = getAccountCreator("polkadot");
|
23
|
+
const getCosmosAccount = getAccountCreator("cosmos");
|
24
|
+
|
25
|
+
describe("CryptoCurrency", () => {
|
26
|
+
test("returns all accounts associated to the CryptoCurrency", () => {
|
27
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
28
|
+
const ethAccounts = [getEthAccount(), getEthAccount()];
|
29
|
+
const allAccounts: Account[] = [
|
30
|
+
getCosmosAccount(),
|
31
|
+
...ethAccounts,
|
32
|
+
getBtcAccount(),
|
33
|
+
getPolkadotAccount(),
|
34
|
+
];
|
35
|
+
|
36
|
+
const results = getAccountTuplesForCurrency(ethCurrency, allAccounts);
|
37
|
+
|
38
|
+
expect(results).toHaveLength(2);
|
39
|
+
results.forEach((result, index) => {
|
40
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
41
|
+
expect(result.subAccount).toBeNull();
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
test("returns an empty array if the CryptoCurrency passed has no associated account", () => {
|
46
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
47
|
+
const allAccounts: Account[] = [getCosmosAccount(), getBtcAccount(), getPolkadotAccount()];
|
48
|
+
|
49
|
+
const results = getAccountTuplesForCurrency(ethCurrency, allAccounts);
|
50
|
+
|
51
|
+
expect(results).toHaveLength(0);
|
52
|
+
});
|
53
|
+
|
54
|
+
test("filters based on the accountId map", () => {
|
55
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
56
|
+
const ethAccounts = [getEthAccount(), getEthAccount(), getEthAccount(), getEthAccount()];
|
57
|
+
|
58
|
+
const results = getAccountTuplesForCurrency(
|
59
|
+
ethCurrency,
|
60
|
+
ethAccounts,
|
61
|
+
new Map([[ethAccounts[0].id, true]]),
|
62
|
+
);
|
63
|
+
|
64
|
+
expect(results).toHaveLength(1);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
describe("TokenCurrency", () => {
|
69
|
+
const aaveToken = getTokenById("ethereum/erc20/aave");
|
70
|
+
|
71
|
+
test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
|
72
|
+
const ethAccounts = [
|
73
|
+
{ ...getEthAccount(), subAccounts: [] },
|
74
|
+
{ ...getEthAccount(), subAccounts: [] },
|
75
|
+
];
|
76
|
+
const allAccounts: Account[] = [
|
77
|
+
getCosmosAccount(),
|
78
|
+
...ethAccounts,
|
79
|
+
getBtcAccount(),
|
80
|
+
getPolkadotAccount(),
|
81
|
+
];
|
82
|
+
|
83
|
+
const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
|
84
|
+
|
85
|
+
expect(results).toHaveLength(ethAccounts.length);
|
86
|
+
results.forEach((result, index) => {
|
87
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
88
|
+
expect((result.subAccount as TokenAccount & { token: TokenCurrency }).token).toEqual(
|
89
|
+
aaveToken,
|
90
|
+
);
|
91
|
+
});
|
92
|
+
});
|
93
|
+
|
94
|
+
test("returns correct parent accounts including already existing subAccounts when a TokenCurrency is provided", () => {
|
95
|
+
const ethAccounts = [{ ...getEthAccount(), subAccounts: [aaveToken] }];
|
96
|
+
const allAccounts: Account[] = [
|
97
|
+
getCosmosAccount(),
|
98
|
+
...ethAccounts,
|
99
|
+
getBtcAccount(),
|
100
|
+
getPolkadotAccount(),
|
101
|
+
];
|
102
|
+
|
103
|
+
const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
|
104
|
+
|
105
|
+
expect(results).toHaveLength(ethAccounts.length);
|
106
|
+
results.forEach((result, index) => {
|
107
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
108
|
+
expect((result.subAccount as TokenAccount & { token: TokenCurrency }).token).toEqual(
|
109
|
+
aaveToken,
|
110
|
+
);
|
111
|
+
});
|
112
|
+
});
|
113
|
+
|
114
|
+
test("returns an empty array when a TokenCurrency is provided but the accounts list is empty", () => {
|
115
|
+
const allAccounts: Account[] = [];
|
116
|
+
|
117
|
+
const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
|
118
|
+
expect(results).toHaveLength(0);
|
119
|
+
});
|
120
|
+
|
121
|
+
test("does not filter based on the accountId map", () => {
|
122
|
+
const aaveAccounts = [
|
123
|
+
{ ...getEthAccount(), subAccounts: [aaveToken] },
|
124
|
+
{ ...getEthAccount(), subAccounts: [aaveToken] },
|
125
|
+
{ ...getEthAccount(), subAccounts: [aaveToken] },
|
126
|
+
{ ...getEthAccount(), subAccounts: [aaveToken] },
|
127
|
+
];
|
128
|
+
|
129
|
+
const results = getAccountTuplesForCurrency(
|
130
|
+
aaveToken,
|
131
|
+
aaveAccounts,
|
132
|
+
new Map([[aaveAccounts[0].id, true]]),
|
133
|
+
);
|
134
|
+
|
135
|
+
expect(results).toHaveLength(4);
|
136
|
+
});
|
137
|
+
});
|
138
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* @param hooks - An array of functions that take an array of items of type T and return an array of items of type U or undefined.
|
4
|
+
* @template T - The type of the items in the input array.
|
5
|
+
* @template U - The type of the items in the output array.
|
6
|
+
* @description This function composes multiple hooks into a single hook that processes an array of items of type T and returns an array of items of type T & U.
|
7
|
+
* @returns A function that takes an array of items of type T and returns an array of items of type T & U.
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
export function composeHooks<T, U>(
|
12
|
+
...hooks: Array<(items: T[]) => U[] | undefined>
|
13
|
+
): (items: T[]) => (T & U)[] {
|
14
|
+
return (items: T[]): (T & U)[] => {
|
15
|
+
return hooks.reduce<(T & U)[]>(
|
16
|
+
(acc, hook) => {
|
17
|
+
const result = hook?.(acc as T[]) ?? [];
|
18
|
+
return acc.map((item, i) => ({
|
19
|
+
...item,
|
20
|
+
...result[i],
|
21
|
+
}));
|
22
|
+
},
|
23
|
+
items as (T & U)[],
|
24
|
+
);
|
25
|
+
};
|
26
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
2
|
+
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
3
|
+
import { makeEmptyTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
|
4
|
+
|
5
|
+
export type AccountTuple = {
|
6
|
+
account: Account;
|
7
|
+
subAccount: TokenAccount | null;
|
8
|
+
};
|
9
|
+
|
10
|
+
export function getAccountTuplesForCurrency(
|
11
|
+
currency: CryptoCurrency | TokenCurrency,
|
12
|
+
allAccounts: Account[],
|
13
|
+
accountIds?: Map<string, boolean>,
|
14
|
+
): AccountTuple[] {
|
15
|
+
const isToken = currency.type === "TokenCurrency";
|
16
|
+
const targetCurrencyId = isToken ? currency.parentCurrency.id : currency.id;
|
17
|
+
|
18
|
+
return allAccounts
|
19
|
+
.filter(
|
20
|
+
account =>
|
21
|
+
account.currency.id === targetCurrencyId &&
|
22
|
+
(isToken ? true : accountIds ? accountIds.has(account.id) : true),
|
23
|
+
)
|
24
|
+
.map(account => {
|
25
|
+
const subAccount = isToken
|
26
|
+
? account.subAccounts?.find(
|
27
|
+
(subAcc): subAcc is TokenAccount =>
|
28
|
+
subAcc.type === "TokenAccount" && subAcc.token.id === currency.id,
|
29
|
+
) || makeEmptyTokenAccount(account, currency)
|
30
|
+
: null;
|
31
|
+
|
32
|
+
return { account, subAccount };
|
33
|
+
});
|
34
|
+
}
|
@@ -51,6 +51,7 @@ import { getSwapStepFromError } from "../../exchange/error";
|
|
51
51
|
import { postSwapCancelled } from "../../exchange/swap";
|
52
52
|
import { DeviceModelId } from "@ledgerhq/types-devices";
|
53
53
|
import { setBroadcastTransaction } from "../../exchange/swap/setBroadcastTransaction";
|
54
|
+
import { FAMILIES_MAPPING_LL_TO_WAPI } from "../constants";
|
54
55
|
|
55
56
|
export { ExchangeType };
|
56
57
|
|
@@ -485,7 +486,9 @@ export const handlers = ({
|
|
485
486
|
});
|
486
487
|
|
487
488
|
const mainFromAccount = getMainAccount(fromAccount, fromParentAccount);
|
488
|
-
const mainFromAccountFamily =
|
489
|
+
const mainFromAccountFamily =
|
490
|
+
FAMILIES_MAPPING_LL_TO_WAPI[mainFromAccount.currency.family] ||
|
491
|
+
mainFromAccount.currency.family;
|
489
492
|
|
490
493
|
if (transaction.family !== mainFromAccountFamily) {
|
491
494
|
return Promise.reject(
|
@@ -741,9 +744,7 @@ async function getStrategy(
|
|
741
744
|
customErrorType?: any,
|
742
745
|
): Promise<Transaction> {
|
743
746
|
const family =
|
744
|
-
currency.type === "TokenCurrency"
|
745
|
-
? (currency.parentCurrency?.family as Transaction["family"])
|
746
|
-
: (currency.family as Transaction["family"]);
|
747
|
+
currency.type === "TokenCurrency" ? currency.parentCurrency?.family : currency.family;
|
747
748
|
|
748
749
|
if (!family) {
|
749
750
|
throw new Error(`TokenCurrency missing parentCurrency family: ${currency.id}`);
|
@@ -755,7 +756,7 @@ async function getStrategy(
|
|
755
756
|
}
|
756
757
|
|
757
758
|
// Normalize family key for strategy lookup
|
758
|
-
const familyKey = family
|
759
|
+
const familyKey = FAMILIES_MAPPING_LL_TO_WAPI[family] || family;
|
759
760
|
const strategy = transactionStrategy?.[familyKey];
|
760
761
|
|
761
762
|
if (!strategy) {
|
@@ -764,7 +765,7 @@ async function getStrategy(
|
|
764
765
|
|
765
766
|
try {
|
766
767
|
return await strategy({
|
767
|
-
family,
|
768
|
+
family: familyKey,
|
768
769
|
amount,
|
769
770
|
recipient,
|
770
771
|
customFeeConfig: customFeeConfig || {},
|