14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useEffect , useRef , useState } from 'react' ;
17
+ import React , { useCallback , useEffect , useRef , useState } from 'react' ;
18
18
import { useTranslation } from 'react-i18next' ;
19
19
import * as backendAPI from '../../../api/backend' ;
20
+ import * as keystoresAPI from '../../../api/keystores' ;
20
21
import { SimpleMarkup } from '../../../utils/markup' ;
21
22
import { Message } from '../../../components/message/message' ;
22
23
import { Button , Input } from '../../../components/forms' ;
@@ -45,10 +46,6 @@ export const AddAccount = () => {
45
46
46
47
const { t } = useTranslation ( ) ;
47
48
48
- useEffect ( ( ) => {
49
- startProcess ( ) ;
50
- } , [ ] ) ;
51
-
52
49
useEffect ( ( ) => {
53
50
if ( step === 'choose-name' ) {
54
51
inputRef . current ?. focus ( ) ;
@@ -59,7 +56,7 @@ export const AddAccount = () => {
59
56
return supportedCoins . length === 1 ;
60
57
} ;
61
58
62
- const startProcess = async ( ) => {
59
+ const startProcess = useCallback ( async ( ) => {
63
60
try {
64
61
const coins = await backendAPI . getSupportedCoins ( ) ;
65
62
const onlyOneCoinIsSupported = ( coins . length === 1 ) ;
@@ -73,7 +70,16 @@ export const AddAccount = () => {
73
70
} catch ( err ) {
74
71
console . error ( err ) ;
75
72
}
76
- } ;
73
+ } , [ ] ) ;
74
+
75
+ useEffect ( ( ) => {
76
+ startProcess ( ) ;
77
+
78
+ const unsubscribe = keystoresAPI . subscribeKeystores ( ( ) => {
79
+ startProcess ( ) ;
80
+ } ) ;
81
+ return unsubscribe ;
82
+ } , [ startProcess ] ) ;
77
83
78
84
const back = ( ) => {
79
85
switch ( step ) {
@@ -122,6 +128,13 @@ export const AddAccount = () => {
122
128
const renderContent = ( ) => {
123
129
switch ( step ) {
124
130
case 'select-coin' :
131
+ if ( supportedCoins . length === 0 ) {
132
+ return (
133
+ < Message type = "info" >
134
+ { t ( 'connectKeystore.promptNoName' ) }
135
+ </ Message >
136
+ ) ;
137
+ }
125
138
return (
126
139
< CoinDropDown
127
140
onChange = { coin => {
0 commit comments