Skip to content

Commit

Permalink
frontend/buy: prompt connecting keystore when selecting an account
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benma committed Nov 9, 2023
1 parent e7b99fa commit bf32c79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 9 additions & 8 deletions frontends/web/src/components/accountselector/accountselector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export type TOption = {
}

type TAccountSelector = {
title: string;
options: TOption[];
selected?: string;
onChange: (value: string) => void;
onProceed: () => void;
title: string;
disabled?: boolean;
options: TOption[];
selected?: string;
onChange: (value: string) => void;
onProceed: () => void;
}

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



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

Expand Down Expand Up @@ -118,11 +119,11 @@ export const AccountSelector = ({ title, options, selected, onChange, onProceed
<Button
primary
onClick={onProceed}
disabled={!selected}>
disabled={!selected || disabled}>
{t('buy.info.next')}
</Button>
</div>
</>

);
};
};
18 changes: 15 additions & 3 deletions frontends/web/src/routes/buy/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { useState, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { route } from '../../utils/route';
import { IAccount } from '../../api/account';
import * as accountApi from '../../api/account';
import { getExchangeSupportedAccounts } from './utils';
import { getBalance } from '../../api/account';
import Guide from './guide';
Expand All @@ -29,13 +29,14 @@ import { View, ViewContent } from '../../components/view/view';
import { HideAmountsButton } from '../../components/hideamountsbutton/hideamountsbutton';

type TProps = {
accounts: IAccount[];
accounts: accountApi.IAccount[];
code: string;
}

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

const { t } = useTranslation();

Expand Down Expand Up @@ -81,7 +82,17 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
});
};

const handleProceed = () => {
const handleProceed = async () => {
setDisabled(true);
try {
const connectResult = await accountApi.connectKeystore(selected);
if (!connectResult.success) {
return;
}
} finally {
setDisabled(false);
}

route(`/buy/exchange/${selected}`);
};
if (options === undefined) {
Expand All @@ -105,6 +116,7 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
) : (
<AccountSelector
title={t('buy.title', { name })}
disabled={disabled}
options={options}
selected={selected}
onChange={handleChangeAccount}
Expand Down

0 comments on commit bf32c79

Please sign in to comment.