@@ -13,31 +13,6 @@ import { decodeAddress } from '@polkadot/util-crypto';
1313
1414import { memo } from '../util' ;
1515
16- function retrieve ( api : ApiInterfaceRx , address : Address | AccountId | AccountIndex | Uint8Array | string | null | undefined ) : Observable < AccountIdAndIndex > {
17- try {
18- // yes, this can fail, don't care too much, catch will catch it
19- const decoded = isU8a ( address )
20- ? address
21- : decodeAddress ( ( address || '' ) . toString ( ) ) ;
22-
23- if ( decoded . length > 8 ) {
24- const accountId = api . registry . createType ( 'AccountId' , decoded ) ;
25-
26- return api . derive . accounts . idToIndex ( accountId ) . pipe (
27- map ( ( accountIndex ) : AccountIdAndIndex => [ accountId , accountIndex ] )
28- ) ;
29- }
30-
31- const accountIndex = api . registry . createType ( 'AccountIndex' , decoded ) ;
32-
33- return api . derive . accounts . indexToId ( accountIndex . toString ( ) ) . pipe (
34- map ( ( accountId ) : AccountIdAndIndex => [ accountId , accountIndex ] )
35- ) ;
36- } catch ( error ) {
37- return of ( [ undefined , undefined ] ) ;
38- }
39- }
40-
4116/**
4217 * @name idAndIndex
4318 * @param {(Address | AccountId | AccountIndex | Uint8Array | string | null) } address - An accounts address in various formats.
@@ -52,6 +27,28 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
5227 * ```
5328 */
5429export function idAndIndex ( instanceId : string , api : ApiInterfaceRx ) : ( address ?: Address | AccountId | AccountIndex | Uint8Array | string | null ) => Observable < AccountIdAndIndex > {
55- return memo ( instanceId , ( address ?: Address | AccountId | AccountIndex | Uint8Array | string | null ) : Observable < AccountIdAndIndex > =>
56- retrieve ( api , address ) ) ;
30+ return memo ( instanceId , ( address ?: Address | AccountId | AccountIndex | Uint8Array | string | null ) : Observable < AccountIdAndIndex > => {
31+ try {
32+ // yes, this can fail, don't care too much, catch will catch it
33+ const decoded = isU8a ( address )
34+ ? address
35+ : decodeAddress ( ( address || '' ) . toString ( ) ) ;
36+
37+ if ( decoded . length > 8 ) {
38+ const accountId = api . registry . createType ( 'AccountId' , decoded ) ;
39+
40+ return api . derive . accounts . idToIndex ( accountId ) . pipe (
41+ map ( ( accountIndex ) : AccountIdAndIndex => [ accountId , accountIndex ] )
42+ ) ;
43+ }
44+
45+ const accountIndex = api . registry . createType ( 'AccountIndex' , decoded ) ;
46+
47+ return api . derive . accounts . indexToId ( accountIndex . toString ( ) ) . pipe (
48+ map ( ( accountId ) : AccountIdAndIndex => [ accountId , accountIndex ] )
49+ ) ;
50+ } catch ( error ) {
51+ return of ( [ undefined , undefined ] ) ;
52+ }
53+ } ) ;
5754}
0 commit comments