mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
xmr/wow wallet restore init fixes
This commit is contained in:
parent
8acf84e222
commit
4356e101f5
4 changed files with 61 additions and 23 deletions
|
@ -52,6 +52,8 @@ import 'package:stackwallet/utilities/text_styles.dart';
|
|||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/monero_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/wownero_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
|
||||
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
|
@ -314,10 +316,22 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
|
|||
mnemonic: mnemonic,
|
||||
);
|
||||
|
||||
if (wallet is EpiccashWallet) {
|
||||
await wallet.init(isRestore: true);
|
||||
} else {
|
||||
await wallet.init();
|
||||
// TODO: extract interface with isRestore param
|
||||
switch (wallet.runtimeType) {
|
||||
case EpiccashWallet:
|
||||
await (wallet as EpiccashWallet).init(isRestore: true);
|
||||
break;
|
||||
|
||||
case MoneroWallet:
|
||||
await (wallet as MoneroWallet).init(isRestore: true);
|
||||
break;
|
||||
|
||||
case WowneroWallet:
|
||||
await (wallet as WowneroWallet).init(isRestore: true);
|
||||
break;
|
||||
|
||||
default:
|
||||
await wallet.init();
|
||||
}
|
||||
|
||||
await wallet.recover(isRescan: false);
|
||||
|
|
|
@ -247,26 +247,26 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
Future<void> init({bool? isRestore}) async {
|
||||
cwWalletService = xmr_dart.monero
|
||||
.createMoneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||
|
||||
if (!(await cwWalletService!.isWalletExit(walletId))) {
|
||||
if (!(await cwWalletService!.isWalletExit(walletId)) && isRestore != true) {
|
||||
WalletInfo walletInfo;
|
||||
WalletCredentials credentials;
|
||||
try {
|
||||
String name = walletId;
|
||||
final dirPath =
|
||||
await pathForWalletDir(name: name, type: WalletType.monero);
|
||||
final path = await pathForWallet(name: name, type: WalletType.monero);
|
||||
await pathForWalletDir(name: walletId, type: WalletType.monero);
|
||||
final path =
|
||||
await pathForWallet(name: walletId, type: WalletType.monero);
|
||||
credentials = xmr_dart.monero.createMoneroNewWalletCredentials(
|
||||
name: name,
|
||||
name: walletId,
|
||||
language: "English",
|
||||
);
|
||||
|
||||
walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, WalletType.monero),
|
||||
name: name,
|
||||
id: WalletBase.idFor(walletId, WalletType.monero),
|
||||
name: walletId,
|
||||
type: WalletType.monero,
|
||||
isRecovery: false,
|
||||
restoreHeight: credentials.height ?? 0,
|
||||
|
@ -332,7 +332,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
|
||||
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
||||
highestPercentCached = 0;
|
||||
await cwWalletBase?.rescan(height: restoreHeight);
|
||||
await cwWalletBase?.rescan(height: restoreHeight ?? 0);
|
||||
});
|
||||
unawaited(refresh());
|
||||
return;
|
||||
|
|
|
@ -246,27 +246,27 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
Future<void> init({bool? isRestore}) async {
|
||||
cwWalletService = wow_dart.wownero
|
||||
.createWowneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||
|
||||
if (!(await cwWalletService!.isWalletExit(walletId))) {
|
||||
if (!(await cwWalletService!.isWalletExit(walletId)) && isRestore != true) {
|
||||
WalletInfo walletInfo;
|
||||
WalletCredentials credentials;
|
||||
try {
|
||||
String name = walletId;
|
||||
final dirPath =
|
||||
await pathForWalletDir(name: name, type: WalletType.wownero);
|
||||
final path = await pathForWallet(name: name, type: WalletType.wownero);
|
||||
await pathForWalletDir(name: walletId, type: WalletType.wownero);
|
||||
final path =
|
||||
await pathForWallet(name: walletId, type: WalletType.wownero);
|
||||
credentials = wow_dart.wownero.createWowneroNewWalletCredentials(
|
||||
name: name,
|
||||
name: walletId,
|
||||
language: "English",
|
||||
seedWordsLength: 14,
|
||||
);
|
||||
|
||||
walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, WalletType.wownero),
|
||||
name: name,
|
||||
id: WalletBase.idFor(walletId, WalletType.wownero),
|
||||
name: walletId,
|
||||
type: WalletType.wownero,
|
||||
isRecovery: false,
|
||||
restoreHeight: credentials.height ?? 0,
|
||||
|
@ -373,7 +373,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
|
||||
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
||||
highestPercentCached = 0;
|
||||
await cwWalletBase?.rescan(height: restoreHeight);
|
||||
await cwWalletBase?.rescan(height: restoreHeight ?? 0);
|
||||
});
|
||||
unawaited(refresh());
|
||||
return;
|
||||
|
|
|
@ -148,7 +148,31 @@ abstract class Wallet<T extends CryptoCurrency> {
|
|||
if (wallet is MnemonicInterface) {
|
||||
if (wallet is CryptonoteWallet) {
|
||||
// currently a special case due to the xmr/wow libraries handling their
|
||||
// own mnemonic generation
|
||||
// own mnemonic generation on new wallet creation
|
||||
// if its a restore we must set them
|
||||
if (mnemonic != null) {
|
||||
if ((await secureStorageInterface.read(
|
||||
key: mnemonicKey(walletId: walletInfo.walletId),
|
||||
)) ==
|
||||
null) {
|
||||
await secureStorageInterface.write(
|
||||
key: mnemonicKey(walletId: walletInfo.walletId),
|
||||
value: mnemonic,
|
||||
);
|
||||
}
|
||||
|
||||
if (mnemonicPassphrase != null) {
|
||||
if ((await secureStorageInterface.read(
|
||||
key: mnemonicPassphraseKey(walletId: walletInfo.walletId),
|
||||
)) ==
|
||||
null) {
|
||||
await secureStorageInterface.write(
|
||||
key: mnemonicPassphraseKey(walletId: walletInfo.walletId),
|
||||
value: mnemonicPassphrase,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await secureStorageInterface.write(
|
||||
key: mnemonicKey(walletId: walletInfo.walletId),
|
||||
|
|
Loading…
Reference in a new issue