mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
extra precautions in init()
This commit is contained in:
parent
061be596f5
commit
0c97fa6635
6 changed files with 78 additions and 43 deletions
|
@ -563,24 +563,30 @@ class EpiccashWallet extends Bip39Wallet {
|
|||
isar: mainDB.isar,
|
||||
);
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"initializeExisting() ${cryptoCurrency.coin.prettyName} wallet",
|
||||
level: LogLevel.Info);
|
||||
try {
|
||||
Logging.instance.log(
|
||||
"initializeExisting() ${cryptoCurrency.coin.prettyName} wallet",
|
||||
level: LogLevel.Info);
|
||||
|
||||
final config = await _getRealConfig();
|
||||
final password =
|
||||
await secureStorageInterface.read(key: '${walletId}_password');
|
||||
final config = await _getRealConfig();
|
||||
final password =
|
||||
await secureStorageInterface.read(key: '${walletId}_password');
|
||||
|
||||
final walletOpen = await epiccash.LibEpiccash.openWallet(
|
||||
config: config,
|
||||
password: password!,
|
||||
);
|
||||
await secureStorageInterface.write(
|
||||
key: '${walletId}_wallet', value: walletOpen);
|
||||
final walletOpen = await epiccash.LibEpiccash.openWallet(
|
||||
config: config,
|
||||
password: password!,
|
||||
);
|
||||
await secureStorageInterface.write(
|
||||
key: '${walletId}_wallet', value: walletOpen);
|
||||
|
||||
await updateNode();
|
||||
// unawaited(updateBalance());
|
||||
// TODO: is there anything else that should be set up here whenever this wallet is first loaded again?
|
||||
await updateNode();
|
||||
} catch (e, s) {
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1074,7 +1080,7 @@ class EpiccashWallet extends Bip39Wallet {
|
|||
value: stringConfig,
|
||||
);
|
||||
|
||||
unawaited(refresh());
|
||||
// unawaited(refresh());
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -118,8 +118,12 @@ class StellarWallet extends Bip39Wallet<Stellar> {
|
|||
await mainDB
|
||||
.updateOrPutAddresses([await _fetchStellarAddress(index: 0)]);
|
||||
}
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
return super.init();
|
||||
}
|
||||
|
|
|
@ -152,8 +152,12 @@ class TezosWallet extends Bip39Wallet<Tezos> {
|
|||
final address = await _getAddressFromMnemonic();
|
||||
await mainDB.updateOrPutAddresses([address]);
|
||||
}
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
|
||||
await super.init();
|
||||
|
|
|
@ -1930,7 +1930,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
|
|||
try {
|
||||
final features = await electrumXClient
|
||||
.getServerFeatures()
|
||||
.timeout(const Duration(seconds: 3));
|
||||
.timeout(const Duration(seconds: 2));
|
||||
|
||||
Logging.instance.log("features: $features", level: LogLevel.Info);
|
||||
|
||||
|
@ -1941,7 +1941,11 @@ mixin ElectrumXInterface on Bip39HDWallet {
|
|||
throw Exception("genesis hash does not match!");
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e/n$s", level: LogLevel.Info);
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
|
||||
await super.init();
|
||||
|
|
|
@ -316,10 +316,18 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
|
|||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
_cachedAddress = await getCurrentReceivingAddress();
|
||||
if (_cachedAddress == null) {
|
||||
_cachedAddress = await _getAddressFromMnemonic();
|
||||
await mainDB.putAddress(_cachedAddress!);
|
||||
try {
|
||||
_cachedAddress = await getCurrentReceivingAddress();
|
||||
if (_cachedAddress == null) {
|
||||
_cachedAddress = await _getAddressFromMnemonic();
|
||||
await mainDB.putAddress(_cachedAddress!);
|
||||
}
|
||||
} catch (e, s) {
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
|
||||
return super.init();
|
||||
|
|
|
@ -52,27 +52,36 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
Address? address = await getCurrentReceivingSparkAddress();
|
||||
if (address == null) {
|
||||
address = await generateNextSparkAddress();
|
||||
await mainDB.putAddress(address);
|
||||
} // TODO add other address types to wallet info?
|
||||
try {
|
||||
Address? address = await getCurrentReceivingSparkAddress();
|
||||
if (address == null) {
|
||||
address = await generateNextSparkAddress();
|
||||
await mainDB.putAddress(address);
|
||||
} // TODO add other address types to wallet info?
|
||||
|
||||
if (_sparkChangeAddressCached == null) {
|
||||
final root = await getRootHDNode();
|
||||
final String derivationPath;
|
||||
if (cryptoCurrency.network == CryptoCurrencyNetwork.test) {
|
||||
derivationPath = "$kSparkBaseDerivationPathTestnet$kDefaultSparkIndex";
|
||||
} else {
|
||||
derivationPath = "$kSparkBaseDerivationPath$kDefaultSparkIndex";
|
||||
if (_sparkChangeAddressCached == null) {
|
||||
final root = await getRootHDNode();
|
||||
final String derivationPath;
|
||||
if (cryptoCurrency.network == CryptoCurrencyNetwork.test) {
|
||||
derivationPath =
|
||||
"$kSparkBaseDerivationPathTestnet$kDefaultSparkIndex";
|
||||
} else {
|
||||
derivationPath = "$kSparkBaseDerivationPath$kDefaultSparkIndex";
|
||||
}
|
||||
final keys = root.derivePath(derivationPath);
|
||||
|
||||
_sparkChangeAddressCached = await LibSpark.getAddress(
|
||||
privateKey: keys.privateKey.data,
|
||||
index: kDefaultSparkIndex,
|
||||
diversifier: kSparkChange,
|
||||
isTestNet: cryptoCurrency.network == CryptoCurrencyNetwork.test,
|
||||
);
|
||||
}
|
||||
final keys = root.derivePath(derivationPath);
|
||||
|
||||
_sparkChangeAddressCached = await LibSpark.getAddress(
|
||||
privateKey: keys.privateKey.data,
|
||||
index: kDefaultSparkIndex,
|
||||
diversifier: kSparkChange,
|
||||
isTestNet: cryptoCurrency.network == CryptoCurrencyNetwork.test,
|
||||
} catch (e, s) {
|
||||
// do nothing, still allow user into wallet
|
||||
Logging.instance.log(
|
||||
"$runtimeType init() failed: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue