Skip to content

Commit 45ecdf0

Browse files
authored
fix: [lw-12707] add back btn into review step for btc send drawer (#1846)
1 parent 24b1438 commit 45ecdf0

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/no-multi-comp */
12
/* eslint-disable promise/catch-or-return */
23
/* eslint-disable no-magic-numbers */
34
/* eslint-disable unicorn/no-null */
@@ -10,14 +11,16 @@ import { PasswordInput } from './PasswordInput';
1011
import { TransactionSuccess } from './TransactionSuccess';
1112
import { TransactionFailed } from './TransactionFailed';
1213
import { useFetchCoinPrice, useRedirection, useWalletManager } from '@hooks';
13-
import { PostHogAction, useObservable } from '@lace/common';
14+
import { DrawerNavigation, PostHogAction, useObservable } from '@lace/common';
1415
import { Bitcoin } from '@lace/bitcoin';
1516
import { Wallet as Cardano } from '@lace/cardano';
1617
import { walletRoutePaths } from '@routes';
1718
import { useDrawer } from '@src/views/browser-view/stores';
1819
import { useWalletStore } from '@src/stores';
1920
import { APP_MODE_POPUP } from '@src/utils/constants';
2021
import { useAnalyticsContext } from '@providers';
22+
import { DrawerContent } from '@src/views/browser-view/components/Drawer';
23+
import { useTranslation } from 'react-i18next';
2124

2225
const SATS_IN_BTC = 100_000_000;
2326

@@ -102,6 +105,7 @@ const btcStringToSatoshisBigint = (btcString: string): bigint => {
102105
};
103106

104107
export const SendFlow: React.FC = () => {
108+
const { t } = useTranslation();
105109
const [step, setStep] = useState<Step>('AMOUNT');
106110

107111
const [amount, setAmount] = useState<string>('');
@@ -126,7 +130,7 @@ export const SendFlow: React.FC = () => {
126130
const btcToUsdRate = useMemo(() => priceResult.bitcoin?.price ?? 0, [priceResult.bitcoin]);
127131
const balance = useObservable(bitcoinWallet.balance$, BigInt(0));
128132

129-
const [config, clearContent] = useDrawer();
133+
const [config, setDrawerConfig] = useDrawer();
130134

131135
const redirectToTransactions = useRedirection(walletRoutePaths.activity);
132136
const redirectToOverview = useRedirection(walletRoutePaths.assets);
@@ -205,6 +209,24 @@ export const SendFlow: React.FC = () => {
205209
});
206210
}, [bitcoinWallet]);
207211

212+
const onClose = useCallback(() => {
213+
if (isPopupView) redirectToOverview();
214+
else {
215+
config?.onClose ? config?.onClose() : setDrawerConfig();
216+
}
217+
}, [setDrawerConfig, config, isPopupView, redirectToOverview]);
218+
219+
const backToAmount = () => {
220+
setStep('AMOUNT');
221+
setDrawerConfig({
222+
...config,
223+
content: DrawerContent.SEND_BITCOIN_TRANSACTION,
224+
renderHeader: () => (
225+
<DrawerNavigation title={<div>{t('browserView.transaction.send.title')}</div>} onCloseIconClick={onClose} />
226+
)
227+
});
228+
};
229+
208230
// Step 1 -> 2
209231
const goToReview = (newFeeRate: number) => {
210232
setFeeRate(newFeeRate);
@@ -220,6 +242,17 @@ export const SendFlow: React.FC = () => {
220242
})
221243
);
222244
setStep('REVIEW');
245+
setDrawerConfig({
246+
...config,
247+
content: DrawerContent.SEND_BITCOIN_TRANSACTION,
248+
renderHeader: () => (
249+
<DrawerNavigation
250+
title={<div>{t('browserView.transaction.send.title')}</div>}
251+
onCloseIconClick={onClose}
252+
onArrowIconClick={backToAmount}
253+
/>
254+
)
255+
});
223256
};
224257
// Step 2 -> 3
225258
const goToPassword = () => setStep('PASSWORD');
@@ -243,13 +276,6 @@ export const SendFlow: React.FC = () => {
243276
}
244277
};
245278

246-
const onClose = useCallback(() => {
247-
if (isPopupView) redirectToOverview();
248-
else {
249-
config?.onClose ? config?.onClose() : clearContent();
250-
}
251-
}, [clearContent, config, isPopupView, redirectToOverview]);
252-
253279
const backToReview = () => setStep('REVIEW');
254280

255281
if (step === 'AMOUNT') {
@@ -302,7 +328,7 @@ export const SendFlow: React.FC = () => {
302328
onClose={onClose}
303329
isPopupView={isPopupView}
304330
onViewTransaction={() => {
305-
clearContent();
331+
setDrawerConfig();
306332
redirectToTransactions();
307333
}}
308334
hash={confirmationHash}

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,25 @@ export const SendStepOne: React.FC<SendStepOneProps> = ({
149149

150150
const fiatValue = `≈ ${new BigNumber(enteredAmount.toString()).toFixed(2, BigNumber.ROUND_HALF_UP)} USD`;
151151

152-
const handleChangeAddress = useCallback(
153-
(value: string) => {
154-
onAddressChange(value);
155-
156-
const result = Bitcoin.validateBitcoinAddress(value, network);
152+
useEffect(() => {
153+
const result = Bitcoin.validateBitcoinAddress(address, network);
157154

158-
switch (result) {
159-
case Bitcoin.AddressValidationResult.Valid:
160-
setIsValidAddress(true);
161-
// eslint-disable-next-line unicorn/no-useless-undefined
162-
setInvalidAddressError(undefined);
163-
break;
164-
case Bitcoin.AddressValidationResult.InvalidNetwork:
165-
setIsValidAddress(false);
166-
setInvalidAddressError(t('general.errors.incorrectAddressNetwork'));
167-
break;
168-
case Bitcoin.AddressValidationResult.InvalidAddress:
169-
setIsValidAddress(false);
170-
setInvalidAddressError(t('general.errors.incorrectAddress'));
171-
break;
172-
}
173-
},
174-
[network, onAddressChange, t]
175-
);
155+
switch (result) {
156+
case Bitcoin.AddressValidationResult.Valid:
157+
setIsValidAddress(true);
158+
// eslint-disable-next-line unicorn/no-useless-undefined
159+
setInvalidAddressError(undefined);
160+
break;
161+
case Bitcoin.AddressValidationResult.InvalidNetwork:
162+
setIsValidAddress(false);
163+
setInvalidAddressError(t('general.errors.incorrectAddressNetwork'));
164+
break;
165+
case Bitcoin.AddressValidationResult.InvalidAddress:
166+
setIsValidAddress(false);
167+
setInvalidAddressError(t('general.errors.incorrectAddress'));
168+
break;
169+
}
170+
}, [address, network, onAddressChange, t]);
176171

177172
const handleCustomFeeKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
178173
const disallowedKeys = ['-', '+', 'e', ','];
@@ -204,7 +199,7 @@ export const SendStepOne: React.FC<SendStepOneProps> = ({
204199
value={address}
205200
data-testid="btc-address-input"
206201
label={t('core.destinationAddressInput.recipientAddressOnly')}
207-
onChange={(value) => handleChangeAddress(value)}
202+
onChange={(value) => onAddressChange(value)}
208203
style={{ width: '100%' }}
209204
/>
210205

0 commit comments

Comments
 (0)