@@ -19,7 +19,6 @@ import '../../../db/isar/main_db.dart';
1919import '../../../models/isar/models/ethereum/eth_contract.dart' ;
2020import '../../../models/isar/models/solana/spl_token.dart' ;
2121import '../../../notifications/show_flush_bar.dart' ;
22- import '../../../services/solana/solana_token_api.dart' ;
2322import '../../../pages_desktop_specific/desktop_home_view.dart' ;
2423import '../../../providers/global/price_provider.dart' ;
2524import '../../../providers/global/wallets_provider.dart' ;
@@ -109,112 +108,11 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
109108
110109 final wallet = ref.read (pWallets).getWallet (widget.walletId);
111110
112- // Handle Ethereum tokens.
111+ // Handle tokens.
113112 if (wallet is EthereumWallet ) {
114113 await wallet.updateTokenContracts (selectedTokens);
115- }
116- // Handle Solana tokens.
117- else if (wallet is SolanaWallet ) {
118- // Get WalletInfo and update Solana token mint addresses.
119- final walletInfo = wallet.info;
120-
121- // Separate selected tokens into default and custom.
122- final defaultTokenMints = DefaultSplTokens .list.map ((e) => e.address).toSet ();
123- final selectedDefaultTokens = selectedTokens.where (
124- (mint) => defaultTokenMints.contains (mint),
125- ).toSet ();
126- final selectedCustomTokens = selectedTokens.where (
127- (mint) => ! defaultTokenMints.contains (mint),
128- ).toSet ();
129-
130- // Update default token mint addresses.
131- await walletInfo.updateSolanaTokenMintAddresses (
132- newMintAddresses: selectedDefaultTokens,
133- isar: MainDB .instance.isar,
134- );
135-
136- // Update custom token mint addresses.
137- await walletInfo.updateSolanaCustomTokenMintAddresses (
138- newMintAddresses: selectedCustomTokens,
139- isar: MainDB .instance.isar,
140- );
141-
142- // Log selected tokens and verify ownership.
143- debugPrint ('===== SOLANA TOKEN OWNERSHIP CHECK =====' );
144- debugPrint ('Wallet: ${walletInfo .name }' );
145- debugPrint ('Selected token mint addresses: $selectedTokens ' );
146-
147- // Get wallet's receiving address for ownership checks.
148- try {
149- final receivingAddressObj = await wallet.getCurrentReceivingAddress ();
150- if (receivingAddressObj == null ) {
151- debugPrint ('Error: Could not get wallet receiving address' );
152- return ;
153- }
154- final receivingAddress = receivingAddressObj.value;
155- debugPrint ('Wallet address: $receivingAddress ' );
156- debugPrint ('' );
157-
158- // Check ownership of each selected token.
159- for (final mintAddress in selectedTokens) {
160- // Find the token entity to get token details.
161- final tokenEntity = tokenEntities.firstWhere (
162- (e) => e.token.address == mintAddress,
163- orElse: () => AddTokenListElementData (
164- // Fallback contract with just the address.
165- EthContract (
166- address: mintAddress,
167- name: 'Unknown Token' ,
168- symbol: mintAddress,
169- decimals: 0 ,
170- type: EthContractType .erc20,
171- ),
172- ),
173- );
174-
175- final tokenName = tokenEntity.token.name;
176- final tokenSymbol = tokenEntity.token.symbol;
177-
178- debugPrint ('Token: $tokenName ($tokenSymbol )' );
179- debugPrint (' Mint: $mintAddress ' );
180-
181- // Check if wallet owns this token using the API.
182- try {
183- // Initialize the RPC client for the SolanaTokenAPI.
184- final tokenApi = SolanaTokenAPI ();
185- final rpcClient = wallet.getRpcClient ();
186-
187- if (rpcClient != null ) {
188- tokenApi.initializeRpcClient (rpcClient);
189-
190- final ownershipResult = await tokenApi.ownsToken (
191- receivingAddress,
192- mintAddress,
193- );
194-
195- if (ownershipResult.isSuccess) {
196- if (ownershipResult.value == true ) {
197- debugPrint ('OWNS token - token account found' );
198- } else {
199- debugPrint ('DOES NOT own token - no token account found' );
200- }
201- } else {
202- debugPrint (
203- 'Error checking ownership: ${ownershipResult .exception }' ,
204- );
205- }
206- } else {
207- debugPrint ('Warning: RPC client not initialized for wallet' );
208- }
209- } catch (e) {
210- debugPrint ('Exception checking ownership: $e ' );
211- }
212- }
213-
214- debugPrint ('========================================' );
215- } catch (e) {
216- debugPrint ('Error getting wallet address: $e ' );
217- }
114+ } else if (wallet is SolanaWallet ) {
115+ await wallet.updateSolanaTokens (selectedTokens);
218116 }
219117 if (mounted) {
220118 if (widget.contractsToMarkSelected == null ) {
@@ -347,29 +245,23 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
347245
348246 final wallet = ref.read (pWallets).getWallet (widget.walletId);
349247
350- // Load appropriate tokens based on wallet type.
351248 if (wallet is SolanaWallet ) {
352- // Load both default and custom Solana tokens.
353- final defaultSplTokens = DefaultSplTokens .list;
354- tokenEntities.addAll (defaultSplTokens.map ((e) => AddTokenListElementData (e)));
355-
356- // Load custom tokens from database
357- final customSplTokens = MainDB .instance.getSplTokens ().findAllSync ();
358-
359- // Deduplicate: only add custom tokens that aren't already in defaults.
360- final seenAddresses = < String > {
361- ...defaultSplTokens.map ((e) => e.address),
362- ...tokenEntities.map ((e) => e.token.address),
363- };
364-
365- for (final token in customSplTokens) {
366- if (! seenAddresses.contains (token.address)) {
367- tokenEntities.add (AddTokenListElementData (token));
368- seenAddresses.add (token.address);
369- }
249+ final contracts = MainDB .instance
250+ .getSplTokens ()
251+ .sortByName ()
252+ .findAllSync ();
253+
254+ if (contracts.isEmpty) {
255+ contracts.addAll (DefaultSplTokens .list);
256+ MainDB .instance
257+ .putSplTokens (contracts)
258+ .then (
259+ (_) => ref.read (priceAnd24hChangeNotifierProvider).updatePrice (),
260+ );
370261 }
262+
263+ tokenEntities.addAll (contracts.map ((e) => AddTokenListElementData (e)));
371264 } else {
372- // Load Ethereum tokens (default behavior for Ethereum wallets).
373265 final contracts = MainDB .instance
374266 .getEthContracts ()
375267 .sortByName ()
0 commit comments