@ledgerhq/cryptoassets 13.32.0 → 13.33.0-nightly.20251108023448

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.
Files changed (39) hide show
  1. package/.unimportedrc.json +7 -2
  2. package/CHANGELOG.md +20 -0
  3. package/lib/data/trc10.json +1 -1
  4. package/lib/data/trc20.json +1 -1
  5. package/lib/legacy/legacy-store.d.ts +0 -4
  6. package/lib/legacy/legacy-store.d.ts.map +1 -1
  7. package/lib/legacy/legacy-store.js +2 -6
  8. package/lib/legacy/legacy-store.js.map +1 -1
  9. package/lib/legacy/legacy-utils.d.ts.map +1 -1
  10. package/lib/legacy/legacy-utils.js +6 -1
  11. package/lib/legacy/legacy-utils.js.map +1 -1
  12. package/lib/tokens.d.ts +6 -16
  13. package/lib/tokens.d.ts.map +1 -1
  14. package/lib/tokens.js +6 -40
  15. package/lib/tokens.js.map +1 -1
  16. package/lib-es/data/trc10.json +1 -1
  17. package/lib-es/data/trc20.json +1 -1
  18. package/lib-es/legacy/legacy-store.d.ts +0 -4
  19. package/lib-es/legacy/legacy-store.d.ts.map +1 -1
  20. package/lib-es/legacy/legacy-store.js +2 -6
  21. package/lib-es/legacy/legacy-store.js.map +1 -1
  22. package/lib-es/legacy/legacy-utils.d.ts.map +1 -1
  23. package/lib-es/legacy/legacy-utils.js +6 -1
  24. package/lib-es/legacy/legacy-utils.js.map +1 -1
  25. package/lib-es/tokens.d.ts +6 -16
  26. package/lib-es/tokens.d.ts.map +1 -1
  27. package/lib-es/tokens.js +6 -23
  28. package/lib-es/tokens.js.map +1 -1
  29. package/package.json +3 -3
  30. package/src/backtest-tokenTypes.test.ts +5 -0
  31. package/src/currencies.test.ts +22 -8
  32. package/src/data/trc10.json +1 -1
  33. package/src/data/trc20.json +1 -1
  34. package/src/hooks.test.ts +9 -7
  35. package/src/legacy/legacy-store.ts +3 -7
  36. package/src/legacy/legacy-utils.ts +7 -2
  37. package/src/legacy/legacy.test.ts +15 -10
  38. package/src/tokens.test.ts +8 -10
  39. package/src/tokens.ts +5 -61
package/src/hooks.test.ts CHANGED
@@ -86,19 +86,21 @@ beforeEach(() => {
86
86
  jest.clearAllMocks();
87
87
 
88
88
  // Default mock implementations
89
- mockFindTokenById.mockImplementation((id: string) => {
89
+ mockFindTokenById.mockImplementation(async (id: string) => {
90
90
  if (id === "ethereum/erc20/usd_coin") {
91
91
  return mockToken;
92
92
  }
93
93
  return undefined;
94
94
  });
95
95
 
96
- mockFindTokenByAddressInCurrency.mockImplementation((address: string, currencyId: string) => {
97
- if (address === "0xA0b86a33E6441b8c4C8C0e4b8b8c4C8C0e4b8b8c4" && currencyId === "ethereum") {
98
- return mockToken;
99
- }
100
- return undefined;
101
- });
96
+ mockFindTokenByAddressInCurrency.mockImplementation(
97
+ async (address: string, currencyId: string) => {
98
+ if (address === "0xA0b86a33E6441b8c4C8C0e4b8b8c4C8C0e4b8b8c4" && currencyId === "ethereum") {
99
+ return mockToken;
100
+ }
101
+ return undefined;
102
+ },
103
+ );
102
104
 
103
105
  mockFindCryptoCurrencyById.mockImplementation((id: string) => {
104
106
  if (id === "bitcoin") {
@@ -2,14 +2,14 @@ import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
2
2
  import type { CryptoAssetsStore } from "@ledgerhq/types-live";
3
3
  import { tokensById, tokensByCurrencyAddress, tokensByCryptoCurrency } from "./legacy-state";
4
4
 
5
- function findTokenById(id: string): TokenCurrency | undefined {
5
+ async function findTokenById(id: string): Promise<TokenCurrency | undefined> {
6
6
  return tokensById[id];
7
7
  }
8
8
 
9
- function findTokenByAddressInCurrency(
9
+ async function findTokenByAddressInCurrency(
10
10
  address: string,
11
11
  currencyId: string,
12
- ): TokenCurrency | undefined {
12
+ ): Promise<TokenCurrency | undefined> {
13
13
  return tokensByCurrencyAddress[currencyId + ":" + address.toLowerCase()];
14
14
  }
15
15
 
@@ -18,10 +18,6 @@ function getTokensSyncHash(currencyId: string): Promise<string> {
18
18
  return Promise.resolve("legacy_" + tokens?.length);
19
19
  }
20
20
 
21
- /**
22
- * Legacy CryptoAssetsStore adapter that wraps the legacy token lookup functions
23
- * and provides the CryptoAssetsStore interface expected by the rest of the codebase.
24
- */
25
21
  export const legacyCryptoAssetsStore: CryptoAssetsStore = {
26
22
  findTokenById,
27
23
  findTokenByAddressInCurrency,
@@ -145,9 +145,14 @@ export function convertTRONTokens(type: "trc10" | "trc20") {
145
145
  | TRC20Token): TokenCurrency => {
146
146
  const parentCurrency = getCryptoCurrencyById("tron");
147
147
 
148
+ // For TRC20 tokens, use contract address as ID to match backend API format
149
+ // API expects lowercase addresses, so normalize here
150
+ // For TRC10 tokens, use numeric ID as before
151
+ const tokenId = type === "trc20" ? contractAddress.toLowerCase() : id;
152
+
148
153
  return {
149
154
  type: "TokenCurrency",
150
- id: `tron/${type}/${id}`,
155
+ id: `tron/${type}/${tokenId}`,
151
156
  contractAddress,
152
157
  parentCurrency,
153
158
  tokenType: type,
@@ -388,6 +393,7 @@ export function convertStellarTokens([
388
393
  ]: StellarToken): TokenCurrency {
389
394
  const parentCurrency = getCryptoCurrencyById("stellar");
390
395
 
396
+ // FIXME: to be discussed with CAL service as values are Uppercase IRL
391
397
  return {
392
398
  type: "TokenCurrency",
393
399
  id: `stellar/asset/${assetCode.toUpperCase()}:${assetIssuer.toUpperCase()}`,
@@ -521,7 +527,6 @@ export function addTokens(list: (TokenCurrency | undefined)[]): void {
521
527
  if (!delisted) tokensArray.push(token);
522
528
  tokensArrayWithDelisted.push(token);
523
529
  tokensById[id] = token;
524
-
525
530
  tokensByCurrencyAddress[parentCurrency.id + ":" + lowCaseContract] = token;
526
531
 
527
532
  if (!(parentCurrency.id in tokensByCryptoCurrency)) {
@@ -324,7 +324,7 @@ describe("Legacy Utils", () => {
324
324
  expect(tokensArray.length).toBe(1);
325
325
  });
326
326
 
327
- it("should handle ticker conflicts (first wins)", () => {
327
+ it("should handle tokens with same ticker", () => {
328
328
  const token1: TokenCurrency = {
329
329
  type: "TokenCurrency",
330
330
  id: "ethereum/erc20/test1",
@@ -349,9 +349,8 @@ describe("Legacy Utils", () => {
349
349
 
350
350
  addTokens([token1, token2]);
351
351
 
352
- // Both tokens should be added successfully
353
- expect(tokensById[token1.id]).toBe(token1);
354
- expect(tokensById[token2.id]).toBe(token2);
352
+ // Both tokens should be added since they have different IDs
353
+ expect(tokensArray.length).toBe(2);
355
354
  });
356
355
 
357
356
  it("should handle undefined tokens", () => {
@@ -573,7 +572,7 @@ describe("legacyCryptoAssetsStore", () => {
573
572
  __clearAllLists();
574
573
  });
575
574
 
576
- it("should find token by id", () => {
575
+ it("should find token by id", async () => {
577
576
  const erc20Token: ERC20Token = [
578
577
  "ethereum",
579
578
  "test_token",
@@ -588,12 +587,12 @@ describe("legacyCryptoAssetsStore", () => {
588
587
 
589
588
  addTokens([convertERC20(erc20Token)].filter(Boolean) as TokenCurrency[]);
590
589
 
591
- const token = legacyCryptoAssetsStore.findTokenById("ethereum/erc20/test_token");
590
+ const token = await legacyCryptoAssetsStore.findTokenById("ethereum/erc20/test_token");
592
591
 
593
592
  expect(token).toMatchObject({ ticker: "TEST" });
594
593
  });
595
594
 
596
- it("should find token by address in currency", () => {
595
+ it("should find token by address in currency", async () => {
597
596
  const erc20Token: ERC20Token = [
598
597
  "ethereum",
599
598
  "test_token",
@@ -608,13 +607,19 @@ describe("legacyCryptoAssetsStore", () => {
608
607
 
609
608
  addTokens([convertERC20(erc20Token)].filter(Boolean) as TokenCurrency[]);
610
609
 
611
- const token = legacyCryptoAssetsStore.findTokenByAddressInCurrency("0xabc123", "ethereum");
610
+ const token = await legacyCryptoAssetsStore.findTokenByAddressInCurrency(
611
+ "0xabc123",
612
+ "ethereum",
613
+ );
612
614
 
613
615
  expect(token).toMatchObject({ ticker: "TEST" });
614
616
  });
615
617
 
616
- it("should return undefined for non-existent token by address", () => {
617
- const token = legacyCryptoAssetsStore.findTokenByAddressInCurrency("0xnonexistent", "ethereum");
618
+ it("should return undefined for non-existent token by address", async () => {
619
+ const token = await legacyCryptoAssetsStore.findTokenByAddressInCurrency(
620
+ "0xnonexistent",
621
+ "ethereum",
622
+ );
618
623
 
619
624
  expect(token).toBeUndefined();
620
625
  });
@@ -1,14 +1,12 @@
1
1
  import { getCryptoCurrencyById } from "./currencies";
2
- import {
3
- addTokens,
4
- convertERC20,
5
- listTokens,
6
- __clearAllLists,
7
- findTokenById,
8
- listTokensForCryptoCurrency,
9
- } from "./tokens";
10
- import { createTokenHash } from "./legacy/legacy-utils";
2
+ import { listTokens, listTokensForCryptoCurrency } from "./tokens";
3
+ import { addTokens, __clearAllLists, createTokenHash, convertERC20 } from "./legacy/legacy-utils";
4
+ import { initializeLegacyTokens } from "./legacy/legacy-data";
11
5
  import { ERC20Token } from "./types";
6
+ import { legacyCryptoAssetsStore } from "./legacy/legacy-store";
7
+
8
+ // Initialize legacy tokens for tests
9
+ initializeLegacyTokens(addTokens);
12
10
 
13
11
  const initMainToken: ERC20Token[] = [
14
12
  [
@@ -119,7 +117,7 @@ describe("tokens", () => {
119
117
  ];
120
118
  addTokens(changeToken.map(convertERC20));
121
119
  expect(listTokens().length).toBe(1);
122
- findTokenById("kiba_inu");
120
+ legacyCryptoAssetsStore.findTokenById("kiba_inu");
123
121
  expect(listTokens({ withDelisted: true }).length).toBe(4);
124
122
 
125
123
  expect(listTokensForCryptoCurrency(ethereumCurrency).length).toBe(1);
package/src/tokens.ts CHANGED
@@ -4,78 +4,22 @@
4
4
 
5
5
  import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
6
6
  import {
7
- addTokens,
8
7
  listTokensLegacy,
9
8
  listTokensForCryptoCurrencyLegacy,
10
9
  type TokensListOptions,
11
- __clearAllLists,
12
- convertERC20,
13
- convertAlgorandASATokens,
14
- convertVechainToken,
15
- convertTRONTokens,
16
- convertMultiversXESDTTokens,
17
- convertCardanoNativeTokens,
18
- convertStellarTokens,
19
- convertJettonToken,
20
- convertSplTokens,
21
- convertSuiTokens,
22
- convertAptCoinTokens,
23
- convertAptFaTokens,
24
- convertHederaTokens,
25
10
  } from "./legacy/legacy-utils";
26
- import { tokensByCurrencyAddress, tokensById } from "./legacy/legacy-state";
27
- import { initializeLegacyTokens } from "./legacy/legacy-data";
28
- import { legacyCryptoAssetsStore } from "./legacy/legacy-store";
29
-
30
- export {
31
- addTokens,
32
- convertERC20,
33
- convertAlgorandASATokens,
34
- convertVechainToken,
35
- convertTRONTokens,
36
- convertMultiversXESDTTokens,
37
- convertCardanoNativeTokens,
38
- convertStellarTokens,
39
- convertJettonToken,
40
- convertSplTokens,
41
- convertSuiTokens,
42
- convertAptCoinTokens,
43
- convertAptFaTokens,
44
- convertHederaTokens,
45
- __clearAllLists,
46
- legacyCryptoAssetsStore,
47
- };
48
-
49
- initializeLegacyTokens(addTokens);
50
-
51
- /**
52
- * @deprecated Please do `await getCryptoAssetsStore().findTokenById(id)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
53
- */
54
- export function findTokenById(id: string): TokenCurrency | undefined {
55
- return tokensById[id];
56
- }
57
-
58
- /**
59
- * @deprecated Please do `await getCryptoAssetsStore().findTokenByAddress(address, currencyId)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
60
- */
61
- export function findTokenByAddressInCurrency(
62
- address: string,
63
- currencyId: string,
64
- ): TokenCurrency | undefined {
65
- return tokensByCurrencyAddress[currencyId + ":" + address.toLowerCase()];
66
- }
67
11
 
68
12
  /**
69
- * @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
70
- * Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
13
+ * @deprecated This function is deprecated since tokens will no longer be listable as we moved to DaDa API everywhere
14
+ * Use the new async token API instead
71
15
  */
72
16
  export function listTokens(options?: Partial<TokensListOptions>): TokenCurrency[] {
73
17
  return listTokensLegacy(options);
74
18
  }
75
19
 
76
20
  /**
77
- * @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
78
- * Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
21
+ * @deprecated This function is deprecated since tokens will no longer be listable as we moved to DaDa API everywhere
22
+ * Use the new async token API instead
79
23
  */
80
24
  export function listTokensForCryptoCurrency(
81
25
  currency: CryptoCurrency,
@@ -85,7 +29,7 @@ export function listTokensForCryptoCurrency(
85
29
  }
86
30
 
87
31
  /**
88
- * @deprecated Prefer using currency.tokenTypes directly.
32
+ *
89
33
  */
90
34
  export function listTokenTypesForCryptoCurrency(currency: CryptoCurrency): string[] {
91
35
  return currency.tokenTypes || [];