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 <omarh.ismail1@gmail.com>

Adegoke David committed May 23, 2024 at 16:21 UTC 461fe1c85990e94d4e18329c2ea9813ce4dbb197
3 files changed +91 -54
cw_solana/lib/default_spl_tokens.dart
+25 -16
@@ -19,6 +19,24 @@ class DefaultSPLTokens {
19 mint: 'usdcsol',
20 enabled: true,
21 ),
22 + SPLToken(
23 + name: 'Bonk',
24 + symbol: 'Bonk',
25 + mintAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263',
26 + decimal: 5,
27 + mint: 'Bonk',
28 + iconPath: 'assets/images/bonk_icon.png',
29 + enabled: true,
30 + ),
31 + SPLToken(
32 + name: 'Raydium',
33 + symbol: 'RAY',
34 + mintAddress: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
35 + decimal: 6,
36 + mint: 'ray',
37 + iconPath: 'assets/images/ray_icon.png',
38 + enabled: true,
39 + ),
40 SPLToken(
41 name: 'Wrapped Ethereum (Sollet)',
42 symbol: 'soETH',
@@ -26,6 +44,7 @@ class DefaultSPLTokens {
44 decimal: 6,
45 mint: 'soEth',
46 iconPath: 'assets/images/eth_icon.png',
47 + enabled: false,
48 ),
49 SPLToken(
50 name: 'Wrapped SOL',
@@ -34,6 +53,7 @@ class DefaultSPLTokens {
53 decimal: 9,
54 mint: 'WSOL',
55 iconPath: 'assets/images/sol_icon.png',
56 + enabled: false,
57 ),
58 SPLToken(
59 name: 'Wrapped Bitcoin (Sollet)',
@@ -42,14 +62,7 @@ class DefaultSPLTokens {
62 decimal: 6,
63 mint: 'btcsol',
64 iconPath: 'assets/images/btc.png',
45 - ),
46 - SPLToken(
47 - name: 'Bonk',
48 - symbol: 'Bonk',
49 - mintAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263',
50 - decimal: 5,
51 - mint: 'Bonk',
52 - iconPath: 'assets/images/bonk_icon.png',
65 + enabled: false,
66 ),
67 SPLToken(
68 name: 'Helium Network Token',
@@ -58,6 +71,7 @@ class DefaultSPLTokens {
71 decimal: 8,
72 mint: 'hnt',
73 iconPath: 'assets/images/hnt_icon.png',
74 + enabled: false,
75 ),
76 SPLToken(
77 name: 'Pyth Network',
@@ -65,14 +79,7 @@ class DefaultSPLTokens {
79 mintAddress: 'HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3',
80 decimal: 6,
81 mint: 'pyth',
68 - ),
69 - SPLToken(
70 - name: 'Raydium',
71 - symbol: 'RAY',
72 - mintAddress: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
73 - decimal: 6,
74 - mint: 'ray',
75 - iconPath: 'assets/images/ray_icon.png',
82 + enabled: false,
83 ),
84 SPLToken(
85 name: 'GMT',
@@ -81,6 +88,7 @@ class DefaultSPLTokens {
88 decimal: 6,
89 mint: 'ray',
90 iconPath: 'assets/images/gmt_icon.png',
91 + enabled: false,
92 ),
93 SPLToken(
94 name: 'AvocadoCoin',
@@ -89,6 +97,7 @@ class DefaultSPLTokens {
97 decimal: 8,
98 mint: 'avdo',
99 iconPath: 'assets/images/avdo_icon.png',
100 + enabled: false,
101 ),
102 ];
103
lib/src/screens/dashboard/dashboard_page.dart
+63 -35
@@ -36,7 +36,7 @@ import 'package:cake_wallet/src/screens/release_notes/release_notes_screen.dart'
36 import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
37 import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
38
39 -class DashboardPage extends StatelessWidget {
39 +class DashboardPage extends StatefulWidget {
40 DashboardPage({
41 required this.bottomSheetService,
42 required this.balancePage,
@@ -50,43 +50,71 @@ class DashboardPage extends StatelessWidget {
50 final WalletAddressListViewModel addressListViewModel;
51
52 @override
53 - Widget build(BuildContext context) {
54 - final screenHeight = MediaQuery.of(context).size.height;
55 - return Scaffold(
56 - body: Builder(
57 - builder: (_) {
58 - final dashboardPageView = RefreshIndicator(
59 - displacement: screenHeight * 0.1,
60 - onRefresh: () async => await dashboardViewModel.refreshDashboard(),
61 - child: SingleChildScrollView(
62 - physics: AlwaysScrollableScrollPhysics(),
63 - child: Container(
64 - height: screenHeight,
65 - child: _DashboardPageView(
66 - balancePage: balancePage,
67 - bottomSheetService: bottomSheetService,
68 - dashboardViewModel: dashboardViewModel,
69 - addressListViewModel: addressListViewModel,
70 - ),
71 - ),
72 - ),
73 - );
53 + State<DashboardPage> createState() => _DashboardPageState();
54 +}
55
75 - if (DeviceInfo.instance.isDesktop) {
76 - if (responsiveLayoutUtil.screenWidth >
77 - ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) {
78 - return getIt.get<DesktopSidebarWrapper>();
79 - } else {
80 - return dashboardPageView;
81 - }
82 - } else if (responsiveLayoutUtil.shouldRenderMobileUI) {
83 - return dashboardPageView;
84 - } else {
85 - return getIt.get<DesktopSidebarWrapper>();
86 - }
87 - },
56 +class _DashboardPageState extends State<DashboardPage> {
57 + @override
58 + void initState() {
59 + super.initState();
60 +
61 + bool isMobileLayout =
62 + responsiveLayoutUtil.screenWidth < ResponsiveLayoutUtilBase.kMobileThreshold;
63 +
64 + reaction((_) => responsiveLayoutUtil.screenWidth, (screenWidth) {
65 + // Check if it was previously in mobile layout, and now changing to desktop
66 + if (isMobileLayout &&
67 + screenWidth > ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) {
68 + setState(() {
69 + isMobileLayout = false;
70 + });
71 + }
72 +
73 + // Check if it was previously in desktop layout, and now changing to mobile
74 + if (!isMobileLayout &&
75 + screenWidth <= ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) {
76 + setState(() {
77 + isMobileLayout = true;
78 + });
79 + }
80 + });
81 + }
82 +
83 + @override
84 + Widget build(BuildContext context) {
85 + Widget dashboardChild;
86 +
87 + final dashboardPageView = RefreshIndicator(
88 + displacement: responsiveLayoutUtil.screenHeight * 0.1,
89 + onRefresh: () async => await widget.dashboardViewModel.refreshDashboard(),
90 + child: SingleChildScrollView(
91 + physics: AlwaysScrollableScrollPhysics(),
92 + child: Container(
93 + height: responsiveLayoutUtil.screenHeight,
94 + child: _DashboardPageView(
95 + balancePage: widget.balancePage,
96 + bottomSheetService: widget.bottomSheetService,
97 + dashboardViewModel: widget.dashboardViewModel,
98 + addressListViewModel: widget.addressListViewModel,
99 + ),
100 + ),
101 ),
102 );
103 +
104 + if (DeviceInfo.instance.isDesktop) {
105 + if (responsiveLayoutUtil.screenWidth >
106 + ResponsiveLayoutUtilBase.kDesktopMaxDashBoardWidthConstraint) {
107 + dashboardChild = getIt.get<DesktopSidebarWrapper>();
108 + } else {
109 + dashboardChild = dashboardPageView;
110 + }
111 + } else if (responsiveLayoutUtil.shouldRenderMobileUI) {
112 + dashboardChild = dashboardPageView;
113 + } else {
114 + dashboardChild = getIt.get<DesktopSidebarWrapper>();
115 + }
116 +
117 + return Scaffold(body: dashboardChild);
118 }
119 }
120
lib/utils/responsive_layout_util.dart
+3 -3
@@ -6,7 +6,7 @@ part 'responsive_layout_util.g.dart';
6 class _ResponsiveLayoutUtil = ResponsiveLayoutUtilBase with _$_ResponsiveLayoutUtil;
7
8 abstract class ResponsiveLayoutUtilBase with Store, WidgetsBindingObserver {
9 - static const double _kMobileThreshold = 550;
9 + static const double kMobileThreshold = 550;
10 static const double kDesktopMaxWidthConstraint = 400;
11 static const double kDesktopMaxDashBoardWidthConstraint = 900;
12 static const double kPopupWidth = 400;
@@ -42,13 +42,13 @@ abstract class ResponsiveLayoutUtilBase with Store, WidgetsBindingObserver {
42
43 @computed
44 bool get shouldRenderMobileUI {
45 - return (screenWidth <= _kMobileThreshold) ||
45 + return (screenWidth <= kMobileThreshold) ||
46 (orientation == Orientation.portrait && screenWidth < screenHeight) ||
47 (orientation == Orientation.landscape && screenWidth < screenHeight);
48 }
49
50 bool get shouldRenderTabletUI {
51 - return screenWidth > _kMobileThreshold && screenWidth < kDesktopMaxDashBoardWidthConstraint;
51 + return screenWidth > kMobileThreshold && screenWidth < kDesktopMaxDashBoardWidthConstraint;
52 }
53 }
54