From 99b809ef17ba59465739aacb101ad453a1225eac Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 11 Jul 2023 08:50:54 -0600 Subject: [PATCH 1/3] fix: bch address book entry address validation --- lib/utilities/address_utils.dart | 46 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/utilities/address_utils.dart b/lib/utilities/address_utils.dart index 454391f56..0093e1d00 100644 --- a/lib/utilities/address_utils.dart +++ b/lib/utilities/address_utils.dart @@ -10,11 +10,11 @@ import 'dart:convert'; +import 'package:bitbox/bitbox.dart' as bitbox; import 'package:bitcoindart/bitcoindart.dart'; import 'package:crypto/crypto.dart'; import 'package:flutter_libepiccash/epic_cash.dart'; import 'package:nanodart/nanodart.dart'; -import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart'; import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart'; import 'package:stackwallet/services/coins/ecash/ecash_wallet.dart'; import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; @@ -64,7 +64,27 @@ class AddressUtils { case Coin.litecoin: return Address.validateAddress(address, litecoin); case Coin.bitcoincash: - return Address.validateAddress(address, bitcoincash); + try { + // 0 for bitcoincash: address scheme, 1 for legacy address + final format = bitbox.Address.detectFormat(address); + + if (coin == Coin.bitcoincashTestnet) { + return true; + } + + if (format == bitbox.Address.formatCashAddr) { + String addr = address; + if (addr.contains(":")) { + addr = addr.split(":").last; + } + + return addr.startsWith("q"); + } else { + return address.startsWith("1"); + } + } catch (e) { + return false; + } case Coin.dogecoin: return Address.validateAddress(address, dogecoin); case Coin.epicCash: @@ -94,7 +114,27 @@ class AddressUtils { case Coin.litecoinTestNet: return Address.validateAddress(address, litecointestnet); case Coin.bitcoincashTestnet: - return Address.validateAddress(address, bitcoincashtestnet); + try { + // 0 for bitcoincash: address scheme, 1 for legacy address + final format = bitbox.Address.detectFormat(address); + + if (coin == Coin.bitcoincashTestnet) { + return true; + } + + if (format == bitbox.Address.formatCashAddr) { + String addr = address; + if (addr.contains(":")) { + addr = addr.split(":").last; + } + + return addr.startsWith("q"); + } else { + return address.startsWith("1"); + } + } catch (e) { + return false; + } case Coin.firoTestNet: return Address.validateAddress(address, firoTestNetwork); case Coin.dogecoinTestNet: From 983cdca73615c7362dba1f21a454e4ee1d2c5f9f Mon Sep 17 00:00:00 2001 From: julian-CStack Date: Wed, 12 Jul 2023 16:03:53 -0600 Subject: [PATCH 2/3] ios files --- ios/Podfile.lock | 34 ++++++++++++---------------- ios/Runner.xcodeproj/project.pbxproj | 18 +++++++++++---- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 76dc00433..b2235ac27 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1,6 +1,4 @@ PODS: - - "app_settings (3.0.0+1)": - - Flutter - barcode_scan2 (0.0.1): - Flutter - MTBBarcodeScanner @@ -112,7 +110,7 @@ PODS: - Flutter - flutter_native_splash (0.0.1): - Flutter - - flutter_secure_storage (3.3.1): + - flutter_secure_storage (6.0.0): - Flutter - integration_test (0.0.1): - Flutter @@ -149,7 +147,6 @@ PODS: - Flutter DEPENDENCIES: - - app_settings (from `.symlinks/plugins/app_settings/ios`) - barcode_scan2 (from `.symlinks/plugins/barcode_scan2/ios`) - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) - cw_monero (from `.symlinks/plugins/cw_monero/ios`) @@ -169,10 +166,10 @@ DEPENDENCIES: - lelantus (from `.symlinks/plugins/lelantus/ios`) - local_auth (from `.symlinks/plugins/local_auth/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`) + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - share_plus (from `.symlinks/plugins/share_plus/ios`) - - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`) + - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - stack_wallet_backup (from `.symlinks/plugins/stack_wallet_backup/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) - wakelock (from `.symlinks/plugins/wakelock/ios`) @@ -188,8 +185,6 @@ SPEC REPOS: - SwiftyGif EXTERNAL SOURCES: - app_settings: - :path: ".symlinks/plugins/app_settings/ios" barcode_scan2: :path: ".symlinks/plugins/barcode_scan2/ios" connectivity_plus: @@ -229,13 +224,13 @@ EXTERNAL SOURCES: package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" path_provider_foundation: - :path: ".symlinks/plugins/path_provider_foundation/ios" + :path: ".symlinks/plugins/path_provider_foundation/darwin" permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" share_plus: :path: ".symlinks/plugins/share_plus/ios" shared_preferences_foundation: - :path: ".symlinks/plugins/shared_preferences_foundation/ios" + :path: ".symlinks/plugins/shared_preferences_foundation/darwin" stack_wallet_backup: :path: ".symlinks/plugins/stack_wallet_backup/ios" url_launcher_ios: @@ -244,13 +239,12 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/wakelock/ios" SPEC CHECKSUMS: - app_settings: d103828c9f5d515c4df9ee754dabd443f7cedcf3 barcode_scan2: 0af2bb63c81b4565aab6cd78278e4c0fa136dbb0 - connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e + connectivity_plus: 07c49e96d7fc92bc9920617b83238c4d178b446a cw_monero: 9816991daff0e3ad0a8be140e31933b5526babd4 cw_shared_external: 2972d872b8917603478117c9957dfca611845a92 cw_wownero: ac53899fa5c6ff46b3fb490aa3b7ca36301fa832 - device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed + device_info_plus: 7545d84d8d1b896cb16a4ff98c19f07ec4b298ea devicelocale: b22617f40038496deffba44747101255cee005b0 DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179 @@ -260,23 +254,23 @@ SPEC CHECKSUMS: flutter_libmonero: da68a616b73dd0374a8419c684fa6b6df2c44ffe flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743 flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef - flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec - integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5 + flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be + integration_test: 13825b8a9334a850581300559b8839134b124670 isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073 lelantus: 417f0221260013dfc052cae9cf4b741b6479edba local_auth: 1740f55d7af0a2e2a8684ce225fe79d8931e808c MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb - package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e - path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852 + package_info_plus: fd030dabf36271f146f1f3beacd48f564b0f17f7 + path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8 permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866 - share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68 - shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca + share_plus: 599aa54e4ea31d4b4c0e9c911bcc26c55e791028 + shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c stack_wallet_backup: 5b8563aba5d8ffbf2ce1944331ff7294a0ec7c03 SwiftProtobuf: 6ef3f0e422ef90d6605ca20b21a94f6c1324d6b3 SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780 - url_launcher_ios: fb12c43172927bb5cf75aeebd073f883801f1993 + url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4 wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f PODFILE CHECKSUM: 57c8aed26fba39d3ec9424816221f294a07c58eb diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 4f2f20dc9..43e1486e6 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -242,6 +242,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -301,7 +302,6 @@ "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework", "${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework", "${BUILT_PRODUCTS_DIR}/SwiftyGif/SwiftyGif.framework", - "${BUILT_PRODUCTS_DIR}/app_settings/app_settings.framework", "${BUILT_PRODUCTS_DIR}/barcode_scan2/barcode_scan2.framework", "${BUILT_PRODUCTS_DIR}/connectivity_plus/connectivity_plus.framework", "${BUILT_PRODUCTS_DIR}/cw_monero/cw_monero.framework", @@ -335,7 +335,6 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyGif.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/app_settings.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/barcode_scan2.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity_plus.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/cw_monero.framework", @@ -505,7 +504,10 @@ ); INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -692,7 +694,10 @@ ); INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -771,7 +776,10 @@ ); INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", From 27d97ebf49dfa6a487073421b9859859a1c570f2 Mon Sep 17 00:00:00 2001 From: julian-CStack Date: Wed, 12 Jul 2023 16:06:06 -0600 Subject: [PATCH 3/3] number format hack/fix --- lib/services/locale_service.dart | 2 +- lib/utilities/amount/amount.dart | 9 +++------ lib/utilities/amount/amount_formatter.dart | 8 +++++--- lib/utilities/amount/amount_input_formatter.dart | 6 ++---- lib/utilities/amount/amount_unit.dart | 9 +++------ lib/utilities/util.dart | 10 ++++++++++ 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/services/locale_service.dart b/lib/services/locale_service.dart index 7f5cde716..8cfb6f765 100644 --- a/lib/services/locale_service.dart +++ b/lib/services/locale_service.dart @@ -21,7 +21,7 @@ class LocaleService extends ChangeNotifier { Future loadLocale({bool notify = true}) async { _locale = Platform.isWindows ? "en_US" - : await Devicelocale.currentLocale ?? "en_US"; + : (await Devicelocale.currentAsLocale)?.toString() ?? "en_US"; if (notify) { notifyListeners(); } diff --git a/lib/utilities/amount/amount.dart b/lib/utilities/amount/amount.dart index 0e8790064..0014a4eab 100644 --- a/lib/utilities/amount/amount.dart +++ b/lib/utilities/amount/amount.dart @@ -11,8 +11,7 @@ import 'dart:convert'; import 'package:decimal/decimal.dart'; -import 'package:intl/number_symbols.dart'; -import 'package:intl/number_symbols_data.dart'; +import 'package:stackwallet/utilities/util.dart'; class Amount { Amount({ @@ -52,8 +51,7 @@ class Amount { } // get number symbols for decimal place and group separator - final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ?? - numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + final numberSymbols = Util.getSymbolsFor(locale: locale); final groupSeparator = numberSymbols?.GROUP_SEP ?? ","; final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? "."; @@ -101,8 +99,7 @@ class Amount { final wholeNumber = decimal.truncate(); // get number symbols for decimal place and group separator - final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ?? - numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + final numberSymbols = Util.getSymbolsFor(locale: locale); final String separator = numberSymbols?.DECIMAL_SEP ?? "."; diff --git a/lib/utilities/amount/amount_formatter.dart b/lib/utilities/amount/amount_formatter.dart index 7c5a8f29b..6743bcd53 100644 --- a/lib/utilities/amount/amount_formatter.dart +++ b/lib/utilities/amount/amount_formatter.dart @@ -22,11 +22,13 @@ final pMaxDecimals = Provider.family( ); final pAmountFormatter = Provider.family((ref, coin) { + final locale = ref.watch( + localeServiceChangeNotifierProvider.select((value) => value.locale), + ); + return AmountFormatter( unit: ref.watch(pAmountUnit(coin)), - locale: ref.watch( - localeServiceChangeNotifierProvider.select((value) => value.locale), - ), + locale: locale, coin: coin, maxDecimals: ref.watch(pMaxDecimals(coin)), ); diff --git a/lib/utilities/amount/amount_input_formatter.dart b/lib/utilities/amount/amount_input_formatter.dart index dfc2b5732..2ac5d7871 100644 --- a/lib/utilities/amount/amount_input_formatter.dart +++ b/lib/utilities/amount/amount_input_formatter.dart @@ -1,9 +1,8 @@ import 'dart:math'; import 'package:flutter/services.dart'; -import 'package:intl/number_symbols.dart'; -import 'package:intl/number_symbols_data.dart'; import 'package:stackwallet/utilities/amount/amount_unit.dart'; +import 'package:stackwallet/utilities/util.dart'; class AmountInputFormatter extends TextInputFormatter { final int decimals; @@ -20,8 +19,7 @@ class AmountInputFormatter extends TextInputFormatter { TextEditingValue formatEditUpdate( TextEditingValue oldValue, TextEditingValue newValue) { // get number symbols for decimal place and group separator - final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ?? - numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + final numberSymbols = Util.getSymbolsFor(locale: locale); final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? "."; final groupSeparator = numberSymbols?.GROUP_SEP ?? ","; diff --git a/lib/utilities/amount/amount_unit.dart b/lib/utilities/amount/amount_unit.dart index 79b36130f..0c0600d7a 100644 --- a/lib/utilities/amount/amount_unit.dart +++ b/lib/utilities/amount/amount_unit.dart @@ -11,11 +11,10 @@ import 'dart:math' as math; import 'package:decimal/decimal.dart'; -import 'package:intl/number_symbols.dart'; -import 'package:intl/number_symbols_data.dart'; import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/util.dart'; // preserve index order as index is used to store value in preferences enum AmountUnit { @@ -188,8 +187,7 @@ extension AmountUnitExt on AmountUnit { } // get number symbols for decimal place and group separator - final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ?? - numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + final numberSymbols = Util.getSymbolsFor(locale: locale); final groupSeparator = numberSymbols?.GROUP_SEP ?? ","; final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? "."; @@ -237,8 +235,7 @@ extension AmountUnitExt on AmountUnit { String returnValue = wholeNumber.toString(); // get number symbols for decimal place and group separator - final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ?? - numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + final numberSymbols = Util.getSymbolsFor(locale: locale); // insert group separator final regex = RegExp(r'\B(?=(\d{3})+(?!\d))'); diff --git a/lib/utilities/util.dart b/lib/utilities/util.dart index 265cd2e06..c73f697cc 100644 --- a/lib/utilities/util.dart +++ b/lib/utilities/util.dart @@ -14,11 +14,21 @@ import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/material.dart'; +import 'package:intl/number_symbols.dart'; +import 'package:intl/number_symbols_data.dart'; abstract class Util { static Directory? libraryPath; static double? screenWidth; + static NumberSymbols? getSymbolsFor({required String locale}) { + return numberFormatSymbols[locale] as NumberSymbols? ?? + numberFormatSymbols[locale.replaceAll("-", "_")] as NumberSymbols? ?? + numberFormatSymbols[locale.substring(3).toLowerCase()] + as NumberSymbols? ?? + numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?; + } + static bool get isDesktop { // special check for running on linux based phones if (Platform.isLinux && screenWidth != null && screenWidth! < 800) {