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:
Adegoke David
2023-11-02 20:17:52 +02:00
committed by GitHub
co-authored by OmarHatem
parent d997ee81a1
commit 9aede1f3c1
32 changed files with 88 additions and 9 deletions
@@ -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);
+14
View File
@@ -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;