Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion app/core/HardwareWallet/HardwareWalletProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ describe('HardwareWalletProvider', () => {
});

describe('retryEnsureDeviceReady (internal, via bottom sheet props)', () => {
it('transitions to connecting state when retrying', async () => {
it('transitions to connecting state when retrying a connection error', async () => {
const { result } = renderWithActions();

act(() => {
Expand Down Expand Up @@ -552,6 +552,45 @@ describe('HardwareWalletProvider', () => {

expect(mockAdapterInstance.ensureDeviceReady).toHaveBeenCalled();
});

it('closes flow instead of retrying after a signing error', async () => {
const { result } = renderWithActions();

await act(async () => {
result.current.actions.showAwaitingConfirmation('transaction');
});

expect(result.current.state.connectionState.status).toBe(
ConnectionStatus.AwaitingConfirmation,
);

await act(async () => {
result.current.actions.hideAwaitingConfirmation();
});

await act(async () => {
result.current.actions.showHardwareWalletError(
new Error('Signing failed'),
);
});

expect(result.current.state.connectionState.status).toBe(
ConnectionStatus.ErrorState,
);

mockAdapterInstance.ensureDeviceReady.mockClear();

const internalRetry =
capturedBottomSheetProps.retryEnsureDeviceReady as () => Promise<void>;
await act(async () => {
await internalRetry();
});

expect(mockAdapterInstance.ensureDeviceReady).not.toHaveBeenCalled();
expect(result.current.state.connectionState.status).toBe(
ConnectionStatus.Disconnected,
);
});
});
});

Expand Down
16 changes: 14 additions & 2 deletions app/core/HardwareWallet/HardwareWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const HardwareWalletProvider: React.FC<HardwareWalletProviderProps> = ({
});

const handleFlowStart = useCallback(() => {
operationTypeRef.current = null;
resetAnalyticsState();
setAnalyticsFlow(derivedAnalyticsFlowRef.current);
}, [resetAnalyticsState]);
Expand Down Expand Up @@ -151,15 +152,26 @@ export const HardwareWalletProvider: React.FC<HardwareWalletProviderProps> = ({
const hideAwaitingConfirmation = useCallback(() => {
DevLogger.log('[HardwareWallet] hideAwaitingConfirmation');
awaitingConfirmationRejectRef.current = null;
operationTypeRef.current = null;
updateConnectionState({ status: ConnectionStatus.Disconnected });
}, [updateConnectionState]);

const handleCloseFlow = useCallback(() => {
operationTypeRef.current = null;
setAnalyticsFlow(HardwareWalletAnalyticsFlow.Connection);
closeFlow();
}, [closeFlow]);

const handleRetryOrClose = useCallback(async () => {
if (operationTypeRef.current !== null) {
DevLogger.log(
'[HardwareWallet] Post-signing error — closing flow instead of retrying',
);
handleCloseFlow();
return;
}
await retryEnsureDeviceReady();
}, [handleCloseFlow, retryEnsureDeviceReady]);

const handleAwaitingConfirmationCancel = useCallback(() => {
DevLogger.log('[HardwareWallet] handleAwaitingConfirmationCancel');
// eslint-disable-next-line no-empty-function
Expand Down Expand Up @@ -200,7 +212,7 @@ export const HardwareWalletProvider: React.FC<HardwareWalletProviderProps> = ({
connectionState={connectionState}
deviceSelection={deviceSelection}
walletType={effectiveWalletType}
retryEnsureDeviceReady={retryEnsureDeviceReady}
retryEnsureDeviceReady={handleRetryOrClose}
selectDevice={selectDevice}
rescan={rescan}
connect={connect}
Expand Down
Loading