mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
fix: Implement totp on exchange to external ticket as well as update UI properly when a preset is selected (#1156)
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
OmarHatem
parent
d997ee81a1
commit
9aede1f3c1
@@ -33,6 +33,7 @@ enum VerboseControlSettings {
|
||||
sendsToNonContacts,
|
||||
sendsToInternalWallets,
|
||||
exchangesToInternalWallets,
|
||||
exchangesToExternalWallets,
|
||||
securityAndBackupSettings,
|
||||
creatingNewWallets,
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ class PreferencesKey {
|
||||
'should_require_totp_2fa_for_sends_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToInternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToExternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_external_wallets';
|
||||
static const shouldRequireTOTP2FAForAddingContacts =
|
||||
'should_require_totp_2fa_for_adding_contacts';
|
||||
static const shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
|
||||
@@ -133,6 +133,17 @@ class _2FAControlsWidget extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
Observer(
|
||||
builder: (context) {
|
||||
return SettingsSwitcherCell(
|
||||
title: S.current.require_for_exchanges_to_external_wallets,
|
||||
value: setup2FAViewModel.shouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
onValueChange: (context, value) async =>
|
||||
setup2FAViewModel.switchShouldRequireTOTP2FAForExchangesToExternalWallets(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
Observer(
|
||||
builder: (context) {
|
||||
return SettingsSwitcherCell(
|
||||
|
||||
@@ -76,6 +76,7 @@ abstract class SettingsStoreBase with Store {
|
||||
required bool initialShouldRequireTOTP2FAForSendsToNonContact,
|
||||
required bool initialShouldRequireTOTP2FAForSendsToInternalWallets,
|
||||
required bool initialShouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
required bool initialShouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
required bool initialShouldRequireTOTP2FAForAddingContacts,
|
||||
required bool initialShouldRequireTOTP2FAForCreatingNewWallets,
|
||||
required bool initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
|
||||
@@ -118,6 +119,8 @@ abstract class SettingsStoreBase with Store {
|
||||
initialShouldRequireTOTP2FAForSendsToInternalWallets,
|
||||
shouldRequireTOTP2FAForExchangesToInternalWallets =
|
||||
initialShouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
shouldRequireTOTP2FAForExchangesToExternalWallets =
|
||||
initialShouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
shouldRequireTOTP2FAForAddingContacts = initialShouldRequireTOTP2FAForAddingContacts,
|
||||
shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
initialShouldRequireTOTP2FAForCreatingNewWallets,
|
||||
@@ -271,6 +274,12 @@ abstract class SettingsStoreBase with Store {
|
||||
PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
requireTOTP2FAForExchangesToInternalWallets));
|
||||
|
||||
reaction(
|
||||
(_) => shouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
(bool requireTOTP2FAForExchangesToExternalWallets) => sharedPreferences.setBool(
|
||||
PreferencesKey.shouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
requireTOTP2FAForExchangesToExternalWallets));
|
||||
|
||||
reaction(
|
||||
(_) => shouldRequireTOTP2FAForAddingContacts,
|
||||
(bool requireTOTP2FAForAddingContacts) => sharedPreferences.setBool(
|
||||
@@ -425,6 +434,9 @@ abstract class SettingsStoreBase with Store {
|
||||
@observable
|
||||
bool shouldRequireTOTP2FAForExchangesToInternalWallets;
|
||||
|
||||
@observable
|
||||
bool shouldRequireTOTP2FAForExchangesToExternalWallets;
|
||||
|
||||
@observable
|
||||
Cake2FAPresetsOptions selectedCake2FAPreset;
|
||||
|
||||
@@ -597,6 +609,9 @@ abstract class SettingsStoreBase with Store {
|
||||
final shouldRequireTOTP2FAForExchangesToInternalWallets = sharedPreferences
|
||||
.getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
|
||||
false;
|
||||
final shouldRequireTOTP2FAForExchangesToExternalWallets = sharedPreferences
|
||||
.getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToExternalWallets) ??
|
||||
false;
|
||||
final shouldRequireTOTP2FAForAddingContacts =
|
||||
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForAddingContacts) ?? false;
|
||||
final shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
@@ -751,6 +766,8 @@ abstract class SettingsStoreBase with Store {
|
||||
shouldRequireTOTP2FAForSendsToInternalWallets,
|
||||
initialShouldRequireTOTP2FAForExchangesToInternalWallets:
|
||||
shouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
initialShouldRequireTOTP2FAForExchangesToExternalWallets:
|
||||
shouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts,
|
||||
initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets,
|
||||
initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings:
|
||||
@@ -835,6 +852,9 @@ abstract class SettingsStoreBase with Store {
|
||||
shouldRequireTOTP2FAForExchangesToInternalWallets = sharedPreferences
|
||||
.getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
|
||||
false;
|
||||
shouldRequireTOTP2FAForExchangesToExternalWallets = sharedPreferences
|
||||
.getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToExternalWallets) ??
|
||||
false;
|
||||
shouldRequireTOTP2FAForAddingContacts =
|
||||
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForAddingContacts) ?? false;
|
||||
shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
|
||||
@@ -237,15 +237,21 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
bool get shouldDisplayTOTP2FAForExchangesToInternalWallet =>
|
||||
_settingsStore.shouldRequireTOTP2FAForExchangesToInternalWallets;
|
||||
|
||||
@computed
|
||||
bool get shouldDisplayTOTP2FAForExchangesToExternalWallet =>
|
||||
_settingsStore.shouldRequireTOTP2FAForExchangesToExternalWallets;
|
||||
|
||||
//* Still open to further optimize these checks
|
||||
//* It works but can be made better
|
||||
@action
|
||||
bool shouldDisplayTOTP() {
|
||||
final isInternalWallet = checkIfWalletIsAnInternalWallet(receiveAddress);
|
||||
|
||||
if (isInternalWallet) {
|
||||
return shouldDisplayTOTP2FAForExchangesToInternalWallet;
|
||||
} else {
|
||||
return shouldDisplayTOTP2FAForExchangesToExternalWallet;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@computed
|
||||
@@ -263,7 +269,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
(wallet.type == WalletType.bitcoin ||
|
||||
wallet.type == WalletType.litecoin ||
|
||||
wallet.type == WalletType.bitcoinCash) &&
|
||||
depositCurrency == wallet.currency;
|
||||
depositCurrency == wallet.currency;
|
||||
|
||||
bool get isMoneroWallet => wallet.type == WalletType.monero;
|
||||
|
||||
@@ -275,14 +281,11 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
case WalletType.bitcoin:
|
||||
return transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow();
|
||||
case WalletType.litecoin:
|
||||
return transactionPriority ==
|
||||
bitcoin!.getLitecoinTransactionPrioritySlow();
|
||||
return transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow();
|
||||
case WalletType.ethereum:
|
||||
return transactionPriority ==
|
||||
ethereum!.getEthereumTransactionPrioritySlow();
|
||||
return transactionPriority == ethereum!.getEthereumTransactionPrioritySlow();
|
||||
case WalletType.bitcoinCash:
|
||||
return transactionPriority ==
|
||||
bitcoinCash!.getBitcoinCashTransactionPrioritySlow();
|
||||
return transactionPriority == bitcoinCash!.getBitcoinCashTransactionPrioritySlow();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -535,7 +538,9 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
@action
|
||||
void calculateDepositAllAmount() {
|
||||
if (wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin || wallet.type == WalletType.bitcoinCash) {
|
||||
if (wallet.type == WalletType.bitcoin ||
|
||||
wallet.type == WalletType.litecoin ||
|
||||
wallet.type == WalletType.bitcoinCash) {
|
||||
final availableBalance = wallet.balance[wallet.currency]!.available;
|
||||
final priority = _settingsStore.priority[wallet.type]!;
|
||||
final fee = wallet.calculateEstimatedFee(priority, null);
|
||||
|
||||
@@ -74,6 +74,10 @@ abstract class Setup2FAViewModelBase with Store {
|
||||
bool get shouldRequireTOTP2FAForExchangesToInternalWallets =>
|
||||
_settingsStore.shouldRequireTOTP2FAForExchangesToInternalWallets;
|
||||
|
||||
@computed
|
||||
bool get shouldRequireTOTP2FAForExchangesToExternalWallets =>
|
||||
_settingsStore.shouldRequireTOTP2FAForExchangesToExternalWallets;
|
||||
|
||||
@computed
|
||||
bool get shouldRequireTOTP2FAForAddingContacts =>
|
||||
_settingsStore.shouldRequireTOTP2FAForAddingContacts;
|
||||
@@ -277,6 +281,7 @@ abstract class Setup2FAViewModelBase with Store {
|
||||
switchShouldRequireTOTP2FAForAddingContacts(false);
|
||||
switchShouldRequireTOTP2FAForCreatingNewWallet(false);
|
||||
switchShouldRequireTOTP2FAForExchangesToInternalWallets(false);
|
||||
switchShouldRequireTOTP2FAForExchangesToExternalWallets(false);
|
||||
switchShouldRequireTOTP2FAForSendsToInternalWallets(false);
|
||||
switchShouldRequireTOTP2FAForAllSecurityAndBackupSettings(false);
|
||||
selected2FASettings.clear();
|
||||
@@ -306,6 +311,7 @@ abstract class Setup2FAViewModelBase with Store {
|
||||
|
||||
@action
|
||||
void selectCakePreset(Cake2FAPresetsOptions preset) {
|
||||
setAllControlsToFalse();
|
||||
presetsMap[preset]?.forEach(toggleControl);
|
||||
_settingsStore.selectedCake2FAPreset = preset;
|
||||
}
|
||||
@@ -324,6 +330,8 @@ abstract class Setup2FAViewModelBase with Store {
|
||||
switchShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
|
||||
VerboseControlSettings.exchangesToInternalWallets:
|
||||
switchShouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
VerboseControlSettings.exchangesToExternalWallets:
|
||||
switchShouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
};
|
||||
|
||||
methodsMap[control]?.call(value);
|
||||
@@ -359,6 +367,12 @@ abstract class Setup2FAViewModelBase with Store {
|
||||
updateSelectedSettings(VerboseControlSettings.exchangesToInternalWallets, value);
|
||||
}
|
||||
|
||||
@action
|
||||
void switchShouldRequireTOTP2FAForExchangesToExternalWallets(bool value) {
|
||||
_settingsStore.shouldRequireTOTP2FAForExchangesToExternalWallets = value;
|
||||
updateSelectedSettings(VerboseControlSettings.exchangesToExternalWallets, value);
|
||||
}
|
||||
|
||||
@action
|
||||
void switchShouldRequireTOTP2FAForAddingContacts(bool value) {
|
||||
_settingsStore.shouldRequireTOTP2FAForAddingContacts = value;
|
||||
|
||||
Reference in New Issue
Block a user