From faa20406663d3fbd441763be51bca96d786a1ee3 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Thu, 30 May 2024 11:02:57 -0700 Subject: [PATCH] [skip ci] path fixes --- cw_lightning/lib/lightning_wallet.dart | 39 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/cw_lightning/lib/lightning_wallet.dart b/cw_lightning/lib/lightning_wallet.dart index daae6e038..bccc7999e 100644 --- a/cw_lightning/lib/lightning_wallet.dart +++ b/cw_lightning/lib/lightning_wallet.dart @@ -149,6 +149,22 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { ); } + Future _handleNodeState(NodeState? nodeState) async { + if (nodeState == null) return; + _balance[CryptoCurrency.btcln] = LightningBalance( + confirmed: nodeState.maxPayableMsat ~/ 1000, + unconfirmed: nodeState.maxReceivableMsat ~/ 1000, + frozen: 0, + ); + } + + Future _handlePayments(List payments) async { + _isTransactionUpdating = true; + final txs = convertToTxInfo(payments); + transactionHistory.addMany(txs); + _isTransactionUpdating = false; + } + Future setupBreez(Uint8List seedBytes) async { final sdk = await BreezSDK(); try { @@ -179,8 +195,9 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { nodeConfig: breezNodeConfig, ); - String workingDir = (await getApplicationDocumentsDirectory()).path; - workingDir = "$workingDir/wallets/lightning/${walletInfo.address}/breez/"; + String workingDir = await pathForWalletDir(name: walletInfo.name, type: type); + workingDir = "$workingDir/breez"; + new Directory(workingDir).createSync(recursive: true); breezConfig = breezConfig.copyWith(workingDir: workingDir); @@ -204,21 +221,17 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { print("Error connecting to Breez: $e\n$s"); } + _nodeStateSub?.cancel(); _nodeStateSub = sdk.nodeStateStream.listen((event) { - if (event == null) return; - _balance[CryptoCurrency.btcln] = LightningBalance( - confirmed: event.maxPayableMsat ~/ 1000, - unconfirmed: event.maxReceivableMsat ~/ 1000, - frozen: 0, - ); + _handleNodeState(event); }); + await _handleNodeState(await sdk.nodeInfo()); - _paymentsSub = sdk.paymentsStream.listen((payments) { - _isTransactionUpdating = true; - final txs = convertToTxInfo(payments); - transactionHistory.addMany(txs); - _isTransactionUpdating = false; + _paymentsSub?.cancel(); + _paymentsSub = sdk.paymentsStream.listen((List payments) { + _handlePayments(payments); }); + await _handlePayments(await sdk.listPayments(req: ListPaymentsRequest())); // TODO: get actual nds service url: // if (Platform.isAndroid || Platform.isIOS) {