index.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/api/api.dart';
  3. import 'package:polkawallet_sdk/service/account.dart';
  4. import 'package:polkawallet_sdk/service/assets.dart';
  5. import 'package:polkawallet_sdk/service/eth/index.dart';
  6. import 'package:polkawallet_sdk/service/gov.dart';
  7. import 'package:polkawallet_sdk/service/keyring.dart';
  8. import 'package:polkawallet_sdk/service/parachain.dart';
  9. import 'package:polkawallet_sdk/service/recovery.dart';
  10. import 'package:polkawallet_sdk/service/setting.dart';
  11. import 'package:polkawallet_sdk/service/staking.dart';
  12. import 'package:polkawallet_sdk/service/tx.dart';
  13. import 'package:polkawallet_sdk/service/uos.dart';
  14. import 'package:polkawallet_sdk/service/walletConnect.dart';
  15. import 'package:polkawallet_sdk/service/webViewRunner.dart';
  16. import 'package:polkawallet_sdk/storage/keyring.dart';
  17. /// The service calling JavaScript API of `polkadot-js/api` directly
  18. /// through [WebViewRunner], providing APIs for [PolkawalletApi].
  19. class SubstrateService {
  20. late ServiceKeyring keyring;
  21. late ServiceSetting setting;
  22. late ServiceAccount account;
  23. late ServiceTx tx;
  24. late ServiceStaking staking;
  25. late ServiceGov gov;
  26. late ServiceParachain parachain;
  27. late ServiceAssets assets;
  28. late ServiceUOS uos;
  29. late ServiceRecovery recovery;
  30. late ServiceWalletConnect walletConnect;
  31. late ServiceEth eth;
  32. WebViewRunner? _web;
  33. WebViewRunner? get webView => _web;
  34. Future<void> init(
  35. Keyring keyringStorage, {
  36. WebViewRunner? webViewParam,
  37. Function? onInitiated,
  38. String? jsCode,
  39. Function? socketDisconnectedAction,
  40. }) async {
  41. keyring = ServiceKeyring(this);
  42. setting = ServiceSetting(this);
  43. account = ServiceAccount(this);
  44. tx = ServiceTx(this);
  45. staking = ServiceStaking(this);
  46. gov = ServiceGov(this);
  47. parachain = ServiceParachain(this);
  48. assets = ServiceAssets(this);
  49. uos = ServiceUOS(this);
  50. recovery = ServiceRecovery(this);
  51. walletConnect = ServiceWalletConnect(this);
  52. eth = ServiceEth(this);
  53. _web = webViewParam ?? WebViewRunner();
  54. await _web!.launch(keyring, keyringStorage, onInitiated,
  55. jsCode: jsCode, socketDisconnectedAction: socketDisconnectedAction);
  56. }
  57. }