From 461fe1c85990e94d4e18329c2ea9813ce4dbb197 Mon Sep 17 00:00:00 2001 From: Adegoke David <64401859+Blazebrain@users.noreply.github.com> Date: Thu, 23 May 2024 16:21:51 +0100 Subject: [PATCH] fix: Desktop resize bug (#1461) * fix: Desktop resize bug * Change default spl tokens * Minor enhancements [skip ci] * minor enhancements [skip ci] --------- Co-authored-by: OmarHatem --- cw_solana/lib/default_spl_tokens.dart | 87 ++++++++-------- lib/src/screens/dashboard/dashboard_page.dart | 98 ++++++++++++------- lib/utils/responsive_layout_util.dart | 6 +- 3 files changed, 114 insertions(+), 77 deletions(-) diff --git a/cw_solana/lib/default_spl_tokens.dart b/cw_solana/lib/default_spl_tokens.dart index 7acad78e0..21b5ef79d 100644 --- a/cw_solana/lib/default_spl_tokens.dart +++ b/cw_solana/lib/default_spl_tokens.dart @@ -19,30 +19,6 @@ class DefaultSPLTokens { mint: 'usdcsol', enabled: true, ), - SPLToken( - name: 'Wrapped Ethereum (Sollet)', - symbol: 'soETH', - mintAddress: '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk', - decimal: 6, - mint: 'soEth', - iconPath: 'assets/images/eth_icon.png', - ), - SPLToken( - name: 'Wrapped SOL', - symbol: 'WSOL', - mintAddress: 'So11111111111111111111111111111111111111112', - decimal: 9, - mint: 'WSOL', - iconPath: 'assets/images/sol_icon.png', - ), - SPLToken( - name: 'Wrapped Bitcoin (Sollet)', - symbol: 'BTC', - mintAddress: '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E', - decimal: 6, - mint: 'btcsol', - iconPath: 'assets/images/btc.png', - ), SPLToken( name: 'Bonk', symbol: 'Bonk', @@ -50,21 +26,7 @@ class DefaultSPLTokens { decimal: 5, mint: 'Bonk', iconPath: 'assets/images/bonk_icon.png', - ), - SPLToken( - name: 'Helium Network Token', - symbol: 'HNT', - mintAddress: 'hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux', - decimal: 8, - mint: 'hnt', - iconPath: 'assets/images/hnt_icon.png', - ), - SPLToken( - name: 'Pyth Network', - symbol: 'PYTH', - mintAddress: 'HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3', - decimal: 6, - mint: 'pyth', + enabled: true, ), SPLToken( name: 'Raydium', @@ -73,6 +35,51 @@ class DefaultSPLTokens { decimal: 6, mint: 'ray', iconPath: 'assets/images/ray_icon.png', + enabled: true, + ), + SPLToken( + name: 'Wrapped Ethereum (Sollet)', + symbol: 'soETH', + mintAddress: '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk', + decimal: 6, + mint: 'soEth', + iconPath: 'assets/images/eth_icon.png', + enabled: false, + ), + SPLToken( + name: 'Wrapped SOL', + symbol: 'WSOL', + mintAddress: 'So11111111111111111111111111111111111111112', + decimal: 9, + mint: 'WSOL', + iconPath: 'assets/images/sol_icon.png', + enabled: false, + ), + SPLToken( + name: 'Wrapped Bitcoin (Sollet)', + symbol: 'BTC', + mintAddress: '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E', + decimal: 6, + mint: 'btcsol', + iconPath: 'assets/images/btc.png', + enabled: false, + ), + SPLToken( + name: 'Helium Network Token', + symbol: 'HNT', + mintAddress: 'hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux', + decimal: 8, + mint: 'hnt', + iconPath: 'assets/images/hnt_icon.png', + enabled: false, + ), + SPLToken( + name: 'Pyth Network', + symbol: 'PYTH', + mintAddress: 'HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3', + decimal: 6, + mint: 'pyth', + enabled: false, ), SPLToken( name: 'GMT', @@ -81,6 +88,7 @@ class DefaultSPLTokens { decimal: 6, mint: 'ray', iconPath: 'assets/images/gmt_icon.png', + enabled: false, ), SPLToken( name: 'AvocadoCoin', @@ -89,6 +97,7 @@ class DefaultSPLTokens { decimal: 8, mint: 'avdo', iconPath: 'assets/images/avdo_icon.png', + enabled: false, ), ]; diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index 8d9dc9829..ec97d191f 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -36,7 +36,7 @@ import 'package:cake_wallet/src/screens/release_notes/release_notes_screen.dart' import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart'; import 'package:cake_wallet/themes/extensions/balance_page_theme.dart'; -class DashboardPage extends StatelessWidget { +class DashboardPage extends StatefulWidget { DashboardPage({ required this.bottomSheetService, required this.balancePage, @@ -50,43 +50,71 @@ class DashboardPage extends StatelessWidget { final WalletAddressListViewModel addressListViewModel; @override - Widget build(BuildContext context) { - final screenHeight = MediaQuery.of(context).size.height; - return Scaffold( - body: Builder( - builder: (_) { - final dashboardPageView = RefreshIndicator( - displacement: screenHeight * 0.1, - onRefresh: () async => await dashboardViewModel.refreshDashboard(), - child: SingleChildScrollView( - physics: AlwaysScrollableScrollPhysics(), - child: Container( - height: screenHeight, - child: _DashboardPageView( - balancePage: balancePage, - bottomSheetService: bottomSheetService, - dashboardViewModel: dashboardViewModel, - addressListViewModel: addressListViewModel, - ), - ), - ), - ); + State createState() => _DashboardPageState(); +} - if (DeviceInfo.instance.isDesktop) { - if (responsiveLayoutUtil.screenWidth > - ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) { - return getIt.get(); - } else { - return dashboardPageView; - } - } else if (responsiveLayoutUtil.shouldRenderMobileUI) { - return dashboardPageView; - } else { - return getIt.get(); - } - }, +class _DashboardPageState extends State { + @override + void initState() { + super.initState(); + + bool isMobileLayout = + responsiveLayoutUtil.screenWidth < ResponsiveLayoutUtilBase.kMobileThreshold; + + reaction((_) => responsiveLayoutUtil.screenWidth, (screenWidth) { + // Check if it was previously in mobile layout, and now changing to desktop + if (isMobileLayout && + screenWidth > ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) { + setState(() { + isMobileLayout = false; + }); + } + + // Check if it was previously in desktop layout, and now changing to mobile + if (!isMobileLayout && + screenWidth <= ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) { + setState(() { + isMobileLayout = true; + }); + } + }); + } + + @override + Widget build(BuildContext context) { + Widget dashboardChild; + + final dashboardPageView = RefreshIndicator( + displacement: responsiveLayoutUtil.screenHeight * 0.1, + onRefresh: () async => await widget.dashboardViewModel.refreshDashboard(), + child: SingleChildScrollView( + physics: AlwaysScrollableScrollPhysics(), + child: Container( + height: responsiveLayoutUtil.screenHeight, + child: _DashboardPageView( + balancePage: widget.balancePage, + bottomSheetService: widget.bottomSheetService, + dashboardViewModel: widget.dashboardViewModel, + addressListViewModel: widget.addressListViewModel, + ), + ), ), ); + + if (DeviceInfo.instance.isDesktop) { + if (responsiveLayoutUtil.screenWidth > + ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) { + dashboardChild = getIt.get(); + } else { + dashboardChild = dashboardPageView; + } + } else if (responsiveLayoutUtil.shouldRenderMobileUI) { + dashboardChild = dashboardPageView; + } else { + dashboardChild = getIt.get(); + } + + return Scaffold(body: dashboardChild); } } diff --git a/lib/utils/responsive_layout_util.dart b/lib/utils/responsive_layout_util.dart index 86a4a3776..aa30b3f07 100644 --- a/lib/utils/responsive_layout_util.dart +++ b/lib/utils/responsive_layout_util.dart @@ -6,7 +6,7 @@ part 'responsive_layout_util.g.dart'; class _ResponsiveLayoutUtil = ResponsiveLayoutUtilBase with _$_ResponsiveLayoutUtil; abstract class ResponsiveLayoutUtilBase with Store, WidgetsBindingObserver { - static const double _kMobileThreshold = 550; + static const double kMobileThreshold = 550; static const double kDesktopMaxWidthConstraint = 400; static const double kDesktopMaxDashBoardWidthConstraint = 900; static const double kPopupWidth = 400; @@ -42,13 +42,13 @@ abstract class ResponsiveLayoutUtilBase with Store, WidgetsBindingObserver { @computed bool get shouldRenderMobileUI { - return (screenWidth <= _kMobileThreshold) || + return (screenWidth <= kMobileThreshold) || (orientation == Orientation.portrait && screenWidth < screenHeight) || (orientation == Orientation.landscape && screenWidth < screenHeight); } bool get shouldRenderTabletUI { - return screenWidth > _kMobileThreshold && screenWidth < kDesktopMaxDashBoardWidthConstraint; + return screenWidth > kMobileThreshold && screenWidth < kDesktopMaxDashBoardWidthConstraint; } }