Skip to content

Commit ea92e32

Browse files
feature/LIVE-19995 Replace CoinFmk cryptoassets lib calls
1 parent 4e3e480 commit ea92e32

File tree

41 files changed

+773
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+773
-59
lines changed

.changeset/weak-mails-divide.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@ledgerhq/coin-tester-evm": minor
3+
"@ledgerhq/coin-bitcoin": minor
4+
"@ledgerhq/coin-evm": minor
5+
"ledger-live-desktop": minor
6+
"live-mobile": minor
7+
"@ledgerhq/live-common": minor
8+
"@ledgerhq/live-countervalues": minor
9+
"@ledgerhq/coin-framework": minor
10+
"@ledgerhq/live-wallet": minor
11+
---
12+
13+
Replace CoinFmk cryptoassets lib calls
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
2+
import { getCryptoAssetsStore } from "@ledgerhq/live-common/bridge/crypto-assets/index";
3+
4+
setCryptoAssetsStoreForCoinFramework(getCryptoAssetsStore());

apps/ledger-live-desktop/src/newArch/hooks/useStake.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { AccountRaw, TokenAccount } from "@ledgerhq/types-live";
88

99
import { fromAccountRaw } from "@ledgerhq/coin-framework/serialization/account";
1010
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
11+
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
12+
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
1113

1214
const raw: AccountRaw = {
1315
id: "js:2:ethereum:0x01:",
@@ -40,6 +42,9 @@ const rawTron: AccountRaw = {
4042
balance: "100000000000000",
4143
};
4244

45+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
46+
setCryptoAssetsStore({} as unknown as CryptoAssetsStore);
47+
4348
const mockEthereumAccount = fromAccountRaw(raw);
4449
const mockTronAccount = fromAccountRaw(rawTron);
4550

apps/ledger-live-desktop/src/renderer/init.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getEnv } from "@ledgerhq/live-env";
44
import { NotEnoughBalance } from "@ledgerhq/errors";
55
import { log } from "@ledgerhq/logs";
66
import "../config/configInit";
7+
import "../config/bridge-setup";
78
import { checkLibs } from "@ledgerhq/live-common/sanityChecks";
89
import { importPostOnboardingState } from "@ledgerhq/live-common/postOnboarding/actions";
910
import i18n from "i18next";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
2+
import { getCryptoAssetsStore } from "@ledgerhq/live-common/bridge/crypto-assets/index";
3+
4+
setCryptoAssetsStoreForCoinFramework(getCryptoAssetsStore());

apps/ledger-live-mobile/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { checkLibs } from "@ledgerhq/live-common/sanityChecks";
1414
import { useCountervaluesExport } from "@ledgerhq/live-countervalues-react";
1515
import { pairId } from "@ledgerhq/live-countervalues/helpers";
1616
import "./config/configInit";
17+
import "./config/bridge-setup";
1718
import isEqual from "lodash/isEqual";
1819
import { postOnboardingSelector } from "@ledgerhq/live-common/postOnboarding/reducer";
1920
import Config from "react-native-config";

apps/ledger-live-mobile/src/newArch/hooks/useStake/useStake.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { AccountRaw, TokenAccount } from "@ledgerhq/types-live";
99

1010
import { fromAccountRaw } from "@ledgerhq/coin-framework/serialization/account";
1111
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
12+
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
13+
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
1214

