mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
Merge branch 'main' into CW-122-Rework-filter-on-the-transactions-list-screen
This commit is contained in:
@@ -14,10 +14,12 @@ part 'auth_view_model.g.dart';
|
||||
class AuthViewModel = AuthViewModelBase with _$AuthViewModel;
|
||||
|
||||
abstract class AuthViewModelBase with Store {
|
||||
AuthViewModelBase(this._authService, this._sharedPreferences,
|
||||
this._settingsStore, this._biometricAuth)
|
||||
AuthViewModelBase(
|
||||
this._authService, this._sharedPreferences, this._settingsStore, this._biometricAuth)
|
||||
: _failureCounter = 0,
|
||||
state = InitialExecutionState();
|
||||
state = InitialExecutionState() {
|
||||
reaction((_) => state, _saveLastAuthTime);
|
||||
}
|
||||
|
||||
static const maxFailedLogins = 3;
|
||||
static const banTimeout = 180; // 3 minutes
|
||||
@@ -28,8 +30,7 @@ abstract class AuthViewModelBase with Store {
|
||||
|
||||
int get pinLength => _settingsStore.pinCodeLength;
|
||||
|
||||
bool get isBiometricalAuthenticationAllowed =>
|
||||
_settingsStore.allowBiometricalAuthentication;
|
||||
bool get isBiometricalAuthenticationAllowed => _settingsStore.allowBiometricalAuthentication;
|
||||
|
||||
@observable
|
||||
int _failureCounter;
|
||||
@@ -114,8 +115,14 @@ abstract class AuthViewModelBase with Store {
|
||||
state = ExecutedSuccessfullyState();
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void _saveLastAuthTime(ExecutionState state) {
|
||||
if (state is ExecutedSuccessfullyState) {
|
||||
_authService.saveLastAuthTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,51 @@
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
part 'ionia_custom_redeem_view_model.g.dart';
|
||||
|
||||
class IoniaCustomRedeemViewModel = IoniaCustomRedeemViewModelBase with _$IoniaCustomRedeemViewModel;
|
||||
|
||||
abstract class IoniaCustomRedeemViewModelBase with Store {
|
||||
IoniaCustomRedeemViewModelBase(this.giftCard)
|
||||
: amount = 0;
|
||||
IoniaCustomRedeemViewModelBase({
|
||||
required this.giftCard,
|
||||
required this.ioniaService,
|
||||
}) : amount = 0,
|
||||
redeemState = InitialExecutionState();
|
||||
|
||||
final IoniaGiftCard giftCard;
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
@observable
|
||||
ExecutionState redeemState;
|
||||
|
||||
@observable
|
||||
double amount;
|
||||
|
||||
@computed
|
||||
double get remaining => amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
|
||||
double get remaining =>
|
||||
amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
|
||||
|
||||
@computed
|
||||
String get formattedRemaining => remaining.toStringAsFixed(2);
|
||||
String get formattedRemaining => remaining.toStringAsFixed(2);
|
||||
|
||||
@computed
|
||||
bool get disableRedeem => amount > giftCard.remainingAmount;
|
||||
|
||||
@action
|
||||
void updateAmount(String text){
|
||||
amount = text.isEmpty ? 0 : (double.parse(text.replaceAll(',', '.')) ?? 0);
|
||||
void updateAmount(String text) {
|
||||
amount = double.tryParse(text.replaceAll(',', '.')) ?? 0;
|
||||
}
|
||||
|
||||
}
|
||||
@action
|
||||
Future<void> addCustomRedeem() async {
|
||||
try {
|
||||
redeemState = IsExecutingState();
|
||||
await ioniaService.redeem(giftCardId: giftCard.id, amount: amount);
|
||||
redeemState = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
redeemState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,19 @@ import 'package:device_display_brightness/device_display_brightness.dart';
|
||||
|
||||
part 'ionia_gift_card_details_view_model.g.dart';
|
||||
|
||||
class IoniaGiftCardDetailsViewModel = IoniaGiftCardDetailsViewModelBase with _$IoniaGiftCardDetailsViewModel;
|
||||
class IoniaGiftCardDetailsViewModel = IoniaGiftCardDetailsViewModelBase
|
||||
with _$IoniaGiftCardDetailsViewModel;
|
||||
|
||||
abstract class IoniaGiftCardDetailsViewModelBase with Store {
|
||||
|
||||
IoniaGiftCardDetailsViewModelBase({
|
||||
required this.ioniaService,
|
||||
required this.giftCard})
|
||||
: redeemState = InitialExecutionState(),
|
||||
remainingAmount = giftCard.remainingAmount,
|
||||
brightness = 0;
|
||||
IoniaGiftCardDetailsViewModelBase({required this.ioniaService, required this.giftCard})
|
||||
: redeemState = InitialExecutionState(),
|
||||
remainingAmount = giftCard.remainingAmount,
|
||||
brightness = 0;
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
|
||||
double brightness;
|
||||
|
||||
|
||||
@observable
|
||||
IoniaGiftCard giftCard;
|
||||
|
||||
@@ -35,21 +33,22 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
|
||||
giftCard.remainingAmount = remainingAmount;
|
||||
try {
|
||||
redeemState = IsExecutingState();
|
||||
await ioniaService.redeem(giftCard);
|
||||
await ioniaService.redeem(giftCardId: giftCard.id, amount: giftCard.remainingAmount);
|
||||
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
|
||||
redeemState = ExecutedSuccessfullyState();
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
redeemState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void updateRemaining(double amount){
|
||||
remainingAmount = amount;
|
||||
Future<void> refeshCard() async {
|
||||
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
|
||||
remainingAmount = giftCard.remainingAmount;
|
||||
}
|
||||
|
||||
void increaseBrightness() async {
|
||||
brightness = await DeviceDisplayBrightness.getBrightness();
|
||||
await DeviceDisplayBrightness.setBrightness(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
||||
}
|
||||
|
||||
|
||||
@observable
|
||||
ExecutionState state;
|
||||
|
||||
@@ -180,6 +180,8 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
WalletType get walletType => _wallet.type;
|
||||
|
||||
String? get walletCurrencyName => _wallet.currency.name?.toLowerCase();
|
||||
|
||||
bool get hasCurrecyChanger => walletType == WalletType.haven;
|
||||
|
||||
@computed
|
||||
@@ -306,7 +308,7 @@ abstract class SendViewModelBase with Store {
|
||||
@action
|
||||
void onClose() =>
|
||||
_settingsStore.fiatCurrency = fiatFromSettings;
|
||||
|
||||
|
||||
@action
|
||||
void setFiatCurrency(FiatCurrency fiat) =>
|
||||
_settingsStore.fiatCurrency = fiat;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/entities/biometric_auth.dart';
|
||||
import 'package:cake_wallet/entities/pin_code_required_duration.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
@@ -7,19 +9,33 @@ part 'security_settings_view_model.g.dart';
|
||||
class SecuritySettingsViewModel = SecuritySettingsViewModelBase with _$SecuritySettingsViewModel;
|
||||
|
||||
abstract class SecuritySettingsViewModelBase with Store {
|
||||
SecuritySettingsViewModelBase(this._settingsStore) : _biometricAuth = BiometricAuth();
|
||||
SecuritySettingsViewModelBase(
|
||||
this._settingsStore,
|
||||
this._authService,
|
||||
) : _biometricAuth = BiometricAuth();
|
||||
|
||||
final BiometricAuth _biometricAuth;
|
||||
final SettingsStore _settingsStore;
|
||||
final AuthService _authService;
|
||||
|
||||
@computed
|
||||
bool get allowBiometricalAuthentication => _settingsStore.allowBiometricalAuthentication;
|
||||
|
||||
@computed
|
||||
PinCodeRequiredDuration get pinCodeRequiredDuration => _settingsStore.pinTimeOutDuration;
|
||||
|
||||
@action
|
||||
Future<bool> biometricAuthenticated() async {
|
||||
return await _biometricAuth.canCheckBiometrics() && await _biometricAuth.isAuthenticated();
|
||||
}
|
||||
|
||||
@action
|
||||
void setAllowBiometricalAuthentication(bool value) => _settingsStore.allowBiometricalAuthentication = value;
|
||||
void setAllowBiometricalAuthentication(bool value) =>
|
||||
_settingsStore.allowBiometricalAuthentication = value;
|
||||
|
||||
@action
|
||||
setPinCodeRequiredDuration(PinCodeRequiredDuration duration) =>
|
||||
_settingsStore.pinTimeOutDuration = duration;
|
||||
|
||||
bool checkPinCodeRiquired() => _authService.requireAuth();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_new_vm.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
@@ -15,9 +15,12 @@ part 'wallet_list_view_model.g.dart';
|
||||
class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
|
||||
|
||||
abstract class WalletListViewModelBase with Store {
|
||||
WalletListViewModelBase(this._walletInfoSource, this._appStore,
|
||||
this._walletLoadingService)
|
||||
: wallets = ObservableList<WalletListItem>() {
|
||||
WalletListViewModelBase(
|
||||
this._walletInfoSource,
|
||||
this._appStore,
|
||||
this._walletLoadingService,
|
||||
this._authService,
|
||||
) : wallets = ObservableList<WalletListItem>() {
|
||||
_updateList();
|
||||
}
|
||||
|
||||
@@ -27,6 +30,7 @@ abstract class WalletListViewModelBase with Store {
|
||||
final AppStore _appStore;
|
||||
final Box<WalletInfo> _walletInfoSource;
|
||||
final WalletLoadingService _walletLoadingService;
|
||||
final AuthService _authService;
|
||||
|
||||
WalletType get currentWalletType => _appStore.wallet!.type;
|
||||
|
||||
@@ -47,12 +51,20 @@ abstract class WalletListViewModelBase with Store {
|
||||
|
||||
void _updateList() {
|
||||
wallets.clear();
|
||||
wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
key: info.key,
|
||||
isCurrent: info.name == _appStore.wallet!.name &&
|
||||
info.type == _appStore.wallet!.type,
|
||||
isEnabled: availableWalletTypes.contains(info.type))));
|
||||
wallets.addAll(
|
||||
_walletInfoSource.values.map(
|
||||
(info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
key: info.key,
|
||||
isCurrent: info.name == _appStore.wallet!.name && info.type == _appStore.wallet!.type,
|
||||
isEnabled: availableWalletTypes.contains(info.type),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool checkIfAuthRequired() {
|
||||
return _authService.requireAuth();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user