Skip to content

Commit

Permalink
fix: return correct translation for user refused on device from swap …
Browse files Browse the repository at this point in the history
…live app
  • Loading branch information
kallen-ledger committed Apr 12, 2024
1 parent 0db1bf8 commit 2d57eca
Showing 1 changed file with 25 additions and 12 deletions.
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,10 @@ 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";
import WebviewErrorDrawer, {
SwapLiveError,
} from "~/renderer/screens/exchange/Swap2/Form/WebviewErrorDrawer";

export const AnimationWrapper = styled.div`
width: 600px;
Expand Down Expand Up @@ -581,9 +589,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 +741,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 +772,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 +790,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 2d57eca

Please sign in to comment.