@ledgerhq/live-common 34.44.0 → 34.45.0-nightly.1
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/alpaca/network/network-alpaca.d.ts +3 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib/device/use-cases/listAppsUseCase.test.js +2 -2
- package/lib/device/use-cases/listAppsUseCase.test.js.map +1 -1
- package/lib/deviceSDK/tasks/core.d.ts +1 -0
- package/lib/deviceSDK/tasks/core.d.ts.map +1 -1
- package/lib/deviceSDK/tasks/core.js +3 -2
- package/lib/deviceSDK/tasks/core.js.map +1 -1
- package/lib/e2e/index.d.ts +3 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/exchange/index.d.ts.map +1 -1
- package/lib/exchange/index.js +1 -0
- package/lib/exchange/index.js.map +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +22 -10
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -1
- package/lib/exchange/swap/hooks/wrapper.d.ts +3 -0
- package/lib/exchange/swap/hooks/wrapper.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/wrapper.js +40 -0
- package/lib/exchange/swap/hooks/wrapper.js.map +1 -0
- package/lib/exchange/swap/postSwapState.d.ts.map +1 -1
- package/lib/exchange/swap/postSwapState.js +63 -4
- package/lib/exchange/swap/postSwapState.js.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.d.ts +4 -1
- package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.js +7 -1
- package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib/exchange/swap/types.d.ts +7 -0
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/families/evm/config.d.ts.map +1 -1
- package/lib/families/evm/config.js +8 -2
- package/lib/families/evm/config.js.map +1 -1
- package/lib/families/stellar/ui.d.ts.map +1 -1
- package/lib/families/stellar/ui.js +8 -2
- package/lib/families/stellar/ui.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hw/customLockScreenLoad.d.ts +1 -9
- package/lib/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib/hw/customLockScreenLoad.js +5 -1
- package/lib/hw/customLockScreenLoad.js.map +1 -1
- package/lib/hw/hooks/useGenuineCheck.d.ts +2 -1
- package/lib/hw/hooks/useGenuineCheck.d.ts.map +1 -1
- package/lib/hw/hooks/useGenuineCheck.js +10 -2
- package/lib/hw/hooks/useGenuineCheck.js.map +1 -1
- package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts +20 -0
- package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +1 -0
- package/lib/modularDrawer/utils/getBalanceAndFiatValue.js +39 -0
- package/lib/modularDrawer/utils/getBalanceAndFiatValue.js.map +1 -0
- package/lib/modularDrawer/utils/index.d.ts +2 -1
- package/lib/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib/modularDrawer/utils/index.js +3 -1
- package/lib/modularDrawer/utils/index.js.map +1 -1
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +10 -0
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib-es/device/use-cases/listAppsUseCase.test.js +1 -1
- package/lib-es/device/use-cases/listAppsUseCase.test.js.map +1 -1
- package/lib-es/deviceSDK/tasks/core.d.ts +1 -0
- package/lib-es/deviceSDK/tasks/core.d.ts.map +1 -1
- package/lib-es/deviceSDK/tasks/core.js +1 -1
- package/lib-es/deviceSDK/tasks/core.js.map +1 -1
- package/lib-es/e2e/index.d.ts +3 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/exchange/index.d.ts.map +1 -1
- package/lib-es/exchange/index.js +1 -0
- package/lib-es/exchange/index.js.map +1 -1
- package/lib-es/exchange/swap/hooks/usePickDefaultAccount.test.js +21 -9
- package/lib-es/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -1
- package/lib-es/exchange/swap/hooks/wrapper.d.ts +3 -0
- package/lib-es/exchange/swap/hooks/wrapper.d.ts.map +1 -0
- package/lib-es/exchange/swap/hooks/wrapper.js +13 -0
- package/lib-es/exchange/swap/hooks/wrapper.js.map +1 -0
- package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
- package/lib-es/exchange/swap/postSwapState.js +63 -4
- package/lib-es/exchange/swap/postSwapState.js.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +4 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.js +7 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib-es/exchange/swap/types.d.ts +7 -0
- package/lib-es/exchange/swap/types.d.ts.map +1 -1
- package/lib-es/families/evm/config.d.ts.map +1 -1
- package/lib-es/families/evm/config.js +8 -2
- package/lib-es/families/evm/config.js.map +1 -1
- package/lib-es/families/stellar/ui.d.ts.map +1 -1
- package/lib-es/families/stellar/ui.js +8 -2
- package/lib-es/families/stellar/ui.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +1 -0
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hw/customLockScreenLoad.d.ts +1 -9
- package/lib-es/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib-es/hw/customLockScreenLoad.js +5 -1
- package/lib-es/hw/customLockScreenLoad.js.map +1 -1
- package/lib-es/hw/hooks/useGenuineCheck.d.ts +2 -1
- package/lib-es/hw/hooks/useGenuineCheck.d.ts.map +1 -1
- package/lib-es/hw/hooks/useGenuineCheck.js +10 -2
- package/lib-es/hw/hooks/useGenuineCheck.js.map +1 -1
- package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts +20 -0
- package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js +32 -0
- package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js.map +1 -0
- package/lib-es/modularDrawer/utils/index.d.ts +2 -1
- package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
- package/lib-es/modularDrawer/utils/index.js +2 -1
- package/lib-es/modularDrawer/utils/index.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +10 -0
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/package.json +73 -73
- package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +10 -0
- package/src/device/use-cases/listAppsUseCase.test.ts +1 -1
- package/src/deviceSDK/tasks/core.ts +1 -1
- package/src/exchange/index.ts +1 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +25 -12
- package/src/exchange/swap/hooks/wrapper.tsx +18 -0
- package/src/exchange/swap/postSwapState.ts +97 -2
- package/src/exchange/swap/setBroadcastTransaction.ts +12 -0
- package/src/exchange/swap/types.ts +7 -0
- package/src/families/evm/config.ts +8 -2
- package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +283 -3
- package/src/families/stellar/ui.ts +10 -3
- package/src/featureFlags/defaultFeatures.ts +1 -0
- package/src/hw/customLockScreenLoad.ts +7 -11
- package/src/hw/hooks/useGenuineCheck.ts +15 -4
- package/src/modularDrawer/utils/getBalanceAndFiatValue.ts +53 -0
- package/src/modularDrawer/utils/index.ts +7 -1
- package/src/wallet-api/Exchange/server.ts +10 -0
@@ -7,6 +7,8 @@ import type {
|
|
7
7
|
GetGenuineCheckFromDeviceIdResult,
|
8
8
|
GetGenuineCheckFromDeviceIdOutput,
|
9
9
|
} from "../getGenuineCheckFromDeviceId";
|
10
|
+
import { isDmkError } from "../../deviceSDK/tasks/core";
|
11
|
+
import { DmkError } from "@ledgerhq/device-management-kit";
|
10
12
|
|
11
13
|
export type GenuineState = "unchecked" | "genuine" | "non-genuine";
|
12
14
|
export type DevicePermissionState =
|
@@ -33,7 +35,7 @@ export type UseGenuineCheckDependencies = {
|
|
33
35
|
export type UseGenuineCheckResult = {
|
34
36
|
genuineState: GenuineState;
|
35
37
|
devicePermissionState: DevicePermissionState;
|
36
|
-
error: Error | null;
|
38
|
+
error: Error | DmkError | null;
|
37
39
|
resetGenuineCheckState: () => void;
|
38
40
|
};
|
39
41
|
|
@@ -46,6 +48,9 @@ const clearTimeoutRef = (timeoutRef: MutableRefObject<NodeJS.Timeout | null>) =>
|
|
46
48
|
}
|
47
49
|
};
|
48
50
|
|
51
|
+
const isDmkDeviceDisconnectedError = (e: unknown): e is DmkError =>
|
52
|
+
isDmkError(e) && e._tag === "DeviceDisconnectedWhileSendingError";
|
53
|
+
|
49
54
|
/**
|
50
55
|
* Hook to check that a device is genuine
|
51
56
|
* It replaces a DeviceAction if we're only interested in getting the genuine check
|
@@ -71,7 +76,7 @@ export const useGenuineCheck = ({
|
|
71
76
|
const [genuineState, setGenuineState] = useState<GenuineState>("unchecked");
|
72
77
|
const [devicePermissionState, setDevicePermissionState] =
|
73
78
|
useState<DevicePermissionState>("unrequested");
|
74
|
-
const [error, setError] = useState<Error | null>(null);
|
79
|
+
const [error, setError] = useState<Error | DmkError | null>(null);
|
75
80
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
76
81
|
|
77
82
|
const resetGenuineCheckState = useCallback(() => {
|
@@ -126,7 +131,7 @@ export const useGenuineCheck = ({
|
|
126
131
|
clearTimeoutRef(timeoutRef);
|
127
132
|
if (e instanceof UserRefusedAllowManager) {
|
128
133
|
setDevicePermissionState("refused");
|
129
|
-
} else if (e instanceof Error) {
|
134
|
+
} else if (e instanceof Error || isDmkDeviceDisconnectedError(e)) {
|
130
135
|
// Probably an error of type DisconnectedDeviceDuringOperation or something else
|
131
136
|
setError(e);
|
132
137
|
} else {
|
@@ -138,7 +143,13 @@ export const useGenuineCheck = ({
|
|
138
143
|
return () => {
|
139
144
|
sub.unsubscribe();
|
140
145
|
};
|
141
|
-
}, [
|
146
|
+
}, [
|
147
|
+
isHookEnabled,
|
148
|
+
deviceId,
|
149
|
+
lockedDeviceTimeoutMs,
|
150
|
+
getGenuineCheckFromDeviceId,
|
151
|
+
permissionTimeoutMs,
|
152
|
+
]);
|
142
153
|
|
143
154
|
return {
|
144
155
|
genuineState,
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
2
|
+
import { isAccount } from "@ledgerhq/coin-framework/account/helpers";
|
3
|
+
import {
|
4
|
+
getPortfolioCount,
|
5
|
+
getBalanceHistoryWithCountervalue,
|
6
|
+
} from "@ledgerhq/live-countervalues/portfolio";
|
7
|
+
import type { CounterValuesState } from "@ledgerhq/live-countervalues/types";
|
8
|
+
import { Currency } from "@ledgerhq/types-cryptoassets";
|
9
|
+
import { Account, TokenAccount } from "@ledgerhq/types-live";
|
10
|
+
import BigNumber from "bignumber.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
*
|
14
|
+
* @param account - The account to get the balance and fiat value for
|
15
|
+
* @param state - The current state of countervalues
|
16
|
+
* @param toCurrency - The currency to convert to
|
17
|
+
* @param discreet - Whether to show the balance in discreet mode
|
18
|
+
* @param showCode - Whether to show the currency code in the formatted balance
|
19
|
+
* @returns An object containing the balance and fiat value
|
20
|
+
*/
|
21
|
+
export const getBalanceAndFiatValue = (
|
22
|
+
account: Account | TokenAccount,
|
23
|
+
state: CounterValuesState,
|
24
|
+
toCurrency: Currency,
|
25
|
+
discreet: boolean = false,
|
26
|
+
showCode: boolean = true,
|
27
|
+
) => {
|
28
|
+
const isAnAccount = isAccount(account);
|
29
|
+
const details = isAnAccount ? account.currency : account.token;
|
30
|
+
const balance = formatCurrencyUnit(details.units[0], account.balance, {
|
31
|
+
showCode,
|
32
|
+
discreet,
|
33
|
+
});
|
34
|
+
|
35
|
+
const count = getPortfolioCount([account], "day");
|
36
|
+
const { history, countervalueAvailable } = getBalanceHistoryWithCountervalue(
|
37
|
+
account,
|
38
|
+
"day",
|
39
|
+
count,
|
40
|
+
state,
|
41
|
+
toCurrency,
|
42
|
+
);
|
43
|
+
|
44
|
+
if (!countervalueAvailable) return { balance, fiatValue: undefined };
|
45
|
+
|
46
|
+
const { countervalue } = history[history.length - 1] ?? {};
|
47
|
+
const fiatValue = formatCurrencyUnit(toCurrency.units[0], BigNumber(countervalue ?? 0), {
|
48
|
+
showCode,
|
49
|
+
discreet,
|
50
|
+
});
|
51
|
+
|
52
|
+
return { balance, fiatValue };
|
53
|
+
};
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
2
2
|
import { CurrenciesByProviderId } from "../../deposit/type";
|
3
3
|
import { haveOneCommonProvider } from "./haveOneCommonProvider";
|
4
|
+
import { getBalanceAndFiatValue } from "./getBalanceAndFiatValue";
|
4
5
|
|
5
6
|
function isCorrespondingCurrency(
|
6
7
|
elem: CryptoOrTokenCurrency,
|
@@ -27,4 +28,9 @@ const getEffectiveCurrency = (
|
|
27
28
|
return provider.currenciesByNetwork.find(elem => currencyIds.includes(elem.id)) ?? currency;
|
28
29
|
};
|
29
30
|
|
30
|
-
export {
|
31
|
+
export {
|
32
|
+
isCorrespondingCurrency,
|
33
|
+
getEffectiveCurrency,
|
34
|
+
haveOneCommonProvider,
|
35
|
+
getBalanceAndFiatValue,
|
36
|
+
};
|
@@ -571,6 +571,9 @@ export const handlers = ({
|
|
571
571
|
targetCurrencyId: toCurrency?.id,
|
572
572
|
hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
|
573
573
|
swapAppVersion,
|
574
|
+
fromAccountId: fromAccount.id,
|
575
|
+
toAccountId: toAccount?.id,
|
576
|
+
amount: amountExpectedTo.toString(),
|
574
577
|
});
|
575
578
|
|
576
579
|
resolve({ operationHash, swapId });
|
@@ -587,6 +590,13 @@ export const handlers = ({
|
|
587
590
|
hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
|
588
591
|
swapType: quoteId ? "fixed" : "float",
|
589
592
|
swapAppVersion,
|
593
|
+
fromAccountId: fromAccount.id,
|
594
|
+
toAccountId: toAccount?.id,
|
595
|
+
refundAddress,
|
596
|
+
payoutAddress,
|
597
|
+
amount: amountExpectedTo.toString(),
|
598
|
+
seedIdFrom: mainFromAccount.seedIdentifier,
|
599
|
+
seedIdTo: toParentAccount?.seedIdentifier || (toAccount as Account)?.seedIdentifier,
|
590
600
|
});
|
591
601
|
|
592
602
|
reject(error);
|