mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
fix: incorrect restore height sometimes being set on monero (#2390)
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -90,8 +90,9 @@ void createWallet(
|
||||
if (status != 0) {
|
||||
throw WalletCreationException(message: newW.errorString());
|
||||
}
|
||||
|
||||
newW.store(path: path);
|
||||
setupBackgroundSync(password, newW);
|
||||
newW.store(path: path);
|
||||
|
||||
currentWallet = newW;
|
||||
currentWallet!.setCacheAttribute(key: "cakewallet.passphrase", value: passphrase);
|
||||
@@ -179,6 +180,8 @@ void restoreWalletFromKeys(
|
||||
throw WalletRestoreFromKeysException(
|
||||
message: newW.errorString());
|
||||
}
|
||||
newW.store(path: path);
|
||||
|
||||
|
||||
// CW-712 - Try to restore deterministic wallet first, if the view key doesn't
|
||||
// match the view key provided
|
||||
@@ -202,6 +205,7 @@ void restoreWalletFromKeys(
|
||||
throw WalletRestoreFromKeysException(
|
||||
message: newW.errorString());
|
||||
}
|
||||
newW.store(path: path);
|
||||
|
||||
setupBackgroundSync(password, newW);
|
||||
}
|
||||
|
||||
@@ -804,28 +804,39 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||
throw Exception("height isn't > $MIN_RESTORE_HEIGHT!");
|
||||
}
|
||||
|
||||
void _setHeightFromDate() {
|
||||
void _setHeightFromDate({int tryNum = 0}) {
|
||||
if (walletInfo.isRecovery) {
|
||||
return;
|
||||
}
|
||||
|
||||
int height = 0;
|
||||
try {
|
||||
height = _getHeightByDate(walletInfo.date);
|
||||
} catch (_) {}
|
||||
height = _getHeightByDate(walletInfo.date.subtract(Duration(days: 14)));
|
||||
if (height <= 0) {
|
||||
throw Exception("height is <= 0");
|
||||
}
|
||||
monero_wallet.setRefreshFromBlockHeight(height: height);
|
||||
} catch (_) {
|
||||
if (tryNum <= 3) {
|
||||
printV("Failed to set height from date, retrying... $tryNum");
|
||||
unawaited(() async {
|
||||
await Future.delayed(Duration(seconds: 10));
|
||||
_setHeightFromDate(tryNum: tryNum + 1);
|
||||
}());
|
||||
}
|
||||
}
|
||||
|
||||
monero_wallet.setRecoveringFromSeed(isRecovery: true);
|
||||
monero_wallet.setRefreshFromBlockHeight(height: height);
|
||||
setupBackgroundSync(password, currentWallet!);
|
||||
}
|
||||
|
||||
int _getHeightDistance(DateTime date) {
|
||||
final distance =
|
||||
DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
|
||||
DateTime.now().difference(date).inSeconds;
|
||||
final daysTmp = (distance / 86400).round();
|
||||
final days = daysTmp < 1 ? 1 : daysTmp;
|
||||
|
||||
return days * 1000;
|
||||
return days * 720; // there are720 blocks per day on xmr
|
||||
}
|
||||
|
||||
int _getHeightByDate(DateTime date) {
|
||||
|
||||
@@ -297,14 +297,14 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
||||
throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
|
||||
}
|
||||
|
||||
final quotes = json.decode(response.body) as List<dynamic>;
|
||||
final quotes = json.decode(response.body) as List<Map<String, dynamic>>;
|
||||
|
||||
Map<String, dynamic> highestQuote = quotes.reduce((current, next) {
|
||||
final currentAmount = current['egressAmount'] as double;
|
||||
final nextAmount = next['egressAmount'] as double;
|
||||
double currentAmount = current['egressAmount'] as double;
|
||||
double nextAmount = next['egressAmount'] as double;
|
||||
|
||||
return currentAmount > nextAmount ? current : next;
|
||||
}) as Map<String, dynamic>;
|
||||
});
|
||||
|
||||
return highestQuote;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user