Generic fixes (#1274)

* Display fees currency as wallet currency not the selected one

* remove unused code
catch balance network issues

* pop send screen when send completes successfully

* revert change [skip ci]

* Enable restoring haven wallets

* verify context is mounted before showing snackbar [skip ci]

* Update privacy [skip ci]

* Add user consent popup to inapp webview permission request
This commit is contained in:
Omar Hatem
2024-01-27 00:51:21 +02:00
committed by GitHub
parent aed60a7282
commit 89fdc0f4d1
36 changed files with 134 additions and 86 deletions
+1 -3
View File
@@ -612,7 +612,6 @@ Future<void> setup({
_walletInfoSource,
getIt.get<AppStore>(),
getIt.get<WalletLoadingService>(),
getIt.get<AuthService>(),
),
);
} else {
@@ -623,7 +622,6 @@ Future<void> setup({
_walletInfoSource,
getIt.get<AppStore>(),
getIt.get<WalletLoadingService>(),
getIt.get<AuthService>(),
),
);
}
@@ -725,7 +723,7 @@ Future<void> setup({
});
getIt.registerFactory(() {
return SecuritySettingsViewModel(getIt.get<SettingsStore>(), getIt.get<AuthService>());
return SecuritySettingsViewModel(getIt.get<SettingsStore>());
});
getIt.registerFactory(() => WalletSeedViewModel(getIt.get<AppStore>().wallet!));
+27 -2
View File
@@ -1,4 +1,7 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:permission_handler/permission_handler.dart';
@@ -14,13 +17,14 @@ class WebViewPage extends BasePage {
@override
Widget body(BuildContext context) {
return WebViewPageBody(_url);
return WebViewPageBody(_title, _url);
}
}
class WebViewPageBody extends StatefulWidget {
WebViewPageBody(this.uri);
WebViewPageBody(this.title, this.uri);
final String title;
final Uri uri;
@override
@@ -40,6 +44,27 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
onPermissionRequest: (controller, request) async {
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
if (!permissionGranted) {
final bool userConsent = await showPopUp<bool>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).privacy,
alertContent: S.of(context).camera_consent(widget.title),
rightButtonText: S.of(context).agree,
leftButtonText: S.of(context).cancel,
actionRightButton: () => Navigator.of(context).pop(true),
actionLeftButton: () => Navigator.of(context).pop(false));
}) ??
false;
/// if user did NOT give the consent then return permission denied
if (!userConsent) {
return PermissionResponse(
resources: request.resources,
action: PermissionResponseAction.DENY,
);
}
permissionGranted = await Permission.camera.request().isGranted;
}
@@ -166,12 +166,16 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
}
try {
changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name));
if (context.mounted) {
changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name));
}
await widget.walletListViewModel.loadWallet(wallet);
hideProgressText();
setState(() {});
} catch (e) {
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
if (context.mounted) {
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
}
}
},
conditionToDetermineIfToUse2FA:
@@ -28,15 +28,18 @@ class NewWalletTypePage extends BasePage {
@override
Widget body(BuildContext context) => WalletTypeForm(
onTypeSelected: onTypeSelected,
walletImage: currentTheme.type == ThemeType.dark ? walletTypeImage : walletTypeLightImage);
onTypeSelected: onTypeSelected,
walletImage: currentTheme.type == ThemeType.dark ? walletTypeImage : walletTypeLightImage,
isCreate: isCreate,
);
}
class WalletTypeForm extends StatefulWidget {
WalletTypeForm({required this.onTypeSelected, required this.walletImage});
WalletTypeForm({required this.onTypeSelected, required this.walletImage, required this.isCreate});
final void Function(BuildContext, WalletType) onTypeSelected;
final Image walletImage;
final bool isCreate;
@override
WalletTypeFormState createState() => WalletTypeFormState();
@@ -131,7 +134,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
throw Exception('Wallet Type is not selected yet.');
}
if (selected == WalletType.haven) {
if (selected == WalletType.haven && widget.isCreate) {
return await showPopUp<void>(
context: context,
builder: (BuildContext context) {
+1 -1
View File
@@ -478,7 +478,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
Text(
output.estimatedFee.toString() +
' ' +
sendViewModel.selectedCryptoCurrency.toString(),
sendViewModel.currency.toString(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
+27 -25
View File
@@ -2,7 +2,6 @@ import 'dart:io';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
import 'package:cake_wallet/entities/provider_types.dart';
import 'package:cake_wallet/entities/cake_2fa_preset_options.dart';
@@ -40,6 +39,7 @@ import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/entities/action_list_display_mode.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cw_core/set_app_secure_native.dart';
part 'settings_store.g.dart';
class SettingsStore = SettingsStoreBase with _$SettingsStore;
@@ -1080,34 +1080,37 @@ abstract class SettingsStoreBase with Store {
priority[WalletType.monero] = monero?.deserializeMoneroTransactionPriority(
raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
priority[WalletType.monero]!;
priority[WalletType.bitcoin] = bitcoin?.deserializeBitcoinTransactionPriority(
sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
priority[WalletType.bitcoin]!;
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
priority[WalletType.haven] = monero?.deserializeMoneroTransactionPriority(
raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!) ??
priority[WalletType.haven]!;
if (bitcoin != null &&
sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority) != null) {
priority[WalletType.bitcoin] = bitcoin!.deserializeBitcoinTransactionPriority(
sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
}
if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
priority[WalletType.litecoin] = bitcoin?.deserializeLitecoinTransactionPriority(
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!) ??
priority[WalletType.litecoin]!;
if (monero != null &&
sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
priority[WalletType.haven] = monero!.deserializeMoneroTransactionPriority(
raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!);
}
if (sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority) != null) {
priority[WalletType.ethereum] = ethereum?.deserializeEthereumTransactionPriority(
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!) ??
priority[WalletType.ethereum]!;
if (bitcoin != null &&
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
priority[WalletType.litecoin] = bitcoin!.deserializeLitecoinTransactionPriority(
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!);
}
if (sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority) != null) {
priority[WalletType.polygon] = polygon?.deserializePolygonTransactionPriority(
sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority)!) ??
priority[WalletType.polygon]!;
if (ethereum != null &&
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority) != null) {
priority[WalletType.ethereum] = ethereum!.deserializeEthereumTransactionPriority(
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
}
if (sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
priority[WalletType.bitcoinCash] = bitcoinCash?.deserializeBitcoinCashTransactionPriority(
sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!) ??
priority[WalletType.bitcoinCash]!;
if (polygon != null &&
sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority) != null) {
priority[WalletType.polygon] = polygon!.deserializePolygonTransactionPriority(
sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority)!);
}
if (bitcoinCash != null &&
sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
priority[WalletType.bitcoinCash] = bitcoinCash!.deserializeBitcoinCashTransactionPriority(
sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!);
}
final generateSubaddresses =
@@ -1187,7 +1190,6 @@ abstract class SettingsStoreBase with Store {
final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
final polygonNodeId = sharedPreferences.getInt(PreferencesKey.currentPolygonNodeIdKey);
final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
final nanoPowNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
final moneroNode = nodeSource.get(nodeId);
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
@@ -1,4 +1,3 @@
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';
@@ -9,14 +8,10 @@ part 'security_settings_view_model.g.dart';
class SecuritySettingsViewModel = SecuritySettingsViewModelBase with _$SecuritySettingsViewModel;
abstract class SecuritySettingsViewModelBase with Store {
SecuritySettingsViewModelBase(
this._settingsStore,
this._authService,
) : _biometricAuth = BiometricAuth();
SecuritySettingsViewModelBase(this._settingsStore) : _biometricAuth = BiometricAuth();
final BiometricAuth _biometricAuth;
final SettingsStore _settingsStore;
final AuthService _authService;
@computed
bool get allowBiometricalAuthentication => _settingsStore.allowBiometricalAuthentication;
@@ -41,8 +36,6 @@ abstract class SecuritySettingsViewModelBase with Store {
_settingsStore.allowBiometricalAuthentication = value;
@action
setPinCodeRequiredDuration(PinCodeRequiredDuration duration) =>
void setPinCodeRequiredDuration(PinCodeRequiredDuration duration) =>
_settingsStore.pinTimeOutDuration = duration;
Future<bool> checkPinCodeRiquired() => _authService.requireAuth();
}
@@ -1,4 +1,3 @@
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/core/wallet_loading_service.dart';
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
import 'package:hive/hive.dart';
@@ -18,7 +17,6 @@ abstract class WalletListViewModelBase with Store {
this._walletInfoSource,
this._appStore,
this._walletLoadingService,
this._authService,
) : wallets = ObservableList<WalletListItem>() {
setOrderType(_appStore.settingsStore.walletListOrder);
reaction((_) => _appStore.wallet, (_) => updateList());
@@ -39,7 +37,6 @@ abstract class WalletListViewModelBase with Store {
final AppStore _appStore;
final Box<WalletInfo> _walletInfoSource;
final WalletLoadingService _walletLoadingService;
final AuthService _authService;
WalletType get currentWalletType => _appStore.wallet!.type;
@@ -160,8 +157,4 @@ abstract class WalletListViewModelBase with Store {
break;
}
}
Future<bool> checkIfAuthRequired() async {
return _authService.requireAuth();
}
}