gov.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:polkawallet_sdk/service/index.dart';
  4. class ServiceGov {
  5. ServiceGov(this.serviceRoot);
  6. final SubstrateService serviceRoot;
  7. Future<List?> getDemocracyUnlocks(String address) async {
  8. final dynamic res = await serviceRoot.webView!
  9. .evalJavascript('gov.getDemocracyUnlocks(api, "$address")');
  10. return res;
  11. }
  12. Future<List?> getExternalLinks(Map params) async {
  13. final dynamic res = await serviceRoot.webView!
  14. .evalJavascript('settings.genLinks(api, ${jsonEncode(params)})');
  15. return res;
  16. }
  17. Future<List?> getReferendumVoteConvictions() async {
  18. final dynamic res = await serviceRoot.webView!
  19. .evalJavascript('gov.getReferendumVoteConvictions(api)');
  20. return res;
  21. }
  22. Future<List> queryReferendums(String address) async {
  23. final dynamic data = await serviceRoot.webView!
  24. .evalJavascript('gov.fetchReferendums(api, "$address")');
  25. if (data != null) {
  26. final List list = data['referendums'];
  27. list.asMap().forEach((k, v) {
  28. v['detail'] = data['details'][k];
  29. });
  30. return list;
  31. }
  32. return [];
  33. }
  34. Future<List?> queryProposals() async {
  35. final dynamic data =
  36. await serviceRoot.webView!.evalJavascript('gov.fetchProposals(api)');
  37. return data;
  38. }
  39. Future<Map?> queryNextExternal() async {
  40. final data =
  41. await serviceRoot.webView!.evalJavascript('gov.fetchExternal(api)');
  42. return data;
  43. }
  44. Future<Map?> queryTreasuryProposal(String id) async {
  45. final dynamic data = await serviceRoot.webView!
  46. .evalJavascript('api.query.treasury.proposals($id)');
  47. return data;
  48. }
  49. Future<Map?> queryCouncilVotes() async {
  50. final dynamic votes =
  51. await serviceRoot.webView!.evalJavascript('gov.fetchCouncilVotes(api)');
  52. return votes;
  53. }
  54. Future<Map?> queryUserCouncilVote(String address) async {
  55. final dynamic votes = await serviceRoot.webView!
  56. .evalJavascript('api.derive.council.votesOf("$address")');
  57. return votes;
  58. }
  59. Future<Map?> queryCouncilInfo() async {
  60. final dynamic info = await serviceRoot.webView!
  61. .evalJavascript('api.derive.elections.info()');
  62. return info;
  63. }
  64. Future<List?> queryCouncilMotions() async {
  65. final dynamic data =
  66. await serviceRoot.webView!.evalJavascript('gov.getCouncilMotions(api)');
  67. return data;
  68. }
  69. Future<Map?> queryTreasuryOverview() async {
  70. final dynamic data = await serviceRoot.webView!
  71. .evalJavascript('gov.getTreasuryOverview(api)');
  72. return data;
  73. }
  74. Future<List?> queryTreasuryTips() async {
  75. final dynamic data =
  76. await serviceRoot.webView!.evalJavascript('gov.getTreasuryTips(api)');
  77. return data;
  78. }
  79. Future<List?> queryDemocracyLocks(String address) async {
  80. final dynamic data = await serviceRoot.webView!
  81. .evalJavascript('api.derive.democracy.locks("$address")');
  82. return data;
  83. }
  84. }