Merge branch 'main' of https://github.com/cake-tech/cake_wallet into CW-600-password-manager

This commit is contained in:
Matthew Fosse 2024-05-28 08:37:39 -07:00
commit fb5074c832
11 changed files with 170 additions and 117 deletions

View file

@ -253,7 +253,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static CryptoCurrency fromString(String name, {CryptoCurrency? walletCurrency}) { static CryptoCurrency fromString(String name, {CryptoCurrency? walletCurrency}) {
try { try {
return CryptoCurrency.all.firstWhere((element) => return CryptoCurrency.all.firstWhere((element) =>
element.title.toLowerCase() == name && element.title.toLowerCase() == name.toLowerCase() &&
(element.tag == null || (element.tag == null ||
element.tag == walletCurrency?.title || element.tag == walletCurrency?.title ||
element.tag == walletCurrency?.tag)); element.tag == walletCurrency?.tag));

View file

@ -399,6 +399,7 @@ extern "C"
return false; return false;
} }
wallet->store(std::string(path));
change_current_wallet(wallet); change_current_wallet(wallet);
return true; return true;
} }
@ -464,6 +465,16 @@ extern "C"
return strdup(get_current_wallet()->address(account_index, address_index).c_str()); 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() const char *seed()
{ {

View file

@ -154,3 +154,7 @@ typedef freeze_coin = Void Function(Int32 index);
typedef thaw_coin = Void Function(Int32 index); typedef thaw_coin = Void Function(Int32 index);
typedef sign_message = Pointer<Utf8> Function(Pointer<Utf8> message, Pointer<Utf8> address); typedef sign_message = Pointer<Utf8> Function(Pointer<Utf8> message, Pointer<Utf8> address);
typedef get_cache_attribute = Pointer<Utf8> Function(Pointer<Utf8> name);
typedef set_cache_attribute = Int8 Function(Pointer<Utf8> name, Pointer<Utf8> value);

View file

@ -154,3 +154,7 @@ typedef FreezeCoin = void Function(int);
typedef ThawCoin = void Function(int); typedef ThawCoin = void Function(int);
typedef SignMessage = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>); typedef SignMessage = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>);
typedef GetCacheAttribute = Pointer<Utf8> Function(Pointer<Utf8>);
typedef SetCacheAttribute = int Function(Pointer<Utf8>, Pointer<Utf8>);

View file

