mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
Linux: fixes for wallet rename (#1000)
* fix: missing MarketPlaceViewModel register * fix: no auth route on wallet list _loadWallet * fix: fixes for wallet rename with password flow * fix: missing monero condition * fix: navigator pop * fix: going back case
This commit is contained in:
parent
62007975e1
commit
8a7ef39f19
11 changed files with 200 additions and 64 deletions
|
@ -276,26 +276,59 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> renameWalletFiles(String newWalletName) async {
|
Future<void> renameWalletFiles(String newWalletName) async {
|
||||||
final currentWalletPath = await pathForWallet(name: name, type: type);
|
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
||||||
final currentCacheFile = File(currentWalletPath);
|
|
||||||
final currentKeysFile = File('$currentWalletPath.keys');
|
|
||||||
final currentAddressListFile = File('$currentWalletPath.address.txt');
|
|
||||||
|
|
||||||
final newWalletPath = await pathForWallet(name: newWalletName, type: type);
|
try {
|
||||||
|
// -- rename the waller folder --
|
||||||
|
final currentWalletDir =
|
||||||
|
Directory(await pathForWalletDir(name: name, type: type));
|
||||||
|
final newWalletDirPath =
|
||||||
|
await pathForWalletDir(name: newWalletName, type: type);
|
||||||
|
await currentWalletDir.rename(newWalletDirPath);
|
||||||
|
|
||||||
// Copies current wallet files into new wallet name's dir and files
|
// -- use new waller folder to rename files with old names still --
|
||||||
if (currentCacheFile.existsSync()) {
|
final renamedWalletPath = newWalletDirPath + '/$name';
|
||||||
await currentCacheFile.copy(newWalletPath);
|
|
||||||
}
|
|
||||||
if (currentKeysFile.existsSync()) {
|
|
||||||
await currentKeysFile.copy('$newWalletPath.keys');
|
|
||||||
}
|
|
||||||
if (currentAddressListFile.existsSync()) {
|
|
||||||
await currentAddressListFile.copy('$newWalletPath.address.txt');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete old name's dir and files
|
final currentCacheFile = File(renamedWalletPath);
|
||||||
await Directory(currentWalletPath).delete(recursive: true);
|
final currentKeysFile = File('$renamedWalletPath.keys');
|
||||||
|
final currentAddressListFile = File('$renamedWalletPath.address.txt');
|
||||||
|
|
||||||
|
final newWalletPath =
|
||||||
|
await pathForWallet(name: newWalletName, type: type);
|
||||||
|
|
||||||
|
if (currentCacheFile.existsSync()) {
|
||||||
|
await currentCacheFile.rename(newWalletPath);
|
||||||
|
}
|
||||||
|
if (currentKeysFile.existsSync()) {
|
||||||
|
await currentKeysFile.rename('$newWalletPath.keys');
|
||||||
|
}
|
||||||
|
if (currentAddressListFile.existsSync()) {
|
||||||
|
await currentAddressListFile.rename('$newWalletPath.address.txt');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
final currentWalletPath = await pathForWallet(name: name, type: type);
|
||||||
|
|
||||||
|
final currentCacheFile = File(currentWalletPath);
|
||||||
|
final currentKeysFile = File('$currentWalletPath.keys');
|
||||||
|
final currentAddressListFile = File('$currentWalletPath.address.txt');
|
||||||
|
|
||||||
|
final newWalletPath =
|
||||||
|
await pathForWallet(name: newWalletName, type: type);
|
||||||
|
|
||||||
|
// Copies current wallet files into new wallet name's dir and files
|
||||||
|
if (currentCacheFile.existsSync()) {
|
||||||
|
await currentCacheFile.copy(newWalletPath);
|
||||||
|
}
|
||||||
|
if (currentKeysFile.existsSync()) {
|
||||||
|
await currentKeysFile.copy('$newWalletPath.keys');
|
||||||
|
}
|
||||||
|
if (currentAddressListFile.existsSync()) {
|
||||||
|
await currentAddressListFile.copy('$newWalletPath.address.txt');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete old name's dir and files
|
||||||
|
await Directory(currentWalletDirPath).delete(recursive: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -25,6 +25,14 @@ class WalletLoadingService {
|
||||||
await keyService.deleteWalletPassword(walletName: name);
|
await keyService.deleteWalletPassword(walletName: name);
|
||||||
|
|
||||||
await walletService.rename(name, walletPassword, newName);
|
await walletService.rename(name, walletPassword, newName);
|
||||||
|
|
||||||
|
// set shared preferences flag based on previous wallet name
|
||||||
|
if (type == WalletType.monero) {
|
||||||
|
final oldNameKey = PreferencesKey.moneroWalletUpdateV1Key(name);
|
||||||
|
final isPasswordUpdated = sharedPreferences.getBool(oldNameKey) ?? false;
|
||||||
|
final newNameKey = PreferencesKey.moneroWalletUpdateV1Key(newName);
|
||||||
|
await sharedPreferences.setBool(newNameKey, isPasswordUpdated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<WalletBase> load(WalletType type, String name, {String? password}) async {
|
Future<WalletBase> load(WalletType type, String name, {String? password}) async {
|
||||||
|
|
|
@ -42,6 +42,7 @@ import 'package:cake_wallet/utils/device_info.dart';
|
||||||
import 'package:cake_wallet/store/anonpay/anonpay_transactions_store.dart';
|
import 'package:cake_wallet/store/anonpay/anonpay_transactions_store.dart';
|
||||||
import 'package:cake_wallet/view_model/anon_invoice_page_view_model.dart';
|
import 'package:cake_wallet/view_model/anon_invoice_page_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/anonpay_details_view_model.dart';
|
import 'package:cake_wallet/view_model/anonpay_details_view_model.dart';
|
||||||
|
import 'package:cake_wallet/view_model/dashboard/market_place_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
|
import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/ionia/ionia_auth_view_model.dart';
|
import 'package:cake_wallet/view_model/ionia/ionia_auth_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/ionia/ionia_buy_card_view_model.dart';
|
import 'package:cake_wallet/view_model/ionia/ionia_buy_card_view_model.dart';
|
||||||
|
@ -898,6 +899,8 @@ Future setup({
|
||||||
getIt.registerFactory<IoniaAnyPay>(() => IoniaAnyPay(
|
getIt.registerFactory<IoniaAnyPay>(() => IoniaAnyPay(
|
||||||
getIt.get<IoniaService>(), getIt.get<AnyPayApi>(), getIt.get<AppStore>().wallet!));
|
getIt.get<IoniaService>(), getIt.get<AnyPayApi>(), getIt.get<AppStore>().wallet!));
|
||||||
|
|
||||||
|
getIt.registerFactory(()=> MarketPlaceViewModel(getIt.get<IoniaService>()));
|
||||||
|
|
||||||
getIt.registerFactory(() => IoniaGiftCardsListViewModel(ioniaService: getIt.get<IoniaService>()));
|
getIt.registerFactory(() => IoniaGiftCardsListViewModel(ioniaService: getIt.get<IoniaService>()));
|
||||||
|
|
||||||
getIt.registerFactory(() => IoniaAuthViewModel(ioniaService: getIt.get<IoniaService>()));
|
getIt.registerFactory(() => IoniaAuthViewModel(ioniaService: getIt.get<IoniaService>()));
|
||||||
|
@ -1067,6 +1070,7 @@ Future setup({
|
||||||
return WalletUnlockPage(
|
return WalletUnlockPage(
|
||||||
getIt.get<WalletUnlockLoadableViewModel>(param1: args),
|
getIt.get<WalletUnlockLoadableViewModel>(param1: args),
|
||||||
args.callback,
|
args.callback,
|
||||||
|
args.authPasswordHandler,
|
||||||
closable: closable);
|
closable: closable);
|
||||||
}, instanceName: 'wallet_unlock_loadable');
|
}, instanceName: 'wallet_unlock_loadable');
|
||||||
|
|
||||||
|
@ -1074,6 +1078,7 @@ Future setup({
|
||||||
return WalletUnlockPage(
|
return WalletUnlockPage(
|
||||||
getIt.get<WalletUnlockVerifiableViewModel>(param1: args),
|
getIt.get<WalletUnlockVerifiableViewModel>(param1: args),
|
||||||
args.callback,
|
args.callback,
|
||||||
|
args.authPasswordHandler,
|
||||||
closable: closable);
|
closable: closable);
|
||||||
}, instanceName: 'wallet_unlock_verifiable');
|
}, instanceName: 'wallet_unlock_verifiable');
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,12 @@ import 'package:another_flushbar/flushbar.dart';
|
||||||
import 'package:cake_wallet/core/auth_service.dart';
|
import 'package:cake_wallet/core/auth_service.dart';
|
||||||
import 'package:cake_wallet/core/wallet_name_validator.dart';
|
import 'package:cake_wallet/core/wallet_name_validator.dart';
|
||||||
import 'package:cake_wallet/palette.dart';
|
import 'package:cake_wallet/palette.dart';
|
||||||
|
import 'package:cake_wallet/routes.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/wallet_unlock/wallet_unlock_arguments.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/show_bar.dart';
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cake_wallet/view_model/wallet_list/wallet_edit_view_model.dart';
|
import 'package:cake_wallet/view_model/wallet_list/wallet_edit_view_model.dart';
|
||||||
|
@ -94,9 +98,36 @@ class WalletEditPage extends BasePage {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await walletEditViewModel.changeName(editingWallet);
|
bool confirmed = false;
|
||||||
Navigator.of(context).pop();
|
|
||||||
walletEditViewModel.resetState();
|
if (SettingsStoreBase
|
||||||
|
.walletPasswordDirectInput) {
|
||||||
|
await Navigator.of(context).pushNamed(
|
||||||
|
Routes.walletUnlockLoadable,
|
||||||
|
arguments: WalletUnlockArguments(
|
||||||
|
authPasswordHandler:
|
||||||
|
(String password) async {
|
||||||
|
await walletEditViewModel
|
||||||
|
.changeName(editingWallet,
|
||||||
|
password: password);
|
||||||
|
},
|
||||||
|
callback: (bool
|
||||||
|
isAuthenticatedSuccessfully,
|
||||||
|
AuthPageState auth) async {
|
||||||
|
if (isAuthenticatedSuccessfully) {
|
||||||
|
auth.close();
|
||||||
|
confirmed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
walletName: editingWallet.name,
|
||||||
|
walletType: editingWallet.type));
|
||||||
|
} else {
|
||||||
|
await walletEditViewModel
|
||||||
|
.changeName(editingWallet);
|
||||||
|
confirmed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confirmed) Navigator.of(context).pop();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import 'package:cake_wallet/main.dart';
|
import 'package:cake_wallet/main.dart';
|
||||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||||
import 'package:cake_wallet/core/auth_service.dart';
|
import 'package:cake_wallet/core/auth_service.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/wallet_unlock/wallet_unlock_arguments.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_bar.dart';
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
|
@ -210,6 +212,20 @@ class WalletListBodyState extends State<WalletListBody> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadWallet(WalletListItem wallet) async {
|
Future<void> _loadWallet(WalletListItem wallet) async {
|
||||||
|
if (SettingsStoreBase.walletPasswordDirectInput) {
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
Routes.walletUnlockLoadable,
|
||||||
|
arguments: WalletUnlockArguments(
|
||||||
|
callback: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
|
||||||
|
if (isAuthenticatedSuccessfully) {
|
||||||
|
auth.close();
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}, walletName: wallet.name,
|
||||||
|
walletType: wallet.type));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await widget.authService.authenticateAction(context,
|
await widget.authService.authenticateAction(context,
|
||||||
onAuthSuccess: (isAuthenticatedSuccessfully) async {
|
onAuthSuccess: (isAuthenticatedSuccessfully) async {
|
||||||
if (!isAuthenticatedSuccessfully) {
|
if (!isAuthenticatedSuccessfully) {
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
|
typedef AuthPasswordHandler = Future<void> Function(String);
|
||||||
|
|
||||||
class WalletUnlockArguments {
|
class WalletUnlockArguments {
|
||||||
WalletUnlockArguments({
|
WalletUnlockArguments(
|
||||||
required this.callback,
|
{required this.callback,
|
||||||
this.walletName,
|
this.walletName,
|
||||||
this.walletType});
|
this.walletType,
|
||||||
|
this.authPasswordHandler});
|
||||||
|
|
||||||
final OnAuthenticationFinished callback;
|
final OnAuthenticationFinished callback;
|
||||||
|
final AuthPasswordHandler? authPasswordHandler;
|
||||||
final String? walletName;
|
final String? walletName;
|
||||||
final WalletType? walletType;
|
final WalletType? walletType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@ import 'package:another_flushbar/flushbar.dart';
|
||||||
import 'package:cake_wallet/core/execution_state.dart';
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/wallet_unlock/wallet_unlock_arguments.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_bar.dart';
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
import 'package:cake_wallet/view_model/wallet_unlock_verifiable_view_model.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cake_wallet/view_model/wallet_unlock_view_model.dart';
|
import 'package:cake_wallet/view_model/wallet_unlock_view_model.dart';
|
||||||
|
@ -17,10 +17,12 @@ class WalletUnlockPage extends StatefulWidget {
|
||||||
WalletUnlockPage(
|
WalletUnlockPage(
|
||||||
this.walletUnlockViewModel,
|
this.walletUnlockViewModel,
|
||||||
this.onAuthenticationFinished,
|
this.onAuthenticationFinished,
|
||||||
|
this.authPasswordHandler,
|
||||||
{required this.closable});
|
{required this.closable});
|
||||||
|
|
||||||
final WalletUnlockViewModel walletUnlockViewModel;
|
final WalletUnlockViewModel walletUnlockViewModel;
|
||||||
final OnAuthenticationFinished onAuthenticationFinished;
|
final OnAuthenticationFinished onAuthenticationFinished;
|
||||||
|
final AuthPasswordHandler? authPasswordHandler;
|
||||||
final bool closable;
|
final bool closable;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -204,7 +206,20 @@ class WalletUnlockPageState extends AuthPageState<WalletUnlockPage> {
|
||||||
child: Observer(
|
child: Observer(
|
||||||
builder: (_) =>
|
builder: (_) =>
|
||||||
LoadingPrimaryButton(
|
LoadingPrimaryButton(
|
||||||
onPressed: () => widget.walletUnlockViewModel.unlock(),
|
onPressed: () async {
|
||||||
|
if (widget.authPasswordHandler != null) {
|
||||||
|
try {
|
||||||
|
await widget.authPasswordHandler!(widget
|
||||||
|
.walletUnlockViewModel.password);
|
||||||
|
widget.walletUnlockViewModel.success();
|
||||||
|
} catch (e) {
|
||||||
|
widget.walletUnlockViewModel.failure(e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.walletUnlockViewModel.unlock();
|
||||||
|
},
|
||||||
text: S.of(context).unlock,
|
text: S.of(context).unlock,
|
||||||
color: Colors.green,
|
color: Colors.green,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
|
@ -213,4 +228,4 @@ class WalletUnlockPageState extends AuthPageState<WalletUnlockPage> {
|
||||||
]))
|
]))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,12 @@ abstract class WalletEditViewModelBase with Store {
|
||||||
final WalletLoadingService _walletLoadingService;
|
final WalletLoadingService _walletLoadingService;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> changeName(WalletListItem walletItem) async {
|
Future<void> changeName(WalletListItem walletItem, {String? password}) async {
|
||||||
state = WalletEditRenamePending();
|
state = WalletEditRenamePending();
|
||||||
await _walletLoadingService.renameWallet(
|
await _walletLoadingService.renameWallet(
|
||||||
walletItem.type, walletItem.name, newName);
|
walletItem.type, walletItem.name, newName,
|
||||||
_walletListViewModel.updateList();
|
password: password);
|
||||||
|
resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -45,11 +46,11 @@ abstract class WalletEditViewModelBase with Store {
|
||||||
final walletService = getIt.get<WalletService>(param1: wallet.type);
|
final walletService = getIt.get<WalletService>(param1: wallet.type);
|
||||||
await walletService.remove(wallet.name);
|
await walletService.remove(wallet.name);
|
||||||
resetState();
|
resetState();
|
||||||
_walletListViewModel.updateList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void resetState() {
|
void resetState() {
|
||||||
|
_walletListViewModel.updateList();
|
||||||
state = WalletEditViewModelInitialState();
|
state = WalletEditViewModelInitialState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,15 @@ import 'package:cake_wallet/view_model/wallet_unlock_view_model.dart';
|
||||||
|
|
||||||
part 'wallet_unlock_loadable_view_model.g.dart';
|
part 'wallet_unlock_loadable_view_model.g.dart';
|
||||||
|
|
||||||
class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase with _$WalletUnlockLoadableViewModel;
|
class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase
|
||||||
|
with _$WalletUnlockLoadableViewModel;
|
||||||
|
|
||||||
abstract class WalletUnlockLoadableViewModelBase extends WalletUnlockViewModel with Store {
|
abstract class WalletUnlockLoadableViewModelBase extends WalletUnlockViewModel
|
||||||
WalletUnlockLoadableViewModelBase(
|
with Store {
|
||||||
this._appStore,
|
WalletUnlockLoadableViewModelBase(this._appStore, this._walletLoadingService,
|
||||||
this._walletLoadingService, {
|
{required this.walletName, required this.walletType})
|
||||||
required this.walletName,
|
: password = '',
|
||||||
required this.walletType})
|
state = InitialExecutionState();
|
||||||
: password = '',
|
|
||||||
state = InitialExecutionState();
|
|
||||||
|
|
||||||
final String walletName;
|
final String walletName;
|
||||||
|
|
||||||
|
@ -43,14 +42,24 @@ class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase with _$W
|
||||||
Future<void> unlock() async {
|
Future<void> unlock() async {
|
||||||
try {
|
try {
|
||||||
state = InitialExecutionState();
|
state = InitialExecutionState();
|
||||||
final wallet = await _walletLoadingService.load(
|
final wallet = await _walletLoadingService.load(walletType, walletName,
|
||||||
walletType,
|
password: password);
|
||||||
walletName,
|
|
||||||
password: password);
|
|
||||||
_appStore.changeCurrentWallet(wallet);
|
_appStore.changeCurrentWallet(wallet);
|
||||||
state = ExecutedSuccessfullyState();
|
success();
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
state = FailureState(e.toString());
|
failure(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@action
|
||||||
|
void success() {
|
||||||
|
state = ExecutedSuccessfullyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@action
|
||||||
|
void failure(e) {
|
||||||
|
state = FailureState(e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@ import 'package:cake_wallet/view_model/wallet_unlock_view_model.dart';
|
||||||
|
|
||||||
part 'wallet_unlock_verifiable_view_model.g.dart';
|
part 'wallet_unlock_verifiable_view_model.g.dart';
|
||||||
|
|
||||||
class WalletUnlockVerifiableViewModel = WalletUnlockVerifiableViewModelBase with _$WalletUnlockVerifiableViewModel;
|
class WalletUnlockVerifiableViewModel = WalletUnlockVerifiableViewModelBase
|
||||||
|
with _$WalletUnlockVerifiableViewModel;
|
||||||
|
|
||||||
abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel with Store {
|
abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel
|
||||||
WalletUnlockVerifiableViewModelBase(
|
with Store {
|
||||||
this.appStore, {
|
WalletUnlockVerifiableViewModelBase(this.appStore,
|
||||||
required this.walletName,
|
{required this.walletName, required this.walletType})
|
||||||
required this.walletType})
|
: password = '',
|
||||||
: password = '',
|
state = InitialExecutionState();
|
||||||
state = InitialExecutionState();
|
|
||||||
|
|
||||||
final String walletName;
|
final String walletName;
|
||||||
|
|
||||||
|
@ -38,12 +38,24 @@ abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel
|
||||||
@override
|
@override
|
||||||
@action
|
@action
|
||||||
Future<void> unlock() async {
|
Future<void> unlock() async {
|
||||||
try {
|
try {
|
||||||
state = appStore.wallet!.password == password
|
state = appStore.wallet!.password == password
|
||||||
? ExecutedSuccessfullyState()
|
? ExecutedSuccessfullyState()
|
||||||
: FailureState(S.current.invalid_password) ;
|
: FailureState(S.current.invalid_password);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
state = FailureState('${S.current.invalid_password}\n${e.toString()}');
|
failure('${S.current.invalid_password}\n${e.toString()}');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@action
|
||||||
|
void success() {
|
||||||
|
state = ExecutedSuccessfullyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@action
|
||||||
|
void failure(e) {
|
||||||
|
state = FailureState(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,6 @@ abstract class WalletUnlockViewModel {
|
||||||
void setPassword(String password);
|
void setPassword(String password);
|
||||||
ExecutionState get state;
|
ExecutionState get state;
|
||||||
Future<void> unlock();
|
Future<void> unlock();
|
||||||
}
|
void success();
|
||||||
|
void failure(dynamic e);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue