From f31d47f1235b41d1fab9827f7b048f7c720c60a6 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 13 Jun 2024 12:00:03 -0600 Subject: [PATCH 1/4] wownero restore tweaks --- lib/wallets/wallet/impl/wownero_wallet.dart | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/wallets/wallet/impl/wownero_wallet.dart b/lib/wallets/wallet/impl/wownero_wallet.dart index ced514aa3..69f42a57d 100644 --- a/lib/wallets/wallet/impl/wownero_wallet.dart +++ b/lib/wallets/wallet/impl/wownero_wallet.dart @@ -12,6 +12,7 @@ import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart'; +import 'package:cw_wownero/api/account_list.dart'; import 'package:cw_wownero/pending_wownero_transaction.dart'; import 'package:cw_wownero/wownero_wallet.dart'; import 'package:decimal/decimal.dart'; @@ -20,6 +21,7 @@ import 'package:flutter_libmonero/view_model/send/output.dart' as wownero_output; import 'package:flutter_libmonero/wownero/wownero.dart' as wow_dart; import 'package:isar/isar.dart'; +import 'package:monero/wownero.dart' as wownerodart; import 'package:mutex/mutex.dart'; import 'package:tuple/tuple.dart'; @@ -383,19 +385,11 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface { _walletCreationService.type = WalletType.wownero; // To restore from a seed final wallet = await _walletCreationService.create(credentials); - // - // final bufferedCreateHeight = (seedWordsLength == 14) - // ? getSeedHeightSync(wallet?.seed.trim() as String) - // : wownero.getHeightByDate( - // date: DateTime.now().subtract(const Duration( - // days: - // 2))); // subtract a couple days to ensure we have a buffer for SWB - // TODO(mrcyjanek): implement - const bufferedCreateHeight = - 1; //getSeedHeightSync(wallet!.seed.trim()); + + final height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!); await info.updateRestoreHeight( - newRestoreHeight: bufferedCreateHeight, + newRestoreHeight: height, isar: mainDB.isar, ); @@ -410,7 +404,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface { value: "", ); - walletInfo.restoreHeight = bufferedCreateHeight; + walletInfo.restoreHeight = height; walletInfo.address = wallet.walletAddresses.address; await DB.instance @@ -515,8 +509,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface { // extract seed height from 14 word seed if (seedLength == 14) { - // TODO(mrcyjanek): implement - height = 1; // getSeedHeightSync(mnemonic.trim()); + height = 0; } else { height = max(height, 0); } @@ -563,7 +556,13 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface { // To restore from a seed final wallet = await cwWalletCreationService .restoreFromSeed(credentials) as WowneroWalletBase; + height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!); walletInfo.address = wallet.walletAddresses.address; + walletInfo.restoreHeight = height; + await info.updateRestoreHeight( + newRestoreHeight: height, + isar: mainDB.isar, + ); await DB.instance .add(boxName: WalletInfo.boxName, value: walletInfo); CwBasedInterface.cwWalletBase?.close(); From 87405bc1ddae0fd96474d0ef2d76647e771b8317 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 13 Jun 2024 12:05:59 -0600 Subject: [PATCH 2/4] call `exit(0)` instead of `SystemNavigator.pop()` if xmr or wow is enabled hack to "fix" the native lib code from causing a complete app lockup on attempting to quit gracefully --- lib/pages_desktop_specific/desktop_menu.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/pages_desktop_specific/desktop_menu.dart b/lib/pages_desktop_specific/desktop_menu.dart index 2b4524bf0..81b99fd8f 100644 --- a/lib/pages_desktop_specific/desktop_menu.dart +++ b/lib/pages_desktop_specific/desktop_menu.dart @@ -20,6 +20,7 @@ import '../providers/desktop/current_desktop_menu_item.dart'; import '../themes/stack_colors.dart'; import '../utilities/assets.dart'; import '../utilities/text_styles.dart'; +import '../wallets/crypto_currency/crypto_currency.dart'; import '../widgets/desktop/desktop_tor_status_button.dart'; import '../widgets/desktop/living_stack_icon.dart'; import 'desktop_menu_item.dart'; @@ -278,8 +279,14 @@ class _DesktopMenuState extends ConsumerState { value: 7, onChanged: (_) { // todo: save stuff/ notify before exit? - // exit(0); - SystemNavigator.pop(); + if (AppConfig.coins + .where((e) => e is Monero || e is Wownero) + .isNotEmpty) { + // hack to insta kill because xmr/wow native lib code sucks + exit(0); + } else { + SystemNavigator.pop(); + } }, controller: controllers[8], ), From fc180dd8c1ab8ee8892c25acac007e51fb940f42 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 13 Jun 2024 14:46:22 -0600 Subject: [PATCH 3/4] simple async queue to write logs to db without holding up the logger to wait for it to complete --- lib/utilities/logger.dart | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/utilities/logger.dart b/lib/utilities/logger.dart index 6af09473a..83949ec5b 100644 --- a/lib/utilities/logger.dart +++ b/lib/utilities/logger.dart @@ -14,6 +14,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:isar/isar.dart'; + import '../models/isar/models/log.dart'; import 'constants.dart'; import 'enums/log_level_enum.dart'; @@ -30,8 +31,10 @@ class Logging { static const core.int defaultPrintLength = 1020; late final Isar? isar; + late final _AsyncLogWriterQueue _queue; Future init(Isar isar) async { + _queue = _AsyncLogWriterQueue(); this.isar = isar; } @@ -62,7 +65,11 @@ class Logging { printFullLength = true; } - isar!.writeTxnSync(() => log.id = isar!.logs.putSync(log)); + _queue.add( + () async => isar!.writeTxn( + () async => await isar!.logs.put(log), + ), + ); if (printToConsole) { final core.String logStr = "Log: ${log.toString()}"; @@ -129,3 +136,33 @@ abstract class Logger { } } } + +/// basic async queue for writing logs in the [Logging] to isar +class _AsyncLogWriterQueue { + final List Function()> _queue = []; + bool _runningLock = false; + + void add(Future Function() futureFunction) { + _queue.add(futureFunction); + _run(); + } + + void _run() async { + if (_runningLock) { + return; + } + _runningLock = true; + try { + while (_queue.isNotEmpty) { + final futureFunction = _queue.removeAt(0); + try { + await futureFunction.call(); + } catch (e, s) { + debugPrint("$e\n$s"); + } + } + } finally { + _runningLock = false; + } + } +} From 65879670ad15612dc7d3aa72e7ac686d789af361 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 13 Jun 2024 17:35:40 -0600 Subject: [PATCH 4/4] desktop swap navigation fix --- lib/pages/exchange_view/confirm_change_now_send.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/pages/exchange_view/confirm_change_now_send.dart b/lib/pages/exchange_view/confirm_change_now_send.dart index 09aac4df9..1b52dfdbe 100644 --- a/lib/pages/exchange_view/confirm_change_now_send.dart +++ b/lib/pages/exchange_view/confirm_change_now_send.dart @@ -147,17 +147,15 @@ class _ConfirmChangeNowSendViewState ); // pop back to wallet - if (mounted) { + if (context.mounted) { if (Util.isDesktop) { + // pop sending dialog Navigator.of(context, rootNavigator: true).pop(); - // stupid hack + // one day we'll do routing right + Navigator.of(context, rootNavigator: true).pop(); if (widget.fromDesktopStep4) { Navigator.of(context, rootNavigator: true).pop(); - Navigator.of(context, rootNavigator: true).pop(); - Navigator.of(context, rootNavigator: true).pop(); - Navigator.of(context, rootNavigator: true).pop(); - Navigator.of(context, rootNavigator: true).pop(); } }