@ledgerhq/live-common 34.50.0-nightly.0 → 34.50.0-nightly.2
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/bridge/generic-alpaca/buildSubAccounts.d.ts +4 -4
- package/lib/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/buildSubAccounts.js +7 -9
- package/lib/bridge/generic-alpaca/buildSubAccounts.js.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.js +4 -6
- package/lib/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib/bridge/generic-alpaca/tests/getAccountShape.test.js +5 -3
- package/lib/bridge/generic-alpaca/tests/getAccountShape.test.js.map +1 -1
- package/lib/e2e/enum/Account.d.ts +2 -0
- package/lib/e2e/enum/Account.d.ts.map +1 -1
- package/lib/e2e/enum/Account.js +4 -0
- package/lib/e2e/enum/Account.js.map +1 -1
- package/lib/e2e/enum/AppInfos.d.ts +1 -0
- package/lib/e2e/enum/AppInfos.d.ts.map +1 -1
- package/lib/e2e/enum/AppInfos.js +1 -0
- package/lib/e2e/enum/AppInfos.js.map +1 -1
- package/lib/e2e/enum/Currency.d.ts +2 -0
- package/lib/e2e/enum/Currency.d.ts.map +1 -1
- package/lib/e2e/enum/Currency.js +4 -0
- package/lib/e2e/enum/Currency.js.map +1 -1
- package/lib/e2e/enum/Network.d.ts +2 -1
- package/lib/e2e/enum/Network.d.ts.map +1 -1
- package/lib/e2e/enum/Network.js +1 -0
- package/lib/e2e/enum/Network.js.map +1 -1
- package/lib/e2e/families/hedera.d.ts +2 -0
- package/lib/e2e/families/hedera.d.ts.map +1 -0
- package/lib/e2e/families/hedera.js +11 -0
- package/lib/e2e/families/hedera.js.map +1 -0
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +12 -0
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/exchange/platform/types.d.ts +2 -0
- package/lib/exchange/platform/types.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +22 -1
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
- package/lib/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
- package/lib/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
- package/lib/families/hedera/exchange.d.ts +9 -0
- package/lib/families/hedera/exchange.d.ts.map +1 -0
- package/lib/families/hedera/exchange.js +36 -0
- package/lib/families/hedera/exchange.js.map +1 -0
- package/lib/hw/actions/completeExchange.d.ts +2 -0
- package/lib/hw/actions/completeExchange.d.ts.map +1 -1
- package/lib/hw/actions/completeExchange.js +1 -0
- package/lib/hw/actions/completeExchange.js.map +1 -1
- package/lib/modularDrawer/hooks/useRightBalanceAsset.d.ts +4 -3
- package/lib/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
- package/lib/modularDrawer/hooks/useRightBalanceAsset.js +13 -47
- package/lib/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
- package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts +1 -5
- package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
- package/lib/modularDrawer/hooks/useRightBalanceNetwork.js +15 -55
- package/lib/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
- package/lib/modularDrawer/modules/createAssetConfiguration.d.ts.map +1 -1
- package/lib/modularDrawer/modules/createAssetConfiguration.js +2 -2
- package/lib/modularDrawer/modules/createAssetConfiguration.js.map +1 -1
- package/lib/modularDrawer/modules/createNetworkConfiguration.d.ts +1 -1
- package/lib/modularDrawer/modules/createNetworkConfiguration.d.ts.map +1 -1
- package/lib/modularDrawer/modules/createNetworkConfiguration.js +1 -3
- package/lib/modularDrawer/modules/createNetworkConfiguration.js.map +1 -1
- package/lib/modularDrawer/utils/__tests__/haveOneCommonAsset.test.d.ts +2 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonAsset.test.d.ts.map +1 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonAsset.test.js +46 -0
- package/lib/modularDrawer/utils/__tests__/haveOneCommonAsset.test.js.map +1 -0
- package/lib/modularDrawer/utils/currencyUtils.d.ts.map +1 -1
- package/lib/modularDrawer/utils/currencyUtils.js.map +1 -1
- package/lib/modularDrawer/utils/{haveOneCommonProvider.d.ts → haveOneCommonAsset.d.ts} +3 -3
- package/lib/modularDrawer/utils/haveOneCommonAsset.d.ts.map +1 -0
- package/lib/modularDrawer/utils/{haveOneCommonProvider.js → haveOneCommonAsset.js} +6 -6
- package/lib/modularDrawer/utils/haveOneCommonAsset.js.map +1 -0
- package/lib/modularDrawer/utils/index.d.ts +2 -4
- package/lib/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib/modularDrawer/utils/index.js +3 -10
- package/lib/modularDrawer/utils/index.js.map +1 -1
- package/lib/modularDrawer/utils/index.test.js +0 -26
- package/lib/modularDrawer/utils/index.test.js.map +1 -1
- package/lib/modularDrawer/utils/type.d.ts +0 -6
- package/lib/modularDrawer/utils/type.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts +4 -4
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.js +7 -9
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.js +4 -6
- package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/getAccountShape.test.js +5 -3
- package/lib-es/bridge/generic-alpaca/tests/getAccountShape.test.js.map +1 -1
- package/lib-es/e2e/enum/Account.d.ts +2 -0
- package/lib-es/e2e/enum/Account.d.ts.map +1 -1
- package/lib-es/e2e/enum/Account.js +4 -0
- package/lib-es/e2e/enum/Account.js.map +1 -1
- package/lib-es/e2e/enum/AppInfos.d.ts +1 -0
- package/lib-es/e2e/enum/AppInfos.d.ts.map +1 -1
- package/lib-es/e2e/enum/AppInfos.js +1 -0
- package/lib-es/e2e/enum/AppInfos.js.map +1 -1
- package/lib-es/e2e/enum/Currency.d.ts +2 -0
- package/lib-es/e2e/enum/Currency.d.ts.map +1 -1
- package/lib-es/e2e/enum/Currency.js +4 -0
- package/lib-es/e2e/enum/Currency.js.map +1 -1
- package/lib-es/e2e/enum/Network.d.ts +2 -1
- package/lib-es/e2e/enum/Network.d.ts.map +1 -1
- package/lib-es/e2e/enum/Network.js +1 -0
- package/lib-es/e2e/enum/Network.js.map +1 -1
- package/lib-es/e2e/families/hedera.d.ts +2 -0
- package/lib-es/e2e/families/hedera.d.ts.map +1 -0
- package/lib-es/e2e/families/hedera.js +7 -0
- package/lib-es/e2e/families/hedera.js.map +1 -0
- package/lib-es/e2e/speculos.d.ts.map +1 -1
- package/lib-es/e2e/speculos.js +12 -0
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/exchange/platform/types.d.ts +2 -0
- package/lib-es/exchange/platform/types.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.js +22 -1
- package/lib-es/exchange/swap/completeExchange.js.map +1 -1
- package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
- package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
- package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
- package/lib-es/families/hedera/exchange.d.ts +9 -0
- package/lib-es/families/hedera/exchange.d.ts.map +1 -0
- package/lib-es/families/hedera/exchange.js +29 -0
- package/lib-es/families/hedera/exchange.js.map +1 -0
- package/lib-es/hw/actions/completeExchange.d.ts +2 -0
- package/lib-es/hw/actions/completeExchange.d.ts.map +1 -1
- package/lib-es/hw/actions/completeExchange.js +1 -0
- package/lib-es/hw/actions/completeExchange.js.map +1 -1
- package/lib-es/modularDrawer/hooks/useRightBalanceAsset.d.ts +4 -3
- package/lib-es/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
- package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js +13 -47
- package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
- package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts +1 -5
- package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
- package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js +15 -55
- package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
- package/lib-es/modularDrawer/modules/createAssetConfiguration.d.ts.map +1 -1
- package/lib-es/modularDrawer/modules/createAssetConfiguration.js +2 -2
- package/lib-es/modularDrawer/modules/createAssetConfiguration.js.map +1 -1
- package/lib-es/modularDrawer/modules/createNetworkConfiguration.d.ts +1 -1
- package/lib-es/modularDrawer/modules/createNetworkConfiguration.d.ts.map +1 -1
- package/lib-es/modularDrawer/modules/createNetworkConfiguration.js +1 -3
- package/lib-es/modularDrawer/modules/createNetworkConfiguration.js.map +1 -1
- package/lib-es/modularDrawer/utils/__tests__/currencyUtils.test.js +1 -1
- package/lib-es/modularDrawer/utils/__tests__/currencyUtils.test.js.map +1 -1
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonAsset.test.d.ts +2 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonAsset.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonAsset.test.js +44 -0
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonAsset.test.js.map +1 -0
- package/lib-es/modularDrawer/utils/currencyUtils.d.ts.map +1 -1
- package/lib-es/modularDrawer/utils/currencyUtils.js.map +1 -1
- package/lib-es/modularDrawer/utils/{haveOneCommonProvider.d.ts → haveOneCommonAsset.d.ts} +3 -3
- package/lib-es/modularDrawer/utils/haveOneCommonAsset.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/{haveOneCommonProvider.js → haveOneCommonAsset.js} +4 -4
- package/lib-es/modularDrawer/utils/haveOneCommonAsset.js.map +1 -0
- package/lib-es/modularDrawer/utils/index.d.ts +2 -4
- package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib-es/modularDrawer/utils/index.js +2 -8
- package/lib-es/modularDrawer/utils/index.js.map +1 -1
- package/lib-es/modularDrawer/utils/index.test.js +1 -27
- package/lib-es/modularDrawer/utils/index.test.js.map +1 -1
- package/lib-es/modularDrawer/utils/type.d.ts +0 -6
- package/lib-es/modularDrawer/utils/type.d.ts.map +1 -1
- package/package.json +37 -35
- package/src/bridge/generic-alpaca/buildSubAccounts.ts +28 -28
- package/src/bridge/generic-alpaca/getAccountShape.ts +9 -12
- package/src/bridge/generic-alpaca/tests/getAccountShape.test.ts +5 -3
- package/src/e2e/enum/Account.ts +10 -0
- package/src/e2e/enum/AppInfos.ts +2 -0
- package/src/e2e/enum/Currency.ts +11 -0
- package/src/e2e/enum/Network.ts +1 -0
- package/src/e2e/families/hedera.ts +7 -0
- package/src/e2e/speculos.ts +12 -0
- package/src/exchange/platform/types.ts +2 -0
- package/src/exchange/swap/completeExchange.ts +32 -2
- package/src/exchange/swap/getIncompatibleCurrencyKeys.ts +4 -0
- package/src/families/hedera/exchange.ts +48 -0
- package/src/hw/actions/completeExchange.ts +3 -0
- package/src/modularDrawer/hooks/useRightBalanceAsset.tsx +16 -76
- package/src/modularDrawer/hooks/useRightBalanceNetwork.tsx +25 -95
- package/src/modularDrawer/modules/createAssetConfiguration.ts +3 -11
- package/src/modularDrawer/modules/createNetworkConfiguration.ts +1 -8
- package/src/modularDrawer/utils/__tests__/currencyUtils.test.ts +1 -1
- package/src/modularDrawer/utils/__tests__/haveOneCommonAsset.test.ts +49 -0
- package/src/modularDrawer/utils/currencyUtils.ts +0 -1
- package/src/modularDrawer/utils/{haveOneCommonProvider.ts → haveOneCommonAsset.ts} +6 -5
- package/src/modularDrawer/utils/index.test.ts +1 -32
- package/src/modularDrawer/utils/index.ts +2 -16
- package/src/modularDrawer/utils/type.ts +0 -6
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +0 -2
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +0 -1
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +0 -28
- package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +0 -1
- package/lib/modularDrawer/utils/buildProviderCurrenciesMap.d.ts +0 -9
- package/lib/modularDrawer/utils/buildProviderCurrenciesMap.d.ts.map +0 -1
- package/lib/modularDrawer/utils/buildProviderCurrenciesMap.js +0 -17
- package/lib/modularDrawer/utils/buildProviderCurrenciesMap.js.map +0 -1
- package/lib/modularDrawer/utils/getProviderCurrency.d.ts +0 -3
- package/lib/modularDrawer/utils/getProviderCurrency.d.ts.map +0 -1
- package/lib/modularDrawer/utils/getProviderCurrency.js +0 -14
- package/lib/modularDrawer/utils/getProviderCurrency.js.map +0 -1
- package/lib/modularDrawer/utils/haveOneCommonProvider.d.ts.map +0 -1
- package/lib/modularDrawer/utils/haveOneCommonProvider.js.map +0 -1
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +0 -2
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +0 -1
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +0 -26
- package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +0 -1
- package/lib-es/modularDrawer/utils/buildProviderCurrenciesMap.d.ts +0 -9
- package/lib-es/modularDrawer/utils/buildProviderCurrenciesMap.d.ts.map +0 -1
- package/lib-es/modularDrawer/utils/buildProviderCurrenciesMap.js +0 -13
- package/lib-es/modularDrawer/utils/buildProviderCurrenciesMap.js.map +0 -1
- package/lib-es/modularDrawer/utils/getProviderCurrency.d.ts +0 -3
- package/lib-es/modularDrawer/utils/getProviderCurrency.d.ts.map +0 -1
- package/lib-es/modularDrawer/utils/getProviderCurrency.js +0 -10
- package/lib-es/modularDrawer/utils/getProviderCurrency.js.map +0 -1
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.d.ts.map +0 -1
- package/lib-es/modularDrawer/utils/haveOneCommonProvider.js.map +0 -1
- package/src/modularDrawer/utils/__tests__/haveOneCommonProvider.test.ts +0 -34
- package/src/modularDrawer/utils/buildProviderCurrenciesMap.tsx +0 -25
- package/src/modularDrawer/utils/getProviderCurrency.ts +0 -13
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { DeviceModelId } from "@ledgerhq/devices";
|
1
2
|
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
2
3
|
import type { Account, AccountLike, AccountRaw, AccountRawLike } from "@ledgerhq/types-live";
|
3
4
|
import type { ExchangeTypes, RateTypes } from "@ledgerhq/hw-app-exchange";
|
@@ -42,6 +43,7 @@ export type StartExchangeInput = {
|
|
42
43
|
|
43
44
|
interface CompleteExchangeInputCommon {
|
44
45
|
rateType?: RateTypes;
|
46
|
+
deviceModelId?: DeviceModelId;
|
45
47
|
deviceId?: string;
|
46
48
|
provider: string;
|
47
49
|
binaryPayload: string;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { Account } from "@ledgerhq/types-live";
|
1
2
|
import {
|
2
3
|
DisconnectedDeviceDuringOperation,
|
3
4
|
TransportStatusError,
|
@@ -13,12 +14,14 @@ import {
|
|
13
14
|
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
|
14
15
|
import { log } from "@ledgerhq/logs";
|
15
16
|
import BigNumber from "bignumber.js";
|
17
|
+
import invariant from "invariant";
|
16
18
|
import { Observable } from "rxjs";
|
17
19
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
18
20
|
import { getCurrencyExchangeConfig } from "../";
|
19
21
|
import { getAccountCurrency, getMainAccount } from "../../account";
|
20
22
|
import { getAccountBridge } from "../../bridge";
|
21
23
|
import { TransactionRefusedOnDevice } from "../../errors";
|
24
|
+
import { handleHederaTrustedFlow } from "../../families/hedera/exchange";
|
22
25
|
import { withDevicePromise } from "../../hw/deviceAccess";
|
23
26
|
import { delay } from "../../promise";
|
24
27
|
import { CompleteExchangeStep, convertTransportError } from "../error";
|
@@ -27,6 +30,7 @@ import { convertToAppExchangePartnerKey, getSwapProvider } from "../providers";
|
|
27
30
|
import { CEXProviderConfig } from "../providers/swap";
|
28
31
|
import { isAddressSanctioned } from "@ledgerhq/coin-framework/sanction/index";
|
29
32
|
import { AddressesSanctionedError } from "@ledgerhq/coin-framework/sanction/errors";
|
33
|
+
import { getCryptoCurrencyById } from "../../currencies";
|
30
34
|
|
31
35
|
const COMPLETE_EXCHANGE_LOG = "SWAP-CompleteExchange";
|
32
36
|
|
@@ -34,8 +38,16 @@ const completeExchange = (
|
|
34
38
|
input: CompleteExchangeInputSwap,
|
35
39
|
): Observable<CompleteExchangeRequestEvent> => {
|
36
40
|
let { transaction } = input; // TODO build a tx from the data
|
37
|
-
|
38
|
-
|
41
|
+
const {
|
42
|
+
deviceId,
|
43
|
+
deviceModelId,
|
44
|
+
exchange,
|
45
|
+
provider,
|
46
|
+
binaryPayload,
|
47
|
+
signature,
|
48
|
+
rateType,
|
49
|
+
exchangeType,
|
50
|
+
} = input;
|
39
51
|
|
40
52
|
const { fromAccount, fromParentAccount } = exchange;
|
41
53
|
const { toAccount, toParentAccount } = exchange;
|
@@ -152,6 +164,24 @@ const completeExchange = (
|
|
152
164
|
await exchange.checkTransactionSignature(goodSign);
|
153
165
|
if (unsubscribed) return;
|
154
166
|
|
167
|
+
// Hedera swap payload is filled with user account address,
|
168
|
+
// but the device app requires the related public key for verification.
|
169
|
+
// Since this key is stored on-chain, we use the TrustedService
|
170
|
+
// to fetch a signed descriptor linking the address to its public key.
|
171
|
+
const hederaCurrency = getCryptoCurrencyById("hedera");
|
172
|
+
let hederaAccount: Account | null = null;
|
173
|
+
if (payoutAccount.currency.family === hederaCurrency.family) {
|
174
|
+
hederaAccount = payoutAccount;
|
175
|
+
} else if (refundAccount.currency.family === hederaCurrency.family) {
|
176
|
+
hederaAccount = refundAccount;
|
177
|
+
}
|
178
|
+
|
179
|
+
if (hederaAccount) {
|
180
|
+
invariant(deviceModelId, "hedera: deviceModelId is not available");
|
181
|
+
await handleHederaTrustedFlow({ exchange, hederaAccount, deviceModelId });
|
182
|
+
if (unsubscribed) return;
|
183
|
+
}
|
184
|
+
|
155
185
|
const payoutAddressParameters = payoutAccountBridge.getSerializedAddressParameters(
|
156
186
|
payoutAccount,
|
157
187
|
mainPayoutCurrency.id,
|
@@ -59,6 +59,10 @@ const INCOMPATIBLE_NANO_S_CURRENCY_KEYS: Keys = {
|
|
59
59
|
title: "swap.incompatibility.cosmos_title",
|
60
60
|
description: "swap.incompatibility.cosmos_description",
|
61
61
|
},
|
62
|
+
hedera: {
|
63
|
+
title: "swap.incompatibility.hedera_title",
|
64
|
+
description: "swap.incompatibility.hedera_description",
|
65
|
+
},
|
62
66
|
osmo: {
|
63
67
|
title: "swap.incompatibility.osmo_title",
|
64
68
|
description: "swap.incompatibility.osmo_description",
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { LatestFirmwareVersionRequired, TransportStatusError } from "@ledgerhq/errors";
|
2
|
+
import Exchange from "@ledgerhq/hw-app-exchange";
|
3
|
+
import { loadPKI } from "@ledgerhq/hw-bolos";
|
4
|
+
import calService from "@ledgerhq/ledger-cal-service";
|
5
|
+
import trustService from "@ledgerhq/ledger-trust-service";
|
6
|
+
import { getEnv } from "@ledgerhq/live-env";
|
7
|
+
import { DeviceModelId } from "@ledgerhq/types-devices";
|
8
|
+
import { Account } from "@ledgerhq/types-live";
|
9
|
+
|
10
|
+
function isPKIUnsupportedError(err: unknown): err is TransportStatusError {
|
11
|
+
return err instanceof TransportStatusError && err.message.includes("0x6a81");
|
12
|
+
}
|
13
|
+
|
14
|
+
export async function handleHederaTrustedFlow({
|
15
|
+
exchange,
|
16
|
+
hederaAccount,
|
17
|
+
deviceModelId,
|
18
|
+
}: {
|
19
|
+
exchange: Exchange;
|
20
|
+
hederaAccount: Account;
|
21
|
+
deviceModelId: DeviceModelId;
|
22
|
+
}) {
|
23
|
+
const serviceEnv = getEnv("MOCK_EXCHANGE_TEST_CONFIG") ? "test" : "prod";
|
24
|
+
|
25
|
+
const cert = await calService.getCertificate(deviceModelId, "trusted_name", "latest", {
|
26
|
+
env: serviceEnv,
|
27
|
+
signatureKind: serviceEnv,
|
28
|
+
});
|
29
|
+
|
30
|
+
try {
|
31
|
+
await loadPKI(exchange.transport, "TRUSTED_NAME", cert.descriptor, cert.signature);
|
32
|
+
} catch (err) {
|
33
|
+
if (isPKIUnsupportedError(err)) {
|
34
|
+
throw new LatestFirmwareVersionRequired("LatestFirmwareVersionRequired");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
const challenge = await exchange.getChallenge();
|
39
|
+
const hexChallenge = challenge.toString(16);
|
40
|
+
|
41
|
+
const trustServiceResult = await trustService.hedera.getPublicKey(
|
42
|
+
hederaAccount.freshAddress,
|
43
|
+
hexChallenge,
|
44
|
+
);
|
45
|
+
const signedDescriptorBuffer = Buffer.from(trustServiceResult.signedDescriptor, "hex");
|
46
|
+
|
47
|
+
await exchange.sendTrustedDescriptor(signedDescriptorBuffer);
|
48
|
+
}
|
@@ -3,6 +3,7 @@ import { scan, tap } from "rxjs/operators";
|
|
3
3
|
import { useEffect, useState } from "react";
|
4
4
|
import type { Action, Device } from "./types";
|
5
5
|
import type { AppState } from "./app";
|
6
|
+
import type { DeviceModelId } from "@ledgerhq/devices";
|
6
7
|
import { log } from "@ledgerhq/logs";
|
7
8
|
import { Exchange } from "../../exchange/types";
|
8
9
|
import { Transaction } from "../../generated/types";
|
@@ -18,6 +19,7 @@ type State = {
|
|
18
19
|
|
19
20
|
type CompleteExchangeState = AppState & State;
|
20
21
|
type CompleteExchangeRequest = {
|
22
|
+
deviceModelId?: DeviceModelId;
|
21
23
|
deviceId?: string;
|
22
24
|
provider: string;
|
23
25
|
transaction: Transaction;
|
@@ -130,6 +132,7 @@ export const createAction = (
|
|
130
132
|
}),
|
131
133
|
completeExchangeExec({
|
132
134
|
deviceId: reduxDeviceFrozen?.deviceId,
|
135
|
+
deviceModelId: reduxDeviceFrozen?.modelId,
|
133
136
|
provider,
|
134
137
|
transaction,
|
135
138
|
binaryPayload,
|
@@ -1,15 +1,11 @@
|
|
1
|
-
import { useMemo } from "react";
|
2
|
-
import type { ReactNode } from "react";
|
1
|
+
import { useMemo, type ReactNode } from "react";
|
3
2
|
import type { CryptoOrTokenCurrency, Currency } from "@ledgerhq/types-cryptoassets";
|
4
3
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
5
4
|
import BigNumber from "bignumber.js";
|
6
5
|
import { counterValueFormatter } from "../utils/counterValueFormatter";
|
7
6
|
import { compareByBalanceThenFiat } from "../utils/sortByBalance";
|
8
7
|
import { UseBalanceDeps } from "../utils/type";
|
9
|
-
import { buildProviderCurrenciesMap } from "../utils/buildProviderCurrenciesMap";
|
10
|
-
import { CurrenciesByProviderId } from "../../deposit/type";
|
11
8
|
import { calculateProviderTotals } from "../utils/calculateProviderTotal";
|
12
|
-
import { getProviderCurrency } from "../utils/getProviderCurrency";
|
13
9
|
import { groupAccountsByAsset } from "../utils/groupAccountsByAsset";
|
14
10
|
|
15
11
|
export type AssetDeps = {
|
@@ -43,10 +39,7 @@ export function createUseRightBalanceAsset({ useBalanceDeps, balanceItem, assets
|
|
43
39
|
return { balance, fiatValue };
|
44
40
|
};
|
45
41
|
|
46
|
-
return function useRightBalanceAsset(
|
47
|
-
assets: CryptoOrTokenCurrency[],
|
48
|
-
currenciesByProvider: CurrenciesByProviderId[],
|
49
|
-
) {
|
42
|
+
return function useRightBalanceAsset(assets: CryptoOrTokenCurrency[]) {
|
50
43
|
const { flattenedAccounts, discreet, state, counterValueCurrency, locale } = useBalanceDeps();
|
51
44
|
|
52
45
|
const grouped = useMemo(
|
@@ -54,92 +47,39 @@ export function createUseRightBalanceAsset({ useBalanceDeps, balanceItem, assets
|
|
54
47
|
[flattenedAccounts, state, counterValueCurrency, discreet],
|
55
48
|
);
|
56
49
|
|
57
|
-
const providerMap = useMemo(
|
58
|
-
() => buildProviderCurrenciesMap(currenciesByProvider),
|
59
|
-
[currenciesByProvider],
|
60
|
-
);
|
61
|
-
|
62
50
|
return useMemo(() => {
|
63
|
-
|
64
|
-
const balanceMap = new Map();
|
65
|
-
|
66
|
-
for (const [, { currencies, mainCurrency }] of assetsMap) {
|
67
|
-
const { totalBalance, totalFiatValue } = calculateProviderTotals(currencies, grouped);
|
51
|
+
const balanceMap = new Map();
|
68
52
|
|
69
|
-
|
70
|
-
|
71
|
-
totalBalance,
|
72
|
-
totalFiatValue,
|
73
|
-
counterValueCurrency,
|
74
|
-
locale,
|
75
|
-
discreet,
|
76
|
-
);
|
77
|
-
|
78
|
-
balanceMap.set(mainCurrency.id, {
|
79
|
-
balance: balance,
|
80
|
-
fiatValue: fiatValue,
|
81
|
-
});
|
82
|
-
}
|
83
|
-
|
84
|
-
const assetsWithBalanceData = assets.map(asset => {
|
85
|
-
const balanceData = balanceMap.get(asset.id) || {};
|
86
|
-
return {
|
87
|
-
asset,
|
88
|
-
balanceData,
|
89
|
-
};
|
90
|
-
});
|
91
|
-
|
92
|
-
assetsWithBalanceData.sort((a, b) =>
|
93
|
-
compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
|
94
|
-
);
|
95
|
-
|
96
|
-
return assetsWithBalanceData.map(({ asset, balanceData }) => ({
|
97
|
-
...asset,
|
98
|
-
rightElement: balanceItem(balanceData),
|
99
|
-
}));
|
100
|
-
}
|
101
|
-
|
102
|
-
const assetsSet = new Set(assets.map(a => a.id));
|
103
|
-
const providerResultsMap = new Map<string, { balance?: string; fiatValue?: string }>();
|
104
|
-
|
105
|
-
for (const [, { currencies, mainCurrency }] of providerMap) {
|
106
|
-
if (!assetsSet.has(mainCurrency.id)) continue;
|
107
|
-
const providerCurrency = getProviderCurrency(mainCurrency, currencies);
|
108
|
-
if (!providerCurrency) continue;
|
109
|
-
|
110
|
-
const { totalBalance, totalFiatValue, hasAccounts } = calculateProviderTotals(
|
111
|
-
currencies,
|
112
|
-
grouped,
|
113
|
-
);
|
114
|
-
if (!hasAccounts) continue;
|
53
|
+
for (const [, { currencies, mainCurrency }] of assetsMap) {
|
54
|
+
const { totalBalance, totalFiatValue } = calculateProviderTotals(currencies, grouped);
|
115
55
|
|
116
56
|
const { balance, fiatValue } = formatProviderResult(
|
117
|
-
|
57
|
+
mainCurrency,
|
118
58
|
totalBalance,
|
119
59
|
totalFiatValue,
|
120
60
|
counterValueCurrency,
|
121
61
|
locale,
|
122
62
|
discreet,
|
123
63
|
);
|
124
|
-
|
64
|
+
|
65
|
+
balanceMap.set(mainCurrency.id, {
|
66
|
+
balance: balance,
|
67
|
+
fiatValue: fiatValue,
|
68
|
+
});
|
125
69
|
}
|
126
70
|
|
127
71
|
const assetsWithBalanceData = assets.map(asset => {
|
128
|
-
const balanceData =
|
72
|
+
const balanceData = balanceMap.get(asset.id) || {};
|
129
73
|
return {
|
130
|
-
asset,
|
74
|
+
...asset,
|
131
75
|
balanceData,
|
76
|
+
rightElement: balanceItem(balanceData),
|
132
77
|
};
|
133
78
|
});
|
134
79
|
|
135
|
-
assetsWithBalanceData.sort((a, b) =>
|
80
|
+
return assetsWithBalanceData.sort((a, b) =>
|
136
81
|
compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
|
137
82
|
);
|
138
|
-
|
139
|
-
return assetsWithBalanceData.map(({ asset, balanceData }) => ({
|
140
|
-
...asset,
|
141
|
-
rightElement: balanceItem(balanceData),
|
142
|
-
}));
|
143
|
-
}, [providerMap, assets, grouped, counterValueCurrency, locale, discreet]);
|
83
|
+
}, [assets, grouped, counterValueCurrency, locale, discreet]);
|
144
84
|
};
|
145
85
|
}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { type ReactNode } from "react";
|
2
2
|
import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
3
3
|
import { compareByBalanceThenFiat } from "../utils/sortByBalance";
|
4
|
-
import {
|
5
|
-
import { CurrenciesByProviderId } from "../../deposit/type";
|
4
|
+
import { UseBalanceDeps } from "../utils/type";
|
6
5
|
import { getBalanceAndFiatValueByAssets } from "../utils/getBalanceAndFiatValueByAssets";
|
7
6
|
|
8
7
|
export type NetworkDeps = {
|
@@ -11,108 +10,39 @@ export type NetworkDeps = {
|
|
11
10
|
};
|
12
11
|
|
13
12
|
type Params = {
|
14
|
-
assets: CryptoOrTokenCurrency[];
|
15
13
|
networks: CryptoOrTokenCurrency[];
|
16
|
-
selectedAssetId: string;
|
17
|
-
currenciesByProvider: CurrenciesByProviderId[];
|
18
14
|
};
|
19
15
|
|
20
16
|
export function createUseRightBalanceNetwork({ useBalanceDeps, balanceItem }: NetworkDeps) {
|
21
|
-
return function useRightBalanceNetwork({
|
22
|
-
assets: networks,
|
23
|
-
selectedAssetId,
|
24
|
-
currenciesByProvider,
|
25
|
-
networks: actualNetworks,
|
26
|
-
}: Params) {
|
17
|
+
return function useRightBalanceNetwork({ networks }: Params) {
|
27
18
|
const { flattenedAccounts, discreet, state, counterValueCurrency, locale } = useBalanceDeps();
|
28
19
|
|
29
|
-
|
30
|
-
if (currenciesByProvider && currenciesByProvider.length > 0) {
|
31
|
-
const providerOfSelectedAsset = currenciesByProvider.find(provider =>
|
32
|
-
provider.currenciesByNetwork.some(currency => currency.id === selectedAssetId),
|
33
|
-
);
|
34
|
-
|
35
|
-
if (providerOfSelectedAsset) {
|
36
|
-
const pairs = networks.map(network => ({
|
37
|
-
network,
|
38
|
-
asset: providerOfSelectedAsset.currenciesByNetwork.find(currency =>
|
39
|
-
currency.type === "TokenCurrency"
|
40
|
-
? currency.parentCurrency.id === network.id
|
41
|
-
: currency.id === network.id,
|
42
|
-
),
|
43
|
-
}));
|
44
|
-
|
45
|
-
const validAssets = pairs.filter(p => p.asset).map(p => p.asset!);
|
46
|
-
|
47
|
-
const allBalanceData =
|
48
|
-
validAssets.length > 0
|
49
|
-
? getBalanceAndFiatValueByAssets(
|
50
|
-
flattenedAccounts,
|
51
|
-
validAssets,
|
52
|
-
state,
|
53
|
-
counterValueCurrency,
|
54
|
-
discreet,
|
55
|
-
locale,
|
56
|
-
)
|
57
|
-
: [];
|
58
|
-
|
59
|
-
const balanceMap = new Map(allBalanceData.map(b => [b.id, b]));
|
60
|
-
|
61
|
-
const networkWithBalanceData = pairs.map(({ network, asset }) => {
|
62
|
-
const balanceData: BalanceUI = asset ? balanceMap.get(asset.id) || {} : {};
|
63
|
-
return {
|
64
|
-
network,
|
65
|
-
balanceData,
|
66
|
-
};
|
67
|
-
});
|
68
|
-
|
69
|
-
networkWithBalanceData.sort((a, b) =>
|
70
|
-
compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
|
71
|
-
);
|
72
|
-
|
73
|
-
return networkWithBalanceData.map(({ network, balanceData }) => ({
|
74
|
-
...network,
|
75
|
-
rightElement: balanceItem(balanceData),
|
76
|
-
}));
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
const networkBalanceData = getBalanceAndFiatValueByAssets(
|
81
|
-
flattenedAccounts,
|
82
|
-
actualNetworks,
|
83
|
-
state,
|
84
|
-
counterValueCurrency,
|
85
|
-
discreet,
|
86
|
-
locale,
|
87
|
-
);
|
88
|
-
|
89
|
-
const balanceMap = new Map(networkBalanceData.map(b => [b.id, b]));
|
90
|
-
|
91
|
-
const networksWithBalance = actualNetworks.map(network => {
|
92
|
-
const balanceData = balanceMap.get(network.id) || {};
|
93
|
-
return {
|
94
|
-
network,
|
95
|
-
balanceData,
|
96
|
-
};
|
97
|
-
});
|
98
|
-
|
99
|
-
networksWithBalance.sort((a, b) =>
|
100
|
-
compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
|
101
|
-
);
|
102
|
-
|
103
|
-
return networksWithBalance.map(({ network, balanceData }) => ({
|
104
|
-
...network,
|
105
|
-
rightElement: balanceItem(balanceData),
|
106
|
-
}));
|
107
|
-
}, [
|
108
|
-
networks,
|
109
|
-
selectedAssetId,
|
110
|
-
currenciesByProvider,
|
20
|
+
const networkBalanceData = getBalanceAndFiatValueByAssets(
|
111
21
|
flattenedAccounts,
|
22
|
+
networks,
|
112
23
|
state,
|
113
24
|
counterValueCurrency,
|
114
25
|
discreet,
|
115
26
|
locale,
|
116
|
-
|
27
|
+
);
|
28
|
+
|
29
|
+
const balanceMap = new Map(networkBalanceData.map(b => [b.id, b]));
|
30
|
+
|
31
|
+
const networksWithBalance = networks.map(network => {
|
32
|
+
const balanceData = balanceMap.get(network.id) || {};
|
33
|
+
return {
|
34
|
+
network,
|
35
|
+
balanceData,
|
36
|
+
};
|
37
|
+
});
|
38
|
+
|
39
|
+
networksWithBalance.sort((a, b) =>
|
40
|
+
compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
|
41
|
+
);
|
42
|
+
|
43
|
+
return networksWithBalance.map(({ network, balanceData }) => ({
|
44
|
+
...network,
|
45
|
+
rightElement: balanceItem(balanceData),
|
46
|
+
}));
|
117
47
|
};
|
118
48
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
2
2
|
import { AssetType, CreateAssetConfigurationHook, AssetConfigurationDeps } from "../utils/type";
|
3
|
-
import { CurrenciesByProviderId } from "../../deposit/type";
|
4
3
|
import { composeHooks } from "../../utils/composeHooks";
|
5
4
|
import { useLeftApyModule } from "../hooks/modules/useLeftApyModule";
|
6
5
|
import { createUseRightBalanceAsset } from "../hooks/useRightBalanceAsset";
|
@@ -46,7 +45,7 @@ const getLeftElement =
|
|
46
45
|
|
47
46
|
const createAssetConfigurationHook: CreateAssetConfigurationHook =
|
48
47
|
deps =>
|
49
|
-
({ assetsConfiguration
|
48
|
+
({ assetsConfiguration }) => {
|
50
49
|
const { rightElement, leftElement } = assetsConfiguration ?? {};
|
51
50
|
|
52
51
|
const rightHook = getRightElement(deps)(rightElement);
|
@@ -54,18 +53,11 @@ const createAssetConfigurationHook: CreateAssetConfigurationHook =
|
|
54
53
|
|
55
54
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
56
55
|
const hooks = [rightHook, leftHook].filter(Boolean) as Array<
|
57
|
-
(
|
58
|
-
assets: CryptoOrTokenCurrency[],
|
59
|
-
currenciesByProvider?: CurrenciesByProviderId[],
|
60
|
-
) => AssetType[]
|
56
|
+
(assets: CryptoOrTokenCurrency[]) => AssetType[]
|
61
57
|
>;
|
62
58
|
|
63
59
|
return (assets: CryptoOrTokenCurrency[]) => {
|
64
|
-
const composedHook = composeHooks<CryptoOrTokenCurrency, AssetType>(
|
65
|
-
...hooks.map(
|
66
|
-
hook => (assets: CryptoOrTokenCurrency[]) => hook(assets, currenciesByProvider),
|
67
|
-
),
|
68
|
-
);
|
60
|
+
const composedHook = composeHooks<CryptoOrTokenCurrency, AssetType>(...hooks);
|
69
61
|
return composedHook(assets);
|
70
62
|
};
|
71
63
|
};
|
@@ -53,12 +53,7 @@ export const getRightElement =
|
|
53
53
|
|
54
54
|
export const createNetworkConfigurationHook =
|
55
55
|
(NetworkConfigurationDeps: NetworkConfigurationDeps) =>
|
56
|
-
({
|
57
|
-
networksConfig,
|
58
|
-
selectedAssetId,
|
59
|
-
currenciesByProvider,
|
60
|
-
accounts$,
|
61
|
-
}: CreateNetworkConfigurationHookProps) => {
|
56
|
+
({ networksConfig, accounts$ }: CreateNetworkConfigurationHookProps) => {
|
62
57
|
const { leftElement, rightElement } = networksConfig ?? {};
|
63
58
|
const leftHook = getLeftElement(NetworkConfigurationDeps)(leftElement);
|
64
59
|
const rightHook = getRightElement(NetworkConfigurationDeps)(rightElement);
|
@@ -75,8 +70,6 @@ export const createNetworkConfigurationHook =
|
|
75
70
|
hook => () =>
|
76
71
|
hook({
|
77
72
|
assets,
|
78
|
-
selectedAssetId,
|
79
|
-
currenciesByProvider: currenciesByProvider || [],
|
80
73
|
accounts$,
|
81
74
|
networks,
|
82
75
|
}),
|
@@ -10,10 +10,10 @@ import {
|
|
10
10
|
safeCurrencyLookup,
|
11
11
|
} from "../currencyUtils";
|
12
12
|
import {
|
13
|
-
usdcToken,
|
14
13
|
mockBaseCryptoCurrency,
|
15
14
|
mockBtcCryptoCurrency,
|
16
15
|
mockEthCryptoCurrency,
|
16
|
+
usdcToken,
|
17
17
|
} from "../../__mocks__/currencies.mock";
|
18
18
|
|
19
19
|
describe("safeCurrencyLookup", () => {
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { haveOneCommonAsset } from "../haveOneCommonAsset";
|
2
|
+
import { AssetData } from "../type";
|
3
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/lib/currencies";
|
4
|
+
|
5
|
+
const MOCK_ASSETS_SORTED: AssetData[] = [
|
6
|
+
{
|
7
|
+
asset: {
|
8
|
+
id: "ethereum",
|
9
|
+
ticker: "ETH",
|
10
|
+
name: "Ethereum",
|
11
|
+
assetsIds: {
|
12
|
+
ethereum: "ethereum",
|
13
|
+
arbitrum: "arbitrum",
|
14
|
+
},
|
15
|
+
metaCurrencyId: "urn:crypto:meta-currency:ethereum",
|
16
|
+
},
|
17
|
+
networks: [getCryptoCurrencyById("ethereum"), getCryptoCurrencyById("arbitrum")],
|
18
|
+
},
|
19
|
+
{
|
20
|
+
asset: {
|
21
|
+
id: "bitcoin",
|
22
|
+
ticker: "BTC",
|
23
|
+
name: "Bitcoin",
|
24
|
+
assetsIds: {
|
25
|
+
bitcoin: "bitcoin",
|
26
|
+
},
|
27
|
+
metaCurrencyId: "bitcoin",
|
28
|
+
},
|
29
|
+
networks: [getCryptoCurrencyById("bitcoin")],
|
30
|
+
},
|
31
|
+
];
|
32
|
+
|
33
|
+
describe("haveOneCommonAsset", () => {
|
34
|
+
it("should return false for an empty array", () => {
|
35
|
+
expect(haveOneCommonAsset([], [])).toBe(false);
|
36
|
+
});
|
37
|
+
|
38
|
+
it("should return true for a single currency with one provider", () => {
|
39
|
+
expect(haveOneCommonAsset(["bitcoin"], MOCK_ASSETS_SORTED)).toBe(true);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("should return false for multiple currencies with different providers", () => {
|
43
|
+
expect(haveOneCommonAsset(["bitcoin", "ethereum"], MOCK_ASSETS_SORTED)).toBe(false);
|
44
|
+
});
|
45
|
+
|
46
|
+
it("should return true for multiple currencies with the same provider", () => {
|
47
|
+
expect(haveOneCommonAsset(["ethereum", "arbitrum"], MOCK_ASSETS_SORTED)).toBe(true);
|
48
|
+
});
|
49
|
+
});
|
@@ -4,7 +4,6 @@ import { isTokenCurrency } from "../../currencies";
|
|
4
4
|
import { CurrenciesByProviderId } from "../../deposit/type";
|
5
5
|
|
6
6
|
export type ProviderCoverageMap = Map<string, Set<string>>;
|
7
|
-
|
8
7
|
export const safeCurrencyLookup = (id: string): CryptoOrTokenCurrency | null => {
|
9
8
|
try {
|
10
9
|
return getTokenOrCryptoCurrencyById(id);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { AssetData } from "./type";
|
2
2
|
|
3
3
|
/**
|
4
4
|
* This function checks if all currencies in the provided array
|
@@ -8,9 +8,10 @@ import { CurrenciesByProviderId } from "../../deposit/type";
|
|
8
8
|
* @param currenciesByProvider array of currencies grouped by provider
|
9
9
|
* @returns boolean indicating whether all currencies in the array have one common provider
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
|
+
export const haveOneCommonAsset = (
|
12
13
|
currenciesIdsArray: string[],
|
13
|
-
currenciesByProvider:
|
14
|
+
currenciesByProvider: AssetData[],
|
14
15
|
): boolean => {
|
15
16
|
if (currenciesIdsArray.length === 0) return false;
|
16
17
|
|
@@ -18,8 +19,8 @@ export const haveOneCommonProvider = (
|
|
18
19
|
|
19
20
|
for (const currencyId of currenciesIdsArray) {
|
20
21
|
for (const provider of currenciesByProvider) {
|
21
|
-
if (provider.
|
22
|
-
providerIds.add(provider.
|
22
|
+
if (provider.networks.some(currency => currency.id === currencyId)) {
|
23
|
+
providerIds.add(provider.asset.id);
|
23
24
|
if (providerIds.size > 1) {
|
24
25
|
return false;
|
25
26
|
}
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import { isCorrespondingCurrency
|
1
|
+
import { isCorrespondingCurrency } from "./index";
|
2
2
|
|
3
3
|
import { createFixtureCryptoCurrency } from "../../mock/fixtures/cryptoCurrencies";
|
4
4
|
import { cryptocurrenciesById } from "@ledgerhq/cryptoassets";
|
5
5
|
import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
6
|
-
import type { CurrenciesByProviderId } from "../../deposit/type";
|
7
6
|
|
8
7
|
describe("isCorrespondingCurrency", () => {
|
9
8
|
const evmCurrency = createFixtureCryptoCurrency("evm");
|
@@ -42,33 +41,3 @@ describe("isCorrespondingCurrency", () => {
|
|
42
41
|
expect(isCorrespondingCurrency(bitcoinCurrency, evmCurrency)).toBe(false);
|
43
42
|
});
|
44
43
|
});
|
45
|
-
|
46
|
-
describe("getEffectiveCurrency", () => {
|
47
|
-
const parent = createFixtureCryptoCurrency("evm");
|
48
|
-
const token: CryptoOrTokenCurrency = {
|
49
|
-
type: "TokenCurrency",
|
50
|
-
id: "ethereum/erc20/usdc",
|
51
|
-
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
52
|
-
parentCurrency: parent,
|
53
|
-
tokenType: "erc20",
|
54
|
-
name: "USD Coin",
|
55
|
-
ticker: "USDC",
|
56
|
-
units: [{ name: "USD Coin", code: "USDC", magnitude: 6 }],
|
57
|
-
};
|
58
|
-
const provider: CurrenciesByProviderId = {
|
59
|
-
providerId: "provider1",
|
60
|
-
currenciesByNetwork: [parent, token],
|
61
|
-
};
|
62
|
-
|
63
|
-
it("returns currency if id is in currencyIds", () => {
|
64
|
-
expect(getEffectiveCurrency(token, provider, [token.id])).toBe(token);
|
65
|
-
});
|
66
|
-
|
67
|
-
it("returns first matching currency from provider if id not in currencyIds", () => {
|
68
|
-
expect(getEffectiveCurrency(token, provider, [parent.id])).toBe(parent);
|
69
|
-
});
|
70
|
-
|
71
|
-
it("returns currency if no match in provider", () => {
|
72
|
-
expect(getEffectiveCurrency(token, provider, ["notfound"])).toBe(token);
|
73
|
-
});
|
74
|
-
});
|