diff --git a/cw_decred/lib/wallet.dart b/cw_decred/lib/wallet.dart index 2c7af61f0..a63a5e2e5 100644 --- a/cw_decred/lib/wallet.dart +++ b/cw_decred/lib/wallet.dart @@ -222,7 +222,7 @@ abstract class DecredWalletBase Future checkSync() async { final syncStatusJSON = await _libwallet.syncStatus(walletInfo.name); - final decoded = json.decode(syncStatusJSON); + final decoded = json.decode(syncStatusJSON.isEmpty ? "{}" : syncStatusJSON); final syncStatusCode = decoded["syncstatuscode"] ?? 0; // final syncStatusStr = decoded["syncstatus"] ?? ""; diff --git a/lib/core/utilities.dart b/lib/core/utilities.dart new file mode 100644 index 000000000..1278dfc44 --- /dev/null +++ b/lib/core/utilities.dart @@ -0,0 +1,9 @@ +extension EnhancedList on Iterable { + T? firstWhereOrNull(bool Function(T element) test) { + try { + return firstWhere(test); + } catch (e) { + return null; + } + } +} \ No newline at end of file diff --git a/lib/src/screens/backup/backup_page.dart b/lib/src/screens/backup/backup_page.dart index 408fad2d3..12c8594ae 100644 --- a/lib/src/screens/backup/backup_page.dart +++ b/lib/src/screens/backup/backup_page.dart @@ -3,10 +3,9 @@ import 'package:cake_wallet/core/execution_state.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; -import 'package:cake_wallet/src/widgets/trail_button.dart'; import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/themes/extensions/cake_text_theme.dart'; import 'package:cake_wallet/utils/clipboard_util.dart'; import 'package:cake_wallet/utils/exception_handler.dart'; import 'package:cake_wallet/utils/share_util.dart'; @@ -76,7 +75,9 @@ class BackupPage extends BasePage { Navigator.of(context).pushNamed(Routes.editBackupPassword), text: S.of(context).change_password, color: Theme.of(context).cardColor, - textColor: Colors.white, + textColor: Theme.of(context) + .extension()! + .buttonTextColor, ), SizedBox(height: 10), Observer( diff --git a/lib/src/widgets/primary_button.dart b/lib/src/widgets/primary_button.dart index d5800aa5b..fcabe5b83 100644 --- a/lib/src/widgets/primary_button.dart +++ b/lib/src/widgets/primary_button.dart @@ -104,7 +104,7 @@ class LoadingPrimaryButton extends StatelessWidget { ), )), child: isLoading - ? CupertinoActivityIndicator(animating: true) + ? CupertinoActivityIndicator(animating: true, color: textColor) : Text(text, style: TextStyle( fontSize: 15.0, diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 5f6b415b9..1e32f3189 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/core/utilities.dart'; import 'package:cake_wallet/decred/decred.dart'; import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart'; import 'package:cake_wallet/core/secure_storage.dart'; @@ -12,13 +13,13 @@ import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/cake_2fa_preset_options.dart'; import 'package:cake_wallet/entities/country.dart'; +import 'package:cake_wallet/entities/default_settings_migration.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/fiat_api_mode.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/entities/language_service.dart'; import 'package:cake_wallet/entities/pin_code_required_duration.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; -import 'package:cake_wallet/entities/provider_types.dart'; import 'package:cake_wallet/entities/secret_store_key.dart'; import 'package:cake_wallet/entities/seed_phrase_length.dart'; import 'package:cake_wallet/entities/seed_type.dart'; @@ -37,11 +38,8 @@ import 'package:cake_wallet/themes/theme_list.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/package_info.dart'; import 'package:cake_wallet/view_model/settings/sync_mode.dart'; -import 'package:cake_wallet/wallet_type_utils.dart'; -import 'package:cake_wallet/wownero/wownero.dart'; import 'package:cw_core/node.dart'; import 'package:cw_core/set_app_secure_native.dart'; -import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/utils/print_verbose.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:device_info_plus/device_info_plus.dart'; @@ -312,7 +310,7 @@ abstract class SettingsStoreBase with Store { reaction((_) => disableTradeOption, (bool disableTradeOption) => sharedPreferences.setBool(PreferencesKey.disableTradeOption, disableTradeOption)); - + reaction( (_) => disableBulletin, (bool disableBulletin) => @@ -1038,7 +1036,6 @@ abstract class SettingsStoreBase with Store { sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey); final bitcoinCashElectrumServerId = sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey); - final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey); final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey); final polygonNodeId = sharedPreferences.getInt(PreferencesKey.currentPolygonNodeIdKey); final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey); @@ -1048,20 +1045,35 @@ abstract class SettingsStoreBase with Store { final wowneroNodeId = sharedPreferences.getInt(PreferencesKey.currentWowneroNodeIdKey); final zanoNodeId = sharedPreferences.getInt(PreferencesKey.currentZanoNodeIdKey); final decredNodeId = sharedPreferences.getInt(PreferencesKey.currentDecredNodeIdKey); - final moneroNode = nodeSource.get(nodeId); - final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId); - final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId); - final havenNode = nodeSource.get(havenNodeId); - final ethereumNode = nodeSource.get(ethereumNodeId); - final polygonNode = nodeSource.get(polygonNodeId); - final bitcoinCashElectrumServer = nodeSource.get(bitcoinCashElectrumServerId); - final nanoNode = nodeSource.get(nanoNodeId); - final decredNode = nodeSource.get(decredNodeId); - final nanoPowNode = powNodeSource.get(nanoPowNodeId); - final solanaNode = nodeSource.get(solanaNodeId); - final tronNode = nodeSource.get(tronNodeId); - final wowneroNode = nodeSource.get(wowneroNodeId); - final zanoNode = nodeSource.get(zanoNodeId); + + /// get the selected node, if null, then use the default + final moneroNode = nodeSource.get(nodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == newCakeWalletMoneroUri); + final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == newCakeWalletBitcoinUri); + final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == cakeWalletLitecoinElectrumUri); + final ethereumNode = nodeSource.get(ethereumNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == ethereumDefaultNodeUri); + final polygonNode = nodeSource.get(polygonNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == polygonDefaultNodeUri); + final bitcoinCashElectrumServer = nodeSource.get(bitcoinCashElectrumServerId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == cakeWalletBitcoinCashDefaultNodeUri); + final nanoNode = nodeSource.get(nanoNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == nanoDefaultNodeUri); + final decredNode = nodeSource.get(decredNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == decredDefaultUri); + final nanoPowNode = powNodeSource.get(nanoPowNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == nanoDefaultPowNodeUri); + final solanaNode = nodeSource.get(solanaNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == solanaDefaultNodeUri); + final tronNode = nodeSource.get(tronNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == tronDefaultNodeUri); + final wowneroNode = nodeSource.get(wowneroNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == wowneroDefaultNodeUri); + final zanoNode = nodeSource.get(zanoNodeId) ?? + nodeSource.values.firstWhereOrNull((e) => e.uriRaw == zanoDefaultNodeUri); + final packageInfo = await PackageInfo.fromPlatform(); final deviceName = await _getDeviceName() ?? ''; final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true; @@ -1107,10 +1119,6 @@ abstract class SettingsStoreBase with Store { nodes[WalletType.litecoin] = litecoinElectrumServer; } - if (havenNode != null) { - nodes[WalletType.haven] = havenNode; - } - if (ethereumNode != null) { nodes[WalletType.ethereum] = ethereumNode; } diff --git a/lib/view_model/anon_invoice_page_view_model.dart b/lib/view_model/anon_invoice_page_view_model.dart index 39992dca7..05467bd71 100644 --- a/lib/view_model/anon_invoice_page_view_model.dart +++ b/lib/view_model/anon_invoice_page_view_model.dart @@ -107,20 +107,24 @@ abstract class AnonInvoicePageViewModelBase with Store { return; } } - final result = await anonPayApi.createInvoice(AnonPayRequest( - cryptoCurrency: cryptoCurrency, - address: address, - amount: amount.isEmpty ? null : amount, - description: description, - email: receipientEmail, - name: receipientName, - fiatEquivalent: - selectedCurrency is FiatCurrency ? (selectedCurrency as FiatCurrency).raw : null, - )); + try { + final result = await anonPayApi.createInvoice(AnonPayRequest( + cryptoCurrency: cryptoCurrency, + address: address, + amount: amount.isEmpty ? null : amount, + description: description, + email: receipientEmail, + name: receipientName, + fiatEquivalent: + selectedCurrency is FiatCurrency ? (selectedCurrency as FiatCurrency).raw : null, + )); - _anonpayInvoiceInfoSource.add(result); + _anonpayInvoiceInfoSource.add(result); - state = ExecutedSuccessfullyState(payload: result); + state = ExecutedSuccessfullyState(payload: result); + } catch (e) { + state = FailureState(e.toString()); + } } @action @@ -156,12 +160,16 @@ abstract class AnonInvoicePageViewModelBase with Store { } Future _fetchLimits() async { - final limit = await anonPayApi.fetchLimits( - cryptoCurrency: cryptoCurrency, - fiatCurrency: selectedCurrency is FiatCurrency ? selectedCurrency as FiatCurrency : null, - ); - minimum = limit.min; - maximum = limit.max != null ? limit.max! / 4 : null; + try { + final limit = await anonPayApi.fetchLimits( + cryptoCurrency: cryptoCurrency, + fiatCurrency: selectedCurrency is FiatCurrency ? selectedCurrency as FiatCurrency : null, + ); + minimum = limit.min; + maximum = limit.max != null ? limit.max! / 4 : null; + } catch (e) { + state = FailureState(e.toString()); + } } @computed diff --git a/lib/view_model/hardware_wallet/ledger_view_model.dart b/lib/view_model/hardware_wallet/ledger_view_model.dart index 4f80aa698..f555da0cf 100644 --- a/lib/view_model/hardware_wallet/ledger_view_model.dart +++ b/lib/view_model/hardware_wallet/ledger_view_model.dart @@ -137,7 +137,9 @@ abstract class LedgerViewModelBase with Store { allowChangeWallet: true, isReconnect: true, onConnectDevice: (context, ledgerVM) async { - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } }, ), ); diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index bd135ef96..96662e0b6 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -216,7 +216,6 @@ abstract class WalletListViewModelBase with Store { await sortGroupByType(); break; case FilterListOrderType.Custom: - default: await reorderAccordingToWalletList(); break; }