@@ -6,20 +6,20 @@ export const hasIdentity = async (
6
6
account : string ,
7
7
) : Promise < [ boolean , boolean ] > => {
8
8
try {
9
- if ( ! ( await chaindata . checkApiConnection ( ) ) ) {
9
+ const api = chaindata . apiPeople ? chaindata . apiPeople : chaindata . api ;
10
+
11
+ if ( ! api ?. isConnected ) {
10
12
return [ false , false ] ;
11
13
}
12
- let identity = await chaindata . api ? .query . identity . identityOf ( account ) ;
14
+ let identity = await api . query . identity . identityOf ( account ) ;
13
15
if ( ! identity || ! identity . isSome ) {
14
16
// check if it's a sub
15
- const superOf = await chaindata . api ? .query . identity . superOf ( account ) ;
17
+ const superOf = await api . query . identity . superOf ( account ) ;
16
18
if ( superOf && superOf . isSome ) {
17
- identity = await chaindata . api ?. query . identity . identityOf (
18
- superOf . unwrap ( ) [ 0 ] ,
19
- ) ;
19
+ identity = await api . query . identity . identityOf ( superOf . unwrap ( ) [ 0 ] ) ;
20
20
}
21
21
}
22
- const identityInfo = await chaindata . api ? .derive . accounts . identity ( account ) ;
22
+ const identityInfo = await api . derive . accounts . identity ( account ) ;
23
23
if ( ! identityInfo ) return null ;
24
24
let verified = false ;
25
25
if ( identity && identity . isSome ) {
@@ -33,7 +33,7 @@ export const hasIdentity = async (
33
33
34
34
return [ identity ? identity . isSome : false , verified ] ;
35
35
} catch ( e ) {
36
- await handleError ( chaindata , e , "hasIdentity" ) ;
36
+ if ( ! chaindata . apiPeople ) await handleError ( chaindata , e , "hasIdentity" ) ;
37
37
return [ false , true ] ;
38
38
}
39
39
} ;
@@ -43,26 +43,26 @@ export const getFormattedIdentity = async (
43
43
addr : string ,
44
44
) : Promise < Identity | null > => {
45
45
try {
46
- if ( ! ( await chaindata . checkApiConnection ( ) ) ) {
46
+ const api = chaindata . apiPeople ? chaindata . apiPeople : chaindata . api ;
47
+ if ( ! api ?. isConnected ) {
47
48
return null ;
48
49
}
49
50
let identity : Identity | null = null ;
50
51
let verified = false ;
51
52
const subAccounts : { name : string ; address : string } [ ] = [ ] ;
52
53
53
- const hasId = await chaindata . api ? .derive . accounts . hasIdentity ( addr ) ;
54
+ const hasId = await api . derive . accounts . hasIdentity ( addr ) ;
54
55
if ( ! hasId || ! hasId . hasIdentity ) return null ;
55
56
56
- const identityInfo = await chaindata . api ? .derive . accounts . identity ( addr ) ;
57
+ const identityInfo = await api . derive . accounts . identity ( addr ) ;
57
58
if ( ! identityInfo ) return null ;
58
59
59
- const hasSubs = await chaindata . api ? .query . identity . subsOf ( addr ) ;
60
+ const hasSubs = await api . query . identity . subsOf ( addr ) ;
60
61
if ( hasSubs && hasSubs [ 1 ] . length > 0 ) {
61
62
for ( const subaccountAddress of hasSubs [ 1 ] ) {
62
- const subAccountIdentity =
63
- await chaindata . api ?. derive . accounts . identity (
64
- subaccountAddress . toString ( ) ,
65
- ) ;
63
+ const subAccountIdentity = await api . derive . accounts . identity (
64
+ subaccountAddress . toString ( ) ,
65
+ ) ;
66
66
if ( subAccountIdentity ) {
67
67
const subAccount : { name : string ; address : string } = {
68
68
name : subAccountIdentity . display || "" ,
@@ -97,21 +97,18 @@ export const getFormattedIdentity = async (
97
97
}
98
98
99
99
if ( parent ) {
100
- const superIdentity =
101
- await chaindata . api ?. derive . accounts . identity ( parent ) ;
100
+ const superIdentity = await api . derive . accounts . identity ( parent ) ;
102
101
if ( superIdentity ) {
103
102
const superAccount : { name : string ; address : string } = {
104
103
name : superIdentity . display || "" ,
105
104
address : parent . toString ( ) ,
106
105
} ;
107
- const subIdentities =
108
- await chaindata . api ?. query . identity . subsOf ( parent ) ;
106
+ const subIdentities = await api . query . identity . subsOf ( parent ) ;
109
107
if ( subIdentities && subIdentities [ 1 ] . length > 0 ) {
110
108
for ( const subaccountAddress of subIdentities [ 1 ] ) {
111
- const subAccountIdentity =
112
- await chaindata . api ?. derive . accounts . identity (
113
- subaccountAddress . toString ( ) ,
114
- ) ;
109
+ const subAccountIdentity = await api . derive . accounts . identity (
110
+ subaccountAddress . toString ( ) ,
111
+ ) ;
115
112
if ( subAccountIdentity ) {
116
113
const subAccount : { name : string ; address : string } = {
117
114
name : subAccountIdentity . display || "" ,
@@ -158,7 +155,8 @@ export const getFormattedIdentity = async (
158
155
159
156
return identity ;
160
157
} catch ( e ) {
161
- await handleError ( chaindata , e , "getFormattedIdentity" ) ;
158
+ if ( ! chaindata . apiPeople )
159
+ await handleError ( chaindata , e , "getFormattedIdentity" ) ;
162
160
return null ;
163
161
}
164
162
} ;
0 commit comments