Skip to content

Commit 739cb78

Browse files
authored
fix: show confirmation drawer when canceling transaction in bitcoin-mode (#1856)
1 parent b508a0c commit 739cb78

File tree

2 files changed

+103
-61
lines changed

2 files changed

+103
-61
lines changed

apps/browser-extension-wallet/src/views/bitcoin-mode/features/send/components/SendFlow.module.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@
1111
margin: 0 -40px;
1212
width: calc(100% + 80px);
1313
}
14+
15+
.modalContent {
16+
display: flex;
17+
flex-direction: column;
18+
align-items: center;
19+
justify-content: center;
20+
text-align: center;
21+
color: var(--text-color-secondary);
22+
@include text-body-medium;
23+
}

apps/browser-extension-wallet/src/views/bitcoin-mode/features/send/components/SendFlow.tsx

Lines changed: 93 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PasswordInput } from './PasswordInput';
1111
import { TransactionSuccess } from './TransactionSuccess';
1212
import { TransactionFailed } from './TransactionFailed';
1313
import { useFetchCoinPrice, useRedirection, useWalletManager } from '@hooks';
14-
import { DrawerNavigation, PostHogAction, useObservable } from '@lace/common';
14+
import { DrawerNavigation, PostHogAction, useKeyboardShortcut, useObservable } from '@lace/common';
1515
import { Bitcoin } from '@lace/bitcoin';
1616
import { Wallet as Cardano } from '@lace/cardano';
1717
import { walletRoutePaths } from '@routes';
@@ -21,6 +21,8 @@ import { APP_MODE_POPUP } from '@src/utils/constants';
2121
import { useAnalyticsContext } from '@providers';
2222
import { DrawerContent } from '@src/views/browser-view/components/Drawer';
2323
import { useTranslation } from 'react-i18next';
24+
import { WarningModal } from '@views/browser/components';
25+
import styles from './SendFlow.module.scss';
2426

2527
const SATS_IN_BTC = 100_000_000;
2628

@@ -123,6 +125,7 @@ export const SendFlow: React.FC = () => {
123125
const [network, setWalletNetwork] = useState<Bitcoin.Network | null>(null);
124126
const [confirmationHash, setConfirmationHash] = useState<string>('');
125127
const [txError, setTxError] = useState<Error | undefined>();
128+
const [isWarningModalVisible, setIsWarningModalVisible] = useState(false);
126129

127130
const { priceResult } = useFetchCoinPrice();
128131
const { bitcoinWallet } = useWalletManager();
@@ -209,12 +212,16 @@ export const SendFlow: React.FC = () => {
209212
});
210213
}, [bitcoinWallet]);
211214

212-
const onClose = useCallback(() => {
215+
const onClose = useCallback(() => setIsWarningModalVisible(true), []);
216+
217+
const confirmOnClose = useCallback(() => {
213218
if (isPopupView) redirectToOverview();
214219
else {
215220
config?.onClose ? config?.onClose() : setDrawerConfig();
216221
}
217-
}, [setDrawerConfig, config, isPopupView, redirectToOverview]);
222+
}, [isPopupView, redirectToOverview, config, setDrawerConfig]);
223+
224+
useKeyboardShortcut(['Escape'], () => (step === 'AMOUNT' ? confirmOnClose() : onClose()));
218225

