apiWalletConnect.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:polkawallet_sdk/api/api.dart';
  2. import 'package:polkawallet_sdk/api/types/walletConnect/pairingData.dart';
  3. import 'package:polkawallet_sdk/api/types/walletConnect/payloadData.dart';
  4. import 'package:polkawallet_sdk/service/walletConnect.dart';
  5. class ApiWalletConnect {
  6. ApiWalletConnect(this.apiRoot, this.service);
  7. final PolkawalletApi apiRoot;
  8. final ServiceWalletConnect service;
  9. void initClient(
  10. String uri,
  11. String address,
  12. int chainId, {
  13. required Function(WCPeerMetaData) onPairing,
  14. required Function(Map) onPaired,
  15. required Function(WCCallRequestData) onCallRequest,
  16. required Function(String) onDisconnect,
  17. Map? cachedSession,
  18. }) {
  19. service.initClient(uri, address, chainId, onPairing: (Map peerMeta) {
  20. onPairing(WCPeerMetaData.fromJson(peerMeta));
  21. }, onPaired: (Map session) {
  22. onPaired(session);
  23. }, onCallRequest: (Map payload) {
  24. onCallRequest(WCCallRequestData.fromJson(payload));
  25. }, onDisconnect: (uri) {
  26. onDisconnect(uri);
  27. }, cachedSession: cachedSession);
  28. }
  29. Future<void> disconnect() async {
  30. await service.disconnect();
  31. }
  32. Future<void> confirmPairing(bool approve) async {
  33. await service.confirmPairing(approve);
  34. }
  35. Future<WCCallRequestResult?> confirmPayload(
  36. int id, bool approve, String password, Map gasOptions) async {
  37. final res = await service.confirmPayload(id, approve, password, gasOptions);
  38. return WCCallRequestResult.fromJson(res);
  39. }
  40. Future<void> changeAccount(String address) async {
  41. await service.changeAccount(address);
  42. }
  43. Future<void> changeNetwork(int chainId, String address) async {
  44. await service.changeNetwork(chainId, address);
  45. }
  46. }