Skip to content

Commit

Permalink
[bugfix/LIVE-11512]: return correct translation for user refused on d…
Browse files Browse the repository at this point in the history
…evice from swap-live-app (#6665)

* fix: return correct translation for user refused on device from swap live app

* chore: add changeset

* bugfix: lint

---------

Co-authored-by: Chuck Ng <[email protected]>
  • Loading branch information
kallen-ledger and cng-ledger committed Apr 22, 2024
1 parent 1b17628 commit 07d85e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-llamas-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Correct translations for user refused from swap-live-app
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
LockedDeviceError,
FirmwareNotRecognized,
} from "@ledgerhq/errors";
import { LatestFirmwareVersionRequired, DeviceNotOnboarded } from "@ledgerhq/live-common/errors";
import {
LatestFirmwareVersionRequired,
DeviceNotOnboarded,
TransactionRefusedOnDevice,
} from "@ledgerhq/live-common/errors";
import { DeviceModelId, getDeviceModel } from "@ledgerhq/devices";
import { Device } from "@ledgerhq/live-common/hw/actions/types";
import {
Expand Down Expand Up @@ -67,6 +71,7 @@ import Installing from "~/renderer/modals/UpdateFirmwareModal/Installing";
import { ErrorBody } from "../ErrorBody";
import LinkWithExternalIcon from "../LinkWithExternalIcon";
import { closePlatformAppDrawer } from "~/renderer/actions/UI";
import { CompleteExchangeError } from "@ledgerhq/live-common/exchange/error";

export const AnimationWrapper = styled.div`
width: 600px;
Expand Down Expand Up @@ -581,9 +586,9 @@ export const renderWarningOutdated = ({
</Wrapper>
);

// Quick fix: the error LockedDeviceError should be catched
// Quick fix: the tmpError LockedDeviceError should be catched
// inside all the device actions and mapped to an event of type "lockedDevice".
// With this fix, we can catch all the device action error that were not catched upstream.
// With this fix, we can catch all the device action tmpError that were not catched upstream.
// If LockedDeviceError is thrown from outside a device action and renderError was not called
// it is still handled by GenericErrorView.
export const renderLockedDeviceError = ({
Expand Down Expand Up @@ -733,18 +738,23 @@ export const renderError = ({
withDescription?: boolean;
Icon?: (props: { color?: string | undefined; size?: number | undefined }) => JSX.Element;
}) => {
let tmpError = error;
// Redirects from renderError and not from DeviceActionDefaultRendering because renderError
// can be used directly by other component
if (error instanceof LockedDeviceError) {
if (tmpError instanceof LockedDeviceError) {
return renderLockedDeviceError({ t, onRetry, device, inlineRetry });
} else if (error instanceof DeviceNotOnboarded) {
} else if (tmpError instanceof DeviceNotOnboarded) {
return <DeviceNotOnboardedErrorComponent t={t} device={device} />;
} else if (error instanceof FirmwareNotRecognized) {
} else if (tmpError instanceof FirmwareNotRecognized) {
return <FirmwareNotRecognizedErrorComponent onRetry={onRetry} />;
} else if (tmpError instanceof CompleteExchangeError) {
if (tmpError.message === "User refused") {
tmpError = new TransactionRefusedOnDevice();
}
}

// if no supportLink is provided, we fallback on the related url linked to
// error name, if any
// tmpError name, if any
const supportLinkUrl = supportLink ?? urls.errors[error?.name];

return (
Expand All @@ -759,16 +769,16 @@ export const renderError = ({
</Logo>
)
}
title={<TranslatedError error={error as unknown as Error} noLink />}
title={<TranslatedError error={tmpError as unknown as Error} noLink />}
description={
withDescription && (
<TranslatedError error={error as unknown as Error} field="description" />
<TranslatedError error={tmpError as unknown as Error} field="description" />
)
}
list={
list ? (
<ol style={{ textAlign: "justify" }}>
<TranslatedError error={error as unknown as Error} field="list" />
<TranslatedError error={tmpError as unknown as Error} field="list" />
</ol>
) : undefined
}
Expand All @@ -777,8 +787,8 @@ export const renderError = ({
{managerAppName || requireFirmwareUpdate ? (
<OpenManagerButton
appName={managerAppName}
updateApp={error instanceof UpdateYourApp}
firmwareUpdate={error instanceof LatestFirmwareVersionRequired}
updateApp={tmpError instanceof UpdateYourApp}
firmwareUpdate={tmpError instanceof LatestFirmwareVersionRequired}
/>
) : (
<>
Expand Down

0 comments on commit 07d85e8

Please sign in to comment.