Merge remote-tracking branch 'origin/main' into electrum-sp-refactors

This commit is contained in:
Rafael Saes 2025-04-25 12:45:43 -03:00
commit ab963de769
6 changed files with 64 additions and 26 deletions

View file

@ -650,6 +650,7 @@ Future<void> setup({
return walletKitService; return walletKitService;
}); });
getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>()));
getIt.registerFactory(() => BalancePage( getIt.registerFactory(() => BalancePage(
nftViewModel: getIt.get<NFTViewModel>(), nftViewModel: getIt.get<NFTViewModel>(),
dashboardViewModel: getIt.get<DashboardViewModel>(), dashboardViewModel: getIt.get<DashboardViewModel>(),
@ -1478,7 +1479,6 @@ Future<void> setup({
() => WalletConnectConnectionsView(walletKitService: getIt.get<WalletKitService>()), () => WalletConnectConnectionsView(walletKitService: getIt.get<WalletKitService>()),
); );
getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>()));
getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>())); getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>()));
getIt.registerFactory(() => SignViewModel(getIt.get<AppStore>().wallet!)); getIt.registerFactory(() => SignViewModel(getIt.get<AppStore>().wallet!));

View file

@ -9,8 +9,7 @@ class MainActions {
final bool Function(DashboardViewModel viewModel)? isEnabled; final bool Function(DashboardViewModel viewModel)? isEnabled;
final bool Function(DashboardViewModel viewModel)? canShow; final bool Function(DashboardViewModel viewModel)? canShow;
final Future<void> Function( final Future<void> Function(BuildContext context, DashboardViewModel viewModel) onTap;
BuildContext context, DashboardViewModel viewModel) onTap;
MainActions._({ MainActions._({
required this.name, required this.name,
@ -32,7 +31,12 @@ class MainActions {
name: (context) => S.of(context).wallets, name: (context) => S.of(context).wallets,
image: 'assets/images/wallet_new.png', image: 'assets/images/wallet_new.png',
onTap: (BuildContext context, DashboardViewModel viewModel) async { onTap: (BuildContext context, DashboardViewModel viewModel) async {
Navigator.pushNamed(context, Routes.walletList); Navigator.pushNamed(
context,
Routes.walletList,
arguments: (BuildContext context) =>
Navigator.of(context).pushNamedAndRemoveUntil(Routes.dashboard, (route) => false),
);
}, },
); );
@ -65,7 +69,6 @@ class MainActions {
}, },
); );
static MainActions tradeAction = MainActions._( static MainActions tradeAction = MainActions._(
name: (context) => S.of(context).exchange, name: (context) => S.of(context).exchange,
image: 'assets/images/buy_sell.png', image: 'assets/images/buy_sell.png',
@ -76,4 +79,4 @@ class MainActions {
await Navigator.of(context).pushNamed(Routes.buySellPage, arguments: false); await Navigator.of(context).pushNamed(Routes.buySellPage, arguments: false);
}, },
); );
} }

View file

@ -11,11 +11,27 @@ import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
class NFTListingPage extends StatelessWidget { class NFTListingPage extends StatefulWidget {
final NFTViewModel nftViewModel; final NFTViewModel nftViewModel;
const NFTListingPage({super.key, required this.nftViewModel}); const NFTListingPage({super.key, required this.nftViewModel});
@override
State<NFTListingPage> createState() => _NFTListingPageState();
}
class _NFTListingPageState extends State<NFTListingPage> {
@override
void initState() {
super.initState();
fetchNFTsForWallet();
}
Future<void> fetchNFTsForWallet() async {
await widget.nftViewModel.getNFTAssetByWallet();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final dashboardTheme = Theme.of(context).extension<DashboardPageTheme>()!; final dashboardTheme = Theme.of(context).extension<DashboardPageTheme>()!;
@ -36,11 +52,11 @@ class NFTListingPage extends StatelessWidget {
onPressed: () => Navigator.pushNamed( onPressed: () => Navigator.pushNamed(
context, context,
Routes.importNFTPage, Routes.importNFTPage,
arguments: nftViewModel, arguments: widget.nftViewModel,
), ),
), ),
), ),
if (nftViewModel.isLoading) if (widget.nftViewModel.isLoading)
Expanded( Expanded(
child: Center( child: Center(
child: CircularProgressIndicator( child: CircularProgressIndicator(
@ -53,7 +69,7 @@ class NFTListingPage extends StatelessWidget {
) )
else else
Expanded( Expanded(
child: NFTListWidget(nftViewModel: nftViewModel), child: NFTListWidget(nftViewModel: widget.nftViewModel),
), ),
], ],
); );

View file

@ -14,13 +14,30 @@ class BottomSheetMessageDisplayWidget extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Row(
isError ? S.current.error : S.current.successful, mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: TextStyle( crossAxisAlignment: CrossAxisAlignment.center,
fontSize: 16, children: [
fontWeight: FontWeight.normal, Text(
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor, isError ? S.current.error : S.current.successful,
), style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
),
),
IconButton(
color: Theme.of(context).appBarTheme.titleTextStyle!.color!,
padding: const EdgeInsets.all(0.0),
visualDensity: VisualDensity.compact,
onPressed: () {
if (Navigator.canPop(context)) {
Navigator.pop(context);
}
},
icon: const Icon(Icons.close_sharp),
),
],
), ),
SizedBox(height: 8), SizedBox(height: 8),
Row( Row(
@ -37,6 +54,7 @@ class BottomSheetMessageDisplayWidget extends StatelessWidget {
), ),
], ],
), ),
SizedBox(height: 16),
], ],
); );
} }

View file

@ -73,7 +73,11 @@ class SettingActions {
image: 'assets/images/wallet_menu.png', image: 'assets/images/wallet_menu.png',
onTap: (BuildContext context) { onTap: (BuildContext context) {
Navigator.pop(context); Navigator.pop(context);
Navigator.of(context).pushNamed(Routes.walletList); Navigator.of(context).pushNamed(
Routes.walletList,
arguments: (BuildContext context) =>
Navigator.of(context).pushNamedAndRemoveUntil(Routes.dashboard, (route) => false),
);
}, },
); );

View file

@ -23,11 +23,7 @@ abstract class NFTViewModelBase with Store {
: isLoading = false, : isLoading = false,
isImportNFTLoading = false, isImportNFTLoading = false,
nftAssetByWalletModels = ObservableList(), nftAssetByWalletModels = ObservableList(),
solanaNftAssetModels = ObservableList() { solanaNftAssetModels = ObservableList();
getNFTAssetByWallet();
reaction((_) => appStore.wallet, (_) => getNFTAssetByWallet());
}
final AppStore appStore; final AppStore appStore;
final BottomSheetService bottomSheetService; final BottomSheetService bottomSheetService;
@ -80,6 +76,8 @@ abstract class NFTViewModelBase with Store {
} }
try { try {
if (isLoading) return;
isLoading = true; isLoading = true;
final response = await http.get( final response = await http.get(
@ -114,10 +112,7 @@ abstract class NFTViewModelBase with Store {
nftAssetByWalletModels.addAll(result); nftAssetByWalletModels.addAll(result);
} }
isLoading = false;
} catch (e) { } catch (e) {
isLoading = false;
log(e.toString()); log(e.toString());
bottomSheetService.queueBottomSheet( bottomSheetService.queueBottomSheet(
isModalDismissible: true, isModalDismissible: true,
@ -125,6 +120,8 @@ abstract class NFTViewModelBase with Store {
message: S.current.moralis_nft_error, message: S.current.moralis_nft_error,
), ),
); );
} finally {
isLoading = false;
} }
} }