apiSetting.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'package:polkawallet_sdk/api/api.dart';
  2. import 'package:polkawallet_sdk/api/types/networkStateData.dart';
  3. import 'package:polkawallet_sdk/service/setting.dart';
  4. class ApiSetting {
  5. ApiSetting(this.apiRoot, this.service);
  6. final PolkawalletApi apiRoot;
  7. final ServiceSetting? service;
  8. final _msgChannel = "BestNumber";
  9. /// query network const.
  10. Future<Map?> queryNetworkConst() async {
  11. final Map? res = await service!.queryNetworkConst();
  12. return res;
  13. }
  14. /// query network properties.
  15. Future<NetworkStateData?> queryNetworkProps() async {
  16. final Map? res = await service!.queryNetworkProps();
  17. if (res == null) {
  18. return null;
  19. }
  20. return NetworkStateData.fromJson(res as Map<String, dynamic>);
  21. }
  22. /// subscribe best number.
  23. /// @return [String] msgChannel, call unsubscribeMessage(msgChannel) to unsub.
  24. Future<void> subscribeBestNumber(Function callback) async {
  25. apiRoot.subscribeMessage(
  26. 'api.derive.chain.bestNumber',
  27. [],
  28. _msgChannel,
  29. callback,
  30. );
  31. }
  32. Future<void> unsubscribeBestNumber() async {
  33. apiRoot.service.webView!.unsubscribeMessage(_msgChannel);
  34. }
  35. }