find the first available URL (#2350)

This commit is contained in:
Jaco Greeff 2020-03-09 05:39:45 +01:00 committed by GitHub
parent 1cbbd9b51c
commit b2903d6ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -62,19 +62,19 @@ export default [
{
isHeader: true,
text: 'Live networks',
value: -1
value: ''
},
...LIVE,
{
isHeader: true,
text: 'Test networks',
value: -1
value: ''
},
...TEST,
{
isHeader: true,
text: 'Development',
value: -1
value: ''
},
...DEV
].map((option): Option => ({ ...option, withI18n: true }));

View File

@ -18,11 +18,12 @@ if (Array.isArray(urlOptions.rpc)) {
throw new Error('Invalid WS endpoint specified');
}
const fallbackUrl = availableEndpoints.find(({ value }) => !!value) || { value: 'http://127.0.0.1:9944' };
const apiUrl = urlOptions.rpc // we have a supplied value
? urlOptions.rpc.split('#')[0] // https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9944#/explorer
: [stored.apiUrl, process.env.WS_URL].includes(settings.apiUrl) // overridden, or stored
? settings.apiUrl // keep as-is
: availableEndpoints[0].value as string; // grab first available
: fallbackUrl.value as string; // grab the fallback
// set the default as retrieved here
settings.set({ apiUrl });