@@ -7,18 +7,17 @@ import store from 'store';
7
7
import { createWsEndpoints } from '@polkadot/apps-config' ;
8
8
import { extractIpfsDetails } from '@polkadot/react-hooks/useIpfs' ;
9
9
import { settings } from '@polkadot/ui-settings' ;
10
- import { Endpoint } from '@polkadot/ui-settings/types' ;
11
10
import { assert } from '@polkadot/util' ;
12
11
13
- function networkOrUrl ( apiType : Endpoint ) : void {
14
- if ( apiType . type === 'json-rpc' ) {
15
- console . log ( 'WS endpoint=' , apiType . param ) ;
16
- } else if ( apiType . type === 'substrate-connect' ) {
17
- console . log ( 'Chain of light client is =' , apiType . param ) ;
12
+ function networkOrUrl ( apiUrl : string ) : void {
13
+ if ( apiUrl . startsWith ( 'light://' ) ) {
14
+ console . log ( 'Light endpoint=' , apiUrl . replace ( 'light://' , '' ) ) ;
15
+ } else {
16
+ console . log ( 'WS endpoint =' , apiUrl ) ;
18
17
}
19
18
}
20
19
21
- function getApiType ( ) : Endpoint {
20
+ function getApiUrl ( ) : string {
22
21
// we split here so that both these forms are allowed
23
22
// - http://localhost:3000/?rpc=wss://substrate-rpc.parity.io/#/explorer
24
23
// - http://localhost:3000/#/explorer?rpc=wss://substrate-rpc.parity.io
@@ -31,17 +30,9 @@ function getApiType (): Endpoint {
31
30
// https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9944#/explorer;
32
31
const url = decodeURIComponent ( urlOptions . rpc . split ( '#' ) [ 0 ] ) ;
33
32
34
- assert ( url . startsWith ( 'ws://' ) || url . startsWith ( 'wss://' ) , 'Non-prefixed ws/wss url' ) ;
33
+ assert ( url . startsWith ( 'ws://' ) || url . startsWith ( 'wss://' ) || url . startsWith ( 'light://' ) , 'Non-prefixed ws/wss/light url' ) ;
35
34
36
- return { param : url , type : 'json-rpc' } ;
37
- } else if ( urlOptions . sc ) {
38
- assert ( ! Array . isArray ( urlOptions . sc ) , 'Invalid network specified' ) ;
39
-
40
- // https://polkadot.js.org/apps/?sc=kusama#/explorer;
41
- const network = decodeURIComponent ( urlOptions . sc . split ( '#' ) [ 0 ] ) ;
42
- const chain = network . split ( '-' ) [ 0 ] ;
43
-
44
- return { param : chain , type : 'substrate-connect' } ;
35
+ return url ;
45
36
}
46
37
47
38
const endpoints = createWsEndpoints ( < T = string > ( ) : T => ( '' as unknown as T ) ) ;
@@ -52,25 +43,25 @@ function getApiType (): Endpoint {
52
43
const option = endpoints . find ( ( { dnslink } ) => dnslink === ipnsChain ) ;
53
44
54
45
if ( option ) {
55
- return { param : option . value , type : 'json-rpc' } ;
46
+ return option . value ;
56
47
}
57
48
}
58
49
59
50
const stored = store . get ( 'settings' ) as Record < string , unknown > || { } ;
60
51
const fallbackUrl = endpoints . find ( ( { value } ) => ! ! value ) ;
61
52
62
53
// via settings, or the default chain
63
- return [ stored . apiType , process . env . WS_URL ] . includes ( settings . apiType )
64
- ? settings . apiType // keep as-is
54
+ return [ stored . apiUrl , process . env . WS_URL ] . includes ( settings . apiUrl )
55
+ ? settings . apiUrl // keep as-is
65
56
: fallbackUrl
66
- ? { param : fallbackUrl . value , type : 'json-rpc' } // grab the fallback
67
- : { param : 'ws://127.0.0.1:9944' , type : 'json-rpc' } ; // nothing found, go local
57
+ ? fallbackUrl . value // grab the fallback
58
+ : 'ws://127.0.0.1:9944' ; // nothing found, go local
68
59
}
69
60
70
61
// There cannot be a Substrate Connect light client default (expect only jrpc EndpointType)
71
- const apiType = getApiType ( ) ;
62
+ const apiUrl = getApiUrl ( ) ;
72
63
73
64
// set the default as retrieved here
74
- settings . set ( { apiType } ) ;
65
+ settings . set ( { apiUrl } ) ;
75
66
76
- networkOrUrl ( apiType ) ;
67
+ networkOrUrl ( apiUrl ) ;
0 commit comments