mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-25 08:39:06 +00:00
Sync status
This commit is contained in:
parent
9e9ff7095e
commit
a3aebbdb78
7 changed files with 27 additions and 19 deletions
|
@ -3,6 +3,7 @@ import 'package:bitcoin_base/bitcoin_base.dart';
|
|||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/sync_status.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_bitcoin/litecoin_wallet_addresses.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
|
@ -109,12 +110,23 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
@action
|
||||
@override
|
||||
Future<void> startSync() async {
|
||||
super.startSync();
|
||||
await super.startSync();
|
||||
final stub = CwMweb.stub();
|
||||
Timer.periodic(
|
||||
const Duration(seconds: 1), (timer) async {
|
||||
const Duration(milliseconds: 1500), (timer) async {
|
||||
final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
final resp = await stub.status(StatusRequest());
|
||||
print(resp.blockHeaderHeight);
|
||||
if (resp.blockHeaderHeight < height) {
|
||||
int h = resp.blockHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(height - h, h / height);
|
||||
} else if (resp.mwebHeaderHeight < height) {
|
||||
int h = resp.mwebHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(height - h, h / height);
|
||||
} else if (resp.mwebUtxosHeight < height) {
|
||||
syncStatus = SyncingSyncStatus(1, 0.999);
|
||||
} else {
|
||||
syncStatus = SyncedSyncStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
1
cw_mweb/.gitignore
vendored
1
cw_mweb/.gitignore
vendored
|
@ -28,4 +28,3 @@ migrate_working_dir/
|
|||
.dart_tool/
|
||||
.packages
|
||||
build/
|
||||
libs/
|
||||
|
|
1
cw_mweb/android/.gitignore
vendored
1
cw_mweb/android/.gitignore
vendored
|
@ -6,4 +6,5 @@
|
|||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/libs
|
||||
.cxx
|
||||
|
|
|
@ -17,7 +17,6 @@ class CwMwebPlugin: FlutterPlugin, MethodCallHandler {
|
|||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
|
||||
/// when the Flutter Engine is detached from the Activity
|
||||
private lateinit var channel : MethodChannel
|
||||
private var started = false
|
||||
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "cw_mweb")
|
||||
|
@ -26,12 +25,8 @@ class CwMwebPlugin: FlutterPlugin, MethodCallHandler {
|
|||
|
||||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
||||
if (call.method == "start") {
|
||||
if (started) return
|
||||
val dataDir = call.argument("dataDir") ?: ""
|
||||
val server = Mwebd.newServer("mainnet", dataDir, "")
|
||||
server.start(12345, true)
|
||||
started = true
|
||||
result.success(true)
|
||||
result.success(Mwebd.newServer("", dataDir, "").start(0))
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
|
|
|
@ -3,15 +3,16 @@ import 'cw_mweb_platform_interface.dart';
|
|||
import 'mwebd.pbgrpc.dart';
|
||||
|
||||
class CwMweb {
|
||||
static Future<bool?> start(String dataDir) {
|
||||
return CwMwebPlatform.instance.start(dataDir);
|
||||
static var port;
|
||||
|
||||
static start(String dataDir) async {
|
||||
port = port ?? await CwMwebPlatform.instance.start(dataDir);
|
||||
}
|
||||
|
||||
static stub() {
|
||||
final channel = ClientChannel('127.0.0.1',
|
||||
port: 12345,
|
||||
return RpcClient(ClientChannel('127.0.0.1',
|
||||
port: port,
|
||||
options: const ChannelOptions(
|
||||
credentials: ChannelCredentials.insecure()));
|
||||
return RpcClient(channel);
|
||||
credentials: ChannelCredentials.insecure())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ class MethodChannelCwMweb extends CwMwebPlatform {
|
|||
final methodChannel = const MethodChannel('cw_mweb');
|
||||
|
||||
@override
|
||||
Future<bool?> start(String dataDir) async {
|
||||
final result = await methodChannel.invokeMethod<bool>('start', {'dataDir': dataDir});
|
||||
Future<int?> start(String dataDir) async {
|
||||
final result = await methodChannel.invokeMethod<int>('start', {'dataDir': dataDir});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract class CwMwebPlatform extends PlatformInterface {
|
|||
_instance = instance;
|
||||
}
|
||||
|
||||
Future<bool?> start(String dataDir) {
|
||||
Future<int?> start(String dataDir) {
|
||||
throw UnimplementedError('start() has not been implemented.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue