2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
import type { Theme } from '@mui/material' ;
5
+ import type { ApiPromise } from '@polkadot/api' ;
5
6
import type { DeriveBalancesAll } from '@polkadot/api-derive/types' ;
6
7
import type { AccountJson } from '@polkadot/extension-base/background/types' ;
7
8
import type { Chain } from '@polkadot/extension-chains/types' ;
@@ -11,11 +12,11 @@ import type { Compact, u128 } from '@polkadot/types-codec';
11
12
import type { HexString } from '@polkadot/util/types' ;
12
13
import type { DropdownOption , FastestConnectionType , RecentChainsType , TransactionDetail , UserAddedChains } from './types' ;
13
14
14
- import { ApiPromise , WsProvider } from '@polkadot/api' ;
15
15
import { BN , BN_TEN , BN_ZERO , hexToBn , hexToString , hexToU8a , isHex , stringToU8a , u8aToHex , u8aToString } from '@polkadot/util' ;
16
16
import { decodeAddress , encodeAddress } from '@polkadot/util-crypto' ;
17
17
18
18
import { EXTRA_PRICE_IDS } from './api/getPrices' ;
19
+ import { fastestEndpoint } from './workers/utils' ;
19
20
import allChains from './chains' ;
20
21
import { ASSET_HUBS , BLOCK_RATE , FLOATING_POINT_DIGIT , INITIAL_RECENT_CHAINS_GENESISHASH , PROFILE_COLORS , RELAY_CHAINS_GENESISHASH , SHORT_ADDRESS_CHARACTERS , WESTEND_GENESIS_HASH } from './constants' ;
21
22
@@ -499,18 +500,9 @@ export async function updateRecentChains (addressKey: string, genesisHashKey: st
499
500
500
501
export async function fastestConnection ( endpoints : DropdownOption [ ] ) : Promise < FastestConnectionType > {
501
502
try {
502
- const connections = endpoints . map ( ( { value } ) => {
503
- const wsProvider = new WsProvider ( value as string ) ;
503
+ const urls = endpoints . map ( ( { value } ) => ( { value : value as string } ) ) ;
504
+ const { api , connections } = await fastestEndpoint ( urls ) ;
504
505
505
- const connection = ApiPromise . create ( { provider : wsProvider } ) ;
506
-
507
- return {
508
- connection,
509
- wsProvider
510
- } ;
511
- } ) ;
512
-
513
- const api = await Promise . any ( connections . map ( ( { connection } ) => connection ) ) ;
514
506
// @ts -ignore
515
507
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
516
508
const selectedEndpoint = api . registry . knownTypes . provider . endpoint as string ;
0 commit comments