File tree Expand file tree Collapse file tree 2 files changed +41
-38
lines changed Expand file tree Collapse file tree 2 files changed +41
-38
lines changed Original file line number Diff line number Diff line change @@ -23,43 +23,46 @@ export const list: AccountFormula<ContractWithBalance[]> = {
23
23
true
24
24
) ) ?? [ ]
25
25
26
- const [ contractInfos , balances ] = await Promise . all ( [
27
- Promise . all (
28
- matchingContracts . map ( ( { contractAddress } ) =>
29
- info . compute ( {
30
- ...env ,
26
+ const contractsWithBalance = (
27
+ await Promise . all (
28
+ matchingContracts . map (
29
+ async ( {
31
30
contractAddress,
32
- } )
33
- )
34
- ) ,
35
- Promise . all (
36
- matchingContracts . map ( ( { contractAddress } ) =>
37
- balance . compute ( {
38
- ...env ,
39
- contractAddress,
40
- args : {
41
- address : env . address ,
42
- } ,
43
- } )
44
- )
45
- ) ,
46
- ] )
31
+ } ) : Promise < ContractWithBalance | undefined > => {
32
+ const [ _contractInfo , _balance ] = await Promise . allSettled ( [
33
+ info . compute ( {
34
+ ...env ,
35
+ contractAddress,
36
+ } ) ,
37
+ balance . compute ( {
38
+ ...env ,
39
+ contractAddress,
40
+ args : {
41
+ address : env . address ,
42
+ } ,
43
+ } ) ,
44
+ ] )
47
45
48
- const contractsWithBalance = matchingContracts
49
- // Filter by those with cw20 in the contract name and with a >0 balance.
50
- . map ( ( { contractAddress } , index ) : ContractWithBalance | undefined =>
51
- contractInfos [ index ] ?. contract ?. includes ( 'cw20' ) &&
52
- balances [ index ] !== '0'
53
- ? {
54
- contractAddress,
55
- balance : balances [ index ] ,
56
- }
57
- : undefined
58
- )
59
- . filter (
60
- ( contractWithBalance ) : contractWithBalance is ContractWithBalance =>
61
- ! ! contractWithBalance
46
+ const contractName =
47
+ _contractInfo . status === 'fulfilled'
48
+ ? _contractInfo . value . contract
49
+ : undefined
50
+ const tokenBalance =
51
+ _balance . status === 'fulfilled' ? _balance . value : '0'
52
+
53
+ // Filter by those with cw20 in the contract name (or no name at
54
+ // all) and with a >0 balance.
55
+ return ( ! contractName || contractName . includes ( 'cw20' ) ) &&
56
+ tokenBalance !== '0'
57
+ ? {
58
+ contractAddress,
59
+ balance : tokenBalance ,
60
+ }
61
+ : undefined
62
+ }
63
+ )
62
64
)
65
+ ) . flatMap ( ( result ) => result || [ ] )
63
66
64
67
return contractsWithBalance
65
68
} ,
Original file line number Diff line number Diff line change @@ -7,10 +7,10 @@ export const info: ContractFormula<ContractInfo> = {
7
7
docs : {
8
8
description : 'retrieves the contract info (name and version)' ,
9
9
} ,
10
- compute : async ( { contractAddress, getTransformationMatch } ) => {
11
- const info = (
12
- await getTransformationMatch < ContractInfo > ( contractAddress , 'info' )
13
- ) ?. value
10
+ compute : async ( { contractAddress, getTransformationMatch, get } ) => {
11
+ const info =
12
+ ( await getTransformationMatch < ContractInfo > ( contractAddress , 'info' ) )
13
+ ?. value || ( await get ( contractAddress , 'contract_info' ) )
14
14
15
15
if ( ! info ) {
16
16
throw new Error ( `no contract info found for ${ contractAddress } ` )
You can’t perform that action at this time.
0 commit comments