accountEth.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'dart:convert';
  2. import 'package:http/http.dart';
  3. import 'package:polkawallet_sdk/service/index.dart';
  4. class ServiceAccountEth {
  5. ServiceAccountEth(this.serviceRoot);
  6. final SubstrateService serviceRoot;
  7. /// Get icons of addresses
  8. /// return svg strings
  9. Future<List?> getAddressIcons(List addresses) async {
  10. final dynamic res = await serviceRoot.webView!
  11. .evalJavascript('eth.account.genIcons(${jsonEncode(addresses)})');
  12. return res;
  13. }
  14. Future<String> getNativeTokenBalance(String address) async {
  15. final String? res = await serviceRoot.webView!
  16. .evalJavascript('eth.account.getEthBalance("$address")');
  17. return res ?? '0';
  18. }
  19. Future<List?> getTokenBalance(
  20. String address, List<String> contractAddresses) async {
  21. final List? res = await serviceRoot.webView!.evalJavascript(
  22. 'eth.account.getTokenBalance("$address", ${jsonEncode(contractAddresses)})');
  23. return res;
  24. }
  25. /// Validate address
  26. /// return checksumed address or null
  27. Future<String?> getAddress(String address) async {
  28. final String? res = await serviceRoot.webView!
  29. .evalJavascript('eth.account.getAddress("$address")');
  30. return res;
  31. }
  32. Future<Map> queryEthGasParams() async {
  33. const url =
  34. 'https://gas-api.metaswap.codefi.network/networks/1/suggestedGasFees';
  35. final res = await get(Uri.parse(url));
  36. return jsonDecode(res.body);
  37. }
  38. }
  39. const postHeaders = {"Content-type": "application/json", "Accept": "*/*"};