apiAssets.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/api/api.dart';
  3. import 'package:polkawallet_sdk/api/types/balanceData.dart';
  4. import 'package:polkawallet_sdk/plugin/store/balances.dart';
  5. import 'package:polkawallet_sdk/service/assets.dart';
  6. class ApiAssets {
  7. ApiAssets(this.apiRoot, this.service);
  8. final PolkawalletApi apiRoot;
  9. final ServiceAssets service;
  10. Future<List<TokenBalanceData>> getAssetsAll() async {
  11. final List res = await (service.getAssetsAll() as FutureOr<List<dynamic>>);
  12. return res
  13. .map((e) => TokenBalanceData(
  14. id: e['id'].toString(),
  15. name: e['symbol'],
  16. fullName: e['name'],
  17. symbol: e['symbol'],
  18. decimals: int.parse(e['decimals']),
  19. ))
  20. .toList();
  21. }
  22. Future<List<AssetsBalanceData>> queryAssetsBalances(
  23. List<String> ids, String address) async {
  24. final res = await service.queryAssetsBalances(ids, address);
  25. return res
  26. .asMap()
  27. .map((k, v) {
  28. final e = v ?? {};
  29. e['id'] = ids[k];
  30. return MapEntry(k,
  31. v != null ? AssetsBalanceData.fromJson(e) : AssetsBalanceData());
  32. })
  33. .values
  34. .toList();
  35. }
  36. }