mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
CW-370-add-options-to-enable-disable-buy-and-sell-actions (#920)
* feat: In the privacy settings screen, add 2 options to Enable/Disable Buy and Sell actions * fix: add strings * fix: add the rest of the strings * fix: disable instead of hide buy & sell buttons * fix: use disableSell * fix: main actions able to be onTapped even when disabled
This commit is contained in:
@@ -210,6 +210,8 @@ class BackupService {
|
||||
final currentFiatCurrency = data[PreferencesKey.currentFiatCurrencyKey] as String?;
|
||||
final shouldSaveRecipientAddress = data[PreferencesKey.shouldSaveRecipientAddressKey] as bool?;
|
||||
final isAppSecure = data[PreferencesKey.isAppSecureKey] as bool?;
|
||||
final disableBuy = data[PreferencesKey.disableBuyKey] as bool?;
|
||||
final disableSell = data[PreferencesKey.disableSellKey] as bool?;
|
||||
final currentTransactionPriorityKeyLegacy = data[PreferencesKey.currentTransactionPriorityKeyLegacy] as int?;
|
||||
final allowBiometricalAuthentication = data[PreferencesKey.allowBiometricalAuthenticationKey] as bool?;
|
||||
final currentBitcoinElectrumSererId = data[PreferencesKey.currentBitcoinElectrumSererIdKey] as int?;
|
||||
@@ -251,6 +253,16 @@ class BackupService {
|
||||
PreferencesKey.isAppSecureKey,
|
||||
isAppSecure);
|
||||
|
||||
if (disableBuy != null)
|
||||
await _sharedPreferences.setBool(
|
||||
PreferencesKey.disableBuyKey,
|
||||
disableBuy);
|
||||
|
||||
if (disableSell != null)
|
||||
await _sharedPreferences.setBool(
|
||||
PreferencesKey.disableSellKey,
|
||||
disableSell);
|
||||
|
||||
if (currentTransactionPriorityKeyLegacy != null)
|
||||
await _sharedPreferences.setInt(
|
||||
PreferencesKey.currentTransactionPriorityKeyLegacy,
|
||||
@@ -421,6 +433,10 @@ class BackupService {
|
||||
_sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey),
|
||||
PreferencesKey.shouldSaveRecipientAddressKey: _sharedPreferences
|
||||
.getBool(PreferencesKey.shouldSaveRecipientAddressKey),
|
||||
PreferencesKey.disableBuyKey: _sharedPreferences
|
||||
.getBool(PreferencesKey.disableBuyKey),
|
||||
PreferencesKey.disableSellKey: _sharedPreferences
|
||||
.getBool(PreferencesKey.disableSellKey),
|
||||
PreferencesKey.isDarkThemeLegacy:
|
||||
_sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy),
|
||||
PreferencesKey.currentPinLength:
|
||||
|
||||
@@ -47,23 +47,23 @@ class MainActions {
|
||||
switch (walletType) {
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context).pushNamed(Routes.onramperPage);
|
||||
} else {
|
||||
final uri = getIt
|
||||
.get<OnRamperBuyProvider>()
|
||||
.requestUrl();
|
||||
await launchUrl(uri);
|
||||
if (viewModel.isEnabledBuyAction) {
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context).pushNamed(Routes.onramperPage);
|
||||
} else {
|
||||
final uri = getIt.get<OnRamperBuyProvider>().requestUrl();
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WalletType.monero:
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context).pushNamed(Routes.payfuraPage);
|
||||
} else {
|
||||
final uri = getIt
|
||||
.get<PayfuraBuyProvider>()
|
||||
.requestUrl();
|
||||
await launchUrl(uri);
|
||||
if (viewModel.isEnabledBuyAction) {
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context).pushNamed(Routes.payfuraPage);
|
||||
} else {
|
||||
final uri = getIt.get<PayfuraBuyProvider>().requestUrl();
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -118,12 +118,14 @@ class MainActions {
|
||||
|
||||
switch (walletType) {
|
||||
case WalletType.bitcoin:
|
||||
final moonPaySellProvider = MoonPaySellProvider();
|
||||
final uri = await moonPaySellProvider.requestUrl(
|
||||
currency: viewModel.wallet.currency,
|
||||
refundWalletAddress: viewModel.wallet.walletAddresses.address,
|
||||
);
|
||||
await launchUrl(uri);
|
||||
if (viewModel.isEnabledSellAction) {
|
||||
final moonPaySellProvider = MoonPaySellProvider();
|
||||
final uri = await moonPaySellProvider.requestUrl(
|
||||
currency: viewModel.wallet.currency,
|
||||
refundWalletAddress: viewModel.wallet.walletAddresses.address,
|
||||
);
|
||||
await launchUrl(uri);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
await showPopUp<void>(
|
||||
|
||||
@@ -10,6 +10,8 @@ class PreferencesKey {
|
||||
static const currentBalanceDisplayModeKey = 'current_balance_display_mode';
|
||||
static const shouldSaveRecipientAddressKey = 'save_recipient_address';
|
||||
static const isAppSecureKey = 'is_app_secure';
|
||||
static const disableBuyKey = 'disable_buy';
|
||||
static const disableSellKey = 'disable_sell';
|
||||
static const currentFiatApiModeKey = 'current_fiat_api_mode';
|
||||
static const allowBiometricalAuthenticationKey =
|
||||
'allow_biometrical_authentication';
|
||||
|
||||
@@ -50,11 +50,23 @@ class PrivacyPage extends BasePage {
|
||||
_privacySettingsViewModel.setShouldSaveRecipientAddress(value);
|
||||
}),
|
||||
if (Platform.isAndroid)
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.prevent_screenshots,
|
||||
value: _privacySettingsViewModel.isAppSecure,
|
||||
onValueChange: (BuildContext _, bool value) {
|
||||
_privacySettingsViewModel.setIsAppSecure(value);
|
||||
}),
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.prevent_screenshots,
|
||||
value: _privacySettingsViewModel.isAppSecure,
|
||||
title: S.current.disable_buy,
|
||||
value: _privacySettingsViewModel.disableBuy,
|
||||
onValueChange: (BuildContext _, bool value) {
|
||||
_privacySettingsViewModel.setIsAppSecure(value);
|
||||
_privacySettingsViewModel.setDisableBuy(value);
|
||||
}),
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.disable_sell,
|
||||
value: _privacySettingsViewModel.disableSell,
|
||||
onValueChange: (BuildContext _, bool value) {
|
||||
_privacySettingsViewModel.setDisableSell(value);
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -34,6 +34,8 @@ abstract class SettingsStoreBase with Store {
|
||||
required BalanceDisplayMode initialBalanceDisplayMode,
|
||||
required bool initialSaveRecipientAddress,
|
||||
required bool initialAppSecure,
|
||||
required bool initialDisableBuy,
|
||||
required bool initialDisableSell,
|
||||
required FiatApiMode initialFiatMode,
|
||||
required bool initialAllowBiometricalAuthentication,
|
||||
required ExchangeApiMode initialExchangeStatus,
|
||||
@@ -57,6 +59,8 @@ abstract class SettingsStoreBase with Store {
|
||||
balanceDisplayMode = initialBalanceDisplayMode,
|
||||
shouldSaveRecipientAddress = initialSaveRecipientAddress,
|
||||
isAppSecure = initialAppSecure,
|
||||
disableBuy = initialDisableBuy,
|
||||
disableSell = initialDisableSell,
|
||||
fiatApiMode = initialFiatMode,
|
||||
allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
|
||||
shouldShowMarketPlaceInDashboard = initialShouldShowMarketPlaceInDashboard,
|
||||
@@ -130,6 +134,16 @@ abstract class SettingsStoreBase with Store {
|
||||
}
|
||||
});
|
||||
|
||||
reaction(
|
||||
(_) => disableBuy,
|
||||
(bool disableBuy) => sharedPreferences.setBool(
|
||||
PreferencesKey.disableBuyKey, disableBuy));
|
||||
|
||||
reaction(
|
||||
(_) => disableSell,
|
||||
(bool disableSell) => sharedPreferences.setBool(
|
||||
PreferencesKey.disableSellKey, disableSell));
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
setIsAppSecureNative(isAppSecure);
|
||||
}
|
||||
@@ -217,6 +231,12 @@ abstract class SettingsStoreBase with Store {
|
||||
@observable
|
||||
bool isAppSecure;
|
||||
|
||||
@observable
|
||||
bool disableBuy;
|
||||
|
||||
@observable
|
||||
bool disableSell;
|
||||
|
||||
@observable
|
||||
bool allowBiometricalAuthentication;
|
||||
|
||||
@@ -309,6 +329,10 @@ abstract class SettingsStoreBase with Store {
|
||||
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false;
|
||||
final isAppSecure =
|
||||
sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? false;
|
||||
final disableBuy =
|
||||
sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? false;
|
||||
final disableSell =
|
||||
sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? false;
|
||||
final currentFiatApiMode = FiatApiMode.deserialize(
|
||||
raw: sharedPreferences
|
||||
.getInt(PreferencesKey.currentFiatApiModeKey) ?? FiatApiMode.enabled.raw);
|
||||
@@ -388,6 +412,8 @@ abstract class SettingsStoreBase with Store {
|
||||
initialBalanceDisplayMode: currentBalanceDisplayMode,
|
||||
initialSaveRecipientAddress: shouldSaveRecipientAddress,
|
||||
initialAppSecure: isAppSecure,
|
||||
initialDisableBuy: disableBuy,
|
||||
initialDisableSell: disableSell,
|
||||
initialFiatMode: currentFiatApiMode,
|
||||
initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
|
||||
initialExchangeStatus: exchangeStatus,
|
||||
@@ -435,6 +461,10 @@ abstract class SettingsStoreBase with Store {
|
||||
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? shouldSaveRecipientAddress;
|
||||
isAppSecure =
|
||||
sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? isAppSecure;
|
||||
disableBuy =
|
||||
sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? disableBuy;
|
||||
disableSell =
|
||||
sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? disableSell;
|
||||
allowBiometricalAuthentication = sharedPreferences
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
||||
allowBiometricalAuthentication;
|
||||
|
||||
@@ -46,9 +46,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
required this.anonpayTransactionsStore})
|
||||
: isOutdatedElectrumWallet = false,
|
||||
hasSellAction = false,
|
||||
isEnabledSellAction = false,
|
||||
hasBuyAction = false,
|
||||
isEnabledBuyAction = false,
|
||||
hasExchangeAction = false,
|
||||
isShowFirstYatIntroduction = false,
|
||||
isShowSecondYatIntroduction = false,
|
||||
@@ -287,14 +285,19 @@ abstract class DashboardViewModelBase with Store {
|
||||
@observable
|
||||
bool hasExchangeAction;
|
||||
|
||||
@observable
|
||||
bool isEnabledBuyAction;
|
||||
@computed
|
||||
bool get isEnabledBuyAction =>
|
||||
!settingsStore.disableBuy && wallet.type != WalletType.haven;
|
||||
|
||||
@observable
|
||||
bool hasBuyAction;
|
||||
|
||||
@observable
|
||||
bool isEnabledSellAction;
|
||||
@computed
|
||||
bool get isEnabledSellAction =>
|
||||
!settingsStore.disableSell &&
|
||||
wallet.type != WalletType.haven &&
|
||||
wallet.type != WalletType.monero &&
|
||||
wallet.type != WalletType.litecoin;
|
||||
|
||||
@observable
|
||||
bool hasSellAction;
|
||||
@@ -398,11 +401,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
|
||||
void updateActions() {
|
||||
hasExchangeAction = !isHaven;
|
||||
isEnabledBuyAction = wallet.type != WalletType.haven;
|
||||
hasBuyAction = !isHaven;
|
||||
isEnabledSellAction = wallet.type != WalletType.haven
|
||||
&& wallet.type != WalletType.monero
|
||||
&& wallet.type != WalletType.litecoin;
|
||||
hasSellAction = !isHaven;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@ abstract class PrivacySettingsViewModelBase with Store {
|
||||
@computed
|
||||
bool get isAppSecure => _settingsStore.isAppSecure;
|
||||
|
||||
@computed
|
||||
bool get disableBuy => _settingsStore.disableBuy;
|
||||
|
||||
@computed
|
||||
bool get disableSell => _settingsStore.disableSell;
|
||||
|
||||
@action
|
||||
void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value;
|
||||
|
||||
@@ -36,4 +42,10 @@ abstract class PrivacySettingsViewModelBase with Store {
|
||||
@action
|
||||
void setIsAppSecure(bool value) => _settingsStore.isAppSecure = value;
|
||||
|
||||
@action
|
||||
void setDisableBuy(bool value) => _settingsStore.disableBuy = value;
|
||||
|
||||
@action
|
||||
void setDisableSell(bool value) => _settingsStore.disableSell = value;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user