tx.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:polkawallet_sdk/service/index.dart';
  4. class ServiceTx {
  5. ServiceTx(this.serviceRoot);
  6. final SubstrateService serviceRoot;
  7. Future<Map?> estimateFees(Map txInfo, String params, {String? jsApi}) async {
  8. dynamic res = await serviceRoot.webView!.evalJavascript(
  9. 'keyring.txFeeEstimate(${jsApi ?? 'api'}, ${jsonEncode(txInfo)}, $params)',
  10. );
  11. return res;
  12. }
  13. // Future<dynamic> _testSendTx() async {
  14. // Completer c = new Completer();
  15. // void onComplete(res) {
  16. // c.complete(res);
  17. // }
  18. //
  19. // Timer(Duration(seconds: 6), () => onComplete({'hash': '0x79867'}));
  20. // return c.future;
  21. // }
  22. Future<Map?> signAndSend(Map txInfo, String params, password,
  23. Function(String) onStatusChange) async {
  24. final msgId =
  25. "onStatusChange${serviceRoot.webView!.getEvalJavascriptUID()}";
  26. serviceRoot.webView!.addMsgHandler(msgId, onStatusChange);
  27. final code =
  28. 'keyring.sendTx(api, ${jsonEncode(txInfo)}, $params, "$password", "$msgId")';
  29. // print(code);
  30. final dynamic res = await serviceRoot.webView!.evalJavascript(code);
  31. serviceRoot.webView!.removeMsgHandler(msgId);
  32. return res;
  33. }
  34. }