pass around estimate instead of just rateId

This commit is contained in:
julian 2023-04-28 14:29:10 -06:00
parent da9b679d3c
commit da9b921ddc
8 changed files with 30 additions and 24 deletions

View file

@ -1,5 +1,6 @@
import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart';
import 'package:stackwallet/models/exchange/response_objects/estimate.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
@ -39,13 +40,13 @@ class IncompleteExchangeModel extends ChangeNotifier {
}
}
String? _rateId;
Estimate? _estimate;
String? get rateId => _rateId;
Estimate? get estimate => _estimate;
set rateId(String? rateId) {
if (_rateId != rateId) {
_rateId = rateId;
set estimate(Estimate? estimate) {
if (_estimate != estimate) {
_estimate = estimate;
notifyListeners();
}
}
@ -70,6 +71,6 @@ class IncompleteExchangeModel extends ChangeNotifier {
required this.rateType,
required this.reversed,
required this.walletInitiated,
String? rateId,
}) : _rateId = rateId;
Estimate? estimate,
}) : _estimate = estimate;
}

View file

@ -7,6 +7,7 @@ class Estimate {
final bool reversed;
final String? warningMessage;
final String? rateId;
final String? exchangeProvider;
Estimate({
required this.estimatedAmount,
@ -14,6 +15,7 @@ class Estimate {
required this.reversed,
this.warningMessage,
this.rateId,
this.exchangeProvider,
});
factory Estimate.fromMap(Map<String, dynamic> map) {
@ -38,6 +40,7 @@ class Estimate {
"reversed": reversed,
"warningMessage": warningMessage,
"rateId": rateId,
"exchangeProvider": exchangeProvider,
};
}

View file

@ -554,7 +554,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
? ref.read(exchangeFormStateProvider).receiveAmount!
: estimate.estimatedAmount,
rateType: rateType,
rateId: estimate.rateId,
estimate: estimate,
reversed: estimate.reversed,
walletInitiated: walletInitiated,
);

View file

@ -271,24 +271,26 @@ class _Step3ViewState extends ConsumerState<Step3View> {
? model.refundAddress!
: "",
refundExtraId: "",
rateId: model.rateId,
estimate: model.estimate,
reversed: model.reversed,
);
if (response.value == null) {
if (mounted) {
Navigator.of(context).pop();
}
unawaited(showDialog<void>(
unawaited(
showDialog<void>(
context: context,
barrierDismissible: true,
builder: (_) => StackDialog(
title: "Failed to create trade",
message:
response.exception?.toString(),
message: response.exception
?.toString(),
),
));
),
);
}
return;
}

View file

@ -31,7 +31,7 @@ class ChangeNowExchange extends Exchange {
String? extraId,
required String addressRefund,
required String refundExtraId,
String? rateId,
Estimate? estimate,
required bool reversed,
}) async {
late final ExchangeResponse<ExchangeTransaction> response;
@ -41,7 +41,7 @@ class ChangeNowExchange extends Exchange {
toTicker: to,
receivingAddress: addressTo,
amount: amount,
rateId: rateId!,
rateId: estimate!.rateId!,
extraId: extraId ?? "",
refundAddress: addressRefund,
refundExtraId: refundExtraId,

View file

@ -69,7 +69,7 @@ abstract class Exchange {
String? extraId,
required String addressRefund,
required String refundExtraId,
String? rateId,
Estimate? estimate,
required bool reversed,
});
}

View file

@ -44,7 +44,7 @@ class MajesticBankExchange extends Exchange {
String? extraId,
required String addressRefund,
required String refundExtraId,
String? rateId,
Estimate? estimate,
required bool reversed,
}) async {
ExchangeResponse<MBOrder>? response;

View file

@ -30,7 +30,7 @@ class SimpleSwapExchange extends Exchange {
String? extraId,
required String addressRefund,
required String refundExtraId,
String? rateId,
Estimate? estimate,
required bool reversed,
}) async {
return await SimpleSwapAPI.instance.createNewExchange(