Skip to content

Commit

Permalink
fix: fix bug with sending ordinals from ledger, #ref 5253
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Apr 19, 2024
1 parent f050237 commit 06aef60
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions src/app/features/ledger/hooks/use-ledger-navigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export function useLedgerNavigate() {
return navigate(RouteUrls.ConnectLedger, {
replace: true,
relative: 'route',
state: { tx: bytesToHex(psbt), inputsToSign },
state: {
tx: bytesToHex(psbt),
inputsToSign,
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

Expand All @@ -59,55 +63,101 @@ export function useLedgerNavigate() {
},

toConnectionSuccessStep(chain: SupportedBlockchains) {
return navigate(RouteUrls.ConnectLedgerSuccess, { replace: true, state: { chain } });
return navigate(RouteUrls.ConnectLedgerSuccess, {
replace: true,
state: {
chain,
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toErrorStep(chain: SupportedBlockchains, errorMessage?: string) {
return navigate(RouteUrls.ConnectLedgerError, {
replace: true,
state: { latestLedgerError: errorMessage, chain },
state: {
latestLedgerError: errorMessage,
chain,
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toAwaitingDeviceOperation({ hasApprovedOperation }: { hasApprovedOperation: boolean }) {
return navigate(RouteUrls.AwaitingDeviceUserAction, {
replace: true,
state: { hasApprovedOperation },
state: {
hasApprovedOperation,
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toPublicKeyMismatchStep() {
return navigate(RouteUrls.LedgerPublicKeyMismatch, { replace: true });
return navigate(RouteUrls.LedgerPublicKeyMismatch, {
replace: true,
state: {
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toDevicePayloadInvalid() {
return navigate(RouteUrls.LedgerDevicePayloadInvalid, { replace: true });
return navigate(RouteUrls.LedgerDevicePayloadInvalid, {
replace: true,
state: {
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toOperationRejectedStep(description?: string) {
return navigate(RouteUrls.LedgerOperationRejected, {
replace: true,
state: { description },
state: {
backgroundLocation: { pathname: RouteUrls.Home },
description,
},
});
},

toDeviceDisconnectStep() {
return navigate(RouteUrls.LedgerDisconnected, { replace: true });
return navigate(RouteUrls.LedgerDisconnected, {
replace: true,
state: {
backgroundLocation: { pathname: RouteUrls.Home },
},
});
},

toBroadcastErrorStep(error: string) {
return navigate(RouteUrls.LedgerBroadcastError, { replace: true, state: { error } });
return navigate(RouteUrls.LedgerBroadcastError, {
replace: true,
state: {
backgroundLocation: { pathname: RouteUrls.Home },
error,
},
});
},

cancelLedgerAction() {
return navigate('..', { relative: 'path', replace: true, state: { ...location.state } });
// for send ordinal '..' brings you back to the `choose-fee` step but you lose context of the ordinal
const backLocation = location.pathname.match(RouteUrls.SendOrdinalInscription)
? RouteUrls.Home
: '..';

return navigate(backLocation, {
relative: 'path',
replace: true,
state: { ...location.state },
});
},

cancelLedgerActionAndReturnHome() {
return navigate(RouteUrls.Home);
},
}),

[location.state, navigate]
[location, navigate]
);
}

0 comments on commit 06aef60

Please sign in to comment.