Skip to content

Commit ad701cd

Browse files
committed
frontend: use accounts instead of supported coins
Use the accounts array to determine which selections (drop-downs) to show in the explorer selection settings. This is better than using the supported coins endpoint because it does not require a keystore to be connected.
1 parent 733bf8d commit ad701cd

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

frontends/web/src/routes/router.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const AppRouter = ({ devices, deviceIDs, devicesKey, accounts, activeAcco
230230
<Route path="device-settings/passphrase/:deviceID" element={PassphraseEl} />
231231
<Route path="advanced-settings" element={AdvancedSettingsEl} />
232232
<Route path="electrum" element={<ElectrumSettings />} />
233-
<Route path="select-explorer" element={<SelectExplorerSettings />} />
233+
<Route path="select-explorer" element={<SelectExplorerSettings accounts={accounts}/>} />
234234
<Route path="manage-accounts" element={
235235
<ManageAccounts
236236
accounts={accounts}

frontends/web/src/routes/settings/advanced-settings.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const AdvancedSettings = ({ deviceIDs, hasAccounts }: TPagePropsWithSetti
9090
<EnableAuthSetting backendConfig={backendConfig} onChangeConfig={setConfig} />
9191
<EnableTorProxySetting proxyConfig={proxyConfig} onChangeConfig={setConfig} />
9292
<ConnectFullNodeSetting />
93-
{ deviceIDs.length > 0 ? <SelectExplorerSetting /> : null }
93+
{ hasAccounts ? <SelectExplorerSetting /> : null }
9494
</WithSettingsTabs>
9595
</ViewContent>
9696
</View>

frontends/web/src/routes/settings/select-explorer.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ import { Header } from '../../components/layout';
2424
import { BlockExplorers } from './block-explorers';
2525
import * as backendAPI from '../../api/backend';
2626
import { getConfig, setConfig } from '../../utils/config';
27-
import { CoinCode } from '../../api/account';
27+
import { CoinCode, IAccount } from '../../api/account';
2828
import { MobileHeader } from './components/mobile-header';
2929
import { useCallback, useEffect, useRef, useState } from 'react';
3030

31-
export const SelectExplorerSettings = () => {
31+
type TSelectExplorerSettingsProps = {
32+
accounts: IAccount[];
33+
}
34+
35+
export const SelectExplorerSettings = ({ accounts }: TSelectExplorerSettingsProps) => {
3236
const { t } = useTranslation();
3337

3438
const initialConfig = useRef<any>();
3539
const [config, setConfigState] = useState<any>();
3640

37-
const [supportedCoins, setSupportedCoins] = useState<backendAPI.ICoin[]>([]);
41+
const availableCoins = new Set(accounts.map(account => account.coinCode));
3842
const [allSelections, setAllSelections] = useState<backendAPI.TAvailableExplorers>();
3943

4044
const [saveDisabled, setSaveDisabled] = useState(true);
@@ -68,13 +72,11 @@ export const SelectExplorerSettings = () => {
6872

6973
useEffect(() => {
7074
const fetchData = async () => {
71-
const coins = await backendAPI.getSupportedCoins();
7275
const allExplorerSelection = await backendAPI.getAvailableExplorers();
7376

7477
// if set alongside config it will 'update' with it, but we want it to stay the same after initialization.
7578
initialConfig.current = await getConfig();
7679

77-
setSupportedCoins(coins);
7880
setAllSelections(allExplorerSelection);
7981
};
8082

@@ -99,14 +101,14 @@ export const SelectExplorerSettings = () => {
99101
</>
100102
}/>
101103
<div className="content padded">
102-
{supportedCoins.map(coin => {
104+
{ Array.from(availableCoins).map(coin => {
103105
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] ?? []}
107109
handleOnChange={handleChange}
108-
selectedPrefix={config.backend.blockExplorers?.[coin.coinCode]}/>;
109-
})}
110+
selectedPrefix={config.backend.blockExplorers?.[coin]}/>;
111+
}) }
110112
</div>
111113
<div className="content padded" style={{ display: 'flex', justifyContent: 'space-between' }}>
112114
<ButtonLink

0 commit comments

Comments
 (0)