Skip to content

Commit

Permalink
Merge pull request #889 from cypherstack/testing
Browse files Browse the repository at this point in the history
tweaks and fixes
  • Loading branch information
julian-CStack authored Jun 14, 2024
2 parents cb4a9b5 + 6587967 commit b204d8b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
10 changes: 4 additions & 6 deletions lib/pages/exchange_view/confirm_change_now_send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
11 changes: 9 additions & 2 deletions lib/pages_desktop_specific/desktop_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -278,8 +279,14 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
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],
),
Expand Down
39 changes: 38 additions & 1 deletion lib/utilities/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,8 +31,10 @@ class Logging {
static const core.int defaultPrintLength = 1020;

late final Isar? isar;
late final _AsyncLogWriterQueue _queue;

Future<void> init(Isar isar) async {
_queue = _AsyncLogWriterQueue();
this.isar = isar;
}

Expand Down Expand Up @@ -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()}";
Expand Down Expand Up @@ -129,3 +136,33 @@ abstract class Logger {
}
}
}

/// basic async queue for writing logs in the [Logging] to isar
class _AsyncLogWriterQueue {
final List<Future<void> Function()> _queue = [];
bool _runningLock = false;

void add(Future<void> 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;
}
}
}
27 changes: 13 additions & 14 deletions lib/wallets/wallet/impl/wownero_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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,
);

Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<WalletInfo>(boxName: WalletInfo.boxName, value: walletInfo);
CwBasedInterface.cwWalletBase?.close();
Expand Down

0 comments on commit b204d8b

Please sign in to comment.