Skip to content

Commit b204d8b

Browse files
Merge pull request #889 from cypherstack/testing
tweaks and fixes
2 parents cb4a9b5 + 6587967 commit b204d8b

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

lib/pages/exchange_view/confirm_change_now_send.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,15 @@ class _ConfirmChangeNowSendViewState
147147
);
148148

149149
// pop back to wallet
150-
if (mounted) {
150+
if (context.mounted) {
151151
if (Util.isDesktop) {
152+
// pop sending dialog
152153
Navigator.of(context, rootNavigator: true).pop();
153154

154-
// stupid hack
155+
// one day we'll do routing right
156+
Navigator.of(context, rootNavigator: true).pop();
155157
if (widget.fromDesktopStep4) {
156158
Navigator.of(context, rootNavigator: true).pop();
157-
Navigator.of(context, rootNavigator: true).pop();
158-
Navigator.of(context, rootNavigator: true).pop();
159-
Navigator.of(context, rootNavigator: true).pop();
160-
Navigator.of(context, rootNavigator: true).pop();
161159
}
162160
}
163161

lib/pages_desktop_specific/desktop_menu.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import '../providers/desktop/current_desktop_menu_item.dart';
2020
import '../themes/stack_colors.dart';
2121
import '../utilities/assets.dart';
2222
import '../utilities/text_styles.dart';
23+
import '../wallets/crypto_currency/crypto_currency.dart';
2324
import '../widgets/desktop/desktop_tor_status_button.dart';
2425
import '../widgets/desktop/living_stack_icon.dart';
2526
import 'desktop_menu_item.dart';
@@ -278,8 +279,14 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
278279
value: 7,
279280
onChanged: (_) {
280281
// todo: save stuff/ notify before exit?
281-
// exit(0);
282-
SystemNavigator.pop();
282+
if (AppConfig.coins
283+
.where((e) => e is Monero || e is Wownero)
284+
.isNotEmpty) {
285+
// hack to insta kill because xmr/wow native lib code sucks
286+
exit(0);
287+
} else {
288+
SystemNavigator.pop();
289+
}
283290
},
284291
controller: controllers[8],
285292
),

lib/utilities/logger.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'dart:io';
1414

1515
import 'package:flutter/foundation.dart';
1616
import 'package:isar/isar.dart';
17+
1718
import '../models/isar/models/log.dart';
1819
import 'constants.dart';
1920
import 'enums/log_level_enum.dart';
@@ -30,8 +31,10 @@ class Logging {
3031
static const core.int defaultPrintLength = 1020;
3132

3233
late final Isar? isar;
34+
late final _AsyncLogWriterQueue _queue;
3335

3436
Future<void> init(Isar isar) async {
37+
_queue = _AsyncLogWriterQueue();
3538
this.isar = isar;
3639
}
3740

@@ -62,7 +65,11 @@ class Logging {
6265
printFullLength = true;
6366
}
6467

65-
isar!.writeTxnSync(() => log.id = isar!.logs.putSync(log));
68+
_queue.add(
69+
() async => isar!.writeTxn(
70+
() async => await isar!.logs.put(log),
71+
),
72+
);
6673

6774
if (printToConsole) {
6875
final core.String logStr = "Log: ${log.toString()}";
@@ -129,3 +136,33 @@ abstract class Logger {
129136
}
130137
}
131138
}
139+
140+
/// basic async queue for writing logs in the [Logging] to isar
141+
class _AsyncLogWriterQueue {
142+
final List<Future<void> Function()> _queue = [];
143+
bool _runningLock = false;
144+
145+
void add(Future<void> Function() futureFunction) {
146+
_queue.add(futureFunction);
147+
_run();
148+
}
149+
150+
void _run() async {
151+
if (_runningLock) {
152+
return;
153+
}
154+
_runningLock = true;
155+
try {
156+
while (_queue.isNotEmpty) {
157+
final futureFunction = _queue.removeAt(0);
158+
try {
159+
await futureFunction.call();
160+
} catch (e, s) {
161+
debugPrint("$e\n$s");
162+
}
163+
}
164+
} finally {
165+
_runningLock = false;
166+
}
167+
}
168+
}

lib/wallets/wallet/impl/wownero_wallet.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:cw_core/wallet_credentials.dart';
1212
import 'package:cw_core/wallet_info.dart';
1313
import 'package:cw_core/wallet_type.dart';
1414
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
15+
import 'package:cw_wownero/api/account_list.dart';
1516
import 'package:cw_wownero/pending_wownero_transaction.dart';
1617
import 'package:cw_wownero/wownero_wallet.dart';
1718
import 'package:decimal/decimal.dart';
@@ -20,6 +21,7 @@ import 'package:flutter_libmonero/view_model/send/output.dart'
2021
as wownero_output;
2122
import 'package:flutter_libmonero/wownero/wownero.dart' as wow_dart;
2223
import 'package:isar/isar.dart';
24+
import 'package:monero/wownero.dart' as wownerodart;
2325
import 'package:mutex/mutex.dart';
2426
import 'package:tuple/tuple.dart';
2527

@@ -383,19 +385,11 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
383385
_walletCreationService.type = WalletType.wownero;
384386
// To restore from a seed
385387
final wallet = await _walletCreationService.create(credentials);
386-
//
387-
// final bufferedCreateHeight = (seedWordsLength == 14)
388-
// ? getSeedHeightSync(wallet?.seed.trim() as String)
389-
// : wownero.getHeightByDate(
390-
// date: DateTime.now().subtract(const Duration(
391-
// days:
392-
// 2))); // subtract a couple days to ensure we have a buffer for SWB
393-
// TODO(mrcyjanek): implement
394-
const bufferedCreateHeight =
395-
1; //getSeedHeightSync(wallet!.seed.trim());
388+
389+
final height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!);
396390

397391
await info.updateRestoreHeight(
398-
newRestoreHeight: bufferedCreateHeight,
392+
newRestoreHeight: height,
399393
isar: mainDB.isar,
400394
);
401395

@@ -410,7 +404,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
410404
value: "",
411405
);
412406

413-
walletInfo.restoreHeight = bufferedCreateHeight;
407+
walletInfo.restoreHeight = height;
414408

415409
walletInfo.address = wallet.walletAddresses.address;
416410
await DB.instance
@@ -515,8 +509,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
515509

516510
// extract seed height from 14 word seed
517511
if (seedLength == 14) {
518-
// TODO(mrcyjanek): implement
519-
height = 1; // getSeedHeightSync(mnemonic.trim());
512+
height = 0;
520513
} else {
521514
height = max(height, 0);
522515
}
@@ -563,7 +556,13 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
563556
// To restore from a seed
564557
final wallet = await cwWalletCreationService
565558
.restoreFromSeed(credentials) as WowneroWalletBase;
559+
height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!);
566560
walletInfo.address = wallet.walletAddresses.address;
561+
walletInfo.restoreHeight = height;
562+
await info.updateRestoreHeight(
563+
newRestoreHeight: height,
564+
isar: mainDB.isar,
565+
);
567566
await DB.instance
568567
.add<WalletInfo>(boxName: WalletInfo.boxName, value: walletInfo);
569568
CwBasedInterface.cwWalletBase?.close();

0 commit comments

Comments
 (0)