@@ -6,20 +6,20 @@ export const hasIdentity = async (
66 account : string ,
77) : Promise < [ boolean , boolean ] > => {
88 try {
9- if ( ! ( await chaindata . checkApiConnection ( ) ) ) {
9+ const api = chaindata . apiPeople ? chaindata . apiPeople : chaindata . api ;
10+
11+ if ( ! api ?. isConnected ) {
1012 return [ false , false ] ;
1113 }
12- let identity = await chaindata . api ? .query . identity . identityOf ( account ) ;
14+ let identity = await api . query . identity . identityOf ( account ) ;
1315 if ( ! identity || ! identity . isSome ) {
1416 // 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 ) ;
1618 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 ] ) ;
2020 }
2121 }
22- const identityInfo = await chaindata . api ? .derive . accounts . identity ( account ) ;
22+ const identityInfo = await api . derive . accounts . identity ( account ) ;
2323 if ( ! identityInfo ) return null ;
2424 let verified = false ;
2525 if ( identity && identity . isSome ) {
@@ -33,7 +33,7 @@ export const hasIdentity = async (
3333
3434 return [ identity ? identity . isSome : false , verified ] ;
3535 } catch ( e ) {
36- await handleError ( chaindata , e , "hasIdentity" ) ;
36+ if ( ! chaindata . apiPeople ) await handleError ( chaindata , e , "hasIdentity" ) ;
3737 return [ false , true ] ;
3838 }
3939} ;
@@ -43,26 +43,26 @@ export const getFormattedIdentity = async (
4343 addr : string ,
4444) : Promise < Identity | null > => {
4545 try {
46- if ( ! ( await chaindata . checkApiConnection ( ) ) ) {
46+ const api = chaindata . apiPeople ? chaindata . apiPeople : chaindata . api ;
47+ if ( ! api ?. isConnected ) {
4748 return null ;
4849 }
4950 let identity : Identity | null = null ;
5051 let verified = false ;
5152 const subAccounts : { name : string ; address : string } [ ] = [ ] ;
5253
53- const hasId = await chaindata . api ? .derive . accounts . hasIdentity ( addr ) ;
54+ const hasId = await api . derive . accounts . hasIdentity ( addr ) ;
5455 if ( ! hasId || ! hasId . hasIdentity ) return null ;
5556
56- const identityInfo = await chaindata . api ? .derive . accounts . identity ( addr ) ;
57+ const identityInfo = await api . derive . accounts . identity ( addr ) ;
5758 if ( ! identityInfo ) return null ;
5859
59- const hasSubs = await chaindata . api ? .query . identity . subsOf ( addr ) ;
60+ const hasSubs = await api . query . identity . subsOf ( addr ) ;
6061 if ( hasSubs && hasSubs [ 1 ] . length > 0 ) {
6162 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+ ) ;
6666 if ( subAccountIdentity ) {
6767 const subAccount : { name : string ; address : string } = {
6868 name : subAccountIdentity . display || "" ,
@@ -97,21 +97,18 @@ export const getFormattedIdentity = async (
9797 }
9898
9999 if ( parent ) {
100- const superIdentity =
101- await chaindata . api ?. derive . accounts . identity ( parent ) ;
100+ const superIdentity = await api . derive . accounts . identity ( parent ) ;
102101 if ( superIdentity ) {
103102 const superAccount : { name : string ; address : string } = {
104103 name : superIdentity . display || "" ,
105104 address : parent . toString ( ) ,
106105 } ;
107- const subIdentities =
108- await chaindata . api ?. query . identity . subsOf ( parent ) ;
106+ const subIdentities = await api . query . identity . subsOf ( parent ) ;
109107 if ( subIdentities && subIdentities [ 1 ] . length > 0 ) {
110108 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+ ) ;
115112 if ( subAccountIdentity ) {
116113 const subAccount : { name : string ; address : string } = {
117114 name : subAccountIdentity . display || "" ,
@@ -158,7 +155,8 @@ export const getFormattedIdentity = async (
158155
159156 return identity ;
160157 } catch ( e ) {
161- await handleError ( chaindata , e , "getFormattedIdentity" ) ;
158+ if ( ! chaindata . apiPeople )
159+ await handleError ( chaindata , e , "getFormattedIdentity" ) ;
162160 return null ;
163161 }
164162} ;
0 commit comments