fix donation link saved regardless of the current wallet (#1491)
Some checks are pending
Cache Dependencies / test (push) Waiting to run

This commit is contained in:
Omar Hatem 2024-06-21 02:17:19 +03:00 committed by GitHub
parent 1690f6af1e
commit 4a0096985a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 58 additions and 38 deletions

View file

@ -456,7 +456,7 @@ class SolanaWalletClient {
funder: ownerKeypair, funder: ownerKeypair,
); );
} catch (e) { } catch (e) {
throw Exception('Insufficient lamports balance to complete this transaction'); throw Exception('Insufficient SOL balance to complete this transaction');
} }
// Input by the user // Input by the user

View file

@ -77,6 +77,7 @@ class PreferencesKey {
static const moneroSeedType = 'monero_seed_type'; static const moneroSeedType = 'monero_seed_type';
static const clearnetDonationLink = 'clearnet_donation_link'; static const clearnetDonationLink = 'clearnet_donation_link';
static const onionDonationLink = 'onion_donation_link'; static const onionDonationLink = 'onion_donation_link';
static const donationLinkWalletName = 'donation_link_wallet_name';
static const lastSeenAppVersion = 'last_seen_app_version'; static const lastSeenAppVersion = 'last_seen_app_version';
static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard'; static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard';
static const isNewInstall = 'is_new_install'; static const isNewInstall = 'is_new_install';

View file

@ -3,7 +3,6 @@ import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart';
import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart';
import 'package:cake_wallet/anonpay/anonpay_donation_link_info.dart'; import 'package:cake_wallet/anonpay/anonpay_donation_link_info.dart';
import 'package:cake_wallet/entities/preferences_key.dart'; import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cw_core/receive_page_option.dart'; import 'package:cw_core/receive_page_option.dart';
@ -14,7 +13,6 @@ import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart';
import 'package:cake_wallet/utils/share_util.dart'; import 'package:cake_wallet/utils/share_util.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
@ -171,8 +169,7 @@ class AddressPage extends BasePage {
textSize: 14, textSize: 14,
height: 50, height: 50,
); );
} } else {
else {
return const SizedBox(); return const SizedBox();
} }
}), }),
@ -204,8 +201,12 @@ class AddressPage extends BasePage {
final sharedPreferences = getIt.get<SharedPreferences>(); final sharedPreferences = getIt.get<SharedPreferences>();
final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink); final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink); final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink);
final donationWalletName =
sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
if (clearnetUrl != null && onionUrl != null) { if (clearnetUrl != null &&
onionUrl != null &&
addressListViewModel.wallet.name == donationWalletName) {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
Routes.anonPayReceivePage, Routes.anonPayReceivePage,

View file

@ -60,8 +60,7 @@ class AnonPayInvoicePage extends BasePage {
@override @override
Widget middle(BuildContext context) => PresentReceiveOptionPicker( Widget middle(BuildContext context) => PresentReceiveOptionPicker(
receiveOptionViewModel: receiveOptionViewModel, receiveOptionViewModel: receiveOptionViewModel, color: titleColor(context));
color: titleColor(context));
@override @override
Widget trailing(BuildContext context) => TrailButton( Widget trailing(BuildContext context) => TrailButton(
@ -99,18 +98,24 @@ class AnonPayInvoicePage extends BasePage {
child: ScrollableWithBottomSection( child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(bottom: 24), contentPadding: EdgeInsets.only(bottom: 24),
content: Container( content: Container(
decoration: responsiveLayoutUtil.shouldRenderMobileUI ? BoxDecoration( decoration: responsiveLayoutUtil.shouldRenderMobileUI
? BoxDecoration(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)), bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)),
gradient: LinearGradient( gradient: LinearGradient(
colors: [ colors: [
Theme.of(context).extension<ExchangePageTheme>()!.firstGradientTopPanelColor, Theme.of(context)
Theme.of(context).extension<ExchangePageTheme>()!.secondGradientTopPanelColor, .extension<ExchangePageTheme>()!
.firstGradientTopPanelColor,
Theme.of(context)
.extension<ExchangePageTheme>()!
.secondGradientTopPanelColor,
], ],
begin: Alignment.topLeft, begin: Alignment.topLeft,
end: Alignment.bottomRight, end: Alignment.bottomRight,
), ),
) : null, )
: null,
child: Observer(builder: (_) { child: Observer(builder: (_) {
return Padding( return Padding(
padding: EdgeInsets.fromLTRB(24, 120, 24, 0), padding: EdgeInsets.fromLTRB(24, 120, 24, 0),
@ -143,7 +148,9 @@ class AnonPayInvoicePage extends BasePage {
: S.of(context).anonpay_description("a donation link", "donate"), : S.of(context).anonpay_description("a donation link", "donate"),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Theme.of(context).extension<ExchangePageTheme>()!.receiveAmountColor, color: Theme.of(context)
.extension<ExchangePageTheme>()!
.receiveAmountColor,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 12), fontSize: 12),
), ),
@ -199,8 +206,12 @@ class AnonPayInvoicePage extends BasePage {
final sharedPreferences = getIt.get<SharedPreferences>(); final sharedPreferences = getIt.get<SharedPreferences>();
final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink); final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink); final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink);
final donationWalletName =
sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
if (clearnetUrl != null && onionUrl != null) { if (clearnetUrl != null &&
onionUrl != null &&
anonInvoicePageViewModel.currentWalletName == donationWalletName) {
Navigator.pushReplacementNamed(context, Routes.anonPayReceivePage, Navigator.pushReplacementNamed(context, Routes.anonPayReceivePage,
arguments: AnonpayDonationLinkInfo( arguments: AnonpayDonationLinkInfo(
clearnetUrl: clearnetUrl, clearnetUrl: clearnetUrl,

View file

@ -150,6 +150,7 @@ abstract class AnonInvoicePageViewModelBase with Store {
await sharedPreferences.setString(PreferencesKey.clearnetDonationLink, result.clearnetUrl); await sharedPreferences.setString(PreferencesKey.clearnetDonationLink, result.clearnetUrl);
await sharedPreferences.setString(PreferencesKey.onionDonationLink, result.onionUrl); await sharedPreferences.setString(PreferencesKey.onionDonationLink, result.onionUrl);
await sharedPreferences.setString(PreferencesKey.donationLinkWalletName, _wallet.name);
state = ExecutedSuccessfullyState(payload: result); state = ExecutedSuccessfullyState(payload: result);
} }
@ -163,6 +164,9 @@ abstract class AnonInvoicePageViewModelBase with Store {
maximum = limit.max != null ? limit.max! / 4 : null; maximum = limit.max != null ? limit.max! / 4 : null;
} }
@computed
String get currentWalletName => _wallet.name;
@action @action
void reset() { void reset() {
selectedCurrency = walletTypeToCryptoCurrency(_wallet.type); selectedCurrency = walletTypeToCryptoCurrency(_wallet.type);
@ -177,7 +181,10 @@ abstract class AnonInvoicePageViewModelBase with Store {
Future<void> _getPreviousDonationLink() async { Future<void> _getPreviousDonationLink() async {
if (pageOption == ReceivePageOption.anonPayDonationLink) { if (pageOption == ReceivePageOption.anonPayDonationLink) {
final donationLink = sharedPreferences.getString(PreferencesKey.clearnetDonationLink); final donationLink = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
if (donationLink != null) { final donationLinkWalletName =
sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
if (donationLink != null && currentWalletName == donationLinkWalletName) {
final url = Uri.parse(donationLink); final url = Uri.parse(donationLink);
url.queryParameters.forEach((key, value) { url.queryParameters.forEach((key, value) {
if (key == 'name') receipientName = value; if (key == 'name') receipientName = value;