index.dart 2.3 KB

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