@ledgerhq/live-common 34.43.0 → 34.44.0-nightly.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/DataModel.test.js +6 -0
- package/lib/DataModel.test.js.map +1 -1
- package/lib/__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json +53 -0
- package/lib/__tests__/accounts/groupPerDay.js +10 -0
- package/lib/__tests__/accounts/groupPerDay.js.map +1 -1
- package/lib/__tests__/test-helpers/environment.js +1 -0
- package/lib/__tests__/test-helpers/environment.js.map +1 -1
- package/lib/__tests__/test-helpers/setup.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/setup.js +6 -0
- package/lib/__tests__/test-helpers/setup.js.map +1 -1
- package/lib/account/serialization.test.js +17 -1
- package/lib/account/serialization.test.js.map +1 -1
- package/lib/appSupportsQuitApp.d.ts +1 -0
- package/lib/appSupportsQuitApp.d.ts.map +1 -1
- package/lib/appSupportsQuitApp.js +1 -0
- package/lib/appSupportsQuitApp.js.map +1 -1
- package/lib/appSupportsQuitApp.test.js +28 -3
- package/lib/appSupportsQuitApp.test.js.map +1 -1
- package/lib/bridge/crypto-assets/index.d.ts.map +1 -1
- package/lib/bridge/crypto-assets/index.js +5 -5
- package/lib/bridge/crypto-assets/index.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +2 -6
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.js +5 -6
- package/lib/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.d.ts +3 -2
- package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/utils.js +6 -2
- package/lib/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.test.d.ts +2 -0
- package/lib/bridge/generic-alpaca/utils.test.d.ts.map +1 -0
- package/lib/bridge/generic-alpaca/utils.test.js +20 -0
- package/lib/bridge/generic-alpaca/utils.test.js.map +1 -0
- package/lib/currencies/sortByMarketcap.test.js +5 -0
- package/lib/currencies/sortByMarketcap.test.js.map +1 -1
- package/lib/e2e/index.d.ts +3 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +45 -15
- 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/families/bitcoin/satstack.test.js +6 -0
- package/lib/families/bitcoin/satstack.test.js.map +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/families/stellar/ui.d.ts +6 -0
- package/lib/families/stellar/ui.d.ts.map +1 -0
- package/lib/families/stellar/ui.js +18 -0
- package/lib/families/stellar/ui.js.map +1 -0
- package/lib/families/tron/data.mock.d.ts.map +1 -1
- package/lib/families/tron/data.mock.js +6 -0
- package/lib/families/tron/data.mock.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts +1 -0
- 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/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/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/helpers.d.ts +1 -0
- package/lib/wallet-api/helpers.d.ts.map +1 -1
- package/lib/wallet-api/helpers.js +16 -1
- package/lib/wallet-api/helpers.js.map +1 -1
- package/lib-es/DataModel.test.js +6 -0
- package/lib-es/DataModel.test.js.map +1 -1
- package/lib-es/__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json +53 -0
- package/lib-es/__tests__/accounts/groupPerDay.js +10 -0
- package/lib-es/__tests__/accounts/groupPerDay.js.map +1 -1
- package/lib-es/__tests__/test-helpers/environment.js +1 -0
- package/lib-es/__tests__/test-helpers/environment.js.map +1 -1
- package/lib-es/__tests__/test-helpers/setup.d.ts.map +1 -1
- package/lib-es/__tests__/test-helpers/setup.js +6 -0
- package/lib-es/__tests__/test-helpers/setup.js.map +1 -1
- package/lib-es/account/serialization.test.js +15 -2
- package/lib-es/account/serialization.test.js.map +1 -1
- package/lib-es/appSupportsQuitApp.d.ts +1 -0
- package/lib-es/appSupportsQuitApp.d.ts.map +1 -1
- package/lib-es/appSupportsQuitApp.js +1 -0
- package/lib-es/appSupportsQuitApp.js.map +1 -1
- package/lib-es/appSupportsQuitApp.test.js +6 -1
- package/lib-es/appSupportsQuitApp.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 +4 -4
- package/lib-es/bridge/crypto-assets/index.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +2 -6
- 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.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.js +6 -7
- package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.d.ts +3 -2
- package/lib-es/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.js +4 -1
- package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.test.d.ts +2 -0
- package/lib-es/bridge/generic-alpaca/utils.test.d.ts.map +1 -0
- package/lib-es/bridge/generic-alpaca/utils.test.js +18 -0
- package/lib-es/bridge/generic-alpaca/utils.test.js.map +1 -0
- package/lib-es/currencies/sortByMarketcap.test.js +5 -0
- package/lib-es/currencies/sortByMarketcap.test.js.map +1 -1
- package/lib-es/e2e/index.d.ts +3 -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 +45 -15
- 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/families/bitcoin/satstack.test.js +6 -0
- package/lib-es/families/bitcoin/satstack.test.js.map +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/families/stellar/ui.d.ts +6 -0
- package/lib-es/families/stellar/ui.d.ts.map +1 -0
- package/lib-es/families/stellar/ui.js +14 -0
- package/lib-es/families/stellar/ui.js.map +1 -0
- package/lib-es/families/tron/data.mock.d.ts.map +1 -1
- package/lib-es/families/tron/data.mock.js +6 -0
- package/lib-es/families/tron/data.mock.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts +1 -0
- 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/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/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/helpers.d.ts +1 -0
- package/lib-es/wallet-api/helpers.d.ts.map +1 -1
- package/lib-es/wallet-api/helpers.js +14 -0
- package/lib-es/wallet-api/helpers.js.map +1 -1
- package/package.json +37 -37
- package/src/DataModel.test.ts +8 -0
- package/src/__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json +53 -0
- package/src/__tests__/accounts/groupPerDay.ts +13 -0
- package/src/__tests__/test-helpers/environment.ts +1 -0
- package/src/__tests__/test-helpers/setup.ts +8 -0
- package/src/account/serialization.test.ts +20 -2
- package/src/appSupportsQuitApp.test.ts +7 -1
- package/src/appSupportsQuitApp.ts +1 -0
- package/src/bridge/crypto-assets/index.ts +6 -6
- package/src/bridge/generic-alpaca/alpaca/index.ts +3 -3
- package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +3 -8
- package/src/bridge/generic-alpaca/getAccountShape.ts +6 -7
- package/src/bridge/generic-alpaca/signOperation.ts +1 -1
- package/src/bridge/generic-alpaca/utils.test.ts +19 -0
- package/src/bridge/generic-alpaca/utils.ts +7 -6
- package/src/currencies/sortByMarketcap.test.ts +7 -0
- package/src/e2e/speculos.ts +77 -21
- package/src/e2e/speculosCI.ts +32 -10
- package/src/families/bitcoin/satstack.test.ts +7 -0
- package/src/families/solana/bridge/mock-data.ts +52 -316
- package/src/families/solana/bridge/mock.ts +3 -3
- package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +1930 -94
- package/src/families/stellar/ui.ts +15 -0
- package/src/families/tron/data.mock.ts +8 -0
- package/src/featureFlags/defaultFeatures.ts +1 -0
- package/src/modularDrawer/__mocks__/accounts.mock.ts +43 -0
- 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/helpers.ts +16 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
import { StellarOperationExtra } from "./types";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Format stellar memo value for display.
|
5
|
+
*/
|
6
|
+
export const formatMemo = (extra: StellarOperationExtra): string | undefined => {
|
7
|
+
switch (extra?.memo?.type) {
|
8
|
+
case "MEMO_ID":
|
9
|
+
case "MEMO_TEXT":
|
10
|
+
case "MEMO_HASH":
|
11
|
+
case "MEMO_RETURN":
|
12
|
+
return extra?.memo.value;
|
13
|
+
}
|
14
|
+
return undefined;
|
15
|
+
};
|
@@ -1,10 +1,18 @@
|
|
1
1
|
import { fromAccountRaw } from "../../account/serialization";
|
2
2
|
import { TronAccount } from "@ledgerhq/coin-tron/types/index";
|
3
|
+
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
|
4
|
+
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
|
3
5
|
|
4
6
|
export const __NEXT_REWARD_DATE__ = new Date(Date.now() - 6 * 60 * 60 * 1000);
|
5
7
|
|
6
8
|
export const __LAST_VOTING_DATE__ = new Date(Date.now() - 6 * 60 * 60 * 1000);
|
7
9
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
11
|
+
setCryptoAssetsStoreForCoinFramework({
|
12
|
+
findTokenById: (_: string) => undefined,
|
13
|
+
findTokenByAddressInCurrency: (_: string, __: string) => undefined,
|
14
|
+
} as unknown as CryptoAssetsStore);
|
15
|
+
|
8
16
|
export const mockAccount = fromAccountRaw({
|
9
17
|
id: "js:2:tron:TRON_ID:",
|
10
18
|
seedIdentifier: "TRON_ID",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { genAccount } from "@ledgerhq/coin-framework/lib/mocks/account";
|
2
|
+
import BigNumber from "bignumber.js";
|
3
|
+
import { mockBtcCryptoCurrency } from "./currencies.mock";
|
4
|
+
import { mockArbitrumCryptoCurrency } from "./currencies.mock";
|
5
|
+
import { mockEthCryptoCurrency } from "./currencies.mock";
|
6
|
+
import { mockBaseCryptoCurrency } from "./currencies.mock";
|
7
|
+
import { mockScrollCryptoCurrency } from "./currencies.mock";
|
8
|
+
|
9
|
+
export const MOCKED_ARB_ACCOUNT = {
|
10
|
+
type: "Account",
|
11
|
+
id: "arbitrum1",
|
12
|
+
balance: new BigNumber(34455),
|
13
|
+
creationDate: "2024-12-10T09:27:22.000Z",
|
14
|
+
currency: mockArbitrumCryptoCurrency,
|
15
|
+
derivationMode: "",
|
16
|
+
freshAddress: "s37rhmi7hsm3i73hsm7i3hm83m8h87hsm87h3s8h33",
|
17
|
+
};
|
18
|
+
|
19
|
+
export const ETH_ACCOUNT = genAccount("ethereum-1", {
|
20
|
+
currency: mockEthCryptoCurrency,
|
21
|
+
});
|
22
|
+
export const ETH_ACCOUNT_2 = genAccount("ethereum-2", {
|
23
|
+
currency: mockEthCryptoCurrency,
|
24
|
+
});
|
25
|
+
export const BTC_ACCOUNT = genAccount("bitcoin-1", {
|
26
|
+
currency: mockBtcCryptoCurrency,
|
27
|
+
});
|
28
|
+
export const ARB_ACCOUNT = genAccount("arbitrum-1", {
|
29
|
+
currency: mockArbitrumCryptoCurrency,
|
30
|
+
tokenIds: ["arbitrum/erc20/arbitrum"],
|
31
|
+
});
|
32
|
+
export const ETH_ACCOUNT_WITH_USDC = genAccount("ethereum-usdc", {
|
33
|
+
currency: mockEthCryptoCurrency,
|
34
|
+
tokenIds: ["ethereum/erc20/usdc"],
|
35
|
+
});
|
36
|
+
export const BASE_ACCOUNT = genAccount("base-1", {
|
37
|
+
currency: mockBaseCryptoCurrency,
|
38
|
+
operationsSize: 100,
|
39
|
+
});
|
40
|
+
export const SCROLL_ACCOUNT = genAccount("scroll-1", {
|
41
|
+
currency: mockScrollCryptoCurrency,
|
42
|
+
operationsSize: 100,
|
43
|
+
});
|
@@ -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
|
+
}
|
@@ -127,3 +127,19 @@ export const stripHexPrefix = (str: string): string => {
|
|
127
127
|
|
128
128
|
return isHexPrefixed(str) ? str.slice(2) : str;
|
129
129
|
};
|
130
|
+
|
131
|
+
export function objectToURLSearchParams(obj: Record<string, unknown>): URLSearchParams {
|
132
|
+
const searchParams = new URLSearchParams();
|
133
|
+
|
134
|
+
Object.entries(obj).forEach(([key, value]) => {
|
135
|
+
if (value !== undefined && value !== null) {
|
136
|
+
if (typeof value === "object") {
|
137
|
+
searchParams.append(key, JSON.stringify(value));
|
138
|
+
} else {
|
139
|
+
searchParams.append(key, String(value));
|
140
|
+
}
|
141
|
+
}
|
142
|
+
});
|
143
|
+
|
144
|
+
return searchParams;
|
145
|
+
}
|