setting.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/service/index.dart';
  3. class ServiceSetting {
  4. ServiceSetting(this.serviceRoot);
  5. final SubstrateService serviceRoot;
  6. Future<Map?> queryNetwork() async {
  7. // fetch network info
  8. List res = await serviceRoot.webView!.evalJavascript(
  9. 'Promise.all([settings.getNetworkProperties(api),api.rpc.system.chain(),settings.getNetworkConst(api)])');
  10. if (res[0] == null || res[1] == null || res[2] == null) {
  11. return null;
  12. }
  13. final Map props = {"props": res[0], "const": res[2]};
  14. props["props"]['name'] = res[1];
  15. return props;
  16. }
  17. Future<Map> queryNetworkConst() async {
  18. final dynamic res = await serviceRoot.webView!
  19. .evalJavascript('settings.getNetworkConst(api)');
  20. return res;
  21. }
  22. Future<Map?> queryNetworkProps() async {
  23. // fetch network info
  24. List res = await serviceRoot.webView!.evalJavascript(
  25. 'Promise.all([settings.getNetworkProperties(api), api.rpc.system.chain()])');
  26. if (res[0] == null || res[1] == null) {
  27. return null;
  28. }
  29. final Map props = res[0];
  30. props['name'] = res[1];
  31. return props;
  32. }
  33. }