@ledgerhq/live-common 34.33.0-nightly.3 → 34.33.0-nightly.5
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.d.ts.map +1 -1
- package/lib/DataModel.js +8 -0
- package/lib/DataModel.js.map +1 -1
- package/lib/DataModel.test.js +46 -0
- package/lib/DataModel.test.js.map +1 -1
- package/lib/domain/getTokensWithFunds.d.ts +3 -0
- package/lib/domain/getTokensWithFunds.d.ts.map +1 -0
- package/lib/domain/getTokensWithFunds.js +36 -0
- package/lib/domain/getTokensWithFunds.js.map +1 -0
- package/lib/domain/getTokensWithFunds.test.d.ts +2 -0
- package/lib/domain/getTokensWithFunds.test.d.ts.map +1 -0
- package/lib/domain/getTokensWithFunds.test.js +71 -0
- package/lib/domain/getTokensWithFunds.test.js.map +1 -0
- package/lib/families/evm/config.d.ts.map +1 -1
- package/lib/families/evm/config.js +63 -0
- package/lib/families/evm/config.js.map +1 -1
- package/lib/families/solana/banner.test.js +1 -0
- package/lib/families/solana/banner.test.js.map +1 -1
- package/lib/wallet-api/constants.d.ts +1 -1
- package/lib-es/DataModel.d.ts.map +1 -1
- package/lib-es/DataModel.js +8 -0
- package/lib-es/DataModel.js.map +1 -1
- package/lib-es/DataModel.test.js +46 -0
- package/lib-es/DataModel.test.js.map +1 -1
- package/lib-es/domain/getTokensWithFunds.d.ts +3 -0
- package/lib-es/domain/getTokensWithFunds.d.ts.map +1 -0
- package/lib-es/domain/getTokensWithFunds.js +32 -0
- package/lib-es/domain/getTokensWithFunds.js.map +1 -0
- package/lib-es/domain/getTokensWithFunds.test.d.ts +2 -0
- package/lib-es/domain/getTokensWithFunds.test.d.ts.map +1 -0
- package/lib-es/domain/getTokensWithFunds.test.js +66 -0
- package/lib-es/domain/getTokensWithFunds.test.js.map +1 -0
- package/lib-es/families/evm/config.d.ts.map +1 -1
- package/lib-es/families/evm/config.js +63 -0
- package/lib-es/families/evm/config.js.map +1 -1
- package/lib-es/families/solana/banner.test.js +1 -0
- package/lib-es/families/solana/banner.test.js.map +1 -1
- package/lib-es/wallet-api/constants.d.ts +1 -1
- package/package.json +36 -36
- package/src/DataModel.test.ts +51 -0
- package/src/DataModel.ts +8 -2
- package/src/domain/getTokensWithFunds.test.ts +94 -0
- package/src/domain/getTokensWithFunds.ts +36 -0
- package/src/families/evm/config.ts +63 -0
- package/src/families/solana/banner.test.ts +1 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ledgerhq/live-common",
|
3
3
|
"description": "Common ground for the Ledger Live apps",
|
4
|
-
"version": "34.33.0-nightly.
|
4
|
+
"version": "34.33.0-nightly.5",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
@@ -162,41 +162,40 @@
|
|
162
162
|
"xstate": "4.38.3",
|
163
163
|
"yargs": "^17.0.0",
|
164
164
|
"zod": "^3.22.4",
|
165
|
-
"@ledgerhq/coin-algorand": "^0.9.5-nightly.
|
166
|
-
"@ledgerhq/coin-aptos": "^1.9.5-nightly.
|
167
|
-
"@ledgerhq/coin-bitcoin": "^0.15.5-nightly.
|
168
|
-
"@ledgerhq/coin-cardano": "^0.8.5-nightly.
|
169
|
-
"@ledgerhq/coin-casper": "^1.6.5-nightly.
|
170
|
-
"@ledgerhq/coin-celo": "^1.1.3-nightly.
|
171
|
-
"@ledgerhq/coin-cosmos": "^0.14.1-nightly.
|
172
|
-
"@ledgerhq/coin-evm": "^2.21.0-nightly.
|
173
|
-
"@ledgerhq/coin-filecoin": "^1.9.5-nightly.
|
174
|
-
"@ledgerhq/coin-framework": "^5.0.1-nightly.
|
175
|
-
"@ledgerhq/coin-hedera": "^1.6.5-nightly.
|
176
|
-
"@ledgerhq/coin-icon": "^0.10.5-nightly.
|
177
|
-
"@ledgerhq/coin-internet_computer": "^1.7.5-nightly.
|
178
|
-
"@ledgerhq/coin-mina": "^1.1.4-nightly.
|
179
|
-
"@ledgerhq/coin-multiversx": "^0.4.5-nightly.
|
180
|
-
"@ledgerhq/coin-
|
181
|
-
"@ledgerhq/coin-
|
182
|
-
"@ledgerhq/coin-
|
183
|
-
"@ledgerhq/coin-
|
184
|
-
"@ledgerhq/coin-
|
185
|
-
"@ledgerhq/coin-
|
186
|
-
"@ledgerhq/coin-
|
187
|
-
"@ledgerhq/coin-
|
188
|
-
"@ledgerhq/coin-
|
189
|
-
"@ledgerhq/coin-vechain": "^2.7.5-nightly.
|
190
|
-
"@ledgerhq/coin-xrp": "^6.0.1-nightly.
|
165
|
+
"@ledgerhq/coin-algorand": "^0.9.5-nightly.1",
|
166
|
+
"@ledgerhq/coin-aptos": "^1.9.5-nightly.1",
|
167
|
+
"@ledgerhq/coin-bitcoin": "^0.15.5-nightly.1",
|
168
|
+
"@ledgerhq/coin-cardano": "^0.8.5-nightly.1",
|
169
|
+
"@ledgerhq/coin-casper": "^1.6.5-nightly.1",
|
170
|
+
"@ledgerhq/coin-celo": "^1.1.3-nightly.1",
|
171
|
+
"@ledgerhq/coin-cosmos": "^0.14.1-nightly.1",
|
172
|
+
"@ledgerhq/coin-evm": "^2.21.0-nightly.1",
|
173
|
+
"@ledgerhq/coin-filecoin": "^1.9.5-nightly.1",
|
174
|
+
"@ledgerhq/coin-framework": "^5.0.1-nightly.1",
|
175
|
+
"@ledgerhq/coin-hedera": "^1.6.5-nightly.1",
|
176
|
+
"@ledgerhq/coin-icon": "^0.10.5-nightly.1",
|
177
|
+
"@ledgerhq/coin-internet_computer": "^1.7.5-nightly.1",
|
178
|
+
"@ledgerhq/coin-mina": "^1.1.4-nightly.1",
|
179
|
+
"@ledgerhq/coin-multiversx": "^0.4.5-nightly.1",
|
180
|
+
"@ledgerhq/coin-polkadot": "^6.0.1-nightly.2",
|
181
|
+
"@ledgerhq/coin-solana": "^0.22.0-nightly.3",
|
182
|
+
"@ledgerhq/coin-stacks": "^0.8.5-nightly.1",
|
183
|
+
"@ledgerhq/coin-stellar": "^5.0.1-nightly.1",
|
184
|
+
"@ledgerhq/coin-sui": "^0.3.2-nightly.1",
|
185
|
+
"@ledgerhq/coin-tezos": "^5.1.0-nightly.2",
|
186
|
+
"@ledgerhq/coin-ton": "^0.9.2-nightly.1",
|
187
|
+
"@ledgerhq/coin-tron": "^3.1.0-nightly.2",
|
188
|
+
"@ledgerhq/coin-near": "^0.11.5-nightly.1",
|
189
|
+
"@ledgerhq/coin-vechain": "^2.7.5-nightly.1",
|
190
|
+
"@ledgerhq/coin-xrp": "^6.0.1-nightly.1",
|
191
191
|
"@ledgerhq/crypto-icons-ui": "^1.14.0-nightly.0",
|
192
|
-
"@ledgerhq/cryptoassets": "^13.
|
192
|
+
"@ledgerhq/cryptoassets": "^13.17.0-nightly.0",
|
193
193
|
"@ledgerhq/device-core": "^0.4.24-nightly.0",
|
194
194
|
"@ledgerhq/devices": "8.4.5-nightly.0",
|
195
195
|
"@ledgerhq/errors": "^6.20.0-nightly.0",
|
196
196
|
"@ledgerhq/hw-app-algorand": "^6.31.0",
|
197
197
|
"@ledgerhq/hw-app-aptos": "^6.34.0",
|
198
198
|
"@ledgerhq/hw-app-btc": "^10.9.0",
|
199
|
-
"@ledgerhq/hw-app-celo": "^6.33.2-nightly.0",
|
200
199
|
"@ledgerhq/hw-app-cosmos": "^6.32.0",
|
201
200
|
"@ledgerhq/hw-app-eth": "^6.45.4-nightly.0",
|
202
201
|
"@ledgerhq/hw-app-exchange": "^0.10.0",
|
@@ -205,28 +204,29 @@
|
|
205
204
|
"@ledgerhq/hw-app-multiversx": "^6.24.0",
|
206
205
|
"@ledgerhq/hw-app-near": "^6.31.0",
|
207
206
|
"@ledgerhq/hw-app-polkadot": "^6.34.0",
|
207
|
+
"@ledgerhq/hw-app-celo": "^6.33.2-nightly.0",
|
208
208
|
"@ledgerhq/hw-app-solana": "^7.4.0",
|
209
209
|
"@ledgerhq/hw-app-str": "^7.2.0",
|
210
210
|
"@ledgerhq/hw-app-sui": "^1.1.0",
|
211
211
|
"@ledgerhq/hw-app-tezos": "^6.31.0",
|
212
212
|
"@ledgerhq/hw-app-trx": "^6.31.0",
|
213
|
-
"@ledgerhq/hw-app-vet": "^0.5.
|
214
|
-
"@ledgerhq/hw-app-xrp": "^6.31.0",
|
213
|
+
"@ledgerhq/hw-app-vet": "^0.5.3-nightly.0",
|
215
214
|
"@ledgerhq/hw-bolos": "6.32.1-nightly.0",
|
216
215
|
"@ledgerhq/hw-transport": "^6.31.5-nightly.0",
|
216
|
+
"@ledgerhq/hw-app-xrp": "^6.31.0",
|
217
217
|
"@ledgerhq/hw-transport-mocker": "^6.29.5-nightly.0",
|
218
218
|
"@ledgerhq/ledger-cal-service": "^0.4.2",
|
219
219
|
"@ledgerhq/ledger-trust-service": "0.3.2",
|
220
220
|
"@ledgerhq/live-config": "^3.1.0",
|
221
|
-
"@ledgerhq/live-countervalues": "^0.5.5-nightly.
|
222
|
-
"@ledgerhq/live-countervalues-react": "^0.2.34-nightly.
|
221
|
+
"@ledgerhq/live-countervalues": "^0.5.5-nightly.1",
|
222
|
+
"@ledgerhq/live-countervalues-react": "^0.2.34-nightly.1",
|
223
223
|
"@ledgerhq/live-env": "^2.8.0",
|
224
224
|
"@ledgerhq/live-hooks": "0.1.0",
|
225
225
|
"@ledgerhq/live-network": "^2.0.7",
|
226
|
-
"@ledgerhq/live-nft": "^0.8.5-nightly.
|
226
|
+
"@ledgerhq/live-nft": "^0.8.5-nightly.1",
|
227
227
|
"@ledgerhq/live-promise": "^0.1.0",
|
228
|
-
"@ledgerhq/live-signer-evm": "^0.4.0-nightly.
|
229
|
-
"@ledgerhq/live-wallet": "^0.10.8-nightly.
|
228
|
+
"@ledgerhq/live-signer-evm": "^0.4.0-nightly.1",
|
229
|
+
"@ledgerhq/live-wallet": "^0.10.8-nightly.1",
|
230
230
|
"@ledgerhq/logs": "^6.12.0",
|
231
231
|
"@ledgerhq/speculos-transport": "^0.2.0",
|
232
232
|
"@ledgerhq/wallet-api-acre-module": "^0.5.0-nightly.1",
|
package/src/DataModel.test.ts
CHANGED
@@ -6,6 +6,10 @@ import {
|
|
6
6
|
APTOS_HARDENED_DERIVATION_PATH,
|
7
7
|
APTOS_NON_HARDENED_DERIVATION_PATH,
|
8
8
|
} from "./families/aptos/consts";
|
9
|
+
import { getCurrencyConfiguration } from "./config";
|
10
|
+
jest.mock("./config", () => ({
|
11
|
+
getCurrencyConfiguration: jest.fn(),
|
12
|
+
}));
|
9
13
|
|
10
14
|
const opRetentionStategy =
|
11
15
|
(maxDaysOld: number, keepFirst: number) =>
|
@@ -40,6 +44,22 @@ const aptosAccount = {
|
|
40
44
|
version: 1,
|
41
45
|
};
|
42
46
|
|
47
|
+
const evmAccount = {
|
48
|
+
data: {
|
49
|
+
currencyId: "ethereum",
|
50
|
+
operations: [
|
51
|
+
{
|
52
|
+
id: "op_evm_001",
|
53
|
+
},
|
54
|
+
{
|
55
|
+
id: "op_evm_002",
|
56
|
+
nftOperations: [{ id: "op_evm_nft_001" }],
|
57
|
+
},
|
58
|
+
],
|
59
|
+
} as AccountRaw,
|
60
|
+
version: 1,
|
61
|
+
};
|
62
|
+
|
43
63
|
describe("DataModel", () => {
|
44
64
|
test("createDataModel for crypto.org account", () => {
|
45
65
|
const migratedCryptoOrgAccount = createDataModel(schema).decode(cryptoOrgAccount);
|
@@ -58,4 +78,35 @@ describe("DataModel", () => {
|
|
58
78
|
const migratedAptosAccountRaw = migratedAptosAccount.at(0) as Account;
|
59
79
|
expect(migratedAptosAccountRaw.freshAddressPath).toEqual(APTOS_HARDENED_DERIVATION_PATH);
|
60
80
|
});
|
81
|
+
|
82
|
+
describe("test for shownNfts true", () => {
|
83
|
+
beforeAll(() => {
|
84
|
+
(getCurrencyConfiguration as jest.Mock).mockReturnValue({
|
85
|
+
showNfts: true,
|
86
|
+
});
|
87
|
+
});
|
88
|
+
|
89
|
+
test("evm account", () => {
|
90
|
+
const data = createDataModel(schema).decode(evmAccount);
|
91
|
+
const account = data.at(0) as Account;
|
92
|
+
expect(account.operations).toEqual([
|
93
|
+
expect.objectContaining({ id: "op_evm_001" }),
|
94
|
+
expect.objectContaining({ id: "op_evm_002" }),
|
95
|
+
]);
|
96
|
+
});
|
97
|
+
});
|
98
|
+
|
99
|
+
describe("test for shownNfts false", () => {
|
100
|
+
beforeAll(() => {
|
101
|
+
(getCurrencyConfiguration as jest.Mock).mockReturnValue({
|
102
|
+
showNfts: false,
|
103
|
+
});
|
104
|
+
});
|
105
|
+
|
106
|
+
test("evm account", () => {
|
107
|
+
const data = createDataModel(schema).decode(evmAccount);
|
108
|
+
const account = data.at(0) as Account;
|
109
|
+
expect(account.operations).toEqual([expect.objectContaining({ id: "op_evm_001" })]);
|
110
|
+
});
|
111
|
+
});
|
61
112
|
});
|
package/src/DataModel.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import BigNumber from "bignumber.js";
|
2
2
|
import { APTOS_NON_HARDENED_DERIVATION_PATH_REGEX } from "./families/aptos/consts";
|
3
|
+
import { getCurrencyConfiguration } from "./config";
|
4
|
+
import { findCryptoCurrencyById } from "./currencies";
|
3
5
|
|
4
6
|
/**
|
5
7
|
* Interface for the end user.
|
@@ -37,11 +39,10 @@ export type DataSchema<R, M> = {
|
|
37
39
|
export function createDataModel<R, M>(schema: DataSchema<R, M>): DataModel<R, M> {
|
38
40
|
const { migrations, encode, decode } = schema;
|
39
41
|
const version = migrations.length;
|
40
|
-
|
41
42
|
function decodeModel(raw) {
|
42
43
|
let { data } = raw;
|
43
44
|
const { currencyId, freshAddressPath } = data;
|
44
|
-
|
45
|
+
const currency = findCryptoCurrencyById(currencyId);
|
45
46
|
// Set 'change' and 'address_index' levels to be hardened for Aptos derivation path
|
46
47
|
if (
|
47
48
|
currencyId === "aptos" &&
|
@@ -65,6 +66,11 @@ export function createDataModel<R, M>(schema: DataSchema<R, M>): DataModel<R, M>
|
|
65
66
|
sequence: 0,
|
66
67
|
};
|
67
68
|
}
|
69
|
+
if (currency && currency.family == "evm" && !getCurrencyConfiguration(currency).showNfts) {
|
70
|
+
if (Array.isArray(data.operations)) {
|
71
|
+
data.operations = data.operations.filter(tx => !("nftOperations" in tx));
|
72
|
+
}
|
73
|
+
}
|
68
74
|
|
69
75
|
for (let i = raw.version; i < version; i++) {
|
70
76
|
data = migrations[i](data);
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import { genAccount } from "@ledgerhq/coin-framework/lib/mocks/account";
|
2
|
+
import { getCryptoCurrencyById } from "@ledgerhq/live-common/currencies/index";
|
3
|
+
import { Account } from "@ledgerhq/types-live";
|
4
|
+
import BigNumber from "bignumber.js";
|
5
|
+
import { getTokensWithFunds } from "./getTokensWithFunds";
|
6
|
+
|
7
|
+
const ETH = getCryptoCurrencyById("ethereum");
|
8
|
+
|
9
|
+
const mockedAccounts: Account[] = [
|
10
|
+
genAccount("mocked-account-2", {
|
11
|
+
currency: ETH,
|
12
|
+
}),
|
13
|
+
];
|
14
|
+
|
15
|
+
describe("getTokensWithFunds", () => {
|
16
|
+
it("should return empty array if no accounts", () => {
|
17
|
+
const result = getTokensWithFunds([]);
|
18
|
+
expect(result).toEqual([]);
|
19
|
+
});
|
20
|
+
|
21
|
+
it("should return array with accounts with funds", () => {
|
22
|
+
const account = mockedAccounts[0];
|
23
|
+
const result = getTokensWithFunds(mockedAccounts);
|
24
|
+
|
25
|
+
expect(account.balance).toBeTruthy();
|
26
|
+
expect(account.balance instanceof BigNumber).toBe(true);
|
27
|
+
expect(account.balance.gt(0)).toBe(true);
|
28
|
+
|
29
|
+
expect(account.subAccounts).toBeDefined();
|
30
|
+
expect(account.subAccounts?.length).toBe(2);
|
31
|
+
|
32
|
+
const [zrxAccount, repAccount] = account.subAccounts || [];
|
33
|
+
|
34
|
+
expect(zrxAccount.balance).toBeTruthy();
|
35
|
+
expect(zrxAccount.balance instanceof BigNumber).toBe(true);
|
36
|
+
expect(zrxAccount.balance.gt(0)).toBe(true);
|
37
|
+
|
38
|
+
expect(repAccount.balance).toBeTruthy();
|
39
|
+
expect(repAccount.balance instanceof BigNumber).toBe(true);
|
40
|
+
expect(repAccount.balance.gt(0)).toBe(true);
|
41
|
+
|
42
|
+
expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
|
43
|
+
});
|
44
|
+
|
45
|
+
it("should return array with accounts with funds", () => {
|
46
|
+
const account = mockedAccounts[0];
|
47
|
+
|
48
|
+
expect(account.balance).toBeTruthy();
|
49
|
+
expect(account.balance instanceof BigNumber).toBe(true);
|
50
|
+
expect(account.balance.gt(0)).toBe(true);
|
51
|
+
|
52
|
+
expect(account.subAccounts).toBeDefined();
|
53
|
+
expect(account.subAccounts?.length).toBe(2);
|
54
|
+
|
55
|
+
const [zrxAccount, repAccount] = account.subAccounts || [];
|
56
|
+
|
57
|
+
const emptyRepAccount = { ...repAccount, balance: new BigNumber(0) };
|
58
|
+
|
59
|
+
expect(zrxAccount.balance).toBeTruthy();
|
60
|
+
expect(zrxAccount.balance instanceof BigNumber).toBe(true);
|
61
|
+
expect(zrxAccount.balance.gt(0)).toBe(true);
|
62
|
+
|
63
|
+
expect(emptyRepAccount.balance).toBeTruthy();
|
64
|
+
expect(emptyRepAccount.balance instanceof BigNumber).toBe(true);
|
65
|
+
expect(emptyRepAccount.balance.gt(0)).toBe(false);
|
66
|
+
|
67
|
+
const accounts = { ...account, subAccounts: [zrxAccount, emptyRepAccount] };
|
68
|
+
|
69
|
+
const result = getTokensWithFunds([accounts]);
|
70
|
+
|
71
|
+
expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum"]);
|
72
|
+
});
|
73
|
+
|
74
|
+
it("should return array with accounts with funds without duplication", () => {
|
75
|
+
const account = mockedAccounts[0];
|
76
|
+
|
77
|
+
expect(account.balance).toBeTruthy();
|
78
|
+
expect(account.balance instanceof BigNumber).toBe(true);
|
79
|
+
expect(account.balance.gt(0)).toBe(true);
|
80
|
+
|
81
|
+
expect(account.subAccounts).toBeDefined();
|
82
|
+
expect(account.subAccounts?.length).toBe(2);
|
83
|
+
|
84
|
+
const [zrxAccount, repAccount] = account.subAccounts || [];
|
85
|
+
|
86
|
+
const accounts = { ...account, subAccounts: [zrxAccount, repAccount, repAccount] };
|
87
|
+
|
88
|
+
expect(accounts.subAccounts.length).toBe(3);
|
89
|
+
|
90
|
+
const result = getTokensWithFunds([accounts]);
|
91
|
+
|
92
|
+
expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
|
93
|
+
});
|
94
|
+
});
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { getParentAccount } from "@ledgerhq/coin-framework/account/helpers";
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
3
|
+
|
4
|
+
export const getTokensWithFunds = (accounts: Account[]): string[] => {
|
5
|
+
if (!accounts?.length) return [];
|
6
|
+
|
7
|
+
const tokensMap = new Map<string, { ticker: string; networkName: string }>();
|
8
|
+
|
9
|
+
for (const account of accounts) {
|
10
|
+
const { balance, currency } = account || {};
|
11
|
+
if (!balance?.gt(0) || !currency) continue;
|
12
|
+
|
13
|
+
const parentAccount = getParentAccount(account, accounts);
|
14
|
+
const networkName = parentAccount?.currency?.name;
|
15
|
+
if (!networkName) continue;
|
16
|
+
|
17
|
+
const mainKey = `${currency.ticker}:${networkName}`;
|
18
|
+
tokensMap.set(mainKey, {
|
19
|
+
ticker: currency.ticker,
|
20
|
+
networkName,
|
21
|
+
});
|
22
|
+
|
23
|
+
account.subAccounts?.forEach(subAccount => {
|
24
|
+
const { balance, token } = subAccount || {};
|
25
|
+
if (!balance?.gt(0) || !token) return;
|
26
|
+
|
27
|
+
const subKey = `${token.ticker}:${networkName}`;
|
28
|
+
tokensMap.set(subKey, {
|
29
|
+
ticker: token.ticker,
|
30
|
+
networkName,
|
31
|
+
});
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
return Array.from(tokensMap.values(), ({ ticker, networkName }) => `${ticker} on ${networkName}`);
|
36
|
+
};
|