From 47764835c36680125e409f54f97646ed83034736 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 1 Dec 2022 18:09:21 +0200 Subject: [PATCH 1/6] Fix nullability issue in create trade response --- lib/exchange/changenow/changenow_exchange_provider.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 20f529733..9910c7b9a 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -114,7 +114,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final uri = Uri.https(apiAuthority, createTradePath); final response = await post(uri, headers: headers, body: json.encode(body)); - + if (response.statusCode == 400) { final responseJSON = json.decode(response.body) as Map; final error = responseJSON['error'] as String; @@ -128,9 +128,9 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final responseJSON = json.decode(response.body) as Map; final id = responseJSON['id'] as String; - final inputAddress = responseJSON['payinAddress'] as String; - final refundAddress = responseJSON['refundAddress'] as String; - final extraId = responseJSON['payinExtraId'] as String; + final inputAddress = responseJSON['payinAddress'] as String?; + final refundAddress = responseJSON['refundAddress'] as String?; + final extraId = responseJSON['payinExtraId'] as String?; return Trade( id: id, From cbe31aa5aa60c269139f1c3e44be126337a274b2 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 1 Dec 2022 18:21:19 +0200 Subject: [PATCH 2/6] Revert allowing nullable values for input and refund addresses --- lib/exchange/changenow/changenow_exchange_provider.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 9910c7b9a..96b6142e6 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -128,8 +128,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final responseJSON = json.decode(response.body) as Map; final id = responseJSON['id'] as String; - final inputAddress = responseJSON['payinAddress'] as String?; - final refundAddress = responseJSON['refundAddress'] as String?; + final inputAddress = responseJSON['payinAddress'] as String; + final refundAddress = responseJSON['refundAddress'] as String; final extraId = responseJSON['payinExtraId'] as String?; return Trade( From dd99508d3e3d894987dc2f5d1616f310c1586fb7 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 1 Dec 2022 22:11:51 +0200 Subject: [PATCH 3/6] Fix static amount value for determining best rate and replace it with the input the user types --- lib/view_model/exchange/exchange_view_model.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 725208324..ff3b66f73 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -296,12 +296,14 @@ abstract class ExchangeViewModelBase with Store { } Future _calculateBestRate() async { + final amount = double.tryParse(depositAmount) ?? double.tryParse(receiveAmount) ?? 1; + final result = await Future.wait( _tradeAvailableProviders .map((element) => element.calculateAmount( from: depositCurrency, to: receiveCurrency, - amount: 1, + amount: amount, isFixedRateMode: isFixedRateMode, isReceiveAmount: false)) ); @@ -311,7 +313,7 @@ abstract class ExchangeViewModelBase with Store { for (int i=0;i Date: Thu, 1 Dec 2022 22:37:13 +0200 Subject: [PATCH 4/6] allow null minimum amount in limits --- lib/view_model/exchange/exchange_view_model.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index ff3b66f73..fd66a4254 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -336,7 +336,7 @@ abstract class ExchangeViewModelBase with Store { ? depositCurrency : receiveCurrency; - double lowestMin = double.maxFinite; + double? lowestMin = double.maxFinite; double? highestMax = 0.0; for (var provider in selectedProviders) { @@ -351,8 +351,8 @@ abstract class ExchangeViewModelBase with Store { to: to, isFixedRateMode: isFixedRateMode); - if (tempLimits.min != null && tempLimits.min! < lowestMin) { - lowestMin = tempLimits.min!; + if (lowestMin != null && (tempLimits.min ?? -1) < lowestMin) { + lowestMin = tempLimits.min; } if (highestMax != null && (tempLimits.max ?? double.maxFinite) > highestMax) { highestMax = tempLimits.max; @@ -362,7 +362,7 @@ abstract class ExchangeViewModelBase with Store { } } - if (lowestMin < double.maxFinite) { + if (lowestMin != double.maxFinite) { limits = Limits(min: lowestMin, max: highestMax); limitsState = LimitsLoadedSuccessfully(limits: limits); From 3bcd31ac44d95235bfb03a46497b71919c3ba28e Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 2 Dec 2022 20:38:16 +0200 Subject: [PATCH 5/6] calculate best rate based on min/max amount --- lib/view_model/exchange/exchange_view_model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index fd66a4254..f9d832843 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -296,7 +296,7 @@ abstract class ExchangeViewModelBase with Store { } Future _calculateBestRate() async { - final amount = double.tryParse(depositAmount) ?? double.tryParse(receiveAmount) ?? 1; + final amount = limits.min ?? limits.max ?? 1; final result = await Future.wait( _tradeAvailableProviders From 116e468581cf862584a640f41a07d77e0879f4f9 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 2 Dec 2022 23:20:06 +0200 Subject: [PATCH 6/6] calculate best rate based on deposit/receive amount --- lib/view_model/exchange/exchange_view_model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index f9d832843..b03415f4a 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -296,7 +296,7 @@ abstract class ExchangeViewModelBase with Store { } Future _calculateBestRate() async { - final amount = limits.min ?? limits.max ?? 1; + final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1; final result = await Future.wait( _tradeAvailableProviders