1315
const raw: AccountRaw = {
1416
id: "js:2:ethereum:0x01:",
@@ -41,6 +43,8 @@ const rawTron: AccountRaw = {
4143
balance: "100000000000000",
4244
};
4345

46+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
47+
setCryptoAssetsStore({} as unknown as CryptoAssetsStore);
4448
const mockEthereumAccount = fromAccountRaw(raw);
4549
const mockTronAccount = fromAccountRaw(rawTron);
4650

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"type": "TokenCurrency",
3+
"id": "bsc/bep20/binance-peg_dai_token",
4+
"ledgerSignature": "3044022032f0a880722af8c9e2196b5c0fc5273e2088f23692bdd2b35f6cf41c4001213f02205226e2023e409c73b031c790c64ae24db67c04b0aefd0d979b8c5002ca969b7b",
5+
"contractAddress": "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3",
6+
"parentCurrency": {
7+
"type": "CryptoCurrency",
8+
"id": "bsc",
9+
"coinType": 60,
10+
"name": "Binance Smart Chain",
11+
"managerAppName": "Ethereum",
12+
"ticker": "BNB",
13+
"scheme": "bsc",
14+
"color": "#F0B90A",
15+
"family": "evm",
16+
"ethereumLikeInfo": {
17+
"chainId": 56
18+
},
19+
"units": [
20+
{
21+
"name": "BNB",
22+
"code": "BNB",
23+
"magnitude": 18
24+
},
25+
{
26+
"name": "Gwei",
27+
"code": "Gwei",
28+
"magnitude": 9
29+
},
30+
{
31+
"name": "Mwei",
32+
"code": "Mwei",
33+
"magnitude": 6
34+
},
35+
{
36+
"name": "Kwei",
37+
"code": "Kwei",
38+
"magnitude": 3
39+
},
40+
{
41+
"name": "wei",
42+
"code": "wei",
43+
"magnitude": 0
44+
}
45+
],
46+
"explorerViews": [
47+
{
48+
"tx": "https://bscscan.com/tx/$hash",
49+
"address": "https://bscscan.com/address/$address",
50+
"token": "https://bscscan.com/token/$contractAddress?a=$address"
51+
}
52+
],
53+
"keywords": [
54+
"bsc",
55+
"bnb",
56+
"binance",
57+
"binance smart chain",
58+
"binance chain"
59+
],
60+
"explorerId": "bnb"
61+
},
62+
"tokenType": "bep20",
63+
"name": "Binance-Peg Dai Token",
64+
"ticker": "DAI",
65+
"delisted": false,
66+
"disableCountervalue": false,
67+
"units": [
68+
{
69+
"name": "Binance-Peg Dai Token",
70+
"code": "DAI",
71+
"magnitude": 18
72+
}
73+
]
74+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"type": "TokenCurrency",
3+
"id": "ethereum/erc20/0x_project",
4+
"ledgerSignature": "304402200ae8634c22762a8ba41d2acb1e068dcce947337c6dd984f13b820d396176952302203306a49d8a6c35b11a61088e1570b3928ca3a0db6bd36f577b5ef87628561ff7",
5+
"contractAddress": "0xE41d2489571d322189246DaFA5ebDe1F4699F498",
6+
"parentCurrency": {
7+
"type": "CryptoCurrency",
8+
"id": "ethereum",
9+
"coinType": 60,
10+
"name": "Ethereum",
11+
"managerAppName": "Ethereum",
12+
"ticker": "ETH",
13+
"scheme": "ethereum",
14+
"color": "#0ebdcd",
15+
"symbol": "Ξ",
16+
"family": "evm",
17+
"blockAvgTime": 15,
18+
"units": [
19+
{
20+
"name": "ether",
21+
"code": "ETH",
22+
"magnitude": 18
23+
},
24+
{
25+
"name": "Gwei",
26+
"code": "Gwei",
27+
"magnitude": 9
28+
},
29+
{
30+
"name": "Mwei",
31+
"code": "Mwei",
32+
"magnitude": 6
33+
},
34+
{
35+
"name": "Kwei",
36+
"code": "Kwei",
37+
"magnitude": 3
38+
},
39+
{
40+
"name": "wei",
41+
"code": "wei",
42+
"magnitude": 0
43+
}
44+
],
45+
"ethereumLikeInfo": {
46+
"chainId": 1
47+
},
48+
"explorerViews": [
49+
{
50+
"tx": "https://etherscan.io/tx/$hash",
51+
"address": "https://etherscan.io/address/$address",
52+
"token": "https://etherscan.io/token/$contractAddress?a=$address"
53+
}
54+
],
55+
"keywords": [
56+
"eth",
57+
"ethereum"
58+
],
59+
"explorerId": "eth"
60+
},
61+
"tokenType": "erc20",
62+
"name": "0x Project",
63+
"ticker": "ZRX",
64+
"delisted": false,
65+
"disableCountervalue": false,
66+
"units": [
67+
{
68+
"name": "0x Project",
69+
"code": "ZRX",
70+
"magnitude": 18
71+
}
72+
]
73+
}

libs/coin-framework/src/account/accountId.unit.test.ts renamed to libs/coin-framework/src/account/accountId.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import { getTokenById } from "@ledgerhq/cryptoassets/tokens";
21
import {
32
decodeTokenAccountId,
43
encodeTokenAccountId,
54
safeDecodeTokenId,
65
safeEncodeTokenId,
76
} from "./accountId";
7+
import tokenData from "./__fixtures__/binance-peg_dai_token.json";
8+
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
9+
import * as cryptoAssets from "../crypto-assets";
10+
import { CryptoAssetsStore } from "../crypto-assets/type";
11+
12+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13+
const TOKEN = tokenData as unknown as TokenCurrency;
814

915
describe("coin-framework", () => {
1016
describe("accountId", () => {
@@ -42,9 +48,8 @@ describe("coin-framework", () => {
4248
describe("encodeTokenAccountId", () => {
4349
it("should return an URI and splitting safe tokenAccountId (no + - _ % \\ /)", () => {
4450
const accountId = "js:2:0xkvn:";
45-
const token = getTokenById("bsc/bep20/binance-peg_dai_token");
4651

47-
const tokenAccountId = encodeTokenAccountId(accountId, token);
52+
const tokenAccountId = encodeTokenAccountId(accountId, TOKEN);
4853
expect(tokenAccountId).toBe(
4954
"js:2:0xkvn:+bsc%2Fbep20%2Fbinance~!dash!~peg~!underscore!~dai~!underscore!~token",
5055
);
@@ -59,13 +64,20 @@ describe("coin-framework", () => {
5964

6065
describe("decodeTokenAccountId", () => {
6166
it("should return an accountId and a token", () => {
67+
jest
68+
.spyOn(cryptoAssets, "getCryptoAssetsStore")
69+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
70+
.mockReturnValue({
71+
findTokenById: (_: unknown) => TOKEN,
72+
} as unknown as CryptoAssetsStore);
73+
6274
expect(
6375
decodeTokenAccountId(
6476
"js:2:0xkvn:+bsc%2Fbep20%2Fbinance~!dash!~peg~!underscore!~dai~!underscore!~token",
6577
),
6678
).toEqual({
6779
accountId: "js:2:0xkvn:",
68-
token: getTokenById("bsc/bep20/binance-peg_dai_token"),
80+
token: TOKEN,
6981
});
7082
});
7183
});

0 commit comments

Comments
 (0)