From 08808a59d111a6f6a4a8ea70b297e25775d1ead3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Olav?= Date: Mon, 9 Sep 2024 09:45:58 +0200 Subject: [PATCH] sail/zcash/cast: set execute time of new bills in the future prior to this change, we executed and recreated bills in a loop --- packages/sidesail/lib/providers/cast_provider.dart | 14 ++++++++------ packages/sidesail/lib/rpc/rpc_zcash.dart | 4 ++-- packages/sidesail/macos/Runner/AppDelegate.swift | 2 +- packages/sidesail/pubspec.lock | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/sidesail/lib/providers/cast_provider.dart b/packages/sidesail/lib/providers/cast_provider.dart index b7088cc4..ad88dc84 100644 --- a/packages/sidesail/lib/providers/cast_provider.dart +++ b/packages/sidesail/lib/providers/cast_provider.dart @@ -26,7 +26,7 @@ class PendingCastBill { required this.executeAction, }) { DateTime now = DateTime.now().toUtc(); - executeTime = DateTime.utc(now.year, now.month, now.day); + executeTime = DateTime.utc(now.year, now.month, now.day + 1); int weekday; @@ -113,7 +113,7 @@ class CastProvider extends ChangeNotifier { for (int i = 1; i <= maxCastFactor; i++) { final newBundle = PendingCastBill( powerOf: i, - executeAction: () => _executeCast(i), + executeAction: () => _executeCast(i, 0), ); log.d( @@ -152,7 +152,9 @@ class CastProvider extends ChangeNotifier { } } - void _executeCast(int powerOf) async { + void _executeCast(int powerOf, int iteration) async { + print('execute cast $iteration'); + try { final bundle = futureCasts.elementAt(powerOf); log.t('executing powerOf=${bundle.powerOf} with amount=${bundle.castAmount}'); @@ -164,13 +166,13 @@ class CastProvider extends ChangeNotifier { final newBill = PendingCastBill( powerOf: bundle.powerOf, - executeAction: () => _executeCast(powerOf), + executeAction: () => _executeCast(powerOf, iteration + 1), ); futureCasts[bundle.powerOf] = newBill; - log.t('recreated next bundle to be executed at ${newBill.executeTime} arraySize=${futureCasts.length}'); + print('recreated next bundle to be executed at ${newBill.executeTime} arraySize=${futureCasts.length}'); + await Future.delayed(const Duration(seconds: 1), () {}); await _zcashProvider.fetch(); - notifyListeners(); } catch (error) { log.e('could not cast ${error.toString()}'); } diff --git a/packages/sidesail/lib/rpc/rpc_zcash.dart b/packages/sidesail/lib/rpc/rpc_zcash.dart index 87d64611..b2d3a1c2 100644 --- a/packages/sidesail/lib/rpc/rpc_zcash.dart +++ b/packages/sidesail/lib/rpc/rpc_zcash.dart @@ -171,7 +171,7 @@ class ZcashRPCLive extends ZCashRPC { } Future _balanceForAccount(int account, int confirmations) async { - final saplingBalance = await _client.call().call('z_getbalanceforaccount', [account, confirmations]).then( + final saplingBalance = await _client().call('z_getbalanceforaccount', [account, confirmations]).then( (res) { final pools = res['pools']; num zBalanceSat = 0; @@ -200,7 +200,7 @@ class ZcashRPCLive extends ZCashRPC { // z_listaddresses. final addresses = await _client().call('z_listaddresses') as List; for (final address in addresses) { - final addressBalance = await _client.call().call('z_getbalance', [address, confirmations]); + final addressBalance = await _client().call('z_getbalance', [address, confirmations]); balance += addressBalance; } diff --git a/packages/sidesail/macos/Runner/AppDelegate.swift b/packages/sidesail/macos/Runner/AppDelegate.swift index d53ef643..8e02df28 100644 --- a/packages/sidesail/macos/Runner/AppDelegate.swift +++ b/packages/sidesail/macos/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true diff --git a/packages/sidesail/pubspec.lock b/packages/sidesail/pubspec.lock index 4526c99c..34399492 100644 --- a/packages/sidesail/pubspec.lock +++ b/packages/sidesail/pubspec.lock @@ -1079,5 +1079,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.5.0-259.0.dev <4.0.0" flutter: ">=3.22.0"