WIP majestic bank order calculate api call

This commit is contained in:
julian 2023-02-02 14:18:27 -06:00
parent 991f128416
commit 3ba9f7d61b
3 changed files with 66 additions and 23 deletions

View file

@ -0,0 +1,21 @@
import 'package:decimal/decimal.dart';
import 'package:stackwallet/models/exchange/majestic_bank/mb_object.dart';
class MBOrderCalculation extends MBObject {
MBOrderCalculation({
required this.fromCurrency,
required this.fromAmount,
required this.receiveCurrency,
required this.receiveAmount,
});
final String fromCurrency;
final Decimal fromAmount;
final String receiveCurrency;
final Decimal receiveAmount;
@override
String toString() {
return "MBOrderCalculation: { $fromCurrency: $fromAmount, $receiveCurrency: $receiveAmount }";
}
}

View file

@ -11,6 +11,8 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import '../../../services/exchange/majestic_bank/majestic_bank_api.dart';
class HiddenSettings extends StatelessWidget {
const HiddenSettings({Key? key}) : super(key: key);
@ -128,27 +130,27 @@ class HiddenSettings extends StatelessWidget {
),
);
}),
// const SizedBox(
// height: 12,
// ),
// Consumer(builder: (_, ref, __) {
// return GestureDetector(
// onTap: () async {
// final x =
// await MajesticBankAPI.instance.getRates();
// print(x);
// },
// child: RoundedWhiteContainer(
// child: Text(
// "Click me",
// style: STextStyles.button(context).copyWith(
// color: Theme.of(context)
// .extension<StackColors>()!
// .accentColorDark),
// ),
// ),
// );
// }),
const SizedBox(
height: 12,
),
Consumer(builder: (_, ref, __) {
return GestureDetector(
onTap: () async {
final x =
await MajesticBankAPI.instance.getLimits();
print(x);
},
child: RoundedWhiteContainer(
child: Text(
"Click me",
style: STextStyles.button(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark),
),
),
);
}),
const SizedBox(
height: 12,
),

View file

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:decimal/decimal.dart';
import 'package:http/http.dart' as http;
import 'package:stackwallet/models/exchange/majestic_bank/mb_limit.dart';
import 'package:stackwallet/models/exchange/majestic_bank/mb_order_calculation.dart';
import 'package:stackwallet/models/exchange/majestic_bank/mb_rate.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
@ -123,15 +124,34 @@ class MajesticBankAPI {
}
}
Future<dynamic> calculateOrder() async {
/// If [reversed] then the amount is the expected receive_amount, otherwise
/// the amount is assumed to be the from_amount.
Future<ExchangeResponse<MBOrderCalculation>> calculateOrder({
required String amount,
required bool reversed,
required String fromCurrency,
required String receiveCurrency,
}) async {
final uri = _buildUri(
endpoint: "calculate",
);
final params = {
"from_currency": fromCurrency,
"receive_currency": receiveCurrency,
};
if (reversed) {
params["receive_amount"] = amount;
} else {
params["from_amount"] = amount;
}
try {
final jsonObject = await _makeGetRequest(uri);
return getPrettyJSONString(jsonObject);
// return getPrettyJSONString(jsonObject);
return ExchangeResponse();
} catch (e, s) {
Logging.instance
.log("calculateOrder exception: $e\n$s", level: LogLevel.Error);