diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index 97f1de275..82ce2cab6 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -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); } diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 6f32af646..a1dd4e23c 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -804,28 +804,39 @@ abstract class MoneroWalletBase extends WalletBase $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) { diff --git a/lib/exchange/provider/chainflip_exchange_provider.dart b/lib/exchange/provider/chainflip_exchange_provider.dart index e587e1e4a..a5f8a171b 100644 --- a/lib/exchange/provider/chainflip_exchange_provider.dart +++ b/lib/exchange/provider/chainflip_exchange_provider.dart @@ -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; + final quotes = json.decode(response.body) as List>; Map 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; + }); return highestQuote; }