mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-24 12:39:37 +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
e53bcc411f
commit
68d3cd49b7
10 changed files with 144 additions and 52 deletions
|
@ -27,7 +27,7 @@ class WalletLoadingService {
|
|||
// otherwise keeps duplicate (old and new names)
|
||||
await keyService.deleteWalletPassword(walletName: name);
|
||||
|
||||
await walletService.rename(name, password, newName);
|
||||
await walletService.rename(name, walletPassword, newName);
|
||||
|
||||
// set shared preferences flag based on previous wallet name
|
||||
if (type == WalletType.monero) {
|
||||
|
|
|
@ -1108,6 +1108,7 @@ Future<void> setup({
|
|||
return WalletUnlockPage(
|
||||
getIt.get<WalletUnlockLoadableViewModel>(param1: args),
|
||||
args.callback,
|
||||
args.authPasswordHandler,
|
||||
closable: closable);
|
||||
}, instanceName: 'wallet_unlock_loadable');
|
||||
|
||||
|
@ -1115,6 +1116,7 @@ Future<void> setup({
|
|||
return WalletUnlockPage(
|
||||
getIt.get<WalletUnlockVerifiableViewModel>(param1: args),
|
||||
args.callback,
|
||||
args.authPasswordHandler,
|
||||
closable: closable);
|
||||
}, 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/wallet_name_validator.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_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_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_list/wallet_edit_view_model.dart';
|
||||
|
@ -94,9 +98,36 @@ class WalletEditPage extends BasePage {
|
|||
);
|
||||
} else {
|
||||
try {
|
||||
await walletEditViewModel.changeName(editingWallet);
|
||||
Navigator.of(context).pop();
|
||||
walletEditViewModel.resetState();
|
||||
bool confirmed = false;
|
||||
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
|
|||
import 'package:cake_wallet/main.dart';
|
||||
import 'package:cake_wallet/src/screens/auth/auth_page.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/themes/extensions/receive_page_theme.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/utils/device_info.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
|
||||
|
@ -250,12 +252,25 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
}
|
||||
|
||||
Future<void> _loadWallet(WalletListItem wallet) async {
|
||||
await widget.authService.authenticateAction(
|
||||
context,
|
||||
onAuthSuccess: (isAuthenticatedSuccessfully) async {
|
||||
if (!isAuthenticatedSuccessfully) {
|
||||
return;
|
||||
}
|
||||
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,
|
||||
onAuthSuccess: (isAuthenticatedSuccessfully) async {
|
||||
if (!isAuthenticatedSuccessfully) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name));
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
typedef AuthPasswordHandler = Future<void> Function(String);
|
||||
|
||||
class WalletUnlockArguments {
|
||||
WalletUnlockArguments({
|
||||
required this.callback,
|
||||
this.walletName,
|
||||
this.walletType});
|
||||
WalletUnlockArguments(
|
||||
{required this.callback,
|
||||
this.walletName,
|
||||
this.walletType,
|
||||
this.authPasswordHandler});
|
||||
|
||||
final OnAuthenticationFinished callback;
|
||||
final AuthPasswordHandler? authPasswordHandler;
|
||||
final String? walletName;
|
||||
final WalletType? walletType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
|||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/src/screens/wallet_unlock/wallet_unlock_arguments.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_unlock_verifiable_view_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -17,10 +18,12 @@ class WalletUnlockPage extends StatefulWidget {
|
|||
WalletUnlockPage(
|
||||
this.walletUnlockViewModel,
|
||||
this.onAuthenticationFinished,
|
||||
this.authPasswordHandler,
|
||||
{required this.closable});
|
||||
|
||||
final WalletUnlockViewModel walletUnlockViewModel;
|
||||
final OnAuthenticationFinished onAuthenticationFinished;
|
||||
final AuthPasswordHandler? authPasswordHandler;
|
||||
final bool closable;
|
||||
|
||||
@override
|
||||
|
@ -204,7 +207,20 @@ class WalletUnlockPageState extends AuthPageState<WalletUnlockPage> {
|
|||
child: Observer(
|
||||
builder: (_) =>
|
||||
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,
|
||||
color: Colors.green,
|
||||
textColor: Colors.white,
|
||||
|
|
|
@ -32,11 +32,12 @@ abstract class WalletEditViewModelBase with Store {
|
|||
final WalletLoadingService _walletLoadingService;
|
||||
|
||||
@action
|
||||
Future<void> changeName(WalletListItem walletItem) async {
|
||||
Future<void> changeName(WalletListItem walletItem, {String? password}) async {
|
||||
state = WalletEditRenamePending();
|
||||
await _walletLoadingService.renameWallet(
|
||||
walletItem.type, walletItem.name, newName);
|
||||
_walletListViewModel.updateList();
|
||||
walletItem.type, walletItem.name, newName,
|
||||
password: password);
|
||||
resetState();
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -45,11 +46,11 @@ abstract class WalletEditViewModelBase with Store {
|
|||
final walletService = getIt.get<WalletService>(param1: wallet.type);
|
||||
await walletService.remove(wallet.name);
|
||||
resetState();
|
||||
_walletListViewModel.updateList();
|
||||
}
|
||||
|
||||
@action
|
||||
void resetState() {
|
||||
_walletListViewModel.updateList();
|
||||
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';
|
||||
|
||||
class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase with _$WalletUnlockLoadableViewModel;
|
||||
class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase
|
||||
with _$WalletUnlockLoadableViewModel;
|
||||
|
||||
abstract class WalletUnlockLoadableViewModelBase extends WalletUnlockViewModel with Store {
|
||||
WalletUnlockLoadableViewModelBase(
|
||||
this._appStore,
|
||||
this._walletLoadingService, {
|
||||
required this.walletName,
|
||||
required this.walletType})
|
||||
: password = '',
|
||||
state = InitialExecutionState();
|
||||
abstract class WalletUnlockLoadableViewModelBase extends WalletUnlockViewModel
|
||||
with Store {
|
||||
WalletUnlockLoadableViewModelBase(this._appStore, this._walletLoadingService,
|
||||
{required this.walletName, required this.walletType})
|
||||
: password = '',
|
||||
state = InitialExecutionState();
|
||||
|
||||
final String walletName;
|
||||
|
||||
|
@ -43,14 +42,24 @@ class WalletUnlockLoadableViewModel = WalletUnlockLoadableViewModelBase with _$W
|
|||
Future<void> unlock() async {
|
||||
try {
|
||||
state = InitialExecutionState();
|
||||
final wallet = await _walletLoadingService.load(
|
||||
walletType,
|
||||
walletName,
|
||||
password: password);
|
||||
final wallet = await _walletLoadingService.load(walletType, walletName,
|
||||
password: password);
|
||||
_appStore.changeCurrentWallet(wallet);
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch(e) {
|
||||
state = FailureState(e.toString());
|
||||
success();
|
||||
} catch (e) {
|
||||
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';
|
||||
|
||||
class WalletUnlockVerifiableViewModel = WalletUnlockVerifiableViewModelBase with _$WalletUnlockVerifiableViewModel;
|
||||
class WalletUnlockVerifiableViewModel = WalletUnlockVerifiableViewModelBase
|
||||
with _$WalletUnlockVerifiableViewModel;
|
||||
|
||||
abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel with Store {
|
||||
WalletUnlockVerifiableViewModelBase(
|
||||
this.appStore, {
|
||||
required this.walletName,
|
||||
required this.walletType})
|
||||
: password = '',
|
||||
state = InitialExecutionState();
|
||||
abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel
|
||||
with Store {
|
||||
WalletUnlockVerifiableViewModelBase(this.appStore,
|
||||
{required this.walletName, required this.walletType})
|
||||
: password = '',
|
||||
state = InitialExecutionState();
|
||||
|
||||
final String walletName;
|
||||
|
||||
|
@ -38,12 +38,24 @@ abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel
|
|||
@override
|
||||
@action
|
||||
Future<void> unlock() async {
|
||||
try {
|
||||
state = appStore.wallet!.password == password
|
||||
? ExecutedSuccessfullyState()
|
||||
: FailureState(S.current.invalid_password) ;
|
||||
} catch(e) {
|
||||
state = FailureState('${S.current.invalid_password}\n${e.toString()}');
|
||||
}
|
||||
try {
|
||||
state = appStore.wallet!.password == password
|
||||
? ExecutedSuccessfullyState()
|
||||
: FailureState(S.current.invalid_password);
|
||||
} catch (e) {
|
||||
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);
|
||||
ExecutionState get state;
|
||||
Future<void> unlock();
|
||||
}
|
||||
void success();
|
||||
void failure(dynamic e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue