17
17
import { useState , useEffect , useCallback } from 'react' ;
18
18
import { useTranslation } from 'react-i18next' ;
19
19
import { route } from '../../utils/route' ;
20
- import { IAccount } from '../../api/account' ;
20
+ import * as accountApi from '../../api/account' ;
21
21
import { getExchangeSupportedAccounts } from './utils' ;
22
22
import { getBalance } from '../../api/account' ;
23
23
import Guide from './guide' ;
@@ -29,13 +29,14 @@ import { View, ViewContent } from '../../components/view/view';
29
29
import { HideAmountsButton } from '../../components/hideamountsbutton/hideamountsbutton' ;
30
30
31
31
type TProps = {
32
- accounts : IAccount [ ] ;
32
+ accounts : accountApi . IAccount [ ] ;
33
33
code : string ;
34
34
}
35
35
36
36
export const BuyInfo = ( { code, accounts } : TProps ) => {
37
37
const [ selected , setSelected ] = useState < string > ( code ) ;
38
38
const [ options , setOptions ] = useState < TOption [ ] > ( ) ;
39
+ const [ disabled , setDisabled ] = useState < boolean > ( false ) ;
39
40
40
41
const { t } = useTranslation ( ) ;
41
42
@@ -52,9 +53,14 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
52
53
53
54
} , [ accounts ] ) ;
54
55
55
- const maybeProceed = useCallback ( ( ) => {
56
+ const maybeProceed = useCallback ( async ( ) => {
56
57
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 } ` ) ;
58
64
}
59
65
} , [ options ] ) ;
60
66
@@ -81,7 +87,17 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
81
87
} ) ;
82
88
} ;
83
89
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
+
85
101
route ( `/buy/exchange/${ selected } ` ) ;
86
102
} ;
87
103
if ( options === undefined ) {
@@ -105,6 +121,7 @@ export const BuyInfo = ({ code, accounts }: TProps) => {
105
121
) : (
106
122
< AccountSelector
107
123
title = { t ( 'buy.title' , { name } ) }
124
+ disabled = { disabled }
108
125
options = { options }
109
126
selected = { selected }
110
127
onChange = { handleChangeAccount }
0 commit comments