recovery.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/service/index.dart';
  3. class ServiceRecovery {
  4. ServiceRecovery(this.serviceRoot);
  5. final SubstrateService serviceRoot;
  6. Future<Map?> queryRecoverable(String address) async {
  7. // address = "J4sW13h2HNerfxTzPGpLT66B3HVvuU32S6upxwSeFJQnAzg";
  8. dynamic res = await serviceRoot.webView!
  9. .evalJavascript('api.query.recovery.recoverable("$address")');
  10. if (res != null) {
  11. res['address'] = address;
  12. }
  13. return res;
  14. }
  15. Future<List> queryRecoverableList(List<String> addresses) async {
  16. final queries =
  17. addresses.map((e) => 'api.query.recovery.recoverable("$e")').toList();
  18. final dynamic ls = await serviceRoot.webView!
  19. .evalJavascript('Promise.all([${queries.join(',')}])');
  20. final res = [];
  21. ls.asMap().forEach((k, v) {
  22. if (v != null) {
  23. v['address'] = addresses[k];
  24. }
  25. res.add(v);
  26. });
  27. return res;
  28. }
  29. Future<List?> queryActiveRecoveryAttempts(
  30. String address, List<String> addressNew) async {
  31. List queries = addressNew
  32. .map((e) => 'api.query.recovery.activeRecoveries("$address", "$e")')
  33. .toList();
  34. final res = await serviceRoot.webView!
  35. .evalJavascript('Promise.all([${queries.join(',')}])');
  36. return res;
  37. }
  38. Future<List?> queryActiveRecoveries(
  39. List<String> addresses, String addressNew) async {
  40. List queries = addresses
  41. .map((e) => 'api.query.recovery.activeRecoveries("$e", "$addressNew")')
  42. .toList();
  43. final res = await serviceRoot.webView!
  44. .evalJavascript('Promise.all([${queries.join(',')}])');
  45. return res;
  46. }
  47. Future<List?> queryRecoveryProxies(List<String> addresses) async {
  48. List queries =
  49. addresses.map((e) => 'api.query.recovery.proxy("$e")').toList();
  50. final res = await serviceRoot.webView!.evalJavascript(
  51. 'Promise.all([${queries.join(',')}])',
  52. allowRepeat: true,
  53. );
  54. return res;
  55. }
  56. }