@@ -23,14 +23,17 @@ import '../../../../utilities/amount/amount.dart';
2323import '../../../../utilities/amount/amount_formatter.dart' ;
2424import '../../../../utilities/enums/wallet_balance_toggle_state.dart' ;
2525import '../../../../utilities/text_styles.dart' ;
26+ import '../../../../wallets/crypto_currency/coins/ethereum.dart' ;
2627import '../../../../wallets/crypto_currency/coins/firo.dart' ;
28+ import '../../../../wallets/crypto_currency/coins/solana.dart' ;
2729import '../../../../wallets/crypto_currency/crypto_currency.dart'
2830 show CryptoCurrency;
2931import '../../../../wallets/isar/providers/eth/current_token_wallet_provider.dart' ;
3032import '../../../../wallets/isar/providers/eth/token_balance_provider.dart' ;
3133import '../../../../wallets/isar/providers/solana/current_sol_token_wallet_provider.dart' ;
3234import '../../../../wallets/isar/providers/solana/sol_token_balance_provider.dart' ;
3335import '../../../../wallets/isar/providers/wallet_info_provider.dart' ;
36+ import '../../../../wallets/wallet/impl/sub_wallets/solana_token_wallet.dart' ;
3437import 'desktop_balance_toggle_button.dart' ;
3538
3639class DesktopWalletSummary extends ConsumerStatefulWidget {
@@ -81,42 +84,43 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
8184 );
8285
8386 // For Ethereum tokens, get the token contract; for Solana tokens, get the token wallet.
84- dynamic tokenContract;
85- dynamic solanaTokenWallet;
87+ final EthContract ? tokenContract;
88+ final SolanaTokenWallet ? solanaTokenWallet;
8689 if (widget.isToken) {
87- try {
88- tokenContract = ref.watch (
89- pCurrentTokenWallet.select ((value) => value! .tokenContract),
90- );
91- } catch (_) {
92- // Ethereum token not found, check for Solana.
93- tokenContract = null ;
94- }
90+ switch (ref.watch (pWalletCoin (walletId))) {
91+ case Ethereum ():
92+ tokenContract = ref.watch (
93+ pCurrentTokenWallet.select ((value) => value! .tokenContract),
94+ );
95+ solanaTokenWallet = null ;
96+ break ;
97+
98+ case Solana ():
99+ tokenContract = null ;
100+ // this cannot be null if coin is sol and isToken is true.
101+ // if it is null, then there is a bug somewhere else.
102+ solanaTokenWallet = ref.watch (pCurrentSolanaTokenWallet)! ;
103+ break ;
95104
96- // Check for Solana token wallet if Ethereum token not found.
97- if (tokenContract == null ) {
98- try {
99- solanaTokenWallet = ref.watch (pCurrentSolanaTokenWallet);
100- } catch (_) {
105+ default :
106+ tokenContract = null ;
101107 solanaTokenWallet = null ;
102- }
103108 }
109+ } else {
110+ tokenContract = null ;
111+ solanaTokenWallet = null ;
104112 }
105113
106114 final price = widget.isToken && tokenContract != null
107115 ? ref.watch (
108116 priceAnd24hChangeNotifierProvider.select (
109- (value) => value.getTokenPrice (
110- (tokenContract as dynamic ).address as String ,
111- ),
117+ (value) => value.getTokenPrice (tokenContract! .address),
112118 ),
113119 )
114120 : widget.isToken && solanaTokenWallet != null
115121 ? ref.watch (
116122 priceAnd24hChangeNotifierProvider.select (
117- (value) => value.getTokenPrice (
118- "${(solanaTokenWallet as dynamic ).tokenMint }" ,
119- ),
123+ (value) => value.getTokenPrice (solanaTokenWallet! .tokenMint),
120124 ),
121125 )
122126 : ref.watch (
@@ -149,15 +153,15 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
149153 balance = ref.watch (
150154 pTokenBalance ((
151155 walletId: walletId,
152- contractAddress: ( tokenContract as dynamic ) .address as String ,
156+ contractAddress: tokenContract.address,
153157 )),
154158 );
155159 } else if (widget.isToken && solanaTokenWallet != null ) {
156160 // Watch Solana token balance from db.
157161 balance = ref.watch (
158162 pSolanaTokenBalance ((
159163 walletId: walletId,
160- tokenMint: ( solanaTokenWallet as dynamic ) .tokenMint,
164+ tokenMint: solanaTokenWallet.tokenMint,
161165 )),
162166 );
163167 } else {
@@ -179,18 +183,13 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
179183 FittedBox (
180184 fit: BoxFit .scaleDown,
181185 child: SelectableText (
182- widget.isToken && solanaTokenWallet != null
183- ? "${balanceToShow .decimal .toStringAsFixed (
184- (solanaTokenWallet as dynamic ).tokenDecimals as int ,
185- )} ${(solanaTokenWallet as dynamic ).tokenSymbol }"
186- : ref
187- .watch (pAmountFormatter (coin))
188- .format (
189- balanceToShow,
190- ethContract: tokenContract != null
191- ? tokenContract as EthContract ?
192- : null ,
193- ),
186+ ref
187+ .watch (pAmountFormatter (coin))
188+ .format (
189+ balanceToShow,
190+ ethContract: tokenContract,
191+ splToken: solanaTokenWallet? .splToken,
192+ ),
194193 style: STextStyles .desktopH3 (context),
195194 ),
196195 ),
@@ -222,7 +221,7 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
222221 walletId: walletId,
223222 initialSyncStatus: widget.initialSyncStatus,
224223 tokenContractAddress: widget.isToken && tokenContract != null
225- ? ( tokenContract as EthContract ) .address
224+ ? tokenContract.address
226225 : null ,
227226 ),
228227
0 commit comments