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/utilities/util.dart';
|
||||||
import 'package:stackwallet/wallets/isar/models/wallet_info.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/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/supporting/epiccash_wallet_info_extension.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
|
@ -314,10 +316,22 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (wallet is EpiccashWallet) {
|
// TODO: extract interface with isRestore param
|
||||||
await wallet.init(isRestore: true);
|
switch (wallet.runtimeType) {
|
||||||
} else {
|
case EpiccashWallet:
|
||||||
await wallet.init();
|
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);
|
await wallet.recover(isRescan: false);
|
||||||
|
|
|
@ -247,26 +247,26 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init({bool? isRestore}) async {
|
||||||
cwWalletService = xmr_dart.monero
|
cwWalletService = xmr_dart.monero
|
||||||
.createMoneroWalletService(DB.instance.moneroWalletInfoBox);
|
.createMoneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||||
|
|
||||||
if (!(await cwWalletService!.isWalletExit(walletId))) {
|
if (!(await cwWalletService!.isWalletExit(walletId)) && isRestore != true) {
|
||||||
WalletInfo walletInfo;
|
WalletInfo walletInfo;
|
||||||
WalletCredentials credentials;
|
WalletCredentials credentials;
|
||||||
try {
|
try {
|
||||||
String name = walletId;
|
|
||||||
final dirPath =
|
final dirPath =
|
||||||
await pathForWalletDir(name: name, type: WalletType.monero);
|
await pathForWalletDir(name: walletId, type: WalletType.monero);
|
||||||
final path = await pathForWallet(name: name, type: WalletType.monero);
|
final path =
|
||||||
|
await pathForWallet(name: walletId, type: WalletType.monero);
|
||||||
credentials = xmr_dart.monero.createMoneroNewWalletCredentials(
|
credentials = xmr_dart.monero.createMoneroNewWalletCredentials(
|
||||||
name: name,
|
name: walletId,
|
||||||
language: "English",
|
language: "English",
|
||||||
);
|
);
|
||||||
|
|
||||||
walletInfo = WalletInfo.external(
|
walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, WalletType.monero),
|
id: WalletBase.idFor(walletId, WalletType.monero),
|
||||||
name: name,
|
name: walletId,
|
||||||
type: WalletType.monero,
|
type: WalletType.monero,
|
||||||
isRecovery: false,
|
isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
restoreHeight: credentials.height ?? 0,
|
||||||
|
@ -332,7 +332,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
|
|
||||||
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
||||||
highestPercentCached = 0;
|
highestPercentCached = 0;
|
||||||
await cwWalletBase?.rescan(height: restoreHeight);
|
await cwWalletBase?.rescan(height: restoreHeight ?? 0);
|
||||||
});
|
});
|
||||||
unawaited(refresh());
|
unawaited(refresh());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -246,27 +246,27 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init({bool? isRestore}) async {
|
||||||
cwWalletService = wow_dart.wownero
|
cwWalletService = wow_dart.wownero
|
||||||
.createWowneroWalletService(DB.instance.moneroWalletInfoBox);
|
.createWowneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||||
|
|
||||||
if (!(await cwWalletService!.isWalletExit(walletId))) {
|
if (!(await cwWalletService!.isWalletExit(walletId)) && isRestore != true) {
|
||||||
WalletInfo walletInfo;
|
WalletInfo walletInfo;
|
||||||
WalletCredentials credentials;
|
WalletCredentials credentials;
|
||||||
try {
|
try {
|
||||||
String name = walletId;
|
|
||||||
final dirPath =
|
final dirPath =
|
||||||
await pathForWalletDir(name: name, type: WalletType.wownero);
|
await pathForWalletDir(name: walletId, type: WalletType.wownero);
|
||||||
final path = await pathForWallet(name: name, type: WalletType.wownero);
|
final path =
|
||||||
|
await pathForWallet(name: walletId, type: WalletType.wownero);
|
||||||
credentials = wow_dart.wownero.createWowneroNewWalletCredentials(
|
credentials = wow_dart.wownero.createWowneroNewWalletCredentials(
|
||||||
name: name,
|
name: walletId,
|
||||||
language: "English",
|
language: "English",
|
||||||
seedWordsLength: 14,
|
seedWordsLength: 14,
|
||||||
);
|
);
|
||||||
|
|
||||||
walletInfo = WalletInfo.external(
|
walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, WalletType.wownero),
|
id: WalletBase.idFor(walletId, WalletType.wownero),
|
||||||
name: name,
|
name: walletId,
|
||||||
type: WalletType.wownero,
|
type: WalletType.wownero,
|
||||||
isRecovery: false,
|
isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
restoreHeight: credentials.height ?? 0,
|
||||||
|
@ -373,7 +373,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
|
|
||||||
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
var restoreHeight = cwWalletBase?.walletInfo.restoreHeight;
|
||||||
highestPercentCached = 0;
|
highestPercentCached = 0;
|
||||||
await cwWalletBase?.rescan(height: restoreHeight);
|
await cwWalletBase?.rescan(height: restoreHeight ?? 0);
|
||||||
});
|
});
|
||||||
unawaited(refresh());
|
unawaited(refresh());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -148,7 +148,31 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
if (wallet is MnemonicInterface) {
|
if (wallet is MnemonicInterface) {
|
||||||
if (wallet is CryptonoteWallet) {
|
if (wallet is CryptonoteWallet) {
|
||||||
// currently a special case due to the xmr/wow libraries handling their
|
// 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 {
|
} else {
|
||||||
await secureStorageInterface.write(
|
await secureStorageInterface.write(
|
||||||
key: mnemonicKey(walletId: walletInfo.walletId),
|
key: mnemonicKey(walletId: walletInfo.walletId),
|
||||||
|
|
Loading…
Reference in a new issue