apiGov.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/api/api.dart';
  3. import 'package:polkawallet_sdk/api/types/gov/genExternalLinksParams.dart';
  4. import 'package:polkawallet_sdk/api/types/gov/proposalInfoData.dart';
  5. import 'package:polkawallet_sdk/api/types/gov/referendumInfoData.dart';
  6. import 'package:polkawallet_sdk/api/types/gov/treasuryOverviewData.dart';
  7. import 'package:polkawallet_sdk/api/types/gov/treasuryTipData.dart';
  8. import 'package:polkawallet_sdk/service/gov.dart';
  9. class ApiGov {
  10. ApiGov(this.apiRoot, this.service);
  11. final PolkawalletApi apiRoot;
  12. final ServiceGov service;
  13. Future<List?> getDemocracyUnlocks(String address) async {
  14. final List? res = await service.getDemocracyUnlocks(address);
  15. return res;
  16. }
  17. Future<List?> getExternalLinks(GenExternalLinksParams params) async {
  18. final List? res = await service.getExternalLinks(params.toJson());
  19. return res;
  20. }
  21. Future<List?> getReferendumVoteConvictions() async {
  22. final List? res = await service.getReferendumVoteConvictions();
  23. return res;
  24. }
  25. Future<List<ReferendumInfo>> queryReferendums(String address) async {
  26. final List data = await service.queryReferendums(address);
  27. if (data.length > 0) {
  28. return data
  29. .map((e) => ReferendumInfo.fromJson(Map<String, dynamic>.of(e)))
  30. .toList();
  31. }
  32. return [];
  33. }
  34. Future<List<ProposalInfoData>> queryProposals() async {
  35. final List data = await (service.queryProposals()) ?? [];
  36. return data
  37. .map((e) => ProposalInfoData.fromJson(Map<String, dynamic>.of(e)))
  38. .toList();
  39. }
  40. Future<ProposalInfoData?> queryNextExternal() async {
  41. final Map? data = await service.queryNextExternal();
  42. return data == null
  43. ? null
  44. : ProposalInfoData.fromJson(Map<String, dynamic>.from(data));
  45. }
  46. Future<Map?> queryTreasuryProposal(String id) async {
  47. final Map? data = await service.queryTreasuryProposal(id);
  48. return data;
  49. }
  50. Future<Map?> queryCouncilVotes() async {
  51. final Map? votes = await service.queryCouncilVotes();
  52. return votes;
  53. }
  54. Future<Map?> queryUserCouncilVote(String address) async {
  55. final Map? votes = await service.queryUserCouncilVote(address);
  56. return votes;
  57. }
  58. Future<Map?> queryCouncilInfo() async {
  59. final Map? info = await service.queryCouncilInfo();
  60. return info;
  61. }
  62. Future<List<CouncilMotionData>> queryCouncilMotions() async {
  63. final List? data = await service.queryCouncilMotions();
  64. if (data != null) {
  65. return data
  66. .map((e) => CouncilMotionData.fromJson(Map<String, dynamic>.of(e)))
  67. .toList();
  68. }
  69. return [];
  70. }
  71. Future<TreasuryOverviewData> queryTreasuryOverview() async {
  72. final Map? data = await service.queryTreasuryOverview();
  73. if (data != null) {
  74. return TreasuryOverviewData.fromJson(
  75. Map<String, dynamic>.of(data as Map<String, dynamic>));
  76. }
  77. return TreasuryOverviewData();
  78. }
  79. Future<List<TreasuryTipData>> queryTreasuryTips() async {
  80. final List? data = await service.queryTreasuryTips();
  81. if (data != null) {
  82. return data
  83. .map((e) => TreasuryTipData.fromJson(Map<String, dynamic>.of(e)))
  84. .toList();
  85. }
  86. return [];
  87. }
  88. Future<List?> getDemocracyLocks(String address) async {
  89. final List? res = await service.queryDemocracyLocks(address);
  90. return res;
  91. }
  92. }