219226
const backToAmount = () => {
220227
setStep('AMOUNT');
@@ -278,67 +285,92 @@ export const SendFlow: React.FC = () => {
278285

279286
const backToReview = () => setStep('REVIEW');
280287

281-
if (step === 'AMOUNT') {
282-
return (
283-
<SendStepOne
284-
onClose={onClose}
285-
isPopupView={isPopupView}
286-
amount={amount}
287-
onAmountChange={setAmount}
288-
address={address}
289-
availableBalance={Number(balance)}
290-
onAddressChange={setAddress}
291-
feeMarkets={feeMarkets}
292-
onEstimatedTimeChange={setEstimatedTime}
293-
onContinue={goToReview}
294-
network={network}
295-
hasUtxosInMempool={hasUtxosInMempool}
296-
/>
297-
);
298-
}
288+
const getSendComponent = () => {
289+
if (step === 'AMOUNT') {
290+
return (
291+
<SendStepOne
292+
onClose={onClose}
293+
isPopupView={isPopupView}
294+
amount={amount}
295+
onAmountChange={setAmount}
296+
address={address}
297+
availableBalance={Number(balance)}
298+
onAddressChange={setAddress}
299+
feeMarkets={feeMarkets}
300+
onEstimatedTimeChange={setEstimatedTime}
301+
onContinue={goToReview}
302+
network={network}
303+
hasUtxosInMempool={hasUtxosInMempool}
304+
/>
305+
);
306+
}
299307

300-
if (step === 'REVIEW') {
301-
return (
302-
<ReviewTransaction
303-
onClose={onClose}
304-
isPopupView={isPopupView}
305-
unsignedTransaction={unsignedTransaction}
306-
btcToUsdRate={btcToUsdRate}
307-
feeRate={feeRate}
308-
estimatedTime={estimatedTime}
309-
onConfirm={goToPassword}
310-
/>
311-
);
312-
}
308+
if (step === 'REVIEW') {
309+
return (
310+
<>
311+
<ReviewTransaction
312+
onClose={onClose}
313+
isPopupView={isPopupView}
314+
unsignedTransaction={unsignedTransaction}
315+
btcToUsdRate={btcToUsdRate}
316+
feeRate={feeRate}
317+
estimatedTime={estimatedTime}
318+
onConfirm={goToPassword}
319+
/>
320+
</>
321+
);
322+
}
313323

314-
if (step === 'PASSWORD') {
315-
return (
316-
<PasswordInput
317-
onClose={onClose}
318-
isPopupView={isPopupView}
319-
onSubmit={handleSubmitTx}
320-
signTransaction={handleSignTransaction}
321-
/>
322-
);
323-
}
324+
if (step === 'PASSWORD') {
325+
return (
326+
<PasswordInput
327+
onClose={onClose}
328+
isPopupView={isPopupView}
329+
onSubmit={handleSubmitTx}
330+
signTransaction={handleSignTransaction}
331+
/>
332+
);
333+
}
324334

325-
if (step === 'DONE') {
326-
return (
327-
<TransactionSuccess
328-
onClose={onClose}
329-
isPopupView={isPopupView}
330-
onViewTransaction={() => {
331-
setDrawerConfig();
332-
redirectToTransactions();
333-
}}
334-
hash={confirmationHash}
335-
/>
336-
);
337-
}
335+
if (step === 'DONE') {
336+
return (
337+
<TransactionSuccess
338+
onClose={onClose}
339+
isPopupView={isPopupView}
340+
onViewTransaction={() => {
341+
setDrawerConfig();
342+
redirectToTransactions();
343+
}}
344+
hash={confirmationHash}
345+
/>
346+
);
347+
}
338348

339-
if (step === 'FAILED') {
340-
return <TransactionFailed onClose={onClose} isPopupView={isPopupView} onBack={backToReview} txError={txError} />;
341-
}
349+
if (step === 'FAILED') {
350+
return <TransactionFailed onClose={onClose} isPopupView={isPopupView} onBack={backToReview} txError={txError} />;
351+
}
352+
353+
return <></>;
354+
};
342355

343-
return <></>;
356+
return (
357+
<>
358+
{getSendComponent()}
359+
<WarningModal
360+
header={t('general.warnings.youHaveToStartAgain')}
361+
content={
362+
<div className={styles.modalContent}>
363+
{t('general.warnings.areYouSureYouWantToExit')}
364+
<br />
365+
{t('general.warnings.thisWillNotBeSaved')}
366+
</div>
367+
}
368+
onConfirm={confirmOnClose}
369+
onCancel={() => setIsWarningModalVisible(false)}
370+
visible={isWarningModalVisible}
371+
isPopupView={isPopupView}
372+
dataTestId="send-warning-modal"
373+
/>
374+
</>
375+
);
344376
};

0 commit comments

Comments
 (0)