apiAssets.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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());
  12. if (res == null) {
  13. return [];
  14. }
  15. return res
  16. .map((e) => TokenBalanceData(
  17. id: e['id'].toString(),
  18. name: e['symbol'],
  19. fullName: e['name'],
  20. symbol: e['symbol'],
  21. decimals: int.parse(e['decimals']),
  22. ))
  23. .toList();
  24. }
  25. Future<List<AssetsBalanceData>> queryAssetsBalances(
  26. List<String> ids, String address) async {
  27. final res = await service.queryAssetsBalances(ids, address);
  28. return res
  29. .asMap()
  30. .map((k, v) {
  31. final e = v ?? {};
  32. e['id'] = ids[k];
  33. return MapEntry(k,
  34. v != null ? AssetsBalanceData.fromJson(e) : AssetsBalanceData());
  35. })
  36. .values
  37. .toList();
  38. }
  39. }