fix: nft popup error triggering multiple times on error or internet failure (#3321)

David Adegoke committed Jun 10, 2026 at 18:20 UTC 303143052aaf49f1399b99d64e9c7714ac9a1dc5
1 file changed +17 -8
lib/view_model/dashboard/nft_view_model.dart
+17 -8
@@ -7,6 +7,7 @@ import 'package:cake_wallet/reactions/wallet_connect.dart';
7 import 'package:cake_wallet/src/screens/wallet_connect/services/bottom_sheet_service.dart';
8 import 'package:cake_wallet/src/screens/wallet_connect/widgets/bottom_sheet/bottom_sheet_message_display_widget.dart';
9 import 'package:cake_wallet/evm/evm.dart';
10 +import 'package:cake_wallet/utils/debounce.dart';
11 import 'package:cw_core/wallet_type.dart';
12 import 'package:cw_core/utils/proxy_wrapper.dart';
13 import 'package:mobx/mobx.dart';
@@ -31,12 +32,14 @@ abstract class NFTViewModelBase with Store {
32 if (wallet != null) return wallet.chainId;
33
34 return null;
34 - }, (_) => getNFTAssetByWallet());
35 + }, (_) => _fetchDebounce.run(() => getNFTAssetByWallet()));
36 }
37 }
38
39 final AppStore appStore;
40 + bool _nftErrorPopupShown = false;
41 final BottomSheetService bottomSheetService;
42 + final Debounce _fetchDebounce = Debounce(const Duration(milliseconds: 500));
43
44 @observable
45 bool isLoading;
@@ -100,6 +103,8 @@ abstract class NFTViewModelBase with Store {
103
104 final decodedResponse = jsonDecode(response.body);
105
106 + _nftErrorPopupShown = false;
107 +
108 if (wallet.type == WalletType.solana) {
109 final results = await Future.wait(
110 (decodedResponse as List<dynamic>).map(
@@ -115,7 +120,8 @@ abstract class NFTViewModelBase with Store {
120
121 solanaNftAssetModels.addAll(results);
122 } else {
118 - final result = WalletNFTsResponseModel.fromJson(decodedResponse as Map<String, dynamic>).result ?? [];
123 + final result =
124 + WalletNFTsResponseModel.fromJson(decodedResponse as Map<String, dynamic>).result ?? [];
125
126 nftAssetByWalletModels.clear();
127
@@ -123,12 +129,15 @@ abstract class NFTViewModelBase with Store {
129 }
130 } catch (e) {
131 log(e.toString());
126 - bottomSheetService.queueBottomSheet(
127 - isModalDismissible: true,
128 - widget: BottomSheetMessageDisplayWidget(
129 - message: S.current.moralis_nft_error,
130 - ),
131 - );
132 + if (!_nftErrorPopupShown) {
133 + _nftErrorPopupShown = true;
134 + bottomSheetService.queueBottomSheet(
135 + isModalDismissible: true,
136 + widget: BottomSheetMessageDisplayWidget(
137 + message: S.current.moralis_nft_error,
138 + ),
139 + );
140 + }
141 } finally {
142 isLoading = false;
143 }