forked from polkawallet-io/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiAssets.dart
54 lines (47 loc) · 1.3 KB
/
apiAssets.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:app/service/index.dart';
import 'package:app/service/walletApi.dart';
class ApiAssets {
ApiAssets(this.apiRoot);
final AppService apiRoot;
Future<Map> updateTxs(int page) async {
final acc = apiRoot.keyring.current;
Map res = await apiRoot.subScan.fetchTransfersAsync(
acc.address,
page,
network: apiRoot.plugin.basic.name,
);
if (page == 0) {
apiRoot.store.assets.clearTxs();
}
// cache first page of txs
await apiRoot.store.assets.addTxs(
res,
acc,
apiRoot.plugin.basic.name,
shouldCache: page == 0,
);
return res;
}
Future<void> fetchMarketPrices() async {
final res = await Future.wait([
WalletApi.getTokenPrices(),
WalletApi.getTokenPriceFromSubScan(apiRoot.plugin.basic.name)
]);
final Map<String, double> prices = {
'KUSD': 1.0,
'AUSD': 1.0,
'USDT': 1.0,
};
if (res[1]['data'] != null) {
final tokenData = res[1]['data']['detail'] as Map;
prices.addAll({
tokenData.keys.toList()[0]:
double.tryParse(tokenData.values.toList()[0]['price'].toString())
});
}
if (res[0]['prices'] != null) {
prices.addAll(Map<String, double>.from(res[0]['prices']));
}
apiRoot.store.assets.setMarketPrices(prices);
}
}