diff --git a/cw_core/lib/crypto_currency.dart b/cw_core/lib/crypto_currency.dart index fabc84051..fb702eca1 100644 --- a/cw_core/lib/crypto_currency.dart +++ b/cw_core/lib/crypto_currency.dart @@ -253,7 +253,7 @@ class CryptoCurrency extends EnumerableItem with Serializable implemen static CryptoCurrency fromString(String name, {CryptoCurrency? walletCurrency}) { try { return CryptoCurrency.all.firstWhere((element) => - element.title.toLowerCase() == name && + element.title.toLowerCase() == name.toLowerCase() && (element.tag == null || element.tag == walletCurrency?.title || element.tag == walletCurrency?.tag)); diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index 87be785ac..01a8d9a51 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -399,6 +399,7 @@ extern "C" return false; } + wallet->store(std::string(path)); change_current_wallet(wallet); return true; } @@ -464,6 +465,16 @@ extern "C" return strdup(get_current_wallet()->address(account_index, address_index).c_str()); } + char *get_cache_attribute(char *name) + { + return strdup(get_current_wallet()->getCacheAttribute(std::string(name)).c_str()); + } + + bool set_cache_attribute(char *name, char *value) + { + get_current_wallet()->setCacheAttribute(std::string(name), std::string(value)); + return true; + } const char *seed() { diff --git a/cw_monero/lib/api/signatures.dart b/cw_monero/lib/api/signatures.dart index bba7b5528..40f338c8c 100644 --- a/cw_monero/lib/api/signatures.dart +++ b/cw_monero/lib/api/signatures.dart @@ -154,3 +154,7 @@ typedef freeze_coin = Void Function(Int32 index); typedef thaw_coin = Void Function(Int32 index); typedef sign_message = Pointer Function(Pointer message, Pointer address); + +typedef get_cache_attribute = Pointer Function(Pointer name); + +typedef set_cache_attribute = Int8 Function(Pointer name, Pointer value); diff --git a/cw_monero/lib/api/types.dart b/cw_monero/lib/api/types.dart index 87d8a153e..6b36ab5e3 100644 --- a/cw_monero/lib/api/types.dart +++ b/cw_monero/lib/api/types.dart @@ -154,3 +154,7 @@ typedef FreezeCoin = void Function(int); typedef ThawCoin = void Function(int); typedef SignMessage = Pointer Function(Pointer, Pointer); + +typedef GetCacheAttribute = Pointer Function(Pointer); + +typedef SetCacheAttribute = int Function(Pointer, Pointer); diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index ffa5fe13b..448c661e6 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -1,26 +1,24 @@ import 'dart:async'; import 'dart:ffi'; -import 'package:ffi/ffi.dart'; -import 'package:cw_monero/api/structs/ut8_box.dart'; + import 'package:cw_monero/api/convert_utf8_to_string.dart'; -import 'package:cw_monero/api/signatures.dart'; -import 'package:cw_monero/api/types.dart'; -import 'package:cw_monero/api/monero_api.dart'; import 'package:cw_monero/api/exceptions/setup_wallet_exception.dart'; +import 'package:cw_monero/api/monero_api.dart'; +import 'package:cw_monero/api/signatures.dart'; +import 'package:cw_monero/api/structs/ut8_box.dart'; +import 'package:cw_monero/api/types.dart'; +import 'package:ffi/ffi.dart'; import 'package:flutter/foundation.dart'; int _boolToInt(bool value) => value ? 1 : 0; -final getFileNameNative = moneroApi - .lookup>('get_filename') - .asFunction(); +final getFileNameNative = + moneroApi.lookup>('get_filename').asFunction(); -final getSeedNative = - moneroApi.lookup>('seed').asFunction(); +final getSeedNative = moneroApi.lookup>('seed').asFunction(); -final getAddressNative = moneroApi - .lookup>('get_address') - .asFunction(); +final getAddressNative = + moneroApi.lookup>('get_address').asFunction(); final getFullBalanceNative = moneroApi .lookup>('get_full_balance') @@ -38,41 +36,34 @@ final getNodeHeightNative = moneroApi .lookup>('get_node_height') .asFunction(); -final isConnectedNative = moneroApi - .lookup>('is_connected') - .asFunction(); +final isConnectedNative = + moneroApi.lookup>('is_connected').asFunction(); -final setupNodeNative = moneroApi - .lookup>('setup_node') - .asFunction(); +final setupNodeNative = + moneroApi.lookup>('setup_node').asFunction(); -final startRefreshNative = moneroApi - .lookup>('start_refresh') - .asFunction(); +final startRefreshNative = + moneroApi.lookup>('start_refresh').asFunction(); final connecToNodeNative = moneroApi .lookup>('connect_to_node') .asFunction(); final setRefreshFromBlockHeightNative = moneroApi - .lookup>( - 'set_refresh_from_block_height') + .lookup>('set_refresh_from_block_height') .asFunction(); final setRecoveringFromSeedNative = moneroApi - .lookup>( - 'set_recovering_from_seed') + .lookup>('set_recovering_from_seed') .asFunction(); -final storeNative = - moneroApi.lookup>('store').asFunction(); +final storeNative = moneroApi.lookup>('store').asFunction(); final setPasswordNative = moneroApi.lookup>('set_password').asFunction(); -final setListenerNative = moneroApi - .lookup>('set_listener') - .asFunction(); +final setListenerNative = + moneroApi.lookup>('set_listener').asFunction(); final getSyncingHeightNative = moneroApi .lookup>('get_syncing_height') @@ -83,8 +74,7 @@ final isNeededToRefreshNative = moneroApi .asFunction(); final isNewTransactionExistNative = moneroApi - .lookup>( - 'is_new_transaction_exist') + .lookup>('is_new_transaction_exist') .asFunction(); final getSecretViewKeyNative = moneroApi @@ -107,9 +97,8 @@ final closeCurrentWalletNative = moneroApi .lookup>('close_current_wallet') .asFunction(); -final onStartupNative = moneroApi - .lookup>('on_startup') - .asFunction(); +final onStartupNative = + moneroApi.lookup>('on_startup').asFunction(); final rescanBlockchainAsyncNative = moneroApi .lookup>('rescan_blockchain') @@ -123,13 +112,19 @@ final setTrustedDaemonNative = moneroApi .lookup>('set_trusted_daemon') .asFunction(); -final trustedDaemonNative = moneroApi - .lookup>('trusted_daemon') - .asFunction(); +final trustedDaemonNative = + moneroApi.lookup>('trusted_daemon').asFunction(); -final signMessageNative = moneroApi - .lookup>('sign_message') - .asFunction(); +final signMessageNative = + moneroApi.lookup>('sign_message').asFunction(); + +final getCacheAttributeNative = moneroApi + .lookup>('get_cache_attribute') + .asFunction(); + +final setCacheAttributeNative = moneroApi + .lookup>('set_cache_attribute') + .asFunction(); int getSyncingHeight() => getSyncingHeightNative(); @@ -144,11 +139,9 @@ String getSeed() => convertUTF8ToString(pointer: getSeedNative()); String getAddress({int accountIndex = 0, int addressIndex = 0}) => convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex)); -int getFullBalance({int accountIndex = 0}) => - getFullBalanceNative(accountIndex); +int getFullBalance({int accountIndex = 0}) => getFullBalanceNative(accountIndex); -int getUnlockedBalance({int accountIndex = 0}) => - getUnlockedBalanceNative(accountIndex); +int getUnlockedBalance({int accountIndex = 0}) => getUnlockedBalanceNative(accountIndex); int getCurrentHeight() => getCurrentHeightNative(); @@ -187,7 +180,7 @@ bool setupNodeSync( passwordPointer, _boolToInt(useSSL), _boolToInt(isLightWallet), - socksProxyAddressPointer, + socksProxyAddressPointer, errorMessagePointer) != 0; @@ -202,8 +195,7 @@ bool setupNodeSync( } if (!isSetupNode) { - throw SetupWalletException( - message: convertUTF8ToString(pointer: errorMessagePointer)); + throw SetupWalletException(message: convertUTF8ToString(pointer: errorMessagePointer)); } return isSetupNode; @@ -213,8 +205,7 @@ void startRefreshSync() => startRefreshNative(); Future connectToNode() async => connecToNodeNative() != 0; -void setRefreshFromBlockHeight({required int height}) => - setRefreshFromBlockHeightNative(height); +void setRefreshFromBlockHeight({required int height}) => setRefreshFromBlockHeightNative(height); void setRecoveringFromSeed({required bool isRecovery}) => setRecoveringFromSeedNative(_boolToInt(isRecovery)); @@ -230,7 +221,7 @@ void setPasswordSync(String password) { final errorMessagePointer = calloc(); final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0; calloc.free(passwordPointer); - + if (!changed) { final message = errorMessagePointer.ref.getValue(); calloc.free(errorMessagePointer); @@ -242,24 +233,19 @@ void setPasswordSync(String password) { void closeCurrentWallet() => closeCurrentWalletNative(); -String getSecretViewKey() => - convertUTF8ToString(pointer: getSecretViewKeyNative()); +String getSecretViewKey() => convertUTF8ToString(pointer: getSecretViewKeyNative()); -String getPublicViewKey() => - convertUTF8ToString(pointer: getPublicViewKeyNative()); +String getPublicViewKey() => convertUTF8ToString(pointer: getPublicViewKeyNative()); -String getSecretSpendKey() => - convertUTF8ToString(pointer: getSecretSpendKeyNative()); +String getSecretSpendKey() => convertUTF8ToString(pointer: getSecretSpendKeyNative()); -String getPublicSpendKey() => - convertUTF8ToString(pointer: getPublicSpendKeyNative()); +String getPublicSpendKey() => convertUTF8ToString(pointer: getPublicSpendKeyNative()); class SyncListener { - SyncListener(this.onNewBlock, this.onNewTransaction) - : _cachedBlockchainHeight = 0, - _lastKnownBlockHeight = 0, - _initialSyncHeight = 0; - + SyncListener(this.onNewBlock, this.onNewTransaction) + : _cachedBlockchainHeight = 0, + _lastKnownBlockHeight = 0, + _initialSyncHeight = 0; void Function(int, int, double) onNewBlock; void Function() onNewTransaction; @@ -281,8 +267,7 @@ class SyncListener { _cachedBlockchainHeight = 0; _lastKnownBlockHeight = 0; _initialSyncHeight = 0; - _updateSyncInfoTimer ??= - Timer.periodic(Duration(milliseconds: 1200), (_) async { + _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { if (isNewTransactionExist()) { onNewTransaction(); } @@ -321,8 +306,8 @@ class SyncListener { void stop() => _updateSyncInfoTimer?.cancel(); } -SyncListener setListeners(void Function(int, int, double) onNewBlock, - void Function() onNewTransaction) { +SyncListener setListeners( + void Function(int, int, double) onNewBlock, void Function() onNewTransaction) { final listener = SyncListener(onNewBlock, onNewTransaction); setListenerNative(); return listener; @@ -364,7 +349,7 @@ Future setupNode( bool isLightWallet = false}) => compute, void>(_setupNodeSync, { 'address': address, - 'login': login , + 'login': login, 'password': password, 'useSSL': useSSL, 'isLightWallet': isLightWallet, @@ -397,3 +382,23 @@ String signMessage(String message, {String address = ""}) { return signature; } + +bool setCacheAttribute(String name, String value) { + final namePointer = name.toNativeUtf8(); + final valuePointer = value.toNativeUtf8(); + + final isSet = setCacheAttributeNative(namePointer, valuePointer); + calloc.free(namePointer); + calloc.free(valuePointer); + + return isSet == 1; +} + +String getCacheAttribute(String name) { + final namePointer = name.toNativeUtf8(); + + final value = convertUTF8ToString(pointer: getCacheAttributeNative(namePointer)); + calloc.free(namePointer); + + return value; +} diff --git a/cw_solana/lib/solana_balance.dart b/cw_solana/lib/solana_balance.dart index b1f0ef153..e88a510dd 100644 --- a/cw_solana/lib/solana_balance.dart +++ b/cw_solana/lib/solana_balance.dart @@ -15,8 +15,8 @@ class SolanaBalance extends Balance { String _balanceFormatted() { String stringBalance = balance.toString(); - if (stringBalance.toString().length >= 6) { - stringBalance = stringBalance.substring(0, 6); + if (stringBalance.toString().length >= 12) { + stringBalance = stringBalance.substring(0, 12); } return stringBalance; } diff --git a/lib/di.dart b/lib/di.dart index c039b68f4..6a97cf62c 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -14,6 +14,7 @@ import 'package:cake_wallet/buy/robinhood/robinhood_buy_provider.dart'; import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/backup_service.dart'; import 'package:cake_wallet/core/key_service.dart'; +import 'package:cake_wallet/core/secure_storage.dart'; import 'package:cake_wallet/core/wallet_connect/wallet_connect_key_service.dart'; import 'package:cake_wallet/core/wallet_connect/wc_bottom_sheet_service.dart'; import 'package:cake_wallet/core/wallet_connect/web3wallet_service.dart'; @@ -26,10 +27,6 @@ import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/parse_address_from_domain.dart'; -import 'package:cake_wallet/view_model/link_view_model.dart'; -import 'package:cake_wallet/tron/tron.dart'; -import 'package:cake_wallet/src/screens/transaction_details/rbf_details_page.dart'; -import 'package:cw_core/receive_page_option.dart'; import 'package:cake_wallet/entities/qr_view_data.dart'; import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; @@ -124,6 +121,7 @@ import 'package:cake_wallet/src/screens/support/support_page.dart'; import 'package:cake_wallet/src/screens/support_chat/support_chat_page.dart'; import 'package:cake_wallet/src/screens/support_other_links/support_other_links_page.dart'; import 'package:cake_wallet/src/screens/trade_details/trade_details_page.dart'; +import 'package:cake_wallet/src/screens/transaction_details/rbf_details_page.dart'; import 'package:cake_wallet/src/screens/transaction_details/transaction_details_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_details_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_list_page.dart'; @@ -147,6 +145,7 @@ import 'package:cake_wallet/store/templates/send_template_store.dart'; import 'package:cake_wallet/store/wallet_list_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; import 'package:cake_wallet/themes/theme_list.dart'; +import 'package:cake_wallet/tron/tron.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; @@ -179,6 +178,7 @@ import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model. import 'package:cake_wallet/view_model/ionia/ionia_gift_cards_list_view_model.dart'; import 'package:cake_wallet/view_model/ionia/ionia_payment_status_view_model.dart'; import 'package:cake_wallet/view_model/ionia/ionia_purchase_merch_view_model.dart'; +import 'package:cake_wallet/view_model/link_view_model.dart'; import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart'; import 'package:cake_wallet/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart'; import 'package:cake_wallet/view_model/monero_account_list/monero_account_list_view_model.dart'; @@ -222,6 +222,7 @@ import 'package:cake_wallet/view_model/wallet_seed_view_model.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/nano_account.dart'; import 'package:cw_core/node.dart'; +import 'package:cw_core/receive_page_option.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/wallet_info.dart'; @@ -233,7 +234,6 @@ import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:cake_wallet/core/secure_storage.dart'; import 'buy/dfx/dfx_buy_provider.dart'; import 'core/totp_request_details.dart'; @@ -795,8 +795,8 @@ Future setup({ getIt.registerFactory(() => ConnectionSyncPage(getIt.get())); - getIt.registerFactory( - () => SecurityBackupPage(getIt.get(), getIt.get())); + getIt.registerFactory(() => SecurityBackupPage(getIt.get(), + getIt.get(), getIt.get().wallet!.isHardwareWallet)); getIt.registerFactory(() => PrivacyPage(getIt.get())); diff --git a/lib/src/screens/contact/contact_page.dart b/lib/src/screens/contact/contact_page.dart index 099be41d5..7dea970ec 100644 --- a/lib/src/screens/contact/contact_page.dart +++ b/lib/src/screens/contact/contact_page.dart @@ -46,6 +46,7 @@ class ContactPage extends BasePage { final TextEditingController _nameController; final TextEditingController _currencyTypeController; final TextEditingController _addressController; + bool _isEffectsApplied = false; @override Widget body(BuildContext context) { @@ -53,15 +54,7 @@ class ContactPage extends BasePage { color: Theme.of(context).extension()!.detailsTitlesColor, height: 8); - reaction((_) => contactViewModel.state, (ExecutionState state) { - if (state is FailureState) { - _onContactSavingFailure(context, state.error); - } - - if (state is ExecutedSuccessfullyState) { - _onContactSavedSuccessfully(context); - } - }); + _setEffects(context); return Observer( builder: (_) => ScrollableWithBottomSection( @@ -177,4 +170,22 @@ class ContactPage extends BasePage { void _onContactSavedSuccessfully(BuildContext context) => Navigator.of(context).pop(); + + void _setEffects(BuildContext context) { + if (_isEffectsApplied) { + return; + } + + _isEffectsApplied = true; + + reaction((_) => contactViewModel.state, (ExecutionState state) { + if (state is FailureState) { + _onContactSavingFailure(context, state.error); + } + + if (state is ExecutedSuccessfullyState) { + _onContactSavedSuccessfully(context); + } + }); + } } diff --git a/lib/src/screens/settings/security_backup_page.dart b/lib/src/screens/settings/security_backup_page.dart index 1f0f58ad4..470f49190 100644 --- a/lib/src/screens/settings/security_backup_page.dart +++ b/lib/src/screens/settings/security_backup_page.dart @@ -9,14 +9,13 @@ import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart'; import 'package:cake_wallet/src/screens/settings/widgets/settings_cell_with_arrow.dart'; import 'package:cake_wallet/src/screens/settings/widgets/settings_picker_cell.dart'; import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart'; -import 'package:cake_wallet/src/widgets/standard_list.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/view_model/settings/security_settings_view_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; class SecurityBackupPage extends BasePage { - SecurityBackupPage(this._securitySettingsViewModel, this._authService); + SecurityBackupPage(this._securitySettingsViewModel, this._authService, [this._isHardwareWallet = false]); final AuthService _authService; @@ -25,20 +24,23 @@ class SecurityBackupPage extends BasePage { final SecuritySettingsViewModel _securitySettingsViewModel; + final bool _isHardwareWallet; + @override Widget body(BuildContext context) { return Container( padding: EdgeInsets.only(top: 10), child: Column(mainAxisSize: MainAxisSize.min, children: [ - SettingsCellWithArrow( - title: S.current.show_keys, - handler: (_) => _authService.authenticateAction( - context, - route: Routes.showKeys, - conditionToDetermineIfToUse2FA: _securitySettingsViewModel - .shouldRequireTOTP2FAForAllSecurityAndBackupSettings, + if (!_isHardwareWallet) + SettingsCellWithArrow( + title: S.current.show_keys, + handler: (_) => _authService.authenticateAction( + context, + route: Routes.showKeys, + conditionToDetermineIfToUse2FA: + _securitySettingsViewModel.shouldRequireTOTP2FAForAllSecurityAndBackupSettings, + ), ), - ), SettingsCellWithArrow( title: S.current.create_backup, handler: (_) => _authService.authenticateAction( diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index bd8ae6dda..f438c5724 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -535,24 +535,29 @@ abstract class DashboardViewModelBase with Store { Future getServicesStatus() async { try { - final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices")); + if (isEnabledBulletinAction) { + final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices")); - if (res.statusCode < 200 || res.statusCode >= 300) { - throw res.body; + if (res.statusCode < 200 || res.statusCode >= 300) { + throw res.body; + } + + final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); + + final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body)); + final currentSha = bytesToHex(hash.bytes); + + final hasUpdates = oldSha != currentSha; + + return ServicesResponse.fromJson( + json.decode(res.body) as Map, + hasUpdates, + currentSha, + ); } - - final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); - - final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body)); - final currentSha = bytesToHex(hash.bytes); - - final hasUpdates = oldSha != currentSha; - - return ServicesResponse.fromJson( - json.decode(res.body) as Map, - hasUpdates, - currentSha, - ); + else { + return ServicesResponse([], false, ''); + } } catch (_) { return ServicesResponse([], false, ''); } diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 4b30ecef3..534e501dd 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -139,8 +139,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor String get pendingTransactionFeeFiatAmount { try { if (pendingTransaction != null) { - final currency = - isEVMCompatibleChain(walletType) ? wallet.currency : selectedCryptoCurrency; + final currency = pendingTransactionFeeCurrency(walletType); final fiat = calculateFiatAmount( price: _fiatConversationStore.prices[currency]!, cryptoAmount: pendingTransaction!.feeFormatted); @@ -153,6 +152,18 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor } } + CryptoCurrency pendingTransactionFeeCurrency(WalletType type) { + switch (type) { + case WalletType.ethereum: + case WalletType.polygon: + case WalletType.tron: + case WalletType.solana: + return wallet.currency; + default: + return selectedCryptoCurrency; + } + } + FiatCurrency get fiat => _settingsStore.fiatCurrency; TransactionPriority get transactionPriority {