fix donation link saved regardless of the current wallet (#1491)

Omar Hatem committed Jun 21, 2024 at 02:17 UTC 4a0096985a520b162cd3e8abe3aa834a1a81dd24
5 files changed +58 -38
cw_solana/lib/solana_client.dart
+1 -1
@@ -456,7 +456,7 @@ class SolanaWalletClient {
456 funder: ownerKeypair,
457 );
458 } catch (e) {
459 - throw Exception('Insufficient lamports balance to complete this transaction');
459 + throw Exception('Insufficient SOL balance to complete this transaction');
460 }
461
462 // Input by the user
lib/entities/preferences_key.dart
+1
@@ -77,6 +77,7 @@ class PreferencesKey {
77 static const moneroSeedType = 'monero_seed_type';
78 static const clearnetDonationLink = 'clearnet_donation_link';
79 static const onionDonationLink = 'onion_donation_link';
80 + static const donationLinkWalletName = 'donation_link_wallet_name';
81 static const lastSeenAppVersion = 'last_seen_app_version';
82 static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard';
83 static const isNewInstall = 'is_new_install';
lib/src/screens/dashboard/pages/address_page.dart
+6 -5
@@ -3,7 +3,6 @@ import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart';
3 import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
4 import 'package:cake_wallet/di.dart';
5 import 'package:cake_wallet/src/screens/base_page.dart';
6 -import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart';
6 import 'package:cake_wallet/anonpay/anonpay_donation_link_info.dart';
7 import 'package:cake_wallet/entities/preferences_key.dart';
8 import 'package:cw_core/receive_page_option.dart';
@@ -14,7 +13,6 @@ import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
13 import 'package:cake_wallet/themes/theme_base.dart';
14 import 'package:cake_wallet/utils/responsive_layout_util.dart';
15 import 'package:cake_wallet/utils/share_util.dart';
17 -import 'package:cake_wallet/utils/show_pop_up.dart';
16 import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
17 import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
18 import 'package:cw_core/wallet_type.dart';
@@ -171,8 +169,7 @@ class AddressPage extends BasePage {
169 textSize: 14,
170 height: 50,
171 );
174 - }
175 - else {
172 + } else {
173 return const SizedBox();
174 }
175 }),
@@ -204,8 +201,12 @@ class AddressPage extends BasePage {
201 final sharedPreferences = getIt.get<SharedPreferences>();
202 final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
203 final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink);
204 + final donationWalletName =
205 + sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
206
208 - if (clearnetUrl != null && onionUrl != null) {
207 + if (clearnetUrl != null &&
208 + onionUrl != null &&
209 + addressListViewModel.wallet.name == donationWalletName) {
210 Navigator.pushNamed(
211 context,
212 Routes.anonPayReceivePage,
lib/src/screens/receive/anonpay_invoice_page.dart
+41 -30
@@ -60,8 +60,7 @@ class AnonPayInvoicePage extends BasePage {
60
61 @override
62 Widget middle(BuildContext context) => PresentReceiveOptionPicker(
63 - receiveOptionViewModel: receiveOptionViewModel,
64 - color: titleColor(context));
63 + receiveOptionViewModel: receiveOptionViewModel, color: titleColor(context));
64
65 @override
66 Widget trailing(BuildContext context) => TrailButton(
@@ -87,30 +86,36 @@ class AnonPayInvoicePage extends BasePage {
86 config: KeyboardActionsConfig(
87 keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
88 keyboardBarColor: Theme.of(context).extension<KeyboardTheme>()!.keyboardBarColor,
90 - nextFocus: false,
91 - actions: [
92 - KeyboardActionsItem(
93 - focusNode: _amountFocusNode,
94 - toolbarButtons: [(_) => KeyboardDoneButton()],
95 - ),
96 - ]),
97 - child: Container(
98 - color: Theme.of(context).colorScheme.background,
99 - child: ScrollableWithBottomSection(
100 - contentPadding: EdgeInsets.only(bottom: 24),
101 - content: Container(
102 - decoration: responsiveLayoutUtil.shouldRenderMobileUI ? BoxDecoration(
103 - borderRadius: BorderRadius.only(
104 - bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)),
105 - gradient: LinearGradient(
106 - colors: [
107 - Theme.of(context).extension<ExchangePageTheme>()!.firstGradientTopPanelColor,
108 - Theme.of(context).extension<ExchangePageTheme>()!.secondGradientTopPanelColor,
109 - ],
110 - begin: Alignment.topLeft,
111 - end: Alignment.bottomRight,
89 + nextFocus: false,
90 + actions: [
91 + KeyboardActionsItem(
92 + focusNode: _amountFocusNode,
93 + toolbarButtons: [(_) => KeyboardDoneButton()],
94 ),
113 - ) : null,
95 + ]),
96 + child: Container(
97 + color: Theme.of(context).colorScheme.background,
98 + child: ScrollableWithBottomSection(
99 + contentPadding: EdgeInsets.only(bottom: 24),
100 + content: Container(
101 + decoration: responsiveLayoutUtil.shouldRenderMobileUI
102 + ? BoxDecoration(
103 + borderRadius: BorderRadius.only(
104 + bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)),
105 + gradient: LinearGradient(
106 + colors: [
107 + Theme.of(context)
108 + .extension<ExchangePageTheme>()!
109 + .firstGradientTopPanelColor,
110 + Theme.of(context)
111 + .extension<ExchangePageTheme>()!
112 + .secondGradientTopPanelColor,
113 + ],
114 + begin: Alignment.topLeft,
115 + end: Alignment.bottomRight,
116 + ),
117 + )
118 + : null,
119 child: Observer(builder: (_) {
120 return Padding(
121 padding: EdgeInsets.fromLTRB(24, 120, 24, 0),
@@ -143,9 +148,11 @@ class AnonPayInvoicePage extends BasePage {
148 : S.of(context).anonpay_description("a donation link", "donate"),
149 textAlign: TextAlign.center,
150 style: TextStyle(
146 - color: Theme.of(context).extension<ExchangePageTheme>()!.receiveAmountColor,
147 - fontWeight: FontWeight.w500,
148 - fontSize: 12),
151 + color: Theme.of(context)
152 + .extension<ExchangePageTheme>()!
153 + .receiveAmountColor,
154 + fontWeight: FontWeight.w500,
155 + fontSize: 12),
156 ),
157 ),
158 ),
@@ -172,7 +179,7 @@ class AnonPayInvoicePage extends BasePage {
179 anonInvoicePageViewModel.generateDonationLink();
180 }
181 },
175 - color: Theme.of(context).primaryColor,
182 + color: Theme.of(context).primaryColor,
183 textColor: Colors.white,
184 isLoading: anonInvoicePageViewModel.state is IsExecutingState,
185 ),
@@ -199,8 +206,12 @@ class AnonPayInvoicePage extends BasePage {
206 final sharedPreferences = getIt.get<SharedPreferences>();
207 final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
208 final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink);
209 + final donationWalletName =
210 + sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
211
203 - if (clearnetUrl != null && onionUrl != null) {
212 + if (clearnetUrl != null &&
213 + onionUrl != null &&
214 + anonInvoicePageViewModel.currentWalletName == donationWalletName) {
215 Navigator.pushReplacementNamed(context, Routes.anonPayReceivePage,
216 arguments: AnonpayDonationLinkInfo(
217 clearnetUrl: clearnetUrl,
lib/view_model/anon_invoice_page_view_model.dart
+9 -2
@@ -150,6 +150,7 @@ abstract class AnonInvoicePageViewModelBase with Store {
150
151 await sharedPreferences.setString(PreferencesKey.clearnetDonationLink, result.clearnetUrl);
152 await sharedPreferences.setString(PreferencesKey.onionDonationLink, result.onionUrl);
153 + await sharedPreferences.setString(PreferencesKey.donationLinkWalletName, _wallet.name);
154
155 state = ExecutedSuccessfullyState(payload: result);
156 }
@@ -163,10 +164,13 @@ abstract class AnonInvoicePageViewModelBase with Store {
164 maximum = limit.max != null ? limit.max! / 4 : null;
165 }
166
167 + @computed
168 + String get currentWalletName => _wallet.name;
169 +
170 @action
171 void reset() {
172 selectedCurrency = walletTypeToCryptoCurrency(_wallet.type);
169 - cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
173 + cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
174 receipientEmail = '';
175 receipientName = '';
176 description = '';
@@ -177,7 +181,10 @@ abstract class AnonInvoicePageViewModelBase with Store {
181 Future<void> _getPreviousDonationLink() async {
182 if (pageOption == ReceivePageOption.anonPayDonationLink) {
183 final donationLink = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
180 - if (donationLink != null) {
184 + final donationLinkWalletName =
185 + sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
186 +
187 + if (donationLink != null && currentWalletName == donationLinkWalletName) {
188 final url = Uri.parse(donationLink);
189 url.queryParameters.forEach((key, value) {
190 if (key == 'name') receipientName = value;