@ -1,26 +1,24 @@
import 'dart:async'; import 'dart:async';
import 'dart:ffi'; 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/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/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'; import 'package:flutter/foundation.dart';
int _boolToInt(bool value) => value ? 1 : 0; int _boolToInt(bool value) => value ? 1 : 0;
final getFileNameNative = moneroApi final getFileNameNative =
.lookup<NativeFunction<get_filename>>('get_filename') moneroApi.lookup<NativeFunction<get_filename>>('get_filename').asFunction<GetFilename>();
.asFunction<GetFilename>();
final getSeedNative = final getSeedNative = moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
final getAddressNative = moneroApi final getAddressNative =
.lookup<NativeFunction<get_address>>('get_address') moneroApi.lookup<NativeFunction<get_address>>('get_address').asFunction<GetAddress>();
.asFunction<GetAddress>();
final getFullBalanceNative = moneroApi final getFullBalanceNative = moneroApi
.lookup<NativeFunction<get_full_balanace>>('get_full_balance') .lookup<NativeFunction<get_full_balanace>>('get_full_balance')
@ -38,41 +36,34 @@ final getNodeHeightNative = moneroApi
.lookup<NativeFunction<get_node_height>>('get_node_height') .lookup<NativeFunction<get_node_height>>('get_node_height')
.asFunction<GetNodeHeight>(); .asFunction<GetNodeHeight>();
final isConnectedNative = moneroApi final isConnectedNative =
.lookup<NativeFunction<is_connected>>('is_connected') moneroApi.lookup<NativeFunction<is_connected>>('is_connected').asFunction<IsConnected>();
.asFunction<IsConnected>();
final setupNodeNative = moneroApi final setupNodeNative =
.lookup<NativeFunction<setup_node>>('setup_node') moneroApi.lookup<NativeFunction<setup_node>>('setup_node').asFunction<SetupNode>();
.asFunction<SetupNode>();
final startRefreshNative = moneroApi final startRefreshNative =
.lookup<NativeFunction<start_refresh>>('start_refresh') moneroApi.lookup<NativeFunction<start_refresh>>('start_refresh').asFunction<StartRefresh>();
.asFunction<StartRefresh>();
final connecToNodeNative = moneroApi final connecToNodeNative = moneroApi
.lookup<NativeFunction<connect_to_node>>('connect_to_node') .lookup<NativeFunction<connect_to_node>>('connect_to_node')
.asFunction<ConnectToNode>(); .asFunction<ConnectToNode>();
final setRefreshFromBlockHeightNative = moneroApi final setRefreshFromBlockHeightNative = moneroApi
.lookup<NativeFunction<set_refresh_from_block_height>>( .lookup<NativeFunction<set_refresh_from_block_height>>('set_refresh_from_block_height')
'set_refresh_from_block_height')
.asFunction<SetRefreshFromBlockHeight>(); .asFunction<SetRefreshFromBlockHeight>();
final setRecoveringFromSeedNative = moneroApi final setRecoveringFromSeedNative = moneroApi
.lookup<NativeFunction<set_recovering_from_seed>>( .lookup<NativeFunction<set_recovering_from_seed>>('set_recovering_from_seed')
'set_recovering_from_seed')
.asFunction<SetRecoveringFromSeed>(); .asFunction<SetRecoveringFromSeed>();
final storeNative = final storeNative = moneroApi.lookup<NativeFunction<store_c>>('store').asFunction<Store>();
moneroApi.lookup<NativeFunction<store_c>>('store').asFunction<Store>();
final setPasswordNative = final setPasswordNative =
moneroApi.lookup<NativeFunction<set_password>>('set_password').asFunction<SetPassword>(); moneroApi.lookup<NativeFunction<set_password>>('set_password').asFunction<SetPassword>();
final setListenerNative = moneroApi final setListenerNative =
.lookup<NativeFunction<set_listener>>('set_listener') moneroApi.lookup<NativeFunction<set_listener>>('set_listener').asFunction<SetListener>();
.asFunction<SetListener>();
final getSyncingHeightNative = moneroApi final getSyncingHeightNative = moneroApi
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height') .lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
@ -83,8 +74,7 @@ final isNeededToRefreshNative = moneroApi
.asFunction<IsNeededToRefresh>(); .asFunction<IsNeededToRefresh>();
final isNewTransactionExistNative = moneroApi final isNewTransactionExistNative = moneroApi
.lookup<NativeFunction<is_new_transaction_exist>>( .lookup<NativeFunction<is_new_transaction_exist>>('is_new_transaction_exist')
'is_new_transaction_exist')
.asFunction<IsNewTransactionExist>(); .asFunction<IsNewTransactionExist>();
final getSecretViewKeyNative = moneroApi final getSecretViewKeyNative = moneroApi
@ -107,9 +97,8 @@ final closeCurrentWalletNative = moneroApi
.lookup<NativeFunction<close_current_wallet>>('close_current_wallet') .lookup<NativeFunction<close_current_wallet>>('close_current_wallet')
.asFunction<CloseCurrentWallet>(); .asFunction<CloseCurrentWallet>();
final onStartupNative = moneroApi final onStartupNative =
.lookup<NativeFunction<on_startup>>('on_startup') moneroApi.lookup<NativeFunction<on_startup>>('on_startup').asFunction<OnStartup>();
.asFunction<OnStartup>();
final rescanBlockchainAsyncNative = moneroApi final rescanBlockchainAsyncNative = moneroApi
.lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain') .lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain')
@ -123,13 +112,19 @@ final setTrustedDaemonNative = moneroApi
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon') .lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
.asFunction<SetTrustedDaemon>(); .asFunction<SetTrustedDaemon>();
final trustedDaemonNative = moneroApi final trustedDaemonNative =
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon') moneroApi.lookup<NativeFunction<trusted_daemon>>('trusted_daemon').asFunction<TrustedDaemon>();
.asFunction<TrustedDaemon>();
final signMessageNative = moneroApi final signMessageNative =
.lookup<NativeFunction<sign_message>>('sign_message') moneroApi.lookup<NativeFunction<sign_message>>('sign_message').asFunction<SignMessage>();
.asFunction<SignMessage>();
final getCacheAttributeNative = moneroApi
.lookup<NativeFunction<get_cache_attribute>>('get_cache_attribute')
.asFunction<GetCacheAttribute>();
final setCacheAttributeNative = moneroApi
.lookup<NativeFunction<set_cache_attribute>>('set_cache_attribute')
.asFunction<SetCacheAttribute>();
int getSyncingHeight() => getSyncingHeightNative(); int getSyncingHeight() => getSyncingHeightNative();
@ -144,11 +139,9 @@ String getSeed() => convertUTF8ToString(pointer: getSeedNative());
String getAddress({int accountIndex = 0, int addressIndex = 0}) => String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex)); convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
int getFullBalance({int accountIndex = 0}) => int getFullBalance({int accountIndex = 0}) => getFullBalanceNative(accountIndex);
getFullBalanceNative(accountIndex);
int getUnlockedBalance({int accountIndex = 0}) => int getUnlockedBalance({int accountIndex = 0}) => getUnlockedBalanceNative(accountIndex);
getUnlockedBalanceNative(accountIndex);
int getCurrentHeight() => getCurrentHeightNative(); int getCurrentHeight() => getCurrentHeightNative();
@ -187,7 +180,7 @@ bool setupNodeSync(
passwordPointer, passwordPointer,
_boolToInt(useSSL), _boolToInt(useSSL),
_boolToInt(isLightWallet), _boolToInt(isLightWallet),
socksProxyAddressPointer, socksProxyAddressPointer,
errorMessagePointer) != errorMessagePointer) !=
0; 0;
@ -202,8 +195,7 @@ bool setupNodeSync(
} }
if (!isSetupNode) { if (!isSetupNode) {
throw SetupWalletException( throw SetupWalletException(message: convertUTF8ToString(pointer: errorMessagePointer));
message: convertUTF8ToString(pointer: errorMessagePointer));
} }
return isSetupNode; return isSetupNode;
@ -213,8 +205,7 @@ void startRefreshSync() => startRefreshNative();
Future<bool> connectToNode() async => connecToNodeNative() != 0; Future<bool> connectToNode() async => connecToNodeNative() != 0;
void setRefreshFromBlockHeight({required int height}) => void setRefreshFromBlockHeight({required int height}) => setRefreshFromBlockHeightNative(height);
setRefreshFromBlockHeightNative(height);
void setRecoveringFromSeed({required bool isRecovery}) => void setRecoveringFromSeed({required bool isRecovery}) =>
setRecoveringFromSeedNative(_boolToInt(isRecovery)); setRecoveringFromSeedNative(_boolToInt(isRecovery));
@ -242,24 +233,19 @@ void setPasswordSync(String password) {
void closeCurrentWallet() => closeCurrentWalletNative(); void closeCurrentWallet() => closeCurrentWalletNative();
String getSecretViewKey() => String getSecretViewKey() => convertUTF8ToString(pointer: getSecretViewKeyNative());
convertUTF8ToString(pointer: getSecretViewKeyNative());
String getPublicViewKey() => String getPublicViewKey() => convertUTF8ToString(pointer: getPublicViewKeyNative());
convertUTF8ToString(pointer: getPublicViewKeyNative());
String getSecretSpendKey() => String getSecretSpendKey() => convertUTF8ToString(pointer: getSecretSpendKeyNative());
convertUTF8ToString(pointer: getSecretSpendKeyNative());
String getPublicSpendKey() => String getPublicSpendKey() => convertUTF8ToString(pointer: getPublicSpendKeyNative());
convertUTF8ToString(pointer: getPublicSpendKeyNative());
class SyncListener { class SyncListener {
SyncListener(this.onNewBlock, this.onNewTransaction) SyncListener(this.onNewBlock, this.onNewTransaction)
: _cachedBlockchainHeight = 0, : _cachedBlockchainHeight = 0,
_lastKnownBlockHeight = 0, _lastKnownBlockHeight = 0,
_initialSyncHeight = 0; _initialSyncHeight = 0;
void Function(int, int, double) onNewBlock; void Function(int, int, double) onNewBlock;
void Function() onNewTransaction; void Function() onNewTransaction;
@ -281,8 +267,7 @@ class SyncListener {
_cachedBlockchainHeight = 0; _cachedBlockchainHeight = 0;
_lastKnownBlockHeight = 0; _lastKnownBlockHeight = 0;
_initialSyncHeight = 0; _initialSyncHeight = 0;
_updateSyncInfoTimer ??= _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async {
Timer.periodic(Duration(milliseconds: 1200), (_) async {
if (isNewTransactionExist()) { if (isNewTransactionExist()) {
onNewTransaction(); onNewTransaction();
} }
@ -321,8 +306,8 @@ class SyncListener {
void stop() => _updateSyncInfoTimer?.cancel(); void stop() => _updateSyncInfoTimer?.cancel();
} }
SyncListener setListeners(void Function(int, int, double) onNewBlock, SyncListener setListeners(
void Function() onNewTransaction) { void Function(int, int, double) onNewBlock, void Function() onNewTransaction) {
final listener = SyncListener(onNewBlock, onNewTransaction); final listener = SyncListener(onNewBlock, onNewTransaction);
setListenerNative(); setListenerNative();
return listener; return listener;
@ -364,7 +349,7 @@ Future<void> setupNode(
bool isLightWallet = false}) => bool isLightWallet = false}) =>
compute<Map<String, Object?>, void>(_setupNodeSync, { compute<Map<String, Object?>, void>(_setupNodeSync, {
'address': address, 'address': address,
'login': login , 'login': login,
'password': password, 'password': password,
'useSSL': useSSL, 'useSSL': useSSL,
'isLightWallet': isLightWallet, 'isLightWallet': isLightWallet,
@ -397,3 +382,23 @@ String signMessage(String message, {String address = ""}) {
return signature; 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;
}

View file

@ -15,8 +15,8 @@ class SolanaBalance extends Balance {
String _balanceFormatted() { String _balanceFormatted() {
String stringBalance = balance.toString(); String stringBalance = balance.toString();
if (stringBalance.toString().length >= 6) { if (stringBalance.toString().length >= 12) {
stringBalance = stringBalance.substring(0, 6); stringBalance = stringBalance.substring(0, 12);
} }
return stringBalance; return stringBalance;
} }

View file

@ -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/auth_service.dart';
import 'package:cake_wallet/core/backup_service.dart'; import 'package:cake_wallet/core/backup_service.dart';
import 'package:cake_wallet/core/key_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/wallet_connect_key_service.dart';
import 'package:cake_wallet/core/wallet_connect/wc_bottom_sheet_service.dart'; import 'package:cake_wallet/core/wallet_connect/wc_bottom_sheet_service.dart';
import 'package:cake_wallet/core/wallet_connect/web3wallet_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/contact_record.dart';
import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart';
import 'package:cake_wallet/entities/parse_address_from_domain.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/qr_view_data.dart';
import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/entities/transaction_description.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_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/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/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/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_details_page.dart';
import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_list_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/wallet_list_store.dart';
import 'package:cake_wallet/store/yat/yat_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/themes/theme_list.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/device_info.dart';
import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/utils/payment_request.dart';
import 'package:cake_wallet/utils/responsive_layout_util.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_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_payment_status_view_model.dart';
import 'package:cake_wallet/view_model/ionia/ionia_purchase_merch_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/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_edit_or_create_view_model.dart';
import 'package:cake_wallet/view_model/monero_account_list/monero_account_list_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/crypto_currency.dart';
import 'package:cw_core/nano_account.dart'; import 'package:cw_core/nano_account.dart';
import 'package:cw_core/node.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/transaction_info.dart';
import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_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:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/core/secure_storage.dart';
import 'buy/dfx/dfx_buy_provider.dart'; import 'buy/dfx/dfx_buy_provider.dart';
import 'core/totp_request_details.dart'; import 'core/totp_request_details.dart';
@ -795,8 +795,8 @@ Future<void> setup({
getIt.registerFactory(() => ConnectionSyncPage(getIt.get<DashboardViewModel>())); getIt.registerFactory(() => ConnectionSyncPage(getIt.get<DashboardViewModel>()));
getIt.registerFactory( getIt.registerFactory(() => SecurityBackupPage(getIt.get<SecuritySettingsViewModel>(),
() => SecurityBackupPage(getIt.get<SecuritySettingsViewModel>(), getIt.get<AuthService>())); getIt.get<AuthService>(), getIt.get<AppStore>().wallet!.isHardwareWallet));
getIt.registerFactory(() => PrivacyPage(getIt.get<PrivacySettingsViewModel>())); getIt.registerFactory(() => PrivacyPage(getIt.get<PrivacySettingsViewModel>()));

View file

@ -46,6 +46,7 @@ class ContactPage extends BasePage {
final TextEditingController _nameController; final TextEditingController _nameController;
final TextEditingController _currencyTypeController; final TextEditingController _currencyTypeController;
final TextEditingController _addressController; final TextEditingController _addressController;
bool _isEffectsApplied = false;
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
@ -53,15 +54,7 @@ class ContactPage extends BasePage {
color: Theme.of(context).extension<TransactionTradeTheme>()!.detailsTitlesColor, color: Theme.of(context).extension<TransactionTradeTheme>()!.detailsTitlesColor,
height: 8); height: 8);
reaction((_) => contactViewModel.state, (ExecutionState state) { _setEffects(context);
if (state is FailureState) {
_onContactSavingFailure(context, state.error);
}
if (state is ExecutedSuccessfullyState) {
_onContactSavedSuccessfully(context);
}
});
return Observer( return Observer(
builder: (_) => ScrollableWithBottomSection( builder: (_) => ScrollableWithBottomSection(
@ -177,4 +170,22 @@ class ContactPage extends BasePage {
void _onContactSavedSuccessfully(BuildContext context) => void _onContactSavedSuccessfully(BuildContext context) =>
Navigator.of(context).pop(); 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);
}
});
}
} }

View file

@ -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_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_picker_cell.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_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/utils/device_info.dart';
import 'package:cake_wallet/view_model/settings/security_settings_view_model.dart'; import 'package:cake_wallet/view_model/settings/security_settings_view_model.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
class SecurityBackupPage extends BasePage { class SecurityBackupPage extends BasePage {
SecurityBackupPage(this._securitySettingsViewModel, this._authService); SecurityBackupPage(this._securitySettingsViewModel, this._authService, [this._isHardwareWallet = false]);
final AuthService _authService; final AuthService _authService;
@ -25,20 +24,23 @@ class SecurityBackupPage extends BasePage {
final SecuritySettingsViewModel _securitySettingsViewModel; final SecuritySettingsViewModel _securitySettingsViewModel;
final bool _isHardwareWallet;
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.only(top: 10), padding: EdgeInsets.only(top: 10),
child: Column(mainAxisSize: MainAxisSize.min, children: [ child: Column(mainAxisSize: MainAxisSize.min, children: [
SettingsCellWithArrow( if (!_isHardwareWallet)
title: S.current.show_keys, SettingsCellWithArrow(
handler: (_) => _authService.authenticateAction( title: S.current.show_keys,
context, handler: (_) => _authService.authenticateAction(
route: Routes.showKeys, context,
conditionToDetermineIfToUse2FA: _securitySettingsViewModel route: Routes.showKeys,
.shouldRequireTOTP2FAForAllSecurityAndBackupSettings, conditionToDetermineIfToUse2FA:
_securitySettingsViewModel.shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
),
), ),
),
SettingsCellWithArrow( SettingsCellWithArrow(
title: S.current.create_backup, title: S.current.create_backup,
handler: (_) => _authService.authenticateAction( handler: (_) => _authService.authenticateAction(

View file

@ -535,24 +535,29 @@ abstract class DashboardViewModelBase with Store {
Future<ServicesResponse> getServicesStatus() async { Future<ServicesResponse> getServicesStatus() async {
try { 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) { if (res.statusCode < 200 || res.statusCode >= 300) {
throw res.body; 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<String, dynamic>,
hasUpdates,
currentSha,
);
} }
else {
final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); return ServicesResponse([], false, '');
}
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<String, dynamic>,
hasUpdates,
currentSha,
);
} catch (_) { } catch (_) {
return ServicesResponse([], false, ''); return ServicesResponse([], false, '');
} }

View file

@ -139,8 +139,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
String get pendingTransactionFeeFiatAmount { String get pendingTransactionFeeFiatAmount {
try { try {
if (pendingTransaction != null) { if (pendingTransaction != null) {
final currency = final currency = pendingTransactionFeeCurrency(walletType);
isEVMCompatibleChain(walletType) ? wallet.currency : selectedCryptoCurrency;
final fiat = calculateFiatAmount( final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[currency]!, price: _fiatConversationStore.prices[currency]!,
cryptoAmount: pendingTransaction!.feeFormatted); 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; FiatCurrency get fiat => _settingsStore.fiatCurrency;
TransactionPriority get transactionPriority { TransactionPriority get transactionPriority {