@ledgerhq/live-common 25.0.0-next.2 → 25.0.0-next.3
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/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/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/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/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,93 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { AccountLike } from "../types";
|
|
3
|
+
import {
|
|
4
|
+
accountToPlatformAccount,
|
|
5
|
+
currencyToPlatformCurrency,
|
|
6
|
+
} from "./converters";
|
|
7
|
+
import {
|
|
8
|
+
filterPlatformAccounts,
|
|
9
|
+
filterPlatformCurrencies,
|
|
10
|
+
AccountFilters,
|
|
11
|
+
CurrencyFilters,
|
|
12
|
+
} from "./filters";
|
|
13
|
+
import { isPlatformSupportedCurrency } from "./helpers";
|
|
14
|
+
import {
|
|
15
|
+
ListPlatformAccount,
|
|
16
|
+
ListPlatformCurrency,
|
|
17
|
+
PlatformCurrency,
|
|
18
|
+
AppManifest,
|
|
19
|
+
} from "./types";
|
|
20
|
+
import { getParentAccount } from "../account";
|
|
21
|
+
import { listCurrencies } from "../currencies";
|
|
22
|
+
|
|
23
|
+
export function usePlatformUrl(
|
|
24
|
+
manifest: AppManifest,
|
|
25
|
+
params: { background: string; text: string; loadDate?: Date },
|
|
26
|
+
inputs: Record<string, string>
|
|
27
|
+
): URL {
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const url = new URL(manifest.url.toString());
|
|
30
|
+
|
|
31
|
+
if (inputs) {
|
|
32
|
+
for (const key in inputs) {
|
|
33
|
+
if (Object.prototype.hasOwnProperty.call(inputs, key)) {
|
|
34
|
+
url.searchParams.set(key, inputs[key]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
url.searchParams.set("backgroundColor", params.background);
|
|
40
|
+
url.searchParams.set("textColor", params.text);
|
|
41
|
+
if (params.loadDate) {
|
|
42
|
+
url.searchParams.set("loadDate", params.loadDate.valueOf().toString());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (manifest.params) {
|
|
46
|
+
url.searchParams.set("params", JSON.stringify(manifest.params));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return url;
|
|
50
|
+
}, [manifest.url, manifest.params, params, inputs]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useListPlatformAccounts(
|
|
54
|
+
accounts: AccountLike[]
|
|
55
|
+
): ListPlatformAccount {
|
|
56
|
+
const platformAccounts = useMemo(() => {
|
|
57
|
+
return accounts.map((account) => {
|
|
58
|
+
const parentAccount = getParentAccount(account, accounts);
|
|
59
|
+
|
|
60
|
+
return accountToPlatformAccount(account, parentAccount);
|
|
61
|
+
});
|
|
62
|
+
}, [accounts]);
|
|
63
|
+
|
|
64
|
+
return useCallback(
|
|
65
|
+
(filters: AccountFilters = {}) => {
|
|
66
|
+
return filterPlatformAccounts(platformAccounts, filters);
|
|
67
|
+
},
|
|
68
|
+
[platformAccounts]
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function usePlatformCurrencies(
|
|
73
|
+
includeTokens = false
|
|
74
|
+
): PlatformCurrency[] {
|
|
75
|
+
return useMemo(
|
|
76
|
+
() =>
|
|
77
|
+
listCurrencies(includeTokens)
|
|
78
|
+
.filter(isPlatformSupportedCurrency)
|
|
79
|
+
.map(currencyToPlatformCurrency),
|
|
80
|
+
[includeTokens]
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function useListPlatformCurrencies(): ListPlatformCurrency {
|
|
85
|
+
const currencies = usePlatformCurrencies(true);
|
|
86
|
+
|
|
87
|
+
return useCallback(
|
|
88
|
+
(filters?: CurrencyFilters) => {
|
|
89
|
+
return filterPlatformCurrencies(currencies, filters || {});
|
|
90
|
+
},
|
|
91
|
+
[currencies]
|
|
92
|
+
);
|
|
93
|
+
}
|
package/src/platform/types.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SignedOperation, CryptoCurrency, TokenCurrency } from "../types";
|
|
2
|
+
import { AccountFilters, CurrencyFilters } from "./filters";
|
|
3
|
+
import {
|
|
4
|
+
Account as PlatformAccount,
|
|
5
|
+
Currency as PlatformCurrency,
|
|
6
|
+
} from "@ledgerhq/live-app-sdk";
|
|
2
7
|
|
|
3
8
|
export type {
|
|
4
9
|
Account as PlatformAccount,
|
|
5
10
|
Currency as PlatformCurrency,
|
|
6
11
|
Unit as PlatformUnit,
|
|
7
12
|
Transaction as PlatformTransaction,
|
|
13
|
+
CryptoCurrency as PlatformCryptoCurrency,
|
|
14
|
+
ERC20TokenCurrency as PlatformERC20TokenCurrency,
|
|
15
|
+
} from "@ledgerhq/live-app-sdk";
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
CurrencyType as PlatformCurrencyType,
|
|
19
|
+
TokenStandard as PlatformTokenStandard,
|
|
8
20
|
} from "@ledgerhq/live-app-sdk";
|
|
9
21
|
|
|
10
22
|
export type TranslatableString = {
|
|
@@ -52,3 +64,13 @@ export type PlatformApi = {
|
|
|
52
64
|
};
|
|
53
65
|
|
|
54
66
|
export type PlatformSignedTransaction = SignedOperation;
|
|
67
|
+
|
|
68
|
+
export type ListPlatformAccount = (
|
|
69
|
+
filters?: AccountFilters
|
|
70
|
+
) => PlatformAccount[];
|
|
71
|
+
|
|
72
|
+
export type ListPlatformCurrency = (
|
|
73
|
+
filters?: CurrencyFilters
|
|
74
|
+
) => PlatformCurrency[];
|
|
75
|
+
|
|
76
|
+
export type PlatformSupportedCurrency = CryptoCurrency | TokenCurrency;
|
|
@@ -8,9 +8,6 @@ import { getCryptoCurrencyById, setSupportedCurrencies } from "../currencies";
|
|
|
8
8
|
import type { Account } from "../types/account";
|
|
9
9
|
import { emptyHistoryCache } from "../account";
|
|
10
10
|
import { setEnv } from "../env";
|
|
11
|
-
import { setPlatformVersion } from "../platform/version";
|
|
12
|
-
|
|
13
|
-
setPlatformVersion("0.0.1");
|
|
14
11
|
|
|
15
12
|
describe("walletconnect", () => {
|
|
16
13
|
const account: Account = {
|