Skip to content

Commit c232335

Browse files
committed
frontend/buy: prompt connecting keystore when selecting an account
It would be prompted automatically later when the device is actually needed, but the UX is better if it is done upfront before spending possibly lots of time in the MoonPay or Pocket widget and then realizing the device is not nearby.
1 parent 992d26d commit c232335

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

frontends/web/src/components/accountselector/accountselector.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ export type TOption = {
3232
}
3333

3434
type TAccountSelector = {
35-
title: string;
36-
options: TOption[];
37-
selected?: string;
38-
onChange: (value: string) => void;
39-
onProceed: () => void;
35+
title: string;
36+
disabled?: boolean;
37+
options: TOption[];
38+
selected?: string;
39+
onChange: (value: string) => void;
40+
onProceed: () => void;
4041
}
4142

4243
const SelectSingleValue: FunctionComponent<SingleValueProps<TOption>> = (props) => {
@@ -80,7 +81,7 @@ const DropdownIndicator: FunctionComponent<DropdownIndicatorProps<TOption>> = (p
8081

8182

8283

83-
export const AccountSelector = ({ title, options, selected, onChange, onProceed }: TAccountSelector) => {
84+
export const AccountSelector = ({ title, disabled, options, selected, onChange, onProceed }: TAccountSelector) => {
8485
const { t } = useTranslation();
8586
const [selectedAccount, setSelectedAccount] = useState<TOption>();
8687

@@ -118,11 +119,11 @@ export const AccountSelector = ({ title, options, selected, onChange, onProceed
118119
<Button
119120
primary
120121
onClick={onProceed}
121-
disabled={!selected}>
122+
disabled={!selected || disabled}>
122123
{t('buy.info.next')}
123124
</Button>
124125
</div>
125126
</>
126127

127128
);
128-
};
129+
};

frontends/web/src/routes/buy/info.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { useState, useEffect, useCallback } from 'react';
1818
import { useTranslation } from 'react-i18next';
1919
import { route } from '../../utils/route';
20-
import { IAccount } from '../../api/account';
20+
import * as accountApi from '../../api/account';
2121
import { getExchangeSupportedAccounts } from './utils';
2222
import { getBalance } from '../../api/account';
2323
import Guide from './guide';
@@ -29,13 +29,14 @@ import { View, ViewContent } from '../../components/view/view';
2929
import { HideAmountsButton } from '../../components/hideamountsbutton/hideamountsbutton';
3030

3131
type TProps = {
32-
accounts: IAccount[];
32+
accounts: accountApi.IAccount[];
3333
code: string;
3434
}
3535

3636
export const BuyInfo = ({ code, accounts }: TProps) => {
3737
const [selected, setSelected] = useState<string>(code);
3838
const [options, setOptions] = useState<TOption[]>();
39+
const [disabled, setDisabled] = useState<boolean>(false);
3940

4041
const { t } = useTranslation();
4142

@@ -52,9 +53,14 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
5253

5354
}, [accounts]);
5455

55-
const maybeProceed = useCallback(() => {
56+
const maybeProceed = useCallback(async () => {
5657
if (options !== undefined && options.length === 1) {
57-
route(`/buy/exchange/${options[0].value}`);
58+
const accountCode = options[0].value;
59+
const connectResult = await accountApi.connectKeystore(accountCode);
60+
if (!connectResult.success) {
61+
return;
62+
}
63+
route(`/buy/exchange/${accountCode}`);
5864
}
5965
}, [options]);
6066

@@ -81,7 +87,17 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
8187
});
8288
};
8389

84-
const handleProceed = () => {
90+
const handleProceed = async () => {
91+
setDisabled(true);
92+
try {
93+
const connectResult = await accountApi.connectKeystore(selected);
94+
if (!connectResult.success) {
95+
return;
96+
}
97+
} finally {
98+
setDisabled(false);
99+
}
100+
85101
route(`/buy/exchange/${selected}`);
86102
};
87103
if (options === undefined) {
@@ -105,6 +121,7 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
105121
) : (
106122
<AccountSelector
107123
title={t('buy.title', { name })}
124+
disabled={disabled}
108125
options={options}
109126
selected={selected}
110127
onChange={handleChangeAccount}

0 commit comments

Comments
 (0)