@ledgerhq/live-common 25.0.0-next.1 → 25.0.0-next.4
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/__tests__/accounts/importAccounts.js +1 -1
- package/lib/__tests__/test-helpers/setup.js +1 -1
- package/lib/account/helpers.d.ts +5 -1
- package/lib/account/helpers.d.ts.map +1 -1
- package/lib/account/helpers.js +28 -1
- package/lib/account/helpers.js.map +1 -1
- package/lib/apps/filtering.test.js +1 -1
- package/lib/countervalues/api/api.d.ts.map +1 -1
- package/lib/countervalues/api/api.js +25 -13
- package/lib/countervalues/api/api.js.map +1 -1
- package/lib/countervalues/logic.d.ts.map +1 -1
- package/lib/countervalues/logic.integration.test.d.ts +1 -1
- package/lib/countervalues/logic.integration.test.d.ts.map +1 -1
- package/lib/countervalues/logic.integration.test.js +78 -2
- package/lib/countervalues/logic.integration.test.js.map +1 -1
- package/lib/countervalues/logic.js +5 -1
- package/lib/countervalues/logic.js.map +1 -1
- package/lib/countervalues/modules/index.d.ts +1 -1
- package/lib/countervalues/modules/index.d.ts.map +1 -1
- package/lib/countervalues/modules/index.js +3 -1
- package/lib/countervalues/modules/index.js.map +1 -1
- package/lib/countervalues/types.d.ts +1 -0
- package/lib/countervalues/types.d.ts.map +1 -1
- package/lib/currencies/helpers.d.ts +9 -0
- package/lib/currencies/helpers.d.ts.map +1 -0
- package/lib/currencies/helpers.js +78 -0
- package/lib/currencies/helpers.js.map +1 -0
- package/lib/currencies/helpers.test.d.ts +2 -0
- package/lib/currencies/helpers.test.d.ts.map +1 -0
- package/lib/currencies/helpers.test.js +20 -0
- package/lib/currencies/helpers.test.js.map +1 -0
- package/lib/currencies/index.d.ts +1 -0
- package/lib/currencies/index.d.ts.map +1 -1
- package/lib/currencies/index.js +1 -0
- package/lib/currencies/index.js.map +1 -1
- package/lib/currencies/react.d.ts +4 -0
- package/lib/currencies/react.d.ts.map +1 -0
- package/lib/currencies/react.js +16 -0
- package/lib/currencies/react.js.map +1 -0
- package/lib/families/hedera/api/mirror.js +1 -1
- package/lib/families/hedera/api/mirror.js.map +1 -1
- package/lib/families/hedera/api/network.d.ts.map +1 -1
- package/lib/families/hedera/api/network.js +3 -1
- package/lib/families/hedera/api/network.js.map +1 -1
- package/lib/families/hedera/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/families/hedera/deviceTransactionConfig.js +7 -0
- package/lib/families/hedera/deviceTransactionConfig.js.map +1 -1
- package/lib/families/hedera/js-synchronisation.d.ts.map +1 -1
- package/lib/families/hedera/js-synchronisation.js +10 -7
- package/lib/families/hedera/js-synchronisation.js.map +1 -1
- package/lib/families/hedera/specs.d.ts.map +1 -1
- package/lib/families/hedera/specs.js +23 -0
- package/lib/families/hedera/specs.js.map +1 -1
- package/lib/families/hedera/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/hedera/speculos-deviceActions.js +5 -1
- package/lib/families/hedera/speculos-deviceActions.js.map +1 -1
- package/lib/families/hedera/transaction.d.ts.map +1 -1
- package/lib/families/hedera/transaction.js +2 -2
- package/lib/families/hedera/transaction.js.map +1 -1
- package/lib/families/hedera/types.d.ts +2 -5
- package/lib/families/hedera/types.d.ts.map +1 -1
- package/lib/families/hedera/types.js +0 -4
- package/lib/families/hedera/types.js.map +1 -1
- package/lib/families/hedera/utils.d.ts.map +1 -1
- package/lib/featureFlags/types.d.ts +1 -1
- package/lib/featureFlags/types.d.ts.map +1 -1
- package/lib/platform/PlatformAppProvider/api/api.mock.js +11 -11
- package/lib/platform/PlatformAppProvider/api/api.mock.js.map +1 -1
- package/lib/platform/PlatformAppProvider/helpers.d.ts +0 -7
- package/lib/platform/PlatformAppProvider/helpers.d.ts.map +1 -1
- package/lib/platform/PlatformAppProvider/helpers.js +1 -29
- package/lib/platform/PlatformAppProvider/helpers.js.map +1 -1
- package/lib/platform/converters.d.ts +4 -4
- package/lib/platform/converters.d.ts.map +1 -1
- package/lib/platform/converters.js +40 -2
- package/lib/platform/converters.js.map +1 -1
- package/lib/platform/filters.d.ts +18 -0
- package/lib/platform/filters.d.ts.map +1 -0
- package/lib/platform/filters.js +63 -0
- package/lib/platform/filters.js.map +1 -0
- package/lib/platform/helpers.d.ts +7 -0
- package/lib/platform/helpers.d.ts.map +1 -0
- package/lib/platform/helpers.js +22 -0
- package/lib/platform/helpers.js.map +1 -0
- package/lib/platform/logic.d.ts +1 -5
- package/lib/platform/logic.d.ts.map +1 -1
- package/lib/platform/logic.js +1 -18
- package/lib/platform/logic.js.map +1 -1
- package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
- package/lib/platform/react.d.ts +11 -0
- package/lib/platform/react.d.ts.map +1 -0
- package/lib/platform/react.js +61 -0
- package/lib/platform/react.js.map +1 -0
- package/lib/platform/types.d.ts +8 -2
- package/lib/platform/types.d.ts.map +1 -1
- package/lib/platform/types.js +15 -0
- package/lib/platform/types.js.map +1 -1
- package/lib/platform/version.test.js +1 -1
- package/lib/walletconnect/walletconnect.test.js +0 -2
- package/lib/walletconnect/walletconnect.test.js.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/accounts/importAccounts.ts +1 -1
- package/src/__tests__/test-helpers/setup.ts +1 -1
- package/src/account/helpers.ts +51 -0
- package/src/apps/filtering.test.ts +1 -1
- package/src/countervalues/api/api.ts +25 -8
- package/src/countervalues/logic.integration.test.ts +71 -1
- package/src/countervalues/logic.ts +3 -1
- package/src/countervalues/modules/index.ts +3 -1
- package/src/countervalues/types.ts +2 -0
- package/src/currencies/helpers.test.ts +21 -0
- package/src/currencies/helpers.ts +69 -0
- package/src/currencies/index.ts +1 -0
- package/src/currencies/react.ts +16 -0
- package/src/families/hedera/api/mirror.ts +1 -1
- package/src/families/hedera/api/network.ts +1 -0
- package/src/families/hedera/deviceTransactionConfig.ts +8 -0
- package/src/families/hedera/js-synchronisation.ts +5 -3
- package/src/families/hedera/specs.ts +56 -5
- package/src/families/hedera/speculos-deviceActions.ts +1 -0
- package/src/families/hedera/transaction.ts +2 -0
- package/src/families/hedera/types.ts +2 -8
- package/src/families/hedera/utils.ts +1 -1
- package/src/featureFlags/types.ts +1 -0
- package/src/platform/PlatformAppProvider/api/api.mock.ts +11 -11
- package/src/platform/PlatformAppProvider/helpers.ts +0 -48
- package/src/platform/converters.ts +60 -6
- package/src/platform/filters.ts +102 -0
- package/src/platform/helpers.ts +33 -0
- package/src/platform/logic.ts +1 -20
- package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
- package/src/platform/react.ts +93 -0
- package/src/platform/types.ts +23 -1
- package/src/platform/version.test.ts +1 -1
- package/src/walletconnect/walletconnect.test.ts +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccountLike } from "../types";
|
|
2
|
+
import { ListPlatformAccount, ListPlatformCurrency, PlatformCurrency, AppManifest } from "./types";
|
|
3
|
+
export declare function usePlatformUrl(manifest: AppManifest, params: {
|
|
4
|
+
background: string;
|
|
5
|
+
text: string;
|
|
6
|
+
loadDate?: Date;
|
|
7
|
+
}, inputs: Record<string, string>): URL;
|
|
8
|
+
export declare function useListPlatformAccounts(accounts: AccountLike[]): ListPlatformAccount;
|
|
9
|
+
export declare function usePlatformCurrencies(includeTokens?: boolean): PlatformCurrency[];
|
|
10
|
+
export declare function useListPlatformCurrencies(): ListPlatformCurrency;
|
|
11
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/platform/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAYvC,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CAAE,EAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,GAAG,CAwBL;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,EAAE,GACtB,mBAAmB,CAerB;AAED,wBAAgB,qBAAqB,CACnC,aAAa,UAAQ,GACpB,gBAAgB,EAAE,CAQpB;AAED,wBAAgB,yBAAyB,IAAI,oBAAoB,CAShE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.useListPlatformCurrencies = exports.usePlatformCurrencies = exports.useListPlatformAccounts = exports.usePlatformUrl = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var converters_1 = require("./converters");
|
|
6
|
+
var filters_1 = require("./filters");
|
|
7
|
+
var helpers_1 = require("./helpers");
|
|
8
|
+
var account_1 = require("../account");
|
|
9
|
+
var currencies_1 = require("../currencies");
|
|
10
|
+
function usePlatformUrl(manifest, params, inputs) {
|
|
11
|
+
return (0, react_1.useMemo)(function () {
|
|
12
|
+
var url = new URL(manifest.url.toString());
|
|
13
|
+
if (inputs) {
|
|
14
|
+
for (var key in inputs) {
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(inputs, key)) {
|
|
16
|
+
url.searchParams.set(key, inputs[key]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
url.searchParams.set("backgroundColor", params.background);
|
|
21
|
+
url.searchParams.set("textColor", params.text);
|
|
22
|
+
if (params.loadDate) {
|
|
23
|
+
url.searchParams.set("loadDate", params.loadDate.valueOf().toString());
|
|
24
|
+
}
|
|
25
|
+
if (manifest.params) {
|
|
26
|
+
url.searchParams.set("params", JSON.stringify(manifest.params));
|
|
27
|
+
}
|
|
28
|
+
return url;
|
|
29
|
+
}, [manifest.url, manifest.params, params, inputs]);
|
|
30
|
+
}
|
|
31
|
+
exports.usePlatformUrl = usePlatformUrl;
|
|
32
|
+
function useListPlatformAccounts(accounts) {
|
|
33
|
+
var platformAccounts = (0, react_1.useMemo)(function () {
|
|
34
|
+
return accounts.map(function (account) {
|
|
35
|
+
var parentAccount = (0, account_1.getParentAccount)(account, accounts);
|
|
36
|
+
return (0, converters_1.accountToPlatformAccount)(account, parentAccount);
|
|
37
|
+
});
|
|
38
|
+
}, [accounts]);
|
|
39
|
+
return (0, react_1.useCallback)(function (filters) {
|
|
40
|
+
if (filters === void 0) { filters = {}; }
|
|
41
|
+
return (0, filters_1.filterPlatformAccounts)(platformAccounts, filters);
|
|
42
|
+
}, [platformAccounts]);
|
|
43
|
+
}
|
|
44
|
+
exports.useListPlatformAccounts = useListPlatformAccounts;
|
|
45
|
+
function usePlatformCurrencies(includeTokens) {
|
|
46
|
+
if (includeTokens === void 0) { includeTokens = false; }
|
|
47
|
+
return (0, react_1.useMemo)(function () {
|
|
48
|
+
return (0, currencies_1.listCurrencies)(includeTokens)
|
|
49
|
+
.filter(helpers_1.isPlatformSupportedCurrency)
|
|
50
|
+
.map(converters_1.currencyToPlatformCurrency);
|
|
51
|
+
}, [includeTokens]);
|
|
52
|
+
}
|
|
53
|
+
exports.usePlatformCurrencies = usePlatformCurrencies;
|
|
54
|
+
function useListPlatformCurrencies() {
|
|
55
|
+
var currencies = usePlatformCurrencies(true);
|
|
56
|
+
return (0, react_1.useCallback)(function (filters) {
|
|
57
|
+
return (0, filters_1.filterPlatformCurrencies)(currencies, filters || {});
|
|
58
|
+
}, [currencies]);
|
|
59
|
+
}
|
|
60
|
+
exports.useListPlatformCurrencies = useListPlatformCurrencies;
|
|
61
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/platform/react.ts"],"names":[],"mappings":";;;AAAA,+BAA6C;AAE7C,2CAGsB;AACtB,qCAKmB;AACnB,qCAAwD;AAOxD,sCAA8C;AAC9C,4CAA+C;AAE/C,SAAgB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IAAM,aAAa,GAAG,IAAA,0BAAgB,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAE1D,OAAO,IAAA,qCAAwB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,IAAA,mBAAW,EAChB,UAAC,OAA4B;QAA5B,wBAAA,EAAA,YAA4B;QAC3B,OAAO,IAAA,gCAAsB,EAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;AACJ,CAAC;AAjBD,0DAiBC;AAED,SAAgB,qBAAqB,CACnC,aAAqB;IAArB,8BAAA,EAAA,qBAAqB;IAErB,OAAO,IAAA,eAAO,EACZ;QACE,OAAA,IAAA,2BAAc,EAAC,aAAa,CAAC;aAC1B,MAAM,CAAC,qCAA2B,CAAC;aACnC,GAAG,CAAC,uCAA0B,CAAC;IAFlC,CAEkC,EACpC,CAAC,aAAa,CAAC,CAChB,CAAC;AACJ,CAAC;AAVD,sDAUC;AAED,SAAgB,yBAAyB;IACvC,IAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,IAAA,mBAAW,EAChB,UAAC,OAAyB;QACxB,OAAO,IAAA,kCAAwB,EAAC,UAAU,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAC;AACJ,CAAC;AATD,8DASC"}
|
package/lib/platform/types.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { SignedOperation, CryptoCurrency, TokenCurrency } from "../types";
|
|
2
|
+
import { AccountFilters, CurrencyFilters } from "./filters";
|
|
3
|
+
import { Account as PlatformAccount, Currency as PlatformCurrency } from "@ledgerhq/live-app-sdk";
|
|
4
|
+
export type { Account as PlatformAccount, Currency as PlatformCurrency, Unit as PlatformUnit, Transaction as PlatformTransaction, CryptoCurrency as PlatformCryptoCurrency, ERC20TokenCurrency as PlatformERC20TokenCurrency, } from "@ledgerhq/live-app-sdk";
|
|
5
|
+
export { CurrencyType as PlatformCurrencyType, TokenStandard as PlatformTokenStandard, } from "@ledgerhq/live-app-sdk";
|
|
3
6
|
export declare type TranslatableString = {
|
|
4
7
|
en: string;
|
|
5
8
|
[locale: string]: string;
|
|
@@ -36,4 +39,7 @@ export declare type PlatformApi = {
|
|
|
36
39
|
fetchManifest: () => Promise<AppManifest[]>;
|
|
37
40
|
};
|
|
38
41
|
export declare type PlatformSignedTransaction = SignedOperation;
|
|
42
|
+
export declare type ListPlatformAccount = (filters?: AccountFilters) => PlatformAccount[];
|
|
43
|
+
export declare type ListPlatformCurrency = (filters?: CurrencyFilters) => PlatformCurrency[];
|
|
44
|
+
export declare type PlatformSupportedCurrency = CryptoCurrency | TokenCurrency;
|
|
39
45
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EACL,OAAO,IAAI,eAAe,EAC1B,QAAQ,IAAI,gBAAgB,EAC7B,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,OAAO,IAAI,eAAe,EAC1B,QAAQ,IAAI,gBAAgB,EAC5B,IAAI,IAAI,YAAY,EACpB,WAAW,IAAI,mBAAmB,EAClC,cAAc,IAAI,sBAAsB,EACxC,kBAAkB,IAAI,0BAA0B,GACjD,MAAM,wBA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CAAC;CAC7C,CAAC;AAEF,oBAAY,yBAAyB,GAAG,eAAe,CAAC;AAExD,oBAAY,mBAAmB,GAAG,CAChC,OAAO,CAAC,EAAE,cAAc,KACrB,eAAe,EAAE,CAAC;AAEvB,oBAAY,oBAAoB,GAAG,CACjC,OAAO,CAAC,EAAE,eAAe,KACtB,gBAAgB,EAAE,CAAC;AAExB,oBAAY,yBAAyB,GAAG,cAAc,GAAG,aAAa,CAAC"}
|
package/lib/platform/types.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
2
13
|
exports.__esModule = true;
|
|
14
|
+
exports.PlatformTokenStandard = exports.PlatformCurrencyType = void 0;
|
|
15
|
+
var live_app_sdk_1 = require("@ledgerhq/live-app-sdk");
|
|
16
|
+
__createBinding(exports, live_app_sdk_1, "CurrencyType", "PlatformCurrencyType");
|
|
17
|
+
__createBinding(exports, live_app_sdk_1, "TokenStandard", "PlatformTokenStandard");
|
|
3
18
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAgBA,uDAGgC;AAF9B,iFAAoC;AACpC,mFAAsC"}
|
|
@@ -3,6 +3,6 @@ exports.__esModule = true;
|
|
|
3
3
|
require("../__tests__/test-helpers/setup");
|
|
4
4
|
var version_1 = require("./version");
|
|
5
5
|
test("version is defined by setup", function () {
|
|
6
|
-
expect((0, version_1.getPlatformVersion)()).toBe("0.0
|
|
6
|
+
expect((0, version_1.getPlatformVersion)()).toBe("1.0.0");
|
|
7
7
|
});
|
|
8
8
|
//# sourceMappingURL=version.test.js.map
|
|
@@ -47,8 +47,6 @@ var index_1 = require("./index");
|
|
|
47
47
|
var currencies_1 = require("../currencies");
|
|
48
48
|
var account_1 = require("../account");
|
|
49
49
|
var env_1 = require("../env");
|
|
50
|
-
var version_1 = require("../platform/version");
|
|
51
|
-
(0, version_1.setPlatformVersion)("0.0.1");
|
|
52
50
|
describe("walletconnect", function () {
|
|
53
51
|
var account = {
|
|
54
52
|
type: "Account",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletconnect.test.js","sourceRoot":"","sources":["../../src/walletconnect/walletconnect.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AACzC,6CAAyC;AACzC,gDAA0B;AAC1B,oCAA6C;AAC7C,iCAA2C;AAE3C,4CAA8E;AAE9E,sCAA+C;AAC/C,8BAAgC;
|
|
1
|
+
{"version":3,"file":"walletconnect.test.js","sourceRoot":"","sources":["../../src/walletconnect/walletconnect.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AACzC,6CAAyC;AACzC,gDAA0B;AAC1B,oCAA6C;AAC7C,iCAA2C;AAE3C,4CAA8E;AAE9E,sCAA+C;AAC/C,8BAAgC;AAEhC,QAAQ,CAAC,eAAe,EAAE;IACxB,IAAM,OAAO,GAAY;QACvB,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,2DAA2D;QAC/D,cAAc,EAAE,EAAE;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|
|
6
6
|
"description": "Common ground for the Ledger Live apps",
|
|
7
|
-
"version": "25.0.0-next.
|
|
7
|
+
"version": "25.0.0-next.4",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"@ledgerhq/hw-transport-mocker": "^6.27.2-next.0",
|
|
126
126
|
"@ledgerhq/hw-transport-node-speculos": "^6.27.2-next.0",
|
|
127
127
|
"@ledgerhq/json-bignumber": "^1.1.0",
|
|
128
|
-
"@ledgerhq/live-app-sdk": "^0.
|
|
128
|
+
"@ledgerhq/live-app-sdk": "^0.7.0",
|
|
129
129
|
"@ledgerhq/logs": "^6.10.0",
|
|
130
130
|
"@polkadot/types": "8.5.1",
|
|
131
131
|
"@polkadot/types-known": "8.5.1",
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
"leb128": "^0.0.5",
|
|
185
185
|
"lodash": "^4.17.21",
|
|
186
186
|
"lru-cache": "5.1.1",
|
|
187
|
+
"minimatch": "^5.1.0",
|
|
187
188
|
"numeral": "^2.0.6",
|
|
188
189
|
"object-hash": "^2.2.0",
|
|
189
190
|
"performance-now": "^2.1.0",
|
|
@@ -7,7 +7,7 @@ import { setSupportedCurrencies } from "../../currencies";
|
|
|
7
7
|
import { AccountRaw } from "../../types";
|
|
8
8
|
import { setPlatformVersion } from "../../platform/version";
|
|
9
9
|
|
|
10
|
-
setPlatformVersion("0.0
|
|
10
|
+
setPlatformVersion("1.0.0");
|
|
11
11
|
|
|
12
12
|
setSupportedCurrencies(["ethereum"]);
|
|
13
13
|
describe("importAccountsMakeItems", () => {
|
package/src/account/helpers.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
SubAccount,
|
|
9
9
|
TokenCurrency,
|
|
10
10
|
TokenAccount,
|
|
11
|
+
ChildAccount,
|
|
11
12
|
} from "../types";
|
|
12
13
|
import { getEnv } from "../env";
|
|
13
14
|
import { encodeTokenAccountId } from "./accountId";
|
|
@@ -26,6 +27,7 @@ export const getMainAccount = (
|
|
|
26
27
|
invariant(mainAccount, "an account is expected");
|
|
27
28
|
return mainAccount as Account;
|
|
28
29
|
};
|
|
30
|
+
|
|
29
31
|
export const getAccountCurrency = (account: AccountLike) => {
|
|
30
32
|
switch (account.type) {
|
|
31
33
|
case "Account":
|
|
@@ -39,6 +41,7 @@ export const getAccountCurrency = (account: AccountLike) => {
|
|
|
39
41
|
throw new Error("invalid account.type=" + (account as AccountLike).type);
|
|
40
42
|
}
|
|
41
43
|
};
|
|
44
|
+
|
|
42
45
|
export const getAccountUnit = (account: AccountLike): Unit => {
|
|
43
46
|
switch (account.type) {
|
|
44
47
|
case "Account":
|
|
@@ -54,6 +57,7 @@ export const getAccountUnit = (account: AccountLike): Unit => {
|
|
|
54
57
|
throw new Error("invalid account.type=" + (account as AccountLike).type);
|
|
55
58
|
}
|
|
56
59
|
};
|
|
60
|
+
|
|
57
61
|
export const getAccountName = (account: AccountLike): string => {
|
|
58
62
|
switch (account.type) {
|
|
59
63
|
case "Account":
|
|
@@ -67,6 +71,7 @@ export const getAccountName = (account: AccountLike): string => {
|
|
|
67
71
|
throw new Error("invalid account.type=" + (account as AccountLike).type);
|
|
68
72
|
}
|
|
69
73
|
};
|
|
74
|
+
|
|
70
75
|
export const getAccountSpendableBalance = (account: AccountLike): BigNumber => {
|
|
71
76
|
switch (account.type) {
|
|
72
77
|
case "Account":
|
|
@@ -80,6 +85,7 @@ export const getAccountSpendableBalance = (account: AccountLike): BigNumber => {
|
|
|
80
85
|
throw new Error("invalid account.type=" + (account as AccountLike).type);
|
|
81
86
|
}
|
|
82
87
|
};
|
|
88
|
+
|
|
83
89
|
export const isAccountEmpty = (a: AccountLike): boolean => {
|
|
84
90
|
if (
|
|
85
91
|
a.type === "Account" &&
|
|
@@ -95,6 +101,7 @@ export const isAccountEmpty = (a: AccountLike): boolean => {
|
|
|
95
101
|
a.type === "Account" && a.subAccounts && a.subAccounts.length;
|
|
96
102
|
return a.operationsCount === 0 && a.balance.isZero() && !hasSubAccounts;
|
|
97
103
|
};
|
|
104
|
+
|
|
98
105
|
export function areAllOperationsLoaded(account: AccountLike): boolean {
|
|
99
106
|
if (account.operationsCount !== account.operations.length) {
|
|
100
107
|
return false;
|
|
@@ -106,8 +113,10 @@ export function areAllOperationsLoaded(account: AccountLike): boolean {
|
|
|
106
113
|
|
|
107
114
|
return true;
|
|
108
115
|
}
|
|
116
|
+
|
|
109
117
|
export const isAccountBalanceSignificant = (a: AccountLike): boolean =>
|
|
110
118
|
a.balance.gt(100);
|
|
119
|
+
|
|
111
120
|
// in future, could be a per currency thing
|
|
112
121
|
// clear account to a bare minimal version that can be restored via sync
|
|
113
122
|
// will preserve the balance to avoid user panic
|
|
@@ -153,12 +162,14 @@ export function clearAccount<T extends AccountLike>(account: T): T {
|
|
|
153
162
|
delete copy.nfts;
|
|
154
163
|
return copy as T;
|
|
155
164
|
}
|
|
165
|
+
|
|
156
166
|
export function findSubAccountById(
|
|
157
167
|
account: Account,
|
|
158
168
|
id: string
|
|
159
169
|
): SubAccount | null | undefined {
|
|
160
170
|
return (account.subAccounts || []).find((a) => a.id === id);
|
|
161
171
|
}
|
|
172
|
+
|
|
162
173
|
// get the token accounts of an account, ignoring those that are zero IF user don't want them
|
|
163
174
|
export function listSubAccounts(account: Account): SubAccount[] {
|
|
164
175
|
const accounts = account.subAccounts || [];
|
|
@@ -169,9 +180,11 @@ export function listSubAccounts(account: Account): SubAccount[] {
|
|
|
169
180
|
|
|
170
181
|
return accounts;
|
|
171
182
|
}
|
|
183
|
+
|
|
172
184
|
export type FlattenAccountsOptions = {
|
|
173
185
|
enforceHideEmptySubAccounts?: boolean;
|
|
174
186
|
};
|
|
187
|
+
|
|
175
188
|
export function flattenAccounts(
|
|
176
189
|
topAccounts: AccountLikeArray,
|
|
177
190
|
o: FlattenAccountsOptions = {}
|
|
@@ -195,16 +208,19 @@ export function flattenAccounts(
|
|
|
195
208
|
|
|
196
209
|
return accounts;
|
|
197
210
|
}
|
|
211
|
+
|
|
198
212
|
export const shortAddressPreview = (addr: string, target = 20): string => {
|
|
199
213
|
const slice = Math.floor((target - 3) / 2);
|
|
200
214
|
return addr.length < target - 3
|
|
201
215
|
? addr
|
|
202
216
|
: `${addr.slice(0, slice)}...${addr.slice(addr.length - slice)}`;
|
|
203
217
|
};
|
|
218
|
+
|
|
204
219
|
export const isAccountBalanceUnconfirmed = (account: AccountLike): boolean =>
|
|
205
220
|
account.pendingOperations.some(
|
|
206
221
|
(op) => !account.operations.find((o) => o.hash === op.hash)
|
|
207
222
|
) || account.operations.some((op) => !op.blockHeight);
|
|
223
|
+
|
|
208
224
|
export const isUpToDateAccount = (account: Account | null | undefined) => {
|
|
209
225
|
if (!account) return true;
|
|
210
226
|
const { lastSyncDate, currency } = account;
|
|
@@ -216,6 +232,7 @@ export const isUpToDateAccount = (account: Account | null | undefined) => {
|
|
|
216
232
|
blockAvgTime * 1000 + getEnv("SYNC_OUTDATED_CONSIDERED_DELAY");
|
|
217
233
|
return !outdated;
|
|
218
234
|
};
|
|
235
|
+
|
|
219
236
|
export const getVotesCount = (
|
|
220
237
|
account: AccountLike,
|
|
221
238
|
parentAccount?: Account | null | undefined
|
|
@@ -233,6 +250,7 @@ export const getVotesCount = (
|
|
|
233
250
|
|
|
234
251
|
return 0;
|
|
235
252
|
};
|
|
253
|
+
|
|
236
254
|
export const makeEmptyTokenAccount = (
|
|
237
255
|
account: Account,
|
|
238
256
|
token: TokenCurrency
|
|
@@ -348,3 +366,36 @@ export const findTokenAccountByCurrency = (
|
|
|
348
366
|
|
|
349
367
|
return null; // else return nothing
|
|
350
368
|
};
|
|
369
|
+
|
|
370
|
+
export function isTokenAccount(account: AccountLike): account is TokenAccount {
|
|
371
|
+
return account.type === "TokenAccount";
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function isChildAccount(account: AccountLike): account is ChildAccount {
|
|
375
|
+
return account.type === "ChildAccount";
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export function isSubAccount(account: AccountLike): account is SubAccount {
|
|
379
|
+
return isTokenAccount(account) || isChildAccount(account);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function getParentAccount(
|
|
383
|
+
account: AccountLike,
|
|
384
|
+
accounts: AccountLike[]
|
|
385
|
+
): Account {
|
|
386
|
+
switch (account.type) {
|
|
387
|
+
case "Account":
|
|
388
|
+
return account;
|
|
389
|
+
case "TokenAccount":
|
|
390
|
+
case "ChildAccount": {
|
|
391
|
+
const parentAccount = accounts.find((a) => a.id == account.parentId);
|
|
392
|
+
if (!parentAccount) {
|
|
393
|
+
throw new Error(
|
|
394
|
+
"No 'parentAccount' account provided for token account"
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return parentAccount as Account;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
@@ -5,7 +5,7 @@ import { sortFilterApps } from "./filtering";
|
|
|
5
5
|
import { setSupportedCurrencies } from "../currencies/support";
|
|
6
6
|
import { setPlatformVersion } from "../platform/version";
|
|
7
7
|
|
|
8
|
-
setPlatformVersion("0.0
|
|
8
|
+
setPlatformVersion("1.0.0");
|
|
9
9
|
|
|
10
10
|
type FilteringScenario = {
|
|
11
11
|
name: string;
|
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import URL from "url";
|
|
2
2
|
import { getEnv } from "../../env";
|
|
3
3
|
import network from "../../network";
|
|
4
|
+
import chunk from "lodash/chunk";
|
|
4
5
|
import { formatPerGranularity } from "../helpers";
|
|
5
6
|
import type { CounterValuesAPI, TrackingPair } from "../types";
|
|
7
|
+
import { promiseAllBatched } from "../../promise";
|
|
6
8
|
|
|
7
9
|
const baseURL = () => getEnv("LEDGER_COUNTERVALUES_API");
|
|
8
10
|
|
|
11
|
+
const LATEST_CHUNK = 50;
|
|
12
|
+
|
|
9
13
|
const latest = async (pairs: TrackingPair[], direct?: boolean) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const all = await promiseAllBatched(
|
|
15
|
+
4,
|
|
16
|
+
chunk(pairs, LATEST_CHUNK),
|
|
17
|
+
async (partial) => {
|
|
18
|
+
const { data } = await network({
|
|
19
|
+
method: "GET",
|
|
20
|
+
url: `${baseURL()}/latest${
|
|
21
|
+
direct ? "/direct" : "/indirect"
|
|
22
|
+
}?pairs=${partial
|
|
23
|
+
.map(
|
|
24
|
+
(p) =>
|
|
25
|
+
`${p.from.countervalueTicker ?? p.from.ticker}:${
|
|
26
|
+
p.to.countervalueTicker ?? p.to.ticker
|
|
27
|
+
}`
|
|
28
|
+
)
|
|
29
|
+
.join(",")}`,
|
|
30
|
+
});
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
const data = all.reduce((acc, data) => acc.concat(data), []);
|
|
18
35
|
return data;
|
|
19
36
|
};
|
|
20
37
|
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import "../__tests__/test-helpers/setup";
|
|
1
2
|
import { initialState, loadCountervalues, calculate } from "./logic";
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getFiatCurrencyByTicker,
|
|
5
|
+
getCryptoCurrencyById,
|
|
6
|
+
findCurrencyByTicker,
|
|
7
|
+
} from "../currencies";
|
|
8
|
+
import { getBTCValues } from "../countervalues/mock";
|
|
9
|
+
import { Currency } from "@ledgerhq/cryptoassets";
|
|
10
|
+
|
|
3
11
|
const bitcoin = getCryptoCurrencyById("bitcoin");
|
|
4
12
|
const usd = getFiatCurrencyByTicker("USD");
|
|
5
13
|
const now = Date.now();
|
|
@@ -17,6 +25,7 @@ describe("API sanity", () => {
|
|
|
17
25
|
},
|
|
18
26
|
],
|
|
19
27
|
autofillGaps: false,
|
|
28
|
+
disableAutoRecoverErrors: true,
|
|
20
29
|
});
|
|
21
30
|
|
|
22
31
|
for (let i = 0; i < 7; i++) {
|
|
@@ -40,6 +49,7 @@ describe("API sanity", () => {
|
|
|
40
49
|
},
|
|
41
50
|
],
|
|
42
51
|
autofillGaps: true,
|
|
52
|
+
disableAutoRecoverErrors: true,
|
|
43
53
|
});
|
|
44
54
|
const currentValue = calculate(state, {
|
|
45
55
|
disableRounding: true,
|
|
@@ -60,3 +70,63 @@ describe("API sanity", () => {
|
|
|
60
70
|
}
|
|
61
71
|
});
|
|
62
72
|
});
|
|
73
|
+
|
|
74
|
+
describe("extreme cases", () => {
|
|
75
|
+
test("all tickers against USD", async () => {
|
|
76
|
+
const currencies = Object.keys(getBTCValues())
|
|
77
|
+
.filter((t) => t !== "USD")
|
|
78
|
+
.map(findCurrencyByTicker)
|
|
79
|
+
.filter(Boolean) as Currency[];
|
|
80
|
+
const state = await loadCountervalues(initialState, {
|
|
81
|
+
trackingPairs: currencies.map((from) => ({
|
|
82
|
+
from,
|
|
83
|
+
to: usd,
|
|
84
|
+
startDate: new Date(),
|
|
85
|
+
})),
|
|
86
|
+
autofillGaps: true,
|
|
87
|
+
disableAutoRecoverErrors: true,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const currenciesWithCVs = currencies
|
|
91
|
+
.map((from) =>
|
|
92
|
+
calculate(state, {
|
|
93
|
+
date: new Date(),
|
|
94
|
+
from,
|
|
95
|
+
to: usd,
|
|
96
|
+
value: 1000000,
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
.filter((v) => v && v > 0);
|
|
100
|
+
|
|
101
|
+
expect(currenciesWithCVs.length).toBeGreaterThan(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("all tickers against BTC", async () => {
|
|
105
|
+
const currencies = Object.keys(getBTCValues())
|
|
106
|
+
.filter((t) => t !== "BTC")
|
|
107
|
+
.map(findCurrencyByTicker)
|
|
108
|
+
.filter(Boolean) as Currency[];
|
|
109
|
+
const state = await loadCountervalues(initialState, {
|
|
110
|
+
trackingPairs: currencies.map((from) => ({
|
|
111
|
+
from,
|
|
112
|
+
to: bitcoin,
|
|
113
|
+
startDate: new Date(),
|
|
114
|
+
})),
|
|
115
|
+
autofillGaps: true,
|
|
116
|
+
disableAutoRecoverErrors: true,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const currenciesWithCVs = currencies
|
|
120
|
+
.map((from) =>
|
|
121
|
+
calculate(state, {
|
|
122
|
+
date: new Date(),
|
|
123
|
+
from,
|
|
124
|
+
to: bitcoin,
|
|
125
|
+
value: 1000000,
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
.filter((v) => v && v > 0);
|
|
129
|
+
|
|
130
|
+
expect(currenciesWithCVs.length).toBeGreaterThan(0);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -230,6 +230,7 @@ export async function loadCountervalues(
|
|
|
230
230
|
};
|
|
231
231
|
})
|
|
232
232
|
.catch((e) => {
|
|
233
|
+
if (settings.disableAutoRecoverErrors) throw e;
|
|
233
234
|
// TODO work on the semantic of failure.
|
|
234
235
|
// do we want to opt-in for the 404 cases and make other fails it all?
|
|
235
236
|
// do we want to be resilient on individual pulling / keep error somewhere?
|
|
@@ -254,7 +255,7 @@ export async function loadCountervalues(
|
|
|
254
255
|
return null;
|
|
255
256
|
})
|
|
256
257
|
),
|
|
257
|
-
fetchLatest(latestToFetch)
|
|
258
|
+
fetchLatest(latestToFetch, settings.disableAutoRecoverErrors)
|
|
258
259
|
.then((rates) => {
|
|
259
260
|
const out = {};
|
|
260
261
|
let hasData = false;
|
|
@@ -271,6 +272,7 @@ export async function loadCountervalues(
|
|
|
271
272
|
return out;
|
|
272
273
|
})
|
|
273
274
|
.catch((e) => {
|
|
275
|
+
if (settings.disableAutoRecoverErrors) throw e;
|
|
274
276
|
log(
|
|
275
277
|
"countervalues-error",
|
|
276
278
|
"Failed to fetch latest for " +
|
|
@@ -36,7 +36,8 @@ type CountervaluesJobs = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export const fetchLatest = async (
|
|
39
|
-
pairs: TrackingPair[]
|
|
39
|
+
pairs: TrackingPair[],
|
|
40
|
+
disableAutoRecoverErrors?: boolean
|
|
40
41
|
): Promise<Array<number | null | undefined>> => {
|
|
41
42
|
// a module can override as well. but as latest is a "one api" call,
|
|
42
43
|
// we need to segment the pairs in diff modules
|
|
@@ -88,6 +89,7 @@ export const fetchLatest = async (
|
|
|
88
89
|
}
|
|
89
90
|
})
|
|
90
91
|
.catch((e) => {
|
|
92
|
+
if (disableAutoRecoverErrors) throw e;
|
|
91
93
|
log("error", "latest fetch issue: " + String(e));
|
|
92
94
|
})
|
|
93
95
|
)
|
|
@@ -4,6 +4,8 @@ import type { Currency } from "../types";
|
|
|
4
4
|
export type CountervaluesSettings = {
|
|
5
5
|
trackingPairs: TrackingPair[];
|
|
6
6
|
autofillGaps: boolean;
|
|
7
|
+
// throw exception in "loadCountervalues" if ANY error occurs (for test purpose)
|
|
8
|
+
disableAutoRecoverErrors?: boolean;
|
|
7
9
|
};
|
|
8
10
|
// This is the internal state of countervalues.
|
|
9
11
|
export type CounterValuesState = {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../__tests__/test-helpers/setup";
|
|
2
|
+
import { isPlatformSupportedCurrency } from "../platform/helpers";
|
|
3
|
+
import { isCryptoCurrency, listCurrencies } from "./helpers";
|
|
4
|
+
|
|
5
|
+
describe("Currencies helpers", () => {
|
|
6
|
+
test("listCurrencies without includeTokens", () => {
|
|
7
|
+
const currencies = listCurrencies(false);
|
|
8
|
+
|
|
9
|
+
currencies.forEach((currency) => {
|
|
10
|
+
expect(isCryptoCurrency(currency)).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("listCurrencies with includeTokens", () => {
|
|
15
|
+
const currencies = listCurrencies(true);
|
|
16
|
+
|
|
17
|
+
currencies.forEach((currency) => {
|
|
18
|
+
expect(isPlatformSupportedCurrency(currency)).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|