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

View file

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:http/http.dart' as http; 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_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/majestic_bank/mb_rate.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart'; import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/services/exchange/exchange_response.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( final uri = _buildUri(
endpoint: "calculate", endpoint: "calculate",
); );
final params = {
"from_currency": fromCurrency,
"receive_currency": receiveCurrency,
};
if (reversed) {
params["receive_amount"] = amount;
} else {
params["from_amount"] = amount;
}
try { try {
final jsonObject = await _makeGetRequest(uri); final jsonObject = await _makeGetRequest(uri);
return getPrettyJSONString(jsonObject); // return getPrettyJSONString(jsonObject);
return ExchangeResponse();
} catch (e, s) { } catch (e, s) {
Logging.instance Logging.instance
.log("calculateOrder exception: $e\n$s", level: LogLevel.Error); .log("calculateOrder exception: $e\n$s", level: LogLevel.Error);