@@ -44,7 +44,7 @@ public void Hide()
4444 /// <param name="chain">Chain used to get balances and send transactions.</param>
4545 /// <param name="currency">Define a custom ERC20 currency. Leave it null to use the chains native token.</param>
4646 /// <param name="onClose">(Optional) Callback when the user closes this window.</param>
47- public async void Show ( IWallet wallet , Chain chain , Address currency = null , Action onClose = null )
47+ public async void Show ( IWallet wallet , Chain chain , Address currency = null , string currencySymbol = null , Action onClose = null )
4848 {
4949 _wallet = wallet ;
5050 _chain = chain ;
@@ -53,13 +53,24 @@ public async void Show(IWallet wallet, Chain chain, Address currency = null, Act
5353 _transactionPool . Cleanup ( ) ;
5454
5555 SetOverviewState ( ) ;
56- SetBalance ( 0 ) ;
57-
58- var walletAddress = _wallet . GetWalletAddress ( ) ;
59- var indexer = new ChainIndexer ( _chain ) ;
60- var balanceResponse = await indexer . GetNativeTokenBalance ( walletAddress ) ;
56+ SetBalance ( 0 , string . Empty ) ;
6157
62- SetBalance ( balanceResponse . balanceWei ) ;
58+ var indexer = new ChainIndexer ( _chain ) ;
59+ var walletAddress = _wallet . GetWalletAddress ( ) ;
60+
61+ if ( currency == null )
62+ {
63+ var balanceResponse = await indexer . GetNativeTokenBalance ( walletAddress ) ;
64+ SetNativeBalance ( balanceResponse . balanceWei ) ;
65+ }
66+ else
67+ {
68+ var response = await indexer . GetTokenBalances ( new GetTokenBalancesArgs ( walletAddress , currency , true ) ) ;
69+ var balances = response . balances ;
70+ var balance = balances . Length > 0 ? balances [ 0 ] . balance : 0 ;
71+ SetBalance ( balance , currencySymbol ) ;
72+ }
73+
6374 _messagePopup . gameObject . SetActive ( false ) ;
6475 EnableLoading ( false ) ;
6576
@@ -168,10 +179,15 @@ private async void UnlinkWallet(LinkedWalletData wallet)
168179 _messagePopup . Show ( success ? "Unlinked." : "Failed to unlink" , ! success ) ;
169180 }
170181
171- private void SetBalance ( BigInteger amount )
182+ private void SetNativeBalance ( BigInteger balance )
172183 {
173- var decimals = DecimalNormalizer . ReturnToNormalString ( amount ) ;
174184 var symbol = ChainDictionaries . GasCurrencyOf [ _chain ] ;
185+ SetBalance ( balance , symbol ) ;
186+ }
187+
188+ private void SetBalance ( BigInteger balance , string symbol )
189+ {
190+ var decimals = DecimalNormalizer . ReturnToNormalString ( balance ) ;
175191 _etherBalanceText . text = $ "{ decimals } { symbol } ";
176192 }
177193 }
0 commit comments