From a738b9801c4ba0e623fd809872794f227bc5ebb2 Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Thu, 21 Nov 2024 16:26:47 +0200 Subject: [PATCH 01/12] feat: display incompatibility for LNS swap --- .../components/DeviceAction/index.tsx | 95 ++++++++++++++----- .../components/DeviceAction/rendering.tsx | 12 ++- .../static/i18n/en/app.json | 8 ++ 3 files changed, 89 insertions(+), 26 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx index eefcc43d6128..72e2f1963e63 100644 --- a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx @@ -1,25 +1,25 @@ -import React, { useEffect, Component } from "react"; +import React, { Component, useEffect } from "react"; import BigNumber from "bignumber.js"; import { Trans, useTranslation } from "react-i18next"; import { useDispatch, useSelector } from "react-redux"; import { Action } from "@ledgerhq/live-common/hw/actions/types"; import { - OutdatedApp, - LatestFirmwareVersionRequired, - NoSuchAppOnProvider, EConnResetError, - LanguageInstallRefusedOnDevice, ImageDoesNotExistOnDevice, + LanguageInstallRefusedOnDevice, + LatestFirmwareVersionRequired, + NoSuchAppOnProvider, + OutdatedApp, } from "@ledgerhq/live-common/errors"; import { getCurrentDevice } from "~/renderer/reducers/devices"; import { - setPreferredDeviceModel, - setLastSeenDeviceInfo, addNewDeviceModel, + setLastSeenDeviceInfo, + setPreferredDeviceModel, } from "~/renderer/actions/settings"; import { - storeSelector as settingsSelector, preferredDeviceModelSelector, + storeSelector as settingsSelector, } from "~/renderer/reducers/settings"; import { DeviceModelId } from "@ledgerhq/devices"; import AutoRepair from "~/renderer/components/AutoRepair"; @@ -28,36 +28,36 @@ import SignMessageConfirm from "~/renderer/components/SignMessageConfirm"; import useTheme from "~/renderer/hooks/useTheme"; import { ManagerNotEnoughSpaceError, + TransportRaceCondition, + UnresponsiveDeviceError, UpdateYourApp, UserRefusedAddress, UserRefusedAllowManager, + UserRefusedDeviceNameChange, UserRefusedFirmwareUpdate, UserRefusedOnDevice, - UserRefusedDeviceNameChange, - UnresponsiveDeviceError, - TransportRaceCondition, } from "@ledgerhq/errors"; import { + DeviceNotOnboardedErrorComponent, + HardwareUpdate, InstallingApp, + renderAllowLanguageInstallation, renderAllowManager, renderAllowOpeningApp, + renderAllowRemoveCustomLockscreen, renderBootloaderStep, renderConnectYourDevice, - renderHardwareUpdate, renderError, + renderInstallingLanguage, renderInWrongAppForAccount, + renderListingApps, renderLoading, + renderLockedDeviceError, renderRequestQuitApp, renderRequiresAppInstallation, - renderListingApps, - renderWarningOutdated, - renderSwapDeviceConfirmation, renderSecureTransferDeviceConfirmation, - renderAllowLanguageInstallation, - renderInstallingLanguage, - renderAllowRemoveCustomLockscreen, - renderLockedDeviceError, - DeviceNotOnboardedErrorComponent, + renderSwapDeviceConfirmation, + renderWarningOutdated, } from "./rendering"; import { useGetSwapTrackingProperties } from "~/renderer/screens/exchange/Swap2/utils"; import { @@ -68,8 +68,8 @@ import { DeviceModelInfo, } from "@ledgerhq/types-live"; import { - ExchangeSwap, ExchangeRate, + ExchangeSwap, InitSwapResult, } from "@ledgerhq/live-common/exchange/swap/types"; import { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; @@ -181,6 +181,42 @@ class OnResult

extends Component<{ payload: P; onResult: (_: P) => void }> { } } +type Keys = Record; + +const INCOMPATIBLE_NANO_S_TOKENS_KEYS: Keys = { + sol: { + title: "swap.incompatibility.spl_tokens_title", + description: "swap.incompatibility.spl_tokens_description", + }, +}; + +const INCOMPATIBLE_NANO_S_CURRENCY_KEYS: Keys = { + ton: { + title: "swap.incompatibility.ton_title", + description: "swap.incompatibility.ton_description", + }, + cardano: { + title: "swap.incompatibility.ada_title", + description: "swap.incompatibility.ada_description", + }, +}; + +const getIncompatibleCurrencyKeys = (request: SwapRequest) => { + const exchange = request?.exchange; + const parentFrom = exchange?.fromParentAccount?.currency?.id || ""; + const parentTo = exchange?.toParentAccount?.currency?.id || ""; + const from = + (exchange?.fromAccount.type === "Account" && exchange?.fromAccount?.currency?.id) || ""; + const to = (exchange?.toAccount.type === "Account" && exchange?.toAccount?.currency?.id) || ""; + + return ( + INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentFrom] || + INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentTo] || + INCOMPATIBLE_NANO_S_CURRENCY_KEYS[from] || + INCOMPATIBLE_NANO_S_CURRENCY_KEYS[to] + ); +}; + export const DeviceActionDefaultRendering = ({ status: hookState, payload, @@ -340,8 +376,21 @@ export const DeviceActionDefaultRendering = ({ } } - if (device?.modelId === "nanoS" && (request as SwapRequest)?.provider === "thorswap") { - return renderHardwareUpdate(); + if (device?.modelId === "nanoS") { + const requestAsSwapRequest = request as SwapRequest; + if (requestAsSwapRequest?.provider === "thorswap") { + return ( + + ); + } else { + const keys = getIncompatibleCurrencyKeys(requestAsSwapRequest); + if (keys) { + return ; + } + } } if (listingApps) { diff --git a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/rendering.tsx b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/rendering.tsx index 1b5e65dd3be1..8209e0eb8117 100644 --- a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/rendering.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/rendering.tsx @@ -954,17 +954,23 @@ const OpenSwapBtn = () => { ); }; -export const renderHardwareUpdate = () => ( +export const HardwareUpdate = ({ + i18nKeyTitle, + i18nKeyDescription, +}: { + i18nKeyTitle: string; + i18nKeyDescription: string; +}) => (

NanoS
- <Trans i18nKey="swap.wrongDevice.title" /> + <Trans i18nKey={i18nKeyTitle} /> - + diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 86ad946374f3..0842e56af4ac 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -442,6 +442,14 @@ "cta": "Explore compatible devices", "changeProvider": "Swap with another provider" }, + "incompatibility": { + "ton_title": "Ledger Nano S™ is not compatible with Ton swap on Ledger Live", + "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "spl_tokens_title": "Ledger Nano S™ is not compatible with Solana tokens on Ledger Live", + "spl_tokens_description": "To transact Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "ada_title": "Ledger Nano S™ is not compatible with ADA swap on Ledger Live", + "ada_description": "To swap ADA through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." + }, "providers": { "title": "Choose a provider to swap crypto", "learnMore": "What is Swap?", From 0c92732d42ad70567ba75d13305c82ad61092d72 Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Thu, 21 Nov 2024 16:29:52 +0200 Subject: [PATCH 02/12] feat: display incompatibility for LNS swap --- .changeset/large-otters-refuse.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/large-otters-refuse.md diff --git a/.changeset/large-otters-refuse.md b/.changeset/large-otters-refuse.md new file mode 100644 index 000000000000..7a554c52a539 --- /dev/null +++ b/.changeset/large-otters-refuse.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": patch +--- + +feat: display incompatibility for LNS swap From 44841be48383033e8e76098a37a0ebc7ede6c4de Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Thu, 21 Nov 2024 16:44:25 +0200 Subject: [PATCH 03/12] feat: display incompatibility for LNS swap --- .../src/renderer/components/DeviceAction/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx index 72e2f1963e63..7dab4491b954 100644 --- a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx @@ -184,7 +184,7 @@ class OnResult

extends Component<{ payload: P; onResult: (_: P) => void }> { type Keys = Record; const INCOMPATIBLE_NANO_S_TOKENS_KEYS: Keys = { - sol: { + solana: { title: "swap.incompatibility.spl_tokens_title", description: "swap.incompatibility.spl_tokens_description", }, From d19e99c31fdf64276daa5ed333365209df717434 Mon Sep 17 00:00:00 2001 From: Andrei Covaciu Date: Fri, 22 Nov 2024 11:48:34 +0200 Subject: [PATCH 04/12] feat: Update .changeset/large-otters-refuse.md --- .changeset/large-otters-refuse.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/large-otters-refuse.md b/.changeset/large-otters-refuse.md index 7a554c52a539..12e2b41386b8 100644 --- a/.changeset/large-otters-refuse.md +++ b/.changeset/large-otters-refuse.md @@ -1,5 +1,5 @@ --- -"ledger-live-desktop": patch +"ledger-live-desktop": minor --- feat: display incompatibility for LNS swap From 395bba552cf0bd47a37563b577dee5b426fdb473 Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Tue, 26 Nov 2024 12:38:25 +0200 Subject: [PATCH 05/12] fix: updates text --- apps/ledger-live-desktop/static/i18n/en/app.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 0842e56af4ac..a33603a07b71 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -444,11 +444,11 @@ }, "incompatibility": { "ton_title": "Ledger Nano S™ is not compatible with Ton swap on Ledger Live", - "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", "spl_tokens_title": "Ledger Nano S™ is not compatible with Solana tokens on Ledger Live", - "spl_tokens_description": "To transact Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "spl_tokens_description": "To transact Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", "ada_title": "Ledger Nano S™ is not compatible with ADA swap on Ledger Live", - "ada_description": "To swap ADA through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nanos S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." + "ada_description": "To swap ADA through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." }, "providers": { "title": "Choose a provider to swap crypto", From 0e281324f9ec3a45d7811053aac45518334f908a Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Wed, 4 Dec 2024 11:04:09 +0200 Subject: [PATCH 06/12] feat: updates text --- apps/ledger-live-desktop/static/i18n/en/app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index a33603a07b71..34bd7bf410c2 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -445,8 +445,8 @@ "incompatibility": { "ton_title": "Ledger Nano S™ is not compatible with Ton swap on Ledger Live", "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", - "spl_tokens_title": "Ledger Nano S™ is not compatible with Solana tokens on Ledger Live", - "spl_tokens_description": "To transact Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "spl_tokens_title": "Ledger Nano S™ does not support swapping Solana tokens through Ledger Live", + "spl_tokens_description": "To swap Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", "ada_title": "Ledger Nano S™ is not compatible with ADA swap on Ledger Live", "ada_description": "To swap ADA through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." }, From c9a403f6ef3c0ba57844dddcaac8b65b6275858a Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Wed, 4 Dec 2024 17:05:23 +0200 Subject: [PATCH 07/12] feat: updates text --- apps/ledger-live-desktop/static/i18n/en/app.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 34bd7bf410c2..83f4c2395e9a 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -443,12 +443,12 @@ "changeProvider": "Swap with another provider" }, "incompatibility": { - "ton_title": "Ledger Nano S™ is not compatible with Ton swap on Ledger Live", - "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "ton_title": "Ledger Nano S™ does not support swapping Ton through Ledger Live", + "ton_description": "To swap Ton through Ledger Live, use any other compatible Ledger device, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", "spl_tokens_title": "Ledger Nano S™ does not support swapping Solana tokens through Ledger Live", - "spl_tokens_description": "To swap Solana tokens through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", - "ada_title": "Ledger Nano S™ is not compatible with ADA swap on Ledger Live", - "ada_description": "To swap ADA through Ledger Live, use any other compatible Ledger devices, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." + "spl_tokens_description": "To swap Solana tokens through Ledger Live, use any other compatible Ledger device, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™.", + "ada_title": "Ledger Nano S™ does not support swapping Cardano through Ledger Live", + "ada_description": "To swap Cardano through Ledger Live, use any other compatible Ledger device, such as the Ledger Nano S Plus™, Ledger Nano X™, Ledger Flex™ or Ledger Stax™." }, "providers": { "title": "Choose a provider to swap crypto", From 3decec37e67a6b2270d1ec23268b770e23bdf359 Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Thu, 5 Dec 2024 15:58:50 +0200 Subject: [PATCH 08/12] feat: updates based on review --- .../components/DeviceAction/index.tsx | 58 ++---------- .../src/renderer/components/LiveAppDrawer.tsx | 91 ++++++++++++++----- 2 files changed, 77 insertions(+), 72 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx index 7dab4491b954..a96f71a35fed 100644 --- a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx @@ -181,42 +181,6 @@ class OnResult

extends Component<{ payload: P; onResult: (_: P) => void }> { } } -type Keys = Record; - -const INCOMPATIBLE_NANO_S_TOKENS_KEYS: Keys = { - solana: { - title: "swap.incompatibility.spl_tokens_title", - description: "swap.incompatibility.spl_tokens_description", - }, -}; - -const INCOMPATIBLE_NANO_S_CURRENCY_KEYS: Keys = { - ton: { - title: "swap.incompatibility.ton_title", - description: "swap.incompatibility.ton_description", - }, - cardano: { - title: "swap.incompatibility.ada_title", - description: "swap.incompatibility.ada_description", - }, -}; - -const getIncompatibleCurrencyKeys = (request: SwapRequest) => { - const exchange = request?.exchange; - const parentFrom = exchange?.fromParentAccount?.currency?.id || ""; - const parentTo = exchange?.toParentAccount?.currency?.id || ""; - const from = - (exchange?.fromAccount.type === "Account" && exchange?.fromAccount?.currency?.id) || ""; - const to = (exchange?.toAccount.type === "Account" && exchange?.toAccount?.currency?.id) || ""; - - return ( - INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentFrom] || - INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentTo] || - INCOMPATIBLE_NANO_S_CURRENCY_KEYS[from] || - INCOMPATIBLE_NANO_S_CURRENCY_KEYS[to] - ); -}; - export const DeviceActionDefaultRendering = ({ status: hookState, payload, @@ -376,21 +340,13 @@ export const DeviceActionDefaultRendering = ({ } } - if (device?.modelId === "nanoS") { - const requestAsSwapRequest = request as SwapRequest; - if (requestAsSwapRequest?.provider === "thorswap") { - return ( - - ); - } else { - const keys = getIncompatibleCurrencyKeys(requestAsSwapRequest); - if (keys) { - return ; - } - } + if (device?.modelId === "nanoS" && (request as SwapRequest)?.provider === "thorswap") { + return ( + + ); } if (listingApps) { diff --git a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx index bb20bc94266d..cd114ae02fec 100644 --- a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback, useMemo } from "react"; +import React, { useCallback, useMemo, useState } from "react"; import styled from "styled-components"; import { useDispatch, useSelector } from "react-redux"; import { useTranslation } from "react-i18next"; @@ -29,8 +29,10 @@ import CompleteExchange, { isCompleteExchangeData, } from "~/renderer/modals/Platform/Exchange/CompleteExchange/Body"; import { ExchangeType } from "@ledgerhq/live-common/wallet-api/Exchange/server"; -import { Exchange } from "@ledgerhq/live-common/exchange/types"; -import { renderLoading } from "./DeviceAction/rendering"; +import { Exchange, isExchangeSwap } from "@ledgerhq/live-common/exchange/types"; +import { HardwareUpdate, renderLoading } from "./DeviceAction/rendering"; +import { getCurrentDevice } from "~/renderer/reducers/devices"; +import { ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types"; const Divider = styled(Box)` border: 1px solid ${p => p.theme.colors.palette.divider}; @@ -60,10 +62,45 @@ export function isStartExchangeData(data: unknown): data is StartExchangeData { return "exchangeType" in data; } +type Keys = Record; + +const INCOMPATIBLE_NANO_S_TOKENS_KEYS: Keys = { + solana: { + title: "swap.incompatibility.spl_tokens_title", + description: "swap.incompatibility.spl_tokens_description", + }, +}; + +const INCOMPATIBLE_NANO_S_CURRENCY_KEYS: Keys = { + ton: { + title: "swap.incompatibility.ton_title", + description: "swap.incompatibility.ton_description", + }, + cardano: { + title: "swap.incompatibility.ada_title", + description: "swap.incompatibility.ada_description", + }, +}; +const getIncompatibleCurrencyKeys = (exchange: ExchangeSwap) => { + const parentFrom = exchange?.fromParentAccount?.currency?.id || ""; + const parentTo = exchange?.toParentAccount?.currency?.id || ""; + const from = + (exchange?.fromAccount.type === "Account" && exchange?.fromAccount?.currency?.id) || ""; + const to = (exchange?.toAccount.type === "Account" && exchange?.toAccount?.currency?.id) || ""; + + return ( + INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentFrom] || + INCOMPATIBLE_NANO_S_TOKENS_KEYS[parentTo] || + INCOMPATIBLE_NANO_S_CURRENCY_KEYS[from] || + INCOMPATIBLE_NANO_S_CURRENCY_KEYS[to] + ); +}; + export const LiveAppDrawer = () => { const [dismissDisclaimerChecked, setDismissDisclaimerChecked] = useState(false); const { t } = useTranslation(); const dispatch = useDispatch(); + const device = useSelector(getCurrentDevice); // @ts-expect-error how to type payload? const { @@ -156,23 +193,35 @@ export const LiveAppDrawer = () => { ); - case "EXCHANGE_START": - return data && isStartExchangeData(data) ? ( - renderLoading()} - onResult={result => { - if ("startExchangeResult" in result) { - data.onResult(result.startExchangeResult); - } - if ("startExchangeError" in result) { - data.onCancel?.(result.startExchangeError); - dispatch(closePlatformAppDrawer()); - } - }} - /> - ) : null; + case "EXCHANGE_START": { + if (data && isStartExchangeData(data)) { + if (device?.modelId === "nanoS" && data.exchange && isExchangeSwap(data.exchange)) { + const keys = getIncompatibleCurrencyKeys(data.exchange); + if (keys) { + return ( + + ); + } + } + return ( + renderLoading()} + onResult={result => { + if ("startExchangeResult" in result) { + data.onResult(result.startExchangeResult); + } + if ("startExchangeError" in result) { + data.onCancel?.(result.startExchangeError); + dispatch(closePlatformAppDrawer()); + } + }} + /> + ); + } + return null; + } case "EXCHANGE_COMPLETE": return data && isCompleteExchangeData(data) ? ( { default: return null; } - }, [payload, t, dismissDisclaimerChecked, onContinue, dispatch]); + }, [payload, t, dismissDisclaimerChecked, onContinue, device?.modelId, dispatch]); return ( Date: Thu, 5 Dec 2024 17:17:12 +0200 Subject: [PATCH 09/12] feat: updates based on review --- .../renderer/components/DeviceAction/index.tsx | 18 ------------------ .../src/renderer/components/LiveAppDrawer.tsx | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx index 3ea52492c520..62a32ede3273 100644 --- a/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx @@ -39,7 +39,6 @@ import { } from "@ledgerhq/errors"; import { DeviceNotOnboardedErrorComponent, - HardwareUpdate, InstallingApp, renderAllowLanguageInstallation, renderAllowManager, @@ -83,14 +82,6 @@ import { walletSelector } from "~/renderer/reducers/wallet"; type LedgerError = InstanceType>; -type SwapRequest = { - transaction: Transaction; - exchange: ExchangeSwap; - provider: string; - rate: number; - amountExpectedTo: number; -}; - type PartialNullable = { [P in keyof T]?: T[P] | null; }; @@ -340,15 +331,6 @@ export const DeviceActionDefaultRendering = ({ } } - if (device?.modelId === "nanoS" && (request as SwapRequest)?.provider === "thorswap") { - return ( - - ); - } - if (listingApps) { return renderListingApps(); } diff --git a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx index 49c807fafe06..f11577eef1b7 100644 --- a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx @@ -34,6 +34,7 @@ import { HardwareUpdate, renderLoading } from "./DeviceAction/rendering"; import { createCustomErrorClass } from "@ledgerhq/errors"; import { getCurrentDevice } from "~/renderer/reducers/devices"; import { ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types"; +import { Transaction } from "@ledgerhq/live-common/generated/types"; const Divider = styled(Box)` border: 1px solid ${p => p.theme.colors.palette.divider}; @@ -56,6 +57,14 @@ export type StartExchangeData = { onResult: (startExchangeResult: StartExchangeSuccessResult) => void; }; +type SwapRequest = { + transaction: Transaction; + exchange: ExchangeSwap; + provider: string; + rate: number; + amountExpectedTo: number; +}; + export function isStartExchangeData(data: unknown): data is StartExchangeData { if (data === null || typeof data !== "object") { return false; @@ -199,6 +208,14 @@ export const LiveAppDrawer = () => { case "EXCHANGE_START": { if (data && isStartExchangeData(data)) { if (device?.modelId === "nanoS" && data.exchange && isExchangeSwap(data.exchange)) { + if (data.provider === "thorswap") { + return ( + + ); + } const keys = getIncompatibleCurrencyKeys(data.exchange); if (keys) { return ( From 04eaaf3eef0fdfc0a4e8946f6de9b1c1e788fe4d Mon Sep 17 00:00:00 2001 From: Quentin Jaccarino Date: Fri, 6 Dec 2024 09:20:02 +0100 Subject: [PATCH 10/12] Update apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx --- .../src/renderer/components/LiveAppDrawer.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx index f11577eef1b7..0fb51fd32f96 100644 --- a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx @@ -57,13 +57,6 @@ export type StartExchangeData = { onResult: (startExchangeResult: StartExchangeSuccessResult) => void; }; -type SwapRequest = { - transaction: Transaction; - exchange: ExchangeSwap; - provider: string; - rate: number; - amountExpectedTo: number; -}; export function isStartExchangeData(data: unknown): data is StartExchangeData { if (data === null || typeof data !== "object") { From 096b2765abb08aff25b27c5c8c0809395c3e590c Mon Sep 17 00:00:00 2001 From: Quentin Jaccarino Date: Fri, 6 Dec 2024 09:20:19 +0100 Subject: [PATCH 11/12] Update apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx --- .../src/renderer/components/LiveAppDrawer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx index 0fb51fd32f96..3c5a86352191 100644 --- a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx @@ -57,7 +57,6 @@ export type StartExchangeData = { onResult: (startExchangeResult: StartExchangeSuccessResult) => void; }; - export function isStartExchangeData(data: unknown): data is StartExchangeData { if (data === null || typeof data !== "object") { return false; From 3ffe0541ea2534a243736197096f4c1c0d9e4dae Mon Sep 17 00:00:00 2001 From: andreicovaciu Date: Fri, 6 Dec 2024 11:37:47 +0200 Subject: [PATCH 12/12] fix: lint --- .../src/renderer/components/LiveAppDrawer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx index 3c5a86352191..ac7e7f3c78ef 100644 --- a/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/LiveAppDrawer.tsx @@ -34,7 +34,6 @@ import { HardwareUpdate, renderLoading } from "./DeviceAction/rendering"; import { createCustomErrorClass } from "@ledgerhq/errors"; import { getCurrentDevice } from "~/renderer/reducers/devices"; import { ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types"; -import { Transaction } from "@ledgerhq/live-common/generated/types"; const Divider = styled(Box)` border: 1px solid ${p => p.theme.colors.palette.divider};