@@ -11,7 +11,7 @@ import { PasswordInput } from './PasswordInput';
11
11
import { TransactionSuccess } from './TransactionSuccess' ;
12
12
import { TransactionFailed } from './TransactionFailed' ;
13
13
import { useFetchCoinPrice , useRedirection , useWalletManager } from '@hooks' ;
14
- import { DrawerNavigation , PostHogAction , useObservable } from '@lace/common' ;
14
+ import { DrawerNavigation , PostHogAction , useKeyboardShortcut , useObservable } from '@lace/common' ;
15
15
import { Bitcoin } from '@lace/bitcoin' ;
16
16
import { Wallet as Cardano } from '@lace/cardano' ;
17
17
import { walletRoutePaths } from '@routes' ;
@@ -21,6 +21,8 @@ import { APP_MODE_POPUP } from '@src/utils/constants';
21
21
import { useAnalyticsContext } from '@providers' ;
22
22
import { DrawerContent } from '@src/views/browser-view/components/Drawer' ;
23
23
import { useTranslation } from 'react-i18next' ;
24
+ import { WarningModal } from '@views/browser/components' ;
25
+ import styles from './SendFlow.module.scss' ;
24
26
25
27
const SATS_IN_BTC = 100_000_000 ;
26
28
@@ -123,6 +125,7 @@ export const SendFlow: React.FC = () => {
123
125
const [ network , setWalletNetwork ] = useState < Bitcoin . Network | null > ( null ) ;
124
126
const [ confirmationHash , setConfirmationHash ] = useState < string > ( '' ) ;
125
127
const [ txError , setTxError ] = useState < Error | undefined > ( ) ;
128
+ const [ isWarningModalVisible , setIsWarningModalVisible ] = useState ( false ) ;
126
129
127
130
const { priceResult } = useFetchCoinPrice ( ) ;
128
131
const { bitcoinWallet } = useWalletManager ( ) ;
@@ -209,12 +212,16 @@ export const SendFlow: React.FC = () => {
209
212
} ) ;
210
213
} , [ bitcoinWallet ] ) ;
211
214
212
- const onClose = useCallback ( ( ) => {
215
+ const onClose = useCallback ( ( ) => setIsWarningModalVisible ( true ) , [ ] ) ;
216
+
217
+ const confirmOnClose = useCallback ( ( ) => {
213
218
if ( isPopupView ) redirectToOverview ( ) ;
214
219
else {
215
220
config ?. onClose ? config ?. onClose ( ) : setDrawerConfig ( ) ;
216
221
}
217
- } , [ setDrawerConfig , config , isPopupView , redirectToOverview ] ) ;
222
+ } , [ isPopupView , redirectToOverview , config , setDrawerConfig ] ) ;
223
+
224
+ useKeyboardShortcut ( [ 'Escape' ] , ( ) => ( step === 'AMOUNT' ? confirmOnClose ( ) : onClose ( ) ) ) ;
218
225
219
226
const backToAmount = ( ) => {
220
227
setStep ( 'AMOUNT' ) ;
@@ -278,67 +285,92 @@ export const SendFlow: React.FC = () => {
278
285
279
286
const backToReview = ( ) => setStep ( 'REVIEW' ) ;
280
287
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
+ }
299
307
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
+ }
313
323
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
+ }
324
334
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
+ }
338
348
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
+ } ;
342
355
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
+ ) ;
344
376
} ;
0 commit comments