Skip to content

Commit

Permalink
fix(suite): cancel passphrase during confirmation (#12460)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson authored May 17, 2024
1 parent c00f008 commit 3afd251
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useCallback, useState } from 'react';
import { useIntl } from 'react-intl';

import { PassphraseTypeCard } from '@trezor/components';
import TrezorConnect from '@trezor/connect';
Expand All @@ -9,12 +8,12 @@ import {
selectDevices,
onPassphraseSubmit,
selectDeviceModel,
deviceActions,
} from '@suite-common/wallet-core';
import { useSelector, useDispatch } from 'src/hooks/suite';
import { Translation } from 'src/components/suite';
import type { TrezorDevice } from 'src/types/suite';
import { OpenGuideFromTooltip } from 'src/components/guide';
import messages from 'src/support/messages';
import { SwitchDeviceRenderer } from 'src/views/suite/SwitchDevice/SwitchDeviceRenderer';
import { CardWithDevice } from 'src/views/suite/SwitchDevice/CardWithDevice';
import { PassphraseDescription } from './PassphraseDescription';
Expand All @@ -28,13 +27,16 @@ interface PassphraseModalProps {
export const PassphraseModal = ({ device }: PassphraseModalProps) => {
const [submitted, setSubmitted] = useState(false);
const devices = useSelector(selectDevices);

const authConfirmation =
useSelector(selectIsDiscoveryAuthConfirmationRequired) || device.authConfirm;

const deviceModel = useSelector(selectDeviceModel);
const stateConfirmation = !!device.state;
const hasEmptyPassphraseWallet = deviceUtils
.getDeviceInstances(device, devices)
.find(d => d.useEmptyPassphrase);

const instances = deviceUtils.getDeviceInstances(device, devices);
const hasEmptyPassphraseWallet = instances.find(d => d.useEmptyPassphrase);

const onDeviceOffer = !!(
device.features &&
device.features.capabilities &&
Expand All @@ -43,9 +45,10 @@ export const PassphraseModal = ({ device }: PassphraseModalProps) => {

const dispatch = useDispatch();

const intl = useIntl();

const onCancel = () => TrezorConnect.cancel(intl.formatMessage(messages.TR_CANCELLED));
const onCancel = () => {
TrezorConnect.cancel('auth-confirm-cancel'); // This auth-confirm-cancel' causes the proper cleaning of the state in deviceThunks.authConfirm()
dispatch(deviceActions.forgetDevice(device));
};

const onSubmit = useCallback(
(value: string, passphraseOnDevice?: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ export const PassphraseWalletConfirmation = ({
onSubmit,
onDeviceOffer,
device,
}: PassphraseWalletConfirmationProps) => {
return (
<SwitchDeviceRenderer isCancelable onCancel={onCancel}>
<CardWithDevice onCancel={onCancel} device={device}>
<PassphraseWalletConfirmationContent
onSubmit={onSubmit}
onDeviceOffer={onDeviceOffer}
onCancel={onCancel}
/>
</CardWithDevice>
</SwitchDeviceRenderer>
);
};
}: PassphraseWalletConfirmationProps) => (
<SwitchDeviceRenderer isCancelable onCancel={onCancel}>
<CardWithDevice onCancel={onCancel} device={device}>
<PassphraseWalletConfirmationContent
onSubmit={onSubmit}
onDeviceOffer={onDeviceOffer}
onCancel={onCancel}
/>
</CardWithDevice>
</SwitchDeviceRenderer>
);

0 comments on commit 3afd251

Please sign in to comment.