@@ -2,7 +2,7 @@ import { shortenAddress } from "@remix-ui/helper"
22import { RunTab } from "../types/run-tab"
33import { clearInstances , setAccount , setExecEnv } from "./actions"
44import { displayNotification , displayPopUp , fetchAccountsListFailed , fetchAccountsListRequest , fetchAccountsListSuccess , setMatchPassphrase , setPassphrase } from "./payload"
5- import { RunTabState } from "../types"
5+ import { toChecksumAddress } from '@ethereumjs/util'
66
77export const updateAccountBalances = async ( plugin : RunTab , dispatch : React . Dispatch < any > ) => {
88 const accounts = plugin . REACT_API . accounts . loadedAccounts
@@ -18,17 +18,12 @@ export const updateAccountBalances = async (plugin: RunTab, dispatch: React.Disp
1818export const fillAccountsList = async ( plugin : RunTab , dispatch : React . Dispatch < any > ) => {
1919 try {
2020 dispatch ( fetchAccountsListRequest ( ) )
21- const promise = plugin . blockchain . getAccounts ( )
21+ try {
22+ let accounts = await plugin . blockchain . getAccounts ( )
23+ if ( ! accounts ) accounts = [ ]
2224
23- promise . then ( async ( accounts : string [ ] ) => {
2425 const loadedAccounts = { }
25-
26- if ( ! accounts ) accounts = [ ]
27- // allSettled is undefined..
28- // so the current promise (all) will finish when:
29- // - all the promises resolve
30- // - at least one reject
31- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
26+
3227 for ( const account of accounts ) {
3328 const balance = await plugin . blockchain . getBalanceInEther ( account )
3429 loadedAccounts [ account ] = shortenAddress ( account , balance )
@@ -37,13 +32,12 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
3732
3833 if ( provider === 'injected' ) {
3934 const selectedAddress = plugin . blockchain . getInjectedWeb3Address ( )
40-
41- if ( ! ( Object . keys ( loadedAccounts ) . includes ( selectedAddress ) ) ) setAccount ( dispatch , null )
35+ if ( ! ( Object . keys ( loadedAccounts ) . includes ( toChecksumAddress ( selectedAddress ) ) ) ) setAccount ( dispatch , null )
4236 }
4337 dispatch ( fetchAccountsListSuccess ( loadedAccounts ) )
44- } ) . catch ( ( e ) => {
38+ } catch ( e ) {
4539 dispatch ( fetchAccountsListFailed ( e . message ) )
46- } )
40+ }
4741 } catch ( e ) {
4842 dispatch ( displayPopUp ( `Cannot get account list: ${ e } ` ) )
4943 }
0 commit comments