Skip to content

Commit

Permalink
frontend: create dialog on remember wallet
Browse files Browse the repository at this point in the history
Show dialog when enabling remember wallet to better inform users
about what the feature is. The dialog is an element itself called
EnableRememberWalletDialog.

This dialog is (also) controlled by a new config variable called
hideEnableRememberWalletDialog.

Also created DisableRememberWalletDialog component (just a
refactor).
  • Loading branch information
shonsirsha committed Dec 3, 2024
1 parent 6f207ca commit 7789b86
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 9 deletions.
4 changes: 4 additions & 0 deletions frontends/web/src/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,10 @@
"title": "Language"
},
"remebmerWallet": {
"enable": {
"description": "You can now view the accounts associated with this wallet without inserting your BitBox device. However, the BitBox is still required for making transactions and displaying receive addresses.",
"title": "Wallet remembered"
},
"name": "Remember wallet",
"warning": "This will remove your remembered wallet. To see it again, you will need to plug in the BitBox02 for this wallet. Any coins on this wallet are not affected. Do you want to continue?",
"warningTitle": "Disable remember wallet"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useTranslation } from 'react-i18next';
import { Dialog, DialogButtons } from '@/components/dialog/dialog';
import { Button } from '@/components/forms';

type Props = {
open: boolean;
onClose: () => void;
onConfirm: () => void;
}
export const DisableRememberWalletDialog = ({ open, onClose, onConfirm }: Props) => {
const { t } = useTranslation();

return (
<Dialog title={t('newSettings.appearance.remebmerWallet.warningTitle')} medium onClose={onClose} open={open}>
<p>{t('newSettings.appearance.remebmerWallet.warning')}</p>
<DialogButtons>
<Button primary onClick={onConfirm}>{t('dialog.confirm')}</Button>
<Button secondary onClick={onClose}>{t('dialog.cancel')}</Button>
</DialogButtons>
</Dialog>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Dialog, DialogButtons } from '@/components/dialog/dialog';
import { Button, Checkbox } from '@/components/forms';
import { useLoad } from '@/hooks/api';
import { getConfig, setConfig } from '@/utils/config';

type Props = {
open: boolean;
onClose: () => void;
}
export const EnableRememberWalletDialog = ({ open, onClose }: Props) => {
const { t } = useTranslation();
const config = useLoad(getConfig);
const [checked, setChecked] = useState(false);
const [shouldNotShowDialog, setShouldNotShowDialog] = useState(false);

useEffect(() => {
if (config && config.frontend) {
setShouldNotShowDialog(config.frontend.hideEnableRememberWalletDialog);
}
}, [config]);

if (shouldNotShowDialog) {
return null;
}

return (
<Dialog title={t('newSettings.appearance.remebmerWallet.enable.title')} medium open={open}>
<p>{t('newSettings.appearance.remebmerWallet.enable.description')}</p>
<Checkbox
id="dont_show_enable_remember_wallet"
label={t('buy.info.skip')}
checked={checked}
onChange={(e) => setChecked(e.target.checked)}
/>
<DialogButtons>
<Button primary onClick={() => {
onClose();
if (checked) {
setConfig({ frontend: { hideEnableRememberWalletDialog: true } });
setShouldNotShowDialog(true);
}
}}>{t('button.ok')}</Button>
</DialogButtons>
</Dialog>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import * as backendAPI from '@/api/backend';
import * as accountAPI from '@/api/account';
import { useLoad } from '@/hooks/api';
import { getConfig } from '@/utils/config';
import { Dialog, DialogButtons } from '@/components/dialog/dialog';
import { Button, Label } from '@/components/forms';
import { Label } from '@/components/forms';
import { EnableRememberWalletDialog } from '@/routes/settings/components/manage-accounts/dialogs/enableRememberWalletDialog';
import { DisableRememberWalletDialog } from '@/routes/settings/components/manage-accounts/dialogs/disableRememberWalletDialog';
import style from './watchonlySettings.module.css';

type Props = {
Expand All @@ -34,6 +35,7 @@ export const WatchonlySetting = ({ keystore }: Props) => {
const [disabled, setDisabled] = useState<boolean>(false);
const [watchonly, setWatchonly] = useState<boolean>();
const [warningDialogOpen, setWarningDialogOpen] = useState(false);
const [walletRememberedDialogOpen, setWalletRememberedDialogOpen] = useState(false);
const config = useLoad(getConfig);

useEffect(() => {
Expand All @@ -49,6 +51,7 @@ export const WatchonlySetting = ({ keystore }: Props) => {

if (success) {
setWatchonly(!watchonly);
setWalletRememberedDialogOpen(true);
}
setDisabled(false);
return;
Expand All @@ -74,13 +77,15 @@ export const WatchonlySetting = ({ keystore }: Props) => {

return (
<>
<Dialog title={t('newSettings.appearance.remebmerWallet.warningTitle')} medium onClose={handleCloseDialog} open={warningDialogOpen}>
<p>{t('newSettings.appearance.remebmerWallet.warning')}</p>
<DialogButtons>
<Button primary onClick={handleConfirmDisableWatchonly}>{t('dialog.confirm')}</Button>
<Button secondary onClick={handleCloseDialog}>{t('dialog.cancel')}</Button>
</DialogButtons>
</Dialog>
<DisableRememberWalletDialog
open={warningDialogOpen}
onClose={handleCloseDialog}
onConfirm={handleConfirmDisableWatchonly}
/>
<EnableRememberWalletDialog
open={walletRememberedDialogOpen}
onClose={() => setWalletRememberedDialogOpen(false)}
/>
{ watchonly !== undefined ? (
<Label className={style.label}>
<span className={style.labelText}>
Expand Down

0 comments on commit 7789b86

Please sign in to comment.