Skip unsupported providers when calculating best rate provider (#500)

Omar Hatem committed Sep 7, 2022 at 13:43 UTC 244d20d1b66287b329e9ef8210e8a1836a8d119d
1 file changed +12 -4
lib/view_model/exchange/exchange_view_model.dart
+12 -4
@@ -210,6 +210,10 @@ abstract class ExchangeViewModelBase with Store {
210
211 currentTradeAvailableProviders.clear();
212 for (var provider in selectedProviders) {
213 + /// if this provider is not valid for the current pair, skip it
214 + if (!providersForCurrentPair().contains(provider)) {
215 + continue;
216 + }
217 provider
218 .calculateAmount(
219 from: receiveCurrency,
@@ -232,8 +236,8 @@ abstract class ExchangeViewModelBase with Store {
236 isFixedRateMode: isFixedRateMode,
237 ).then((limits) {
238 /// if the entered amount doesn't exceed the limits of this provider
235 - if ((limits.max ?? double.maxFinite) >= _enteredAmount
236 - && (limits.min ?? 0) <= _enteredAmount) {
239 + if ((limits?.max ?? double.maxFinite) >= _enteredAmount
240 + && (limits?.min ?? 0) <= _enteredAmount) {
241 /// add this provider as its valid for this trade
242 /// will be sorted ascending already since
243 /// we seek the least deposit amount
@@ -263,6 +267,10 @@ abstract class ExchangeViewModelBase with Store {
267
268 currentTradeAvailableProviders.clear();
269 for (var provider in selectedProviders) {
270 + /// if this provider is not valid for the current pair, skip it
271 + if (!providersForCurrentPair().contains(provider)) {
272 + continue;
273 + }
274 provider
275 .calculateAmount(
276 from: depositCurrency,
@@ -286,8 +294,8 @@ abstract class ExchangeViewModelBase with Store {
294 ).then((limits) {
295
296 /// if the entered amount doesn't exceed the limits of this provider
289 - if ((limits.max ?? double.maxFinite) >= _enteredAmount
290 - && (limits.min ?? 0) <= _enteredAmount) {
297 + if ((limits?.max ?? double.maxFinite) >= _enteredAmount
298 + && (limits?.min ?? 0) <= _enteredAmount) {
299 /// add this provider as its valid for this trade
300 /// subtract from maxFinite so the provider
301 /// with the largest amount would be sorted ascending