Skip to content

Commit eb912ae

Browse files
takenagainCharlVS
authored andcommitted
add removed max maker vol models
1 parent c6f04b8 commit eb912ae

File tree

3 files changed

+52
-69
lines changed

3 files changed

+52
-69
lines changed

lib/mm2/mm2_api/mm2_api.dart

+2-69
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:convert';
33

44
import 'package:komodo_defi_types/komodo_defi_types.dart';
5+
import 'package:rational/rational.dart';
56
import 'package:web_dex/bloc/coins_bloc/coins_repo.dart';
67
import 'package:web_dex/mm2/mm2.dart';
78
import 'package:web_dex/mm2/mm2_api/mm2_api_nft.dart';
@@ -86,7 +87,7 @@ class Mm2Api {
8687
Future<String?> getBalance(String abbr) async {
8788
dynamic response;
8889
try {
89-
response = await _call(MyBalanceReq(coin: abbr));
90+
response = await _mm2.call(MyBalanceReq(coin: abbr));
9091
} catch (e, s) {
9192
log(
9293
'Error getting balance $abbr: ${e.toString()}',
@@ -113,74 +114,6 @@ class Mm2Api {
113114
return json['balance'];
114115
}
115116

116-
Future<MaxMakerVolResponse?> getMaxMakerVol(String abbr) async {
117-
dynamic response;
118-
try {
119-
response = await _call(MaxMakerVolRequest(coin: abbr));
120-
} catch (e, s) {
121-
log(
122-
'Error getting max maker vol $abbr: ${e.toString()}',
123-
path: 'api => getMaxMakerVol => _call',
124-
trace: s,
125-
isError: true,
126-
);
127-
return _fallbackToBalance(abbr);
128-
}
129-
130-
Map<String, dynamic> json;
131-
try {
132-
json = jsonDecode(response);
133-
} catch (e, s) {
134-
log(
135-
'Error parsing of max maker vol $abbr response: ${e.toString()}',
136-
path: 'api => getMaxMakerVol => jsonDecode',
137-
trace: s,
138-
isError: true,
139-
);
140-
return _fallbackToBalance(abbr);
141-
}
142-
143-
final error = json['error'];
144-
if (error != null) {
145-
log(
146-
'Error parsing of max maker vol $abbr response: ${error.toString()}',
147-
path: 'api => getMaxMakerVol => error',
148-
isError: true,
149-
);
150-
return _fallbackToBalance(abbr);
151-
}
152-
153-
try {
154-
return MaxMakerVolResponse.fromJson(json['result']);
155-
} catch (e, s) {
156-
log(
157-
'Error constructing MaxMakerVolResponse for $abbr: ${e.toString()}',
158-
path: 'api => getMaxMakerVol => fromJson',
159-
trace: s,
160-
isError: true,
161-
);
162-
return _fallbackToBalance(abbr);
163-
}
164-
}
165-
166-
Future<MaxMakerVolResponse?> _fallbackToBalance(String abbr) async {
167-
final balance = await getBalance(abbr);
168-
if (balance == null) {
169-
log(
170-
'Failed to retrieve balance for fallback construction of MaxMakerVolResponse for $abbr',
171-
path: 'api => _fallbackToBalance',
172-
isError: true,
173-
);
174-
return null;
175-
}
176-
177-
final balanceValue = MaxMakerVolResponseValue(decimal: balance);
178-
return MaxMakerVolResponse(
179-
volume: balanceValue,
180-
balance: balanceValue,
181-
);
182-
}
183-
184117
Future<MaxTakerVolResponse?> _fallbackToBalanceTaker(String abbr) async {
185118
final balance = await getBalance(abbr);
186119
if (balance == null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class MaxMakerVolRequest {
2+
MaxMakerVolRequest({
3+
required this.coin,
4+
});
5+
6+
static const String method = 'max_maker_vol';
7+
final String coin;
8+
late String userpass;
9+
10+
Map<String, dynamic> toJson() {
11+
return <String, dynamic>{
12+
'method': method,
13+
'mmrpc': '2.0',
14+
'userpass': userpass,
15+
'params': {
16+
'coin': coin,
17+
},
18+
};
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class MaxMakerVolResponse {
2+
MaxMakerVolResponse({
3+
required this.volume,
4+
required this.balance,
5+
});
6+
7+
final MaxMakerVolResponseValue volume;
8+
final MaxMakerVolResponseValue balance;
9+
10+
factory MaxMakerVolResponse.fromJson(Map<String, dynamic> json) =>
11+
MaxMakerVolResponse(
12+
volume: MaxMakerVolResponseValue.fromJson(json['volume']),
13+
balance: MaxMakerVolResponseValue.fromJson(json['balance']),
14+
);
15+
}
16+
17+
class MaxMakerVolResponseValue {
18+
MaxMakerVolResponseValue({
19+
required this.decimal,
20+
});
21+
22+
final String decimal;
23+
24+
factory MaxMakerVolResponseValue.fromJson(Map<String, dynamic> json) =>
25+
MaxMakerVolResponseValue(decimal: json['decimal']);
26+
27+
Map<String, String> toJson() => <String, String>{
28+
'decimal': decimal,
29+
};
30+
}

0 commit comments

Comments
 (0)