@ledgerhq/live-common 34.52.0-nightly.20251105023815 → 34.52.0-nightly.20251106023835
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/dada-client/__mocks__/assets.mock.d.ts +383 -0
- package/lib/dada-client/__mocks__/assets.mock.d.ts.map +1 -0
- package/lib/dada-client/__mocks__/assets.mock.js +260 -0
- package/lib/dada-client/__mocks__/assets.mock.js.map +1 -0
- package/lib/dada-client/hooks/useAssetsData.d.ts +2 -1
- package/lib/dada-client/hooks/useAssetsData.d.ts.map +1 -1
- package/lib/dada-client/hooks/useAssetsData.js +2 -2
- package/lib/dada-client/hooks/useAssetsData.js.map +1 -1
- package/lib/dada-client/hooks/useLazyLedgerCurrency.d.ts +13 -0
- package/lib/dada-client/hooks/useLazyLedgerCurrency.d.ts.map +1 -0
- package/lib/dada-client/hooks/useLazyLedgerCurrency.js +34 -0
- package/lib/dada-client/hooks/useLazyLedgerCurrency.js.map +1 -0
- package/lib/dada-client/index.d.ts +2 -0
- package/lib/dada-client/index.d.ts.map +1 -0
- package/lib/dada-client/index.js +18 -0
- package/lib/dada-client/index.js.map +1 -0
- package/lib/dada-client/state-manager/api.js +1 -1
- package/lib/dada-client/state-manager/api.js.map +1 -1
- package/lib/dada-client/utils/currencySelection.d.ts +10 -0
- package/lib/dada-client/utils/currencySelection.d.ts.map +1 -0
- package/lib/dada-client/utils/currencySelection.js +34 -0
- package/lib/dada-client/utils/currencySelection.js.map +1 -0
- package/lib/families/near/config.d.ts.map +1 -1
- package/lib/families/near/config.js +1 -0
- package/lib/families/near/config.js.map +1 -1
- package/lib/market/hooks/useMarketDataProvider.d.ts.map +1 -1
- package/lib/market/hooks/useMarketDataProvider.js +4 -7
- package/lib/market/hooks/useMarketDataProvider.js.map +1 -1
- package/lib/market/utils/currencyFormatter.d.ts +2 -3
- package/lib/market/utils/currencyFormatter.d.ts.map +1 -1
- package/lib/market/utils/currencyFormatter.js +3 -6
- package/lib/market/utils/currencyFormatter.js.map +1 -1
- package/lib/market/utils/types.d.ts +0 -2
- package/lib/market/utils/types.d.ts.map +1 -1
- package/lib/market/utils/types.js.map +1 -1
- package/lib-es/dada-client/__mocks__/assets.mock.d.ts +383 -0
- package/lib-es/dada-client/__mocks__/assets.mock.d.ts.map +1 -0
- package/lib-es/dada-client/__mocks__/assets.mock.js +257 -0
- package/lib-es/dada-client/__mocks__/assets.mock.js.map +1 -0
- package/lib-es/dada-client/hooks/useAssetsData.d.ts +2 -1
- package/lib-es/dada-client/hooks/useAssetsData.d.ts.map +1 -1
- package/lib-es/dada-client/hooks/useAssetsData.js +2 -2
- package/lib-es/dada-client/hooks/useAssetsData.js.map +1 -1
- package/lib-es/dada-client/hooks/useLazyLedgerCurrency.d.ts +13 -0
- package/lib-es/dada-client/hooks/useLazyLedgerCurrency.d.ts.map +1 -0
- package/lib-es/dada-client/hooks/useLazyLedgerCurrency.js +27 -0
- package/lib-es/dada-client/hooks/useLazyLedgerCurrency.js.map +1 -0
- package/lib-es/dada-client/index.d.ts +2 -0
- package/lib-es/dada-client/index.d.ts.map +1 -0
- package/lib-es/dada-client/index.js +2 -0
- package/lib-es/dada-client/index.js.map +1 -0
- package/lib-es/dada-client/state-manager/api.js +1 -1
- package/lib-es/dada-client/state-manager/api.js.map +1 -1
- package/lib-es/dada-client/utils/currencySelection.d.ts +10 -0
- package/lib-es/dada-client/utils/currencySelection.d.ts.map +1 -0
- package/lib-es/dada-client/utils/currencySelection.js +30 -0
- package/lib-es/dada-client/utils/currencySelection.js.map +1 -0
- package/lib-es/families/near/config.d.ts.map +1 -1
- package/lib-es/families/near/config.js +1 -0
- package/lib-es/families/near/config.js.map +1 -1
- package/lib-es/market/hooks/useMarketDataProvider.d.ts.map +1 -1
- package/lib-es/market/hooks/useMarketDataProvider.js +2 -5
- package/lib-es/market/hooks/useMarketDataProvider.js.map +1 -1
- package/lib-es/market/utils/currencyFormatter.d.ts +2 -3
- package/lib-es/market/utils/currencyFormatter.d.ts.map +1 -1
- package/lib-es/market/utils/currencyFormatter.js +3 -6
- package/lib-es/market/utils/currencyFormatter.js.map +1 -1
- package/lib-es/market/utils/types.d.ts +0 -2
- package/lib-es/market/utils/types.d.ts.map +1 -1
- package/lib-es/market/utils/types.js.map +1 -1
- package/package.json +72 -72
- package/src/dada-client/README.md +38 -0
- package/src/dada-client/__mocks__/assets.mock.ts +264 -0
- package/src/dada-client/hooks/__tests__/useLazyLedgerCurrency.test.ts +155 -0
- package/src/dada-client/hooks/useAssetsData.ts +14 -9
- package/src/dada-client/hooks/useLazyLedgerCurrency.ts +46 -0
- package/src/dada-client/index.ts +1 -0
- package/src/dada-client/state-manager/api.ts +1 -1
- package/src/dada-client/utils/__test__/currencySelection.test.ts +16 -0
- package/src/dada-client/utils/currencySelection.ts +33 -0
- package/src/families/near/config.ts +1 -0
- package/src/market/hooks/useMarketDataProvider.ts +2 -6
- package/src/market/utils/currencyFormatter.ts +3 -17
- package/src/market/utils/types.ts +0 -2
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
const mockInjectiveCurrency = {
|
|
2
|
+
type: "CryptoCurrency" as const,
|
|
3
|
+
id: "injective",
|
|
4
|
+
name: "Injective",
|
|
5
|
+
ticker: "INJ",
|
|
6
|
+
units: [
|
|
7
|
+
{
|
|
8
|
+
name: "INJ",
|
|
9
|
+
code: "INJ",
|
|
10
|
+
magnitude: 18,
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
family: "injective",
|
|
14
|
+
managerAppName: "Injective",
|
|
15
|
+
coinType: 60,
|
|
16
|
+
scheme: "injective",
|
|
17
|
+
color: "#00F2FE",
|
|
18
|
+
explorerViews: [],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const mockEthereumCurrency = {
|
|
22
|
+
type: "CryptoCurrency" as const,
|
|
23
|
+
id: "ethereum",
|
|
24
|
+
name: "Ethereum",
|
|
25
|
+
ticker: "ETH",
|
|
26
|
+
units: [],
|
|
27
|
+
family: "ethereum",
|
|
28
|
+
managerAppName: "Ethereum",
|
|
29
|
+
coinType: 60,
|
|
30
|
+
scheme: "ethereum",
|
|
31
|
+
color: "#627EEA",
|
|
32
|
+
explorerViews: [],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const mockBscCurrency = {
|
|
36
|
+
type: "CryptoCurrency" as const,
|
|
37
|
+
id: "bsc",
|
|
38
|
+
name: "Binance Smart Chain",
|
|
39
|
+
ticker: "BNB",
|
|
40
|
+
units: [],
|
|
41
|
+
family: "evm",
|
|
42
|
+
managerAppName: "Binance Smart Chain",
|
|
43
|
+
coinType: 60,
|
|
44
|
+
scheme: "bsc",
|
|
45
|
+
color: "#F3BA2F",
|
|
46
|
+
explorerViews: [],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const mockAssetsData = {
|
|
50
|
+
cryptoAssets: {
|
|
51
|
+
"urn:crypto:meta-currency:injective_protocol": {
|
|
52
|
+
id: "urn:crypto:meta-currency:injective_protocol",
|
|
53
|
+
ticker: "INJ",
|
|
54
|
+
name: "Injective",
|
|
55
|
+
assetsIds: {
|
|
56
|
+
injective: "injective",
|
|
57
|
+
ethereum: "ethereum/erc20/injective_token",
|
|
58
|
+
bsc: "bsc/bep20/injective_protocol",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
networks: {
|
|
63
|
+
bsc: { id: "bsc", name: "Binance Smart Chain" },
|
|
64
|
+
ethereum: { id: "ethereum", name: "Ethereum" },
|
|
65
|
+
injective: { id: "injective", name: "Injective" },
|
|
66
|
+
},
|
|
67
|
+
cryptoOrTokenCurrencies: {
|
|
68
|
+
"bsc/bep20/injective_protocol": {
|
|
69
|
+
type: "TokenCurrency" as const,
|
|
70
|
+
id: "bsc/bep20/injective_protocol",
|
|
71
|
+
name: "Injective Protocol",
|
|
72
|
+
ticker: "INJ",
|
|
73
|
+
contractAddress: "0x0",
|
|
74
|
+
parentCurrency: mockBscCurrency,
|
|
75
|
+
tokenType: "bep20",
|
|
76
|
+
units: [
|
|
77
|
+
{
|
|
78
|
+
name: "INJ",
|
|
79
|
+
code: "INJ",
|
|
80
|
+
magnitude: 18,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
"ethereum/erc20/injective_token": {
|
|
85
|
+
type: "TokenCurrency" as const,
|
|
86
|
+
id: "ethereum/erc20/injective_token",
|
|
87
|
+
name: "Injective Token",
|
|
88
|
+
ticker: "INJ",
|
|
89
|
+
contractAddress: "0x0",
|
|
90
|
+
parentCurrency: mockEthereumCurrency,
|
|
91
|
+
tokenType: "erc20",
|
|
92
|
+
units: [
|
|
93
|
+
{
|
|
94
|
+
name: "INJ",
|
|
95
|
+
code: "INJ",
|
|
96
|
+
magnitude: 18,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
injective: mockInjectiveCurrency,
|
|
101
|
+
},
|
|
102
|
+
interestRates: {},
|
|
103
|
+
markets: {},
|
|
104
|
+
currenciesOrder: {
|
|
105
|
+
key: "marketCap",
|
|
106
|
+
order: "desc",
|
|
107
|
+
currenciesIds: ["injective", "ethereum/erc20/injective_token", "bsc/bep20/injective_protocol"],
|
|
108
|
+
metaCurrencyIds: ["urn:crypto:meta-currency:injective_protocol"],
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const mockAssetsDataWithPagination = {
|
|
113
|
+
...mockAssetsData,
|
|
114
|
+
pagination: {
|
|
115
|
+
nextCursor: "cursor-1",
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Bitcoin mock data
|
|
120
|
+
const mockBitcoinCurrency = {
|
|
121
|
+
type: "CryptoCurrency" as const,
|
|
122
|
+
id: "bitcoin",
|
|
123
|
+
name: "Bitcoin",
|
|
124
|
+
ticker: "BTC",
|
|
125
|
+
units: [
|
|
126
|
+
{
|
|
127
|
+
name: "BTC",
|
|
128
|
+
code: "BTC",
|
|
129
|
+
magnitude: 8,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
family: "bitcoin",
|
|
133
|
+
managerAppName: "Bitcoin",
|
|
134
|
+
coinType: 0,
|
|
135
|
+
scheme: "bitcoin",
|
|
136
|
+
color: "#FF9900",
|
|
137
|
+
explorerViews: [],
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const mockBitcoinAssetsData = {
|
|
141
|
+
cryptoAssets: {
|
|
142
|
+
bitcoin: {
|
|
143
|
+
id: "bitcoin",
|
|
144
|
+
ticker: "BTC",
|
|
145
|
+
name: "Bitcoin",
|
|
146
|
+
assetsIds: {
|
|
147
|
+
bitcoin: "bitcoin",
|
|
148
|
+
ethereum: "ethereum/erc20/wrapped_bitcoin",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
networks: {
|
|
153
|
+
bitcoin: { id: "bitcoin", name: "Bitcoin" },
|
|
154
|
+
ethereum: { id: "ethereum", name: "Ethereum" },
|
|
155
|
+
},
|
|
156
|
+
cryptoOrTokenCurrencies: {
|
|
157
|
+
bitcoin: mockBitcoinCurrency,
|
|
158
|
+
"ethereum/erc20/wrapped_bitcoin": {
|
|
159
|
+
type: "TokenCurrency" as const,
|
|
160
|
+
id: "ethereum/erc20/wrapped_bitcoin",
|
|
161
|
+
name: "Wrapped Bitcoin",
|
|
162
|
+
ticker: "WBTC",
|
|
163
|
+
contractAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
164
|
+
parentCurrency: mockEthereumCurrency,
|
|
165
|
+
tokenType: "erc20",
|
|
166
|
+
units: [
|
|
167
|
+
{
|
|
168
|
+
name: "WBTC",
|
|
169
|
+
code: "WBTC",
|
|
170
|
+
magnitude: 8,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
interestRates: {},
|
|
176
|
+
markets: {},
|
|
177
|
+
currenciesOrder: {
|
|
178
|
+
key: "marketCap",
|
|
179
|
+
order: "desc",
|
|
180
|
+
currenciesIds: ["bitcoin", "ethereum/erc20/wrapped_bitcoin"],
|
|
181
|
+
metaCurrencyIds: ["bitcoin"],
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// USDC mock data
|
|
186
|
+
const mockPolygonCurrency = {
|
|
187
|
+
type: "CryptoCurrency" as const,
|
|
188
|
+
id: "polygon",
|
|
189
|
+
name: "Polygon",
|
|
190
|
+
ticker: "MATIC",
|
|
191
|
+
units: [
|
|
192
|
+
{
|
|
193
|
+
name: "MATIC",
|
|
194
|
+
code: "MATIC",
|
|
195
|
+
magnitude: 18,
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
family: "evm",
|
|
199
|
+
managerAppName: "Polygon",
|
|
200
|
+
coinType: 60,
|
|
201
|
+
scheme: "polygon",
|
|
202
|
+
color: "#8247E5",
|
|
203
|
+
explorerViews: [],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export const mockUsdcAssetsData = {
|
|
207
|
+
cryptoAssets: {
|
|
208
|
+
usdc: {
|
|
209
|
+
id: "usdc",
|
|
210
|
+
ticker: "USDC",
|
|
211
|
+
name: "USD Coin",
|
|
212
|
+
assetsIds: {
|
|
213
|
+
ethereum: "ethereum/erc20/usd_coin",
|
|
214
|
+
polygon: "polygon/erc20/usd_coin",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
networks: {
|
|
219
|
+
ethereum: { id: "ethereum", name: "Ethereum" },
|
|
220
|
+
polygon: { id: "polygon", name: "Polygon" },
|
|
221
|
+
},
|
|
222
|
+
cryptoOrTokenCurrencies: {
|
|
223
|
+
"ethereum/erc20/usd_coin": {
|
|
224
|
+
type: "TokenCurrency" as const,
|
|
225
|
+
id: "ethereum/erc20/usd_coin",
|
|
226
|
+
name: "USD Coin",
|
|
227
|
+
ticker: "USDC",
|
|
228
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
229
|
+
parentCurrency: mockEthereumCurrency,
|
|
230
|
+
tokenType: "erc20",
|
|
231
|
+
units: [
|
|
232
|
+
{
|
|
233
|
+
name: "USDC",
|
|
234
|
+
code: "USDC",
|
|
235
|
+
magnitude: 6,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
"polygon/erc20/usd_coin": {
|
|
240
|
+
type: "TokenCurrency" as const,
|
|
241
|
+
id: "polygon/erc20/usd_coin",
|
|
242
|
+
name: "USD Coin (Polygon)",
|
|
243
|
+
ticker: "USDC",
|
|
244
|
+
contractAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
245
|
+
parentCurrency: mockPolygonCurrency,
|
|
246
|
+
tokenType: "erc20",
|
|
247
|
+
units: [
|
|
248
|
+
{
|
|
249
|
+
name: "USDC",
|
|
250
|
+
code: "USDC",
|
|
251
|
+
magnitude: 6,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
interestRates: {},
|
|
257
|
+
markets: {},
|
|
258
|
+
currenciesOrder: {
|
|
259
|
+
key: "marketCap",
|
|
260
|
+
order: "desc",
|
|
261
|
+
currenciesIds: ["ethereum/erc20/usd_coin", "polygon/erc20/usd_coin"],
|
|
262
|
+
metaCurrencyIds: ["usdc"],
|
|
263
|
+
},
|
|
264
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { renderHook } from "@testing-library/react";
|
|
6
|
+
import { useLazyLedgerCurrency } from "../useLazyLedgerCurrency";
|
|
7
|
+
import { assetsDataApi } from "../../state-manager/api";
|
|
8
|
+
import useEnv from "../../../hooks/useEnv";
|
|
9
|
+
import {
|
|
10
|
+
mockAssetsData,
|
|
11
|
+
mockBitcoinAssetsData,
|
|
12
|
+
mockUsdcAssetsData,
|
|
13
|
+
} from "../../__mocks__/assets.mock";
|
|
14
|
+
|
|
15
|
+
jest.mock("../../../hooks/useEnv");
|
|
16
|
+
|
|
17
|
+
jest.mock("../../state-manager/api", () => ({
|
|
18
|
+
assetsDataApi: {
|
|
19
|
+
useLazyGetAssetDataQuery: jest.fn(),
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const mockUseEnv = jest.mocked(useEnv);
|
|
24
|
+
const mockUseLazyGetAssetDataQuery = jest.mocked(assetsDataApi.useLazyGetAssetDataQuery);
|
|
25
|
+
|
|
26
|
+
describe("useLazyLedgerCurrency", () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
mockUseEnv.mockReturnValue(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should return undefined when currency is null", async () => {
|
|
33
|
+
const mockTrigger = jest.fn();
|
|
34
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
35
|
+
|
|
36
|
+
const { result } = renderHook(() =>
|
|
37
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, null),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
41
|
+
|
|
42
|
+
expect(ledgerCurrency).toBeUndefined();
|
|
43
|
+
expect(mockTrigger).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should return undefined when currency has no ledgerIds", async () => {
|
|
47
|
+
const mockTrigger = jest.fn();
|
|
48
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
49
|
+
|
|
50
|
+
const currency = { id: "test" };
|
|
51
|
+
const { result } = renderHook(() =>
|
|
52
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, currency),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
56
|
+
|
|
57
|
+
expect(ledgerCurrency).toBeUndefined();
|
|
58
|
+
expect(mockTrigger).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should return undefined when currency has empty ledgerIds", async () => {
|
|
62
|
+
const mockTrigger = jest.fn();
|
|
63
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
64
|
+
|
|
65
|
+
const currency = { id: "test", ledgerIds: [] };
|
|
66
|
+
const { result } = renderHook(() =>
|
|
67
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, currency),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
71
|
+
|
|
72
|
+
expect(ledgerCurrency).toBeUndefined();
|
|
73
|
+
expect(mockTrigger).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should return the CryptoCurrency when available (Injective example)", async () => {
|
|
77
|
+
const mockResult = mockAssetsData;
|
|
78
|
+
|
|
79
|
+
const mockTrigger = jest.fn().mockReturnValue({
|
|
80
|
+
unwrap: jest.fn().mockResolvedValue(mockResult),
|
|
81
|
+
});
|
|
82
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
83
|
+
|
|
84
|
+
const currency = {
|
|
85
|
+
id: "injective",
|
|
86
|
+
ledgerIds: ["injective", "bsc/bep20/injective_protocol", "ethereum/erc20/injective_token"],
|
|
87
|
+
};
|
|
88
|
+
const { result } = renderHook(() =>
|
|
89
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, currency),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
93
|
+
|
|
94
|
+
expect(ledgerCurrency).toMatchObject({
|
|
95
|
+
type: "CryptoCurrency",
|
|
96
|
+
id: "injective",
|
|
97
|
+
name: "Injective",
|
|
98
|
+
ticker: "INJ",
|
|
99
|
+
});
|
|
100
|
+
expect(mockTrigger).toHaveBeenCalledWith(
|
|
101
|
+
{
|
|
102
|
+
currencyIds: [
|
|
103
|
+
"injective",
|
|
104
|
+
"bsc/bep20/injective_protocol",
|
|
105
|
+
"ethereum/erc20/injective_token",
|
|
106
|
+
],
|
|
107
|
+
product: "lld",
|
|
108
|
+
version: "1.0.0",
|
|
109
|
+
isStaging: false,
|
|
110
|
+
includeTestNetworks: false,
|
|
111
|
+
},
|
|
112
|
+
true,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should return the currency matching metaCurrencyId when available", async () => {
|
|
117
|
+
const mockTrigger = jest.fn().mockReturnValue({
|
|
118
|
+
unwrap: jest.fn().mockResolvedValue(mockBitcoinAssetsData),
|
|
119
|
+
});
|
|
120
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
121
|
+
|
|
122
|
+
const currency = { id: "bitcoin", ledgerIds: ["bitcoin"] };
|
|
123
|
+
const { result } = renderHook(() =>
|
|
124
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, currency),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
128
|
+
|
|
129
|
+
// Should return the currency matching metaCurrencyId (bitcoin)
|
|
130
|
+
expect(ledgerCurrency).toMatchObject({
|
|
131
|
+
type: "CryptoCurrency",
|
|
132
|
+
id: "bitcoin",
|
|
133
|
+
name: "Bitcoin",
|
|
134
|
+
ticker: "BTC",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should return first TokenCurrency when no CryptoCurrency available", async () => {
|
|
139
|
+
const mockTrigger = jest.fn().mockReturnValue({
|
|
140
|
+
unwrap: jest.fn().mockResolvedValue(mockUsdcAssetsData),
|
|
141
|
+
});
|
|
142
|
+
mockUseLazyGetAssetDataQuery.mockReturnValue([mockTrigger, {} as any, {} as any]);
|
|
143
|
+
|
|
144
|
+
const currency = { id: "usdc", ledgerIds: ["ethereum/erc20/usd_coin"] };
|
|
145
|
+
const { result } = renderHook(() =>
|
|
146
|
+
useLazyLedgerCurrency({ product: "lld", version: "1.0.0" }, currency),
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const ledgerCurrency = await result.current.getLedgerCurrency();
|
|
150
|
+
|
|
151
|
+
// Should return the first TokenCurrency since no CryptoCurrency exists
|
|
152
|
+
expect(ledgerCurrency?.type).toBe("TokenCurrency");
|
|
153
|
+
expect(ledgerCurrency?.ticker).toBe("USDC");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -26,8 +26,10 @@ export function useAssetsData({
|
|
|
26
26
|
version,
|
|
27
27
|
isStaging,
|
|
28
28
|
includeTestNetworks,
|
|
29
|
+
skip,
|
|
29
30
|
}: GetAssetsDataParams & {
|
|
30
31
|
areCurrenciesFiltered?: boolean;
|
|
32
|
+
skip?: boolean;
|
|
31
33
|
}) {
|
|
32
34
|
const {
|
|
33
35
|
data,
|
|
@@ -39,15 +41,18 @@ export function useAssetsData({
|
|
|
39
41
|
isFetching,
|
|
40
42
|
isError,
|
|
41
43
|
isFetchingNextPage,
|
|
42
|
-
} = useGetAssetsDataInfiniteQuery(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
} = useGetAssetsDataInfiniteQuery(
|
|
45
|
+
{
|
|
46
|
+
search,
|
|
47
|
+
useCase,
|
|
48
|
+
currencyIds: areCurrenciesFiltered ? currencyIds : undefined,
|
|
49
|
+
product,
|
|
50
|
+
version,
|
|
51
|
+
isStaging,
|
|
52
|
+
includeTestNetworks,
|
|
53
|
+
},
|
|
54
|
+
{ skip },
|
|
55
|
+
);
|
|
51
56
|
|
|
52
57
|
const joinedPages = useMemo(() => {
|
|
53
58
|
return data?.pages.reduce<AssetsDataWithPagination>((acc, page) => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { assetsDataApi } from "../state-manager/api";
|
|
3
|
+
import useEnv from "../../hooks/useEnv";
|
|
4
|
+
import { selectCurrency } from "../utils/currencySelection";
|
|
5
|
+
|
|
6
|
+
interface Currency {
|
|
7
|
+
id?: string;
|
|
8
|
+
ledgerIds?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface LazyLedgerCurrencyOptions {
|
|
12
|
+
product: "lld" | "llm";
|
|
13
|
+
version: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useLazyLedgerCurrency(
|
|
17
|
+
options: LazyLedgerCurrencyOptions,
|
|
18
|
+
currency?: Currency | null,
|
|
19
|
+
) {
|
|
20
|
+
const devMode = useEnv("MANAGER_DEV_MODE");
|
|
21
|
+
|
|
22
|
+
const [triggerGetAssetData] = assetsDataApi.useLazyGetAssetDataQuery();
|
|
23
|
+
|
|
24
|
+
const getLedgerCurrency = useCallback(async () => {
|
|
25
|
+
if (!currency?.ledgerIds || currency.ledgerIds.length === 0) return undefined;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const result = await triggerGetAssetData(
|
|
29
|
+
{
|
|
30
|
+
currencyIds: currency.ledgerIds,
|
|
31
|
+
product: options.product,
|
|
32
|
+
version: options.version,
|
|
33
|
+
isStaging: false,
|
|
34
|
+
includeTestNetworks: devMode,
|
|
35
|
+
},
|
|
36
|
+
true, // prefer cached data
|
|
37
|
+
).unwrap();
|
|
38
|
+
|
|
39
|
+
return selectCurrency(result);
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}, [currency, devMode, options, triggerGetAssetData]);
|
|
44
|
+
|
|
45
|
+
return { getLedgerCurrency };
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./entities";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { selectCurrency } from "../currencySelection";
|
|
2
|
+
import { mockAssetsDataWithPagination } from "../../__mocks__/assets.mock";
|
|
3
|
+
|
|
4
|
+
describe("currencySelection", () => {
|
|
5
|
+
it("should return the correct currency", () => {
|
|
6
|
+
const result = selectCurrency(mockAssetsDataWithPagination);
|
|
7
|
+
expect(result).toBeDefined();
|
|
8
|
+
|
|
9
|
+
expect(result).toMatchObject({
|
|
10
|
+
type: "CryptoCurrency",
|
|
11
|
+
id: "injective",
|
|
12
|
+
name: "Injective",
|
|
13
|
+
ticker: "INJ",
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { AssetsDataWithPagination } from "../state-manager/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Selects the best currency from asset data result based on priority:
|
|
6
|
+
* 1. Main currency (matching metaCurrencyId)
|
|
7
|
+
* 2. CryptoCurrency type
|
|
8
|
+
* 3. First available network
|
|
9
|
+
*/
|
|
10
|
+
export function selectCurrency(
|
|
11
|
+
result: AssetsDataWithPagination,
|
|
12
|
+
): CryptoOrTokenCurrency | undefined {
|
|
13
|
+
const metaCurrencyId = result.currenciesOrder.metaCurrencyIds?.[0];
|
|
14
|
+
if (!metaCurrencyId) return undefined;
|
|
15
|
+
|
|
16
|
+
const assetsIds = result.cryptoAssets[metaCurrencyId]?.assetsIds;
|
|
17
|
+
if (!assetsIds) return undefined;
|
|
18
|
+
|
|
19
|
+
let fallback: CryptoOrTokenCurrency | undefined;
|
|
20
|
+
let crypto: CryptoOrTokenCurrency | undefined;
|
|
21
|
+
|
|
22
|
+
for (const id of Object.values(assetsIds)) {
|
|
23
|
+
const currency = result.cryptoOrTokenCurrencies[id];
|
|
24
|
+
if (!currency) continue;
|
|
25
|
+
|
|
26
|
+
if (currency.id === metaCurrencyId) return currency; // highest priority
|
|
27
|
+
if (!fallback) fallback = currency;
|
|
28
|
+
if (!crypto && currency.type === "CryptoCurrency") crypto = currency;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// CryptoCurrency > fallback (should be a TokenCurrency)
|
|
32
|
+
return crypto ?? fallback;
|
|
33
|
+
}
|
|
@@ -9,6 +9,7 @@ const nearConfig: CurrencyLiveConfigDefinition = {
|
|
|
9
9
|
API_NEAR_PRIVATE_NODE: "https://near.coin.ledger.com/node",
|
|
10
10
|
API_NEAR_PUBLIC_NODE: "https://rpc.mainnet.near.org",
|
|
11
11
|
API_NEAR_INDEXER: "https://near.coin.ledger.com/indexer",
|
|
12
|
+
API_NEARBLOCKS_INDEXER: "https://near-indexer.coin.ledger.com",
|
|
12
13
|
},
|
|
13
14
|
},
|
|
14
15
|
},
|
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
getSupportedCoinsList,
|
|
7
7
|
supportedCounterCurrencies,
|
|
8
8
|
} from "../api";
|
|
9
|
-
import { listCryptoCurrencies } from "@ledgerhq/cryptoassets/currencies";
|
|
10
|
-
import { listTokens } from "@ledgerhq/cryptoassets/tokens";
|
|
11
9
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
12
10
|
|
|
13
11
|
import { useMemo } from "react";
|
|
@@ -25,8 +23,6 @@ import {
|
|
|
25
23
|
Order,
|
|
26
24
|
} from "../utils/types";
|
|
27
25
|
|
|
28
|
-
const cryptoCurrenciesList = [...listCryptoCurrencies(), ...listTokens()];
|
|
29
|
-
|
|
30
26
|
export function useMarketDataProvider() {
|
|
31
27
|
const supportedCurrenciesInLIve = listSupportedCurrencies();
|
|
32
28
|
|
|
@@ -65,7 +61,7 @@ export const useCurrencyData = ({ id, counterCurrency }: MarketCurrencyRequestPa
|
|
|
65
61
|
queryFn: () => fetchCurrency({ id, counterCurrency }),
|
|
66
62
|
refetchInterval: REFETCH_TIME_ONE_MINUTE * BASIC_REFETCH,
|
|
67
63
|
staleTime: REFETCH_TIME_ONE_MINUTE * BASIC_REFETCH,
|
|
68
|
-
select: data => format(data
|
|
64
|
+
select: data => format(data),
|
|
69
65
|
});
|
|
70
66
|
|
|
71
67
|
export const useSupportedCounterCurrencies = () =>
|
|
@@ -104,7 +100,7 @@ export function useMarketData(props: MarketListRequestParams): MarketListRequest
|
|
|
104
100
|
],
|
|
105
101
|
queryFn: () => fetchList({ ...props, page, search }),
|
|
106
102
|
select: (data: MarketItemResponse[]) => ({
|
|
107
|
-
formattedData: currencyFormatter(data
|
|
103
|
+
formattedData: currencyFormatter(data),
|
|
108
104
|
page,
|
|
109
105
|
}),
|
|
110
106
|
refetchOnMount: false,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
1
|
import {
|
|
3
2
|
MarketCurrencyData,
|
|
4
3
|
KeysPriceChange,
|
|
@@ -45,29 +44,16 @@ function sparklineAsSvgData(points: number[]): SparklineSvgData {
|
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export function currencyFormatter(
|
|
49
|
-
data: MarketItemResponse
|
|
50
|
-
cryptoCurrenciesList: (CryptoCurrency | TokenCurrency)[],
|
|
51
|
-
): MarketCurrencyData[] {
|
|
52
|
-
return data.map((currency: MarketItemResponse) => format(currency, cryptoCurrenciesList));
|
|
47
|
+
export function currencyFormatter(data: MarketItemResponse[]): MarketCurrencyData[] {
|
|
48
|
+
return data.map((currency: MarketItemResponse) => format(currency));
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
export const format = (
|
|
56
|
-
currency: MarketItemResponse,
|
|
57
|
-
cryptoCurrenciesList?: (CryptoCurrency | TokenCurrency)[],
|
|
58
|
-
): MarketCurrencyData => {
|
|
59
|
-
const ledgerIdsSet = new Set(currency.ledgerIds.map(id => id.toLowerCase()));
|
|
60
|
-
|
|
61
|
-
const internalCurrency = cryptoCurrenciesList?.find(({ id }) =>
|
|
62
|
-
ledgerIdsSet.has(id.toLowerCase()),
|
|
63
|
-
);
|
|
64
|
-
|
|
51
|
+
export const format = (currency: MarketItemResponse): MarketCurrencyData => {
|
|
65
52
|
return {
|
|
66
53
|
id: currency.id,
|
|
67
54
|
ledgerIds: currency.ledgerIds,
|
|
68
55
|
name: currency.name,
|
|
69
56
|
image: currency.image,
|
|
70
|
-
internalCurrency,
|
|
71
57
|
marketcap: currency.marketCap,
|
|
72
58
|
marketcapRank: currency.marketCapRank,
|
|
73
59
|
totalVolume: currency.totalVolume,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
1
|
import { RefetchOptions, QueryObserverResult } from "@tanstack/react-query";
|
|
3
2
|
import { PortfolioRange } from "@ledgerhq/types-live";
|
|
4
3
|
|
|
@@ -85,7 +84,6 @@ export type MarketCurrencyData = {
|
|
|
85
84
|
ledgerIds: string[];
|
|
86
85
|
name: string;
|
|
87
86
|
image?: string;
|
|
88
|
-
internalCurrency?: CryptoOrTokenCurrency;
|
|
89
87
|
marketcap?: number;
|
|
90
88
|
marketcapRank: number;
|
|
91
89
|
totalVolume: number;
|