Skip to content

Commit

Permalink
frontend: move qr scanner open state to sub-comp.
Browse files Browse the repository at this point in the history
Move the `activeScanQR` state used to control the QR scanner dialog
(open/closed) into the `ReceiverAddressInput` to simplify the component.

We can remove the `activeScanQR` from the back button disabled property
because a) navigation with ESC allows the user to go back anyways and b)
the back button itself is not clickable when there is an active overlay.
  • Loading branch information
NicolaLS committed Sep 2, 2024
1 parent bdf270c commit a20ddcc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ChangeEvent, useCallback, useContext } from 'react';
import { ChangeEvent, useCallback, useContext, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { debug } from '@/utils/env';
import { getReceiveAddressList } from '@/api/account';
Expand All @@ -33,9 +33,7 @@ type TReceiverAddressInputProps = {
addressError?: string;
onInputChange: (value: string) => void;
recipientAddress: string;
activeScanQR: boolean;
parseQRResult: (uri: string) => void;
onChangeActiveScanQR: (activeScanQR: boolean) => void
}

export const ScanQRButton = ({ onClick }: TToggleScanQRButtonProps) => {
Expand All @@ -51,11 +49,10 @@ export const ReceiverAddressInput = ({
addressError,
onInputChange,
recipientAddress,
activeScanQR,
parseQRResult,
onChangeActiveScanQR
}: TReceiverAddressInputProps) => {
const { t } = useTranslation();
const [activeScanQR, setActiveScanQR] = useState(false);

const handleSendToSelf = useCallback(async () => {
if (!accountCode) {
Expand All @@ -71,20 +68,16 @@ export const ReceiverAddressInput = ({
}
}, [accountCode, onInputChange]);

const toggleScanQR = useCallback(() => {
if (activeScanQR) {
onChangeActiveScanQR(false);
return;
}
onChangeActiveScanQR(true);
}, [activeScanQR, onChangeActiveScanQR]);
const toggleScanQR = () => {
setActiveScanQR(activeScanQR => !activeScanQR);
};

return (
<>
{activeScanQR && (
<ScanQRDialog
toggleScanQR={toggleScanQR}
onChangeActiveScanQR={onChangeActiveScanQR}
onChangeActiveScanQR={setActiveScanQR}
parseQRResult={parseQRResult}
/>
)}
Expand All @@ -106,4 +99,4 @@ export const ReceiverAddressInput = ({
</Input>
</>
);
};
};
11 changes: 1 addition & 10 deletions frontends/web/src/routes/account/send/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export type State = {
coinControl: boolean;
btcUnit: BtcUnit;
activeCoinControl: boolean;
activeScanQR: boolean;
note: string;
}

Expand Down Expand Up @@ -113,7 +112,6 @@ class Send extends Component<Props, State> {
coinControl: false,
btcUnit : 'default',
activeCoinControl: false,
activeScanQR: false,
note: '',
customFee: '',
};
Expand Down Expand Up @@ -378,10 +376,6 @@ class Send extends Component<Props, State> {
});
};

private setActiveScanQR = (activeScanQR: boolean) => {
this.setState({ activeScanQR });
};

private parseQRResult = async (uri: string) => {
let address;
let amount = '';
Expand Down Expand Up @@ -481,7 +475,6 @@ class Send extends Component<Props, State> {
signConfirm,
coinControl,
activeCoinControl,
activeScanQR,
note,
} = this.state;

Expand Down Expand Up @@ -548,8 +541,6 @@ class Send extends Component<Props, State> {
onInputChange={this.onReceiverAddressInputChange}
recipientAddress={recipientAddress}
parseQRResult={this.parseQRResult}
activeScanQR={activeScanQR}
onChangeActiveScanQR={this.setActiveScanQR}
/>
</Column>
</Grid>
Expand Down Expand Up @@ -605,7 +596,7 @@ class Send extends Component<Props, State> {
{t('send.button')}
</Button>
<BackButton
disabled={activeCoinControl || activeScanQR}
disabled={activeCoinControl}
enableEsc>
{t('button.back')}
</BackButton>
Expand Down

0 comments on commit a20ddcc

Please sign in to comment.