From dbc005dcf3a704b922d77af7c42c1530d773c4ba Mon Sep 17 00:00:00 2001 From: Hector Chu Date: Sun, 21 Apr 2024 19:58:45 +0100 Subject: [PATCH] Fix stub creation --- cw_bitcoin/lib/litecoin_wallet.dart | 2 +- cw_bitcoin/lib/litecoin_wallet_service.dart | 6 ------ cw_mweb/lib/cw_mweb.dart | 13 ++++++------- cw_mweb/pubspec.yaml | 2 ++ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index 628391eed..b6b996b27 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -111,7 +111,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { @override Future startSync() async { await super.startSync(); - final stub = CwMweb.stub(); + final stub = await CwMweb.stub(); Timer.periodic( const Duration(milliseconds: 1500), (timer) async { final height = await electrumClient.getCurrentBlockChainTip() ?? 0; diff --git a/cw_bitcoin/lib/litecoin_wallet_service.dart b/cw_bitcoin/lib/litecoin_wallet_service.dart index 7f2066c30..ee3b0e628 100644 --- a/cw_bitcoin/lib/litecoin_wallet_service.dart +++ b/cw_bitcoin/lib/litecoin_wallet_service.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'package:path_provider/path_provider.dart'; import 'package:cw_core/unspent_coins_info.dart'; import 'package:hive/hive.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; @@ -11,7 +10,6 @@ import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_base.dart'; -import 'package:cw_mweb/cw_mweb.dart'; import 'package:collection/collection.dart'; class LitecoinWalletService extends WalletService< @@ -28,8 +26,6 @@ class LitecoinWalletService extends WalletService< @override Future create(BitcoinNewWalletCredentials credentials, {bool? isTestnet}) async { - final appDir = await getApplicationSupportDirectory(); - await CwMweb.start(appDir.path); final wallet = await LitecoinWalletBase.create( mnemonic: await generateMnemonic(), password: credentials.password!, @@ -47,8 +43,6 @@ class LitecoinWalletService extends WalletService< @override Future openWallet(String name, String password) async { - final appDir = await getApplicationSupportDirectory(); - await CwMweb.start(appDir.path); final walletInfo = walletInfoSource.values.firstWhereOrNull( (info) => info.id == WalletBase.idFor(name, getType()))!; diff --git a/cw_mweb/lib/cw_mweb.dart b/cw_mweb/lib/cw_mweb.dart index fb3960ab0..a54295673 100644 --- a/cw_mweb/lib/cw_mweb.dart +++ b/cw_mweb/lib/cw_mweb.dart @@ -1,17 +1,16 @@ import 'package:grpc/grpc.dart'; +import 'package:path_provider/path_provider.dart'; import 'cw_mweb_platform_interface.dart'; import 'mwebd.pbgrpc.dart'; class CwMweb { - static var port; + static Future? port; - static start(String dataDir) async { - port = port ?? await CwMwebPlatform.instance.start(dataDir); - } - - static stub() { + static Future stub() async { + final appDir = await getApplicationSupportDirectory(); + port ??= CwMwebPlatform.instance.start(appDir.path); return RpcClient(ClientChannel('127.0.0.1', - port: port, + port: await port ?? 0, options: const ChannelOptions( credentials: ChannelCredentials.insecure()))); } diff --git a/cw_mweb/pubspec.yaml b/cw_mweb/pubspec.yaml index 5416963d8..cfe43c70b 100644 --- a/cw_mweb/pubspec.yaml +++ b/cw_mweb/pubspec.yaml @@ -10,6 +10,8 @@ environment: dependencies: flutter: sdk: flutter + grpc: ^3.2.4 + path_provider: ^2.1.2 plugin_platform_interface: ^2.0.2 dev_dependencies: