@@ -24,17 +24,21 @@ import { Header } from '../../components/layout';
24
24
import { BlockExplorers } from './block-explorers' ;
25
25
import * as backendAPI from '../../api/backend' ;
26
26
import { getConfig , setConfig } from '../../utils/config' ;
27
- import { CoinCode } from '../../api/account' ;
27
+ import { CoinCode , IAccount } from '../../api/account' ;
28
28
import { MobileHeader } from './components/mobile-header' ;
29
29
import { useCallback , useEffect , useRef , useState } from 'react' ;
30
30
31
- export const SelectExplorerSettings = ( ) => {
31
+ type TSelectExplorerSettingsProps = {
32
+ accounts : IAccount [ ] ;
33
+ }
34
+
35
+ export const SelectExplorerSettings = ( { accounts } : TSelectExplorerSettingsProps ) => {
32
36
const { t } = useTranslation ( ) ;
33
37
34
38
const initialConfig = useRef < any > ( ) ;
35
39
const [ config , setConfigState ] = useState < any > ( ) ;
36
40
37
- const [ supportedCoins , setSupportedCoins ] = useState < backendAPI . ICoin [ ] > ( [ ] ) ;
41
+ const availableCoins = new Set ( accounts . map ( account => account . coinCode ) ) ;
38
42
const [ allSelections , setAllSelections ] = useState < backendAPI . TAvailableExplorers > ( ) ;
39
43
40
44
const [ saveDisabled , setSaveDisabled ] = useState ( true ) ;
@@ -68,13 +72,11 @@ export const SelectExplorerSettings = () => {
68
72
69
73
useEffect ( ( ) => {
70
74
const fetchData = async ( ) => {
71
- const coins = await backendAPI . getSupportedCoins ( ) ;
72
75
const allExplorerSelection = await backendAPI . getAvailableExplorers ( ) ;
73
76
74
77
// if set alongside config it will 'update' with it, but we want it to stay the same after initialization.
75
78
initialConfig . current = await getConfig ( ) ;
76
79
77
- setSupportedCoins ( coins ) ;
78
80
setAllSelections ( allExplorerSelection ) ;
79
81
} ;
80
82
@@ -99,14 +101,14 @@ export const SelectExplorerSettings = () => {
99
101
</ >
100
102
} />
101
103
< div className = "content padded" >
102
- { supportedCoins . map ( coin => {
104
+ { Array . from ( availableCoins ) . map ( coin => {
103
105
return < BlockExplorers
104
- key = { coin . coinCode }
105
- coin = { coin . coinCode }
106
- explorerOptions = { allSelections ?. [ coin . coinCode ] ?? [ ] }
106
+ key = { coin }
107
+ coin = { coin }
108
+ explorerOptions = { allSelections ?. [ coin ] ?? [ ] }
107
109
handleOnChange = { handleChange }
108
- selectedPrefix = { config . backend . blockExplorers ?. [ coin . coinCode ] } /> ;
109
- } ) }
110
+ selectedPrefix = { config . backend . blockExplorers ?. [ coin ] } /> ;
111
+ } ) }
110
112
</ div >
111
113
< div className = "content padded" style = { { display : 'flex' , justifyContent : 'space-between' } } >
112
114
< ButtonLink
0 commit comments