mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 11:45:59 +00:00
show trocador provider options
This commit is contained in:
parent
89f806f394
commit
3564426248
4 changed files with 240 additions and 187 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
||||||
|
@ -158,16 +160,23 @@ class ExchangeFormState extends ChangeNotifier {
|
||||||
required String providerName,
|
required String providerName,
|
||||||
required bool shouldUpdateData,
|
required bool shouldUpdateData,
|
||||||
required bool shouldNotifyListeners,
|
required bool shouldNotifyListeners,
|
||||||
|
bool shouldAwait = true,
|
||||||
}) async {
|
}) async {
|
||||||
_exchange = exchange;
|
_exchange = exchange;
|
||||||
_providerName = providerName;
|
_providerName = providerName;
|
||||||
if (shouldUpdateData) {
|
if (shouldUpdateData) {
|
||||||
await _updateRangesAndEstimate(
|
if (shouldAwait) {
|
||||||
shouldNotifyListeners: false,
|
await _updateRangesAndEstimate(
|
||||||
);
|
shouldNotifyListeners: shouldNotifyListeners,
|
||||||
}
|
);
|
||||||
|
} else {
|
||||||
if (shouldNotifyListeners) {
|
unawaited(
|
||||||
|
_updateRangesAndEstimate(
|
||||||
|
shouldNotifyListeners: shouldNotifyListeners,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (shouldNotifyListeners) {
|
||||||
_notify();
|
_notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import 'package:stackwallet/providers/exchange/exchange_form_state_provider.dart
|
||||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||||
import 'package:stackwallet/services/exchange/exchange.dart';
|
import 'package:stackwallet/services/exchange/exchange.dart';
|
||||||
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
||||||
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -21,35 +20,25 @@ import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/exchange/trocador/trocador_kyc_info_button.dart';
|
import 'package:stackwallet/widgets/exchange/trocador/trocador_kyc_info_button.dart';
|
||||||
import 'package:stackwallet/widgets/exchange/trocador/trocador_rating_type_enum.dart';
|
import 'package:stackwallet/widgets/exchange/trocador/trocador_rating_type_enum.dart';
|
||||||
|
|
||||||
class ExchangeProviderOption extends ConsumerStatefulWidget {
|
class ExchangeOption extends ConsumerStatefulWidget {
|
||||||
const ExchangeProviderOption({
|
const ExchangeOption({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.exchange,
|
required this.exchange,
|
||||||
required this.exchangeProvider,
|
|
||||||
required this.fixedRate,
|
required this.fixedRate,
|
||||||
required this.reversed,
|
required this.reversed,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Exchange exchange;
|
final Exchange exchange;
|
||||||
final String exchangeProvider;
|
|
||||||
final bool fixedRate;
|
final bool fixedRate;
|
||||||
final bool reversed;
|
final bool reversed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<ExchangeProviderOption> createState() =>
|
ConsumerState<ExchangeOption> createState() =>
|
||||||
_ExchangeProviderOptionState();
|
_ExchangeMultiProviderOptionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ExchangeProviderOptionState
|
class _ExchangeMultiProviderOptionState extends ConsumerState<ExchangeOption> {
|
||||||
extends ConsumerState<ExchangeProviderOption> {
|
|
||||||
final isDesktop = Util.isDesktop;
|
final isDesktop = Util.isDesktop;
|
||||||
late final String _id;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_id = "${widget.exchange.name} (${widget.exchangeProvider})";
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -62,9 +51,179 @@ class _ExchangeProviderOptionState
|
||||||
final toAmount = ref.watch(
|
final toAmount = ref.watch(
|
||||||
exchangeFormStateProvider.select((value) => value.receiveAmount));
|
exchangeFormStateProvider.select((value) => value.receiveAmount));
|
||||||
|
|
||||||
final selected = ref.watch(exchangeFormStateProvider
|
return AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 500),
|
||||||
|
curve: Curves.easeInOutCubicEmphasized,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (sendCurrency != null &&
|
||||||
|
receivingCurrency != null &&
|
||||||
|
toAmount != null &&
|
||||||
|
toAmount > Decimal.zero &&
|
||||||
|
fromAmount != null &&
|
||||||
|
fromAmount > Decimal.zero)
|
||||||
|
FutureBuilder(
|
||||||
|
future: widget.exchange.getEstimates(
|
||||||
|
sendCurrency.ticker,
|
||||||
|
receivingCurrency.ticker,
|
||||||
|
widget.reversed ? toAmount : fromAmount,
|
||||||
|
widget.fixedRate,
|
||||||
|
widget.reversed,
|
||||||
|
),
|
||||||
|
builder: (context,
|
||||||
|
AsyncSnapshot<ExchangeResponse<List<Estimate>>> snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done &&
|
||||||
|
snapshot.hasData) {
|
||||||
|
final estimates = snapshot.data?.value;
|
||||||
|
|
||||||
|
if (estimates != null && estimates.isNotEmpty) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
for (int i = 0; i < estimates.length; i++)
|
||||||
|
Builder(
|
||||||
|
builder: (context) {
|
||||||
|
final e = estimates[i];
|
||||||
|
int decimals;
|
||||||
|
try {
|
||||||
|
decimals = coinFromTickerCaseInsensitive(
|
||||||
|
receivingCurrency.ticker)
|
||||||
|
.decimals;
|
||||||
|
} catch (_) {
|
||||||
|
decimals = 8; // some reasonable alternative
|
||||||
|
}
|
||||||
|
Amount rate;
|
||||||
|
if (e.reversed) {
|
||||||
|
rate = (toAmount / e.estimatedAmount)
|
||||||
|
.toDecimal(scaleOnInfinitePrecision: 18)
|
||||||
|
.toAmount(fractionDigits: decimals);
|
||||||
|
} else {
|
||||||
|
rate = (e.estimatedAmount / fromAmount)
|
||||||
|
.toDecimal(scaleOnInfinitePrecision: 18)
|
||||||
|
.toAmount(fractionDigits: decimals);
|
||||||
|
}
|
||||||
|
|
||||||
|
final rateString =
|
||||||
|
"1 ${sendCurrency.ticker.toUpperCase()} ~ ${rate.localizedStringAsFixed(
|
||||||
|
locale: ref.watch(
|
||||||
|
localeServiceChangeNotifierProvider
|
||||||
|
.select((value) => value.locale),
|
||||||
|
),
|
||||||
|
)} ${receivingCurrency.ticker.toUpperCase()}";
|
||||||
|
|
||||||
|
return ConditionalParent(
|
||||||
|
condition: i > 0,
|
||||||
|
builder: (child) => Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
isDesktop
|
||||||
|
? Container(
|
||||||
|
height: 1,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.background,
|
||||||
|
)
|
||||||
|
: const SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
child,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: _ProviderOption(
|
||||||
|
key: Key(widget.exchange.name +
|
||||||
|
e.exchangeProvider),
|
||||||
|
exchange: widget.exchange,
|
||||||
|
providerName: e.exchangeProvider,
|
||||||
|
rateString: rateString,
|
||||||
|
kycRating: e.kycRating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else if (snapshot.data?.exception
|
||||||
|
is PairUnavailableException) {
|
||||||
|
return _ProviderOption(
|
||||||
|
exchange: widget.exchange,
|
||||||
|
providerName: widget.exchange.name,
|
||||||
|
rateString: "Unsupported pair",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Logging.instance.log(
|
||||||
|
"$runtimeType failed to fetch rate for ${widget.exchange.name}: ${snapshot.data}",
|
||||||
|
level: LogLevel.Warning,
|
||||||
|
);
|
||||||
|
|
||||||
|
return _ProviderOption(
|
||||||
|
exchange: widget.exchange,
|
||||||
|
providerName: widget.exchange.name,
|
||||||
|
rateString: "Failed to fetch rate",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// show loading
|
||||||
|
return _ProviderOption(
|
||||||
|
exchange: widget.exchange,
|
||||||
|
providerName: widget.exchange.name,
|
||||||
|
rateString: "",
|
||||||
|
loadingString: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProviderOption extends ConsumerStatefulWidget {
|
||||||
|
const _ProviderOption({
|
||||||
|
Key? key,
|
||||||
|
required this.exchange,
|
||||||
|
required this.providerName,
|
||||||
|
required this.rateString,
|
||||||
|
this.kycRating,
|
||||||
|
this.loadingString = false,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final Exchange exchange;
|
||||||
|
final String providerName;
|
||||||
|
final String rateString;
|
||||||
|
final String? kycRating;
|
||||||
|
final bool loadingString;
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<_ProviderOption> createState() => _ProviderOptionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProviderOptionState extends ConsumerState<_ProviderOption> {
|
||||||
|
final isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
late final String _id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_id = "${widget.exchange.name} (${widget.providerName})";
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
bool selected = ref.watch(exchangeFormStateProvider
|
||||||
.select((value) => value.combinedExchangeId)) ==
|
.select((value) => value.combinedExchangeId)) ==
|
||||||
_id;
|
_id;
|
||||||
|
String groupValue = ref.watch(
|
||||||
|
exchangeFormStateProvider.select((value) => value.combinedExchangeId));
|
||||||
|
|
||||||
|
if (ref.watch(
|
||||||
|
exchangeFormStateProvider.select((value) => value.exchange.name)) ==
|
||||||
|
widget.providerName) {
|
||||||
|
selected = true;
|
||||||
|
groupValue = _id;
|
||||||
|
}
|
||||||
|
|
||||||
return ConditionalParent(
|
return ConditionalParent(
|
||||||
condition: isDesktop,
|
condition: isDesktop,
|
||||||
|
@ -75,17 +234,12 @@ class _ExchangeProviderOptionState
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
// showLoading(
|
|
||||||
// whileFuture:
|
|
||||||
ref.read(exchangeFormStateProvider).updateExchange(
|
ref.read(exchangeFormStateProvider).updateExchange(
|
||||||
exchange: widget.exchange,
|
exchange: widget.exchange,
|
||||||
shouldUpdateData: true,
|
shouldUpdateData: true,
|
||||||
shouldNotifyListeners: true,
|
shouldNotifyListeners: true,
|
||||||
providerName: widget.exchangeProvider,
|
providerName: widget.providerName,
|
||||||
// ),
|
shouldAwait: false,
|
||||||
// context: context,
|
|
||||||
// message: "Updating rates",
|
|
||||||
// isDesktop: isDesktop,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -107,15 +261,15 @@ class _ExchangeProviderOptionState
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.radioButtonIconEnabled,
|
.radioButtonIconEnabled,
|
||||||
value: _id,
|
value: _id,
|
||||||
groupValue: ref.watch(exchangeFormStateProvider
|
groupValue: groupValue,
|
||||||
.select((value) => value.combinedExchangeId)),
|
|
||||||
onChanged: (_) {
|
onChanged: (_) {
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
ref.read(exchangeFormStateProvider).updateExchange(
|
ref.read(exchangeFormStateProvider).updateExchange(
|
||||||
exchange: widget.exchange,
|
exchange: widget.exchange,
|
||||||
shouldUpdateData: false,
|
shouldUpdateData: false,
|
||||||
shouldNotifyListeners: true,
|
shouldNotifyListeners: true,
|
||||||
providerName: widget.exchangeProvider,
|
providerName: widget.providerName,
|
||||||
|
shouldAwait: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -149,153 +303,46 @@ class _ExchangeProviderOptionState
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.exchangeProvider,
|
widget.providerName,
|
||||||
style: STextStyles.titleBold12(context).copyWith(
|
style: STextStyles.titleBold12(context).copyWith(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.textDark2,
|
.textDark2,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (sendCurrency != null &&
|
widget.loadingString
|
||||||
receivingCurrency != null &&
|
? AnimatedText(
|
||||||
toAmount != null &&
|
stringsToLoopThrough: const [
|
||||||
toAmount > Decimal.zero &&
|
"Loading",
|
||||||
fromAmount != null &&
|
"Loading.",
|
||||||
fromAmount > Decimal.zero)
|
"Loading..",
|
||||||
FutureBuilder(
|
"Loading...",
|
||||||
future: widget.exchange.getEstimates(
|
],
|
||||||
sendCurrency.ticker,
|
style:
|
||||||
receivingCurrency.ticker,
|
STextStyles.itemSubtitle12(context).copyWith(
|
||||||
widget.reversed ? toAmount : fromAmount,
|
color: Theme.of(context)
|
||||||
widget.fixedRate,
|
.extension<StackColors>()!
|
||||||
widget.reversed,
|
.textSubtitle1,
|
||||||
),
|
),
|
||||||
builder: (context,
|
)
|
||||||
AsyncSnapshot<ExchangeResponse<List<Estimate>>>
|
: Text(
|
||||||
snapshot) {
|
widget.rateString,
|
||||||
if (snapshot.connectionState ==
|
style:
|
||||||
ConnectionState.done &&
|
STextStyles.itemSubtitle12(context).copyWith(
|
||||||
snapshot.hasData) {
|
color: Theme.of(context)
|
||||||
final estimates = snapshot.data?.value;
|
.extension<StackColors>()!
|
||||||
if (estimates != null &&
|
.textSubtitle1,
|
||||||
estimates
|
),
|
||||||
.where((e) =>
|
),
|
||||||
e.exchangeProvider ==
|
|
||||||
widget.exchangeProvider)
|
|
||||||
.isNotEmpty) {
|
|
||||||
final estimate = estimates.firstWhere((e) =>
|
|
||||||
e.exchangeProvider ==
|
|
||||||
widget.exchangeProvider);
|
|
||||||
int decimals;
|
|
||||||
try {
|
|
||||||
decimals = coinFromTickerCaseInsensitive(
|
|
||||||
receivingCurrency.ticker)
|
|
||||||
.decimals;
|
|
||||||
} catch (_) {
|
|
||||||
decimals = 8; // some reasonable alternative
|
|
||||||
}
|
|
||||||
Amount rate;
|
|
||||||
if (estimate.reversed) {
|
|
||||||
rate = (toAmount / estimate.estimatedAmount)
|
|
||||||
.toDecimal(scaleOnInfinitePrecision: 18)
|
|
||||||
.toAmount(fractionDigits: decimals);
|
|
||||||
} else {
|
|
||||||
rate = (estimate.estimatedAmount / fromAmount)
|
|
||||||
.toDecimal(scaleOnInfinitePrecision: 18)
|
|
||||||
.toAmount(fractionDigits: decimals);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConditionalParent(
|
|
||||||
condition: widget.exchange.name ==
|
|
||||||
TrocadorExchange.exchangeName,
|
|
||||||
builder: (child) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
child,
|
|
||||||
TrocadorKYCInfoButton(
|
|
||||||
kycType: TrocadorKYCType.fromString(
|
|
||||||
estimate.kycRating!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
"1 ${sendCurrency.ticker.toUpperCase()} ~ ${rate.localizedStringAsFixed(
|
|
||||||
locale: ref.watch(
|
|
||||||
localeServiceChangeNotifierProvider
|
|
||||||
.select((value) => value.locale),
|
|
||||||
),
|
|
||||||
)} ${receivingCurrency.ticker.toUpperCase()}",
|
|
||||||
style: STextStyles.itemSubtitle12(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (snapshot.data?.exception
|
|
||||||
is PairUnavailableException) {
|
|
||||||
return Text(
|
|
||||||
"Unsupported pair",
|
|
||||||
style: STextStyles.itemSubtitle12(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
Logging.instance.log(
|
|
||||||
"$runtimeType failed to fetch rate for $_id}: ${snapshot.data}",
|
|
||||||
level: LogLevel.Warning,
|
|
||||||
);
|
|
||||||
return Text(
|
|
||||||
"Failed to fetch rate",
|
|
||||||
style: STextStyles.itemSubtitle12(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return AnimatedText(
|
|
||||||
stringsToLoopThrough: const [
|
|
||||||
"Loading",
|
|
||||||
"Loading.",
|
|
||||||
"Loading..",
|
|
||||||
"Loading...",
|
|
||||||
],
|
|
||||||
style: STextStyles.itemSubtitle12(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (!(sendCurrency != null &&
|
|
||||||
receivingCurrency != null &&
|
|
||||||
toAmount != null &&
|
|
||||||
toAmount > Decimal.zero &&
|
|
||||||
fromAmount != null &&
|
|
||||||
fromAmount > Decimal.zero))
|
|
||||||
Text(
|
|
||||||
"n/a",
|
|
||||||
style: STextStyles.itemSubtitle12(context).copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (widget.kycRating != null)
|
||||||
|
TrocadorKYCInfoButton(
|
||||||
|
kycType: TrocadorKYCType.fromString(
|
||||||
|
widget.kycRating!,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -84,9 +84,8 @@ class _ExchangeProviderOptionsState
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
if (showChangeNow)
|
if (showChangeNow)
|
||||||
ExchangeProviderOption(
|
ExchangeOption(
|
||||||
exchange: ChangeNowExchange.instance,
|
exchange: ChangeNowExchange.instance,
|
||||||
exchangeProvider: ChangeNowExchange.exchangeName,
|
|
||||||
fixedRate: widget.fixedRate,
|
fixedRate: widget.fixedRate,
|
||||||
reversed: widget.reversed,
|
reversed: widget.reversed,
|
||||||
),
|
),
|
||||||
|
@ -101,9 +100,8 @@ class _ExchangeProviderOptionsState
|
||||||
height: 16,
|
height: 16,
|
||||||
),
|
),
|
||||||
if (showMajesticBank)
|
if (showMajesticBank)
|
||||||
ExchangeProviderOption(
|
ExchangeOption(
|
||||||
exchange: MajesticBankExchange.instance,
|
exchange: MajesticBankExchange.instance,
|
||||||
exchangeProvider: MajesticBankExchange.exchangeName,
|
|
||||||
fixedRate: widget.fixedRate,
|
fixedRate: widget.fixedRate,
|
||||||
reversed: widget.reversed,
|
reversed: widget.reversed,
|
||||||
),
|
),
|
||||||
|
@ -118,11 +116,10 @@ class _ExchangeProviderOptionsState
|
||||||
height: 16,
|
height: 16,
|
||||||
),
|
),
|
||||||
if (showTrocador)
|
if (showTrocador)
|
||||||
ExchangeProviderOption(
|
ExchangeOption(
|
||||||
fixedRate: widget.fixedRate,
|
fixedRate: widget.fixedRate,
|
||||||
reversed: widget.reversed,
|
reversed: widget.reversed,
|
||||||
exchange: TrocadorExchange.instance,
|
exchange: TrocadorExchange.instance,
|
||||||
exchangeProvider: 'LetsExchange',
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -187,9 +187,7 @@ class TrocadorExchange extends Exchange {
|
||||||
bool fixedRate,
|
bool fixedRate,
|
||||||
bool reversed,
|
bool reversed,
|
||||||
) async {
|
) async {
|
||||||
final isPayment = reversed || fixedRate;
|
final response = reversed
|
||||||
|
|
||||||
final response = isPayment
|
|
||||||
? await TrocadorAPI.getNewPaymentRate(
|
? await TrocadorAPI.getNewPaymentRate(
|
||||||
isOnion: false,
|
isOnion: false,
|
||||||
fromTicker: from,
|
fromTicker: from,
|
||||||
|
@ -215,14 +213,15 @@ class TrocadorExchange extends Exchange {
|
||||||
final List<TrocadorQuote> cOrLowerQuotes = [];
|
final List<TrocadorQuote> cOrLowerQuotes = [];
|
||||||
|
|
||||||
for (final quote in response.value!.quotes) {
|
for (final quote in response.value!.quotes) {
|
||||||
if (quote.fixed == isPayment) {
|
if (quote.fixed == fixedRate &&
|
||||||
|
quote.provider.toLowerCase() != "changenow") {
|
||||||
final rating = quote.kycRating.toLowerCase();
|
final rating = quote.kycRating.toLowerCase();
|
||||||
if (rating == "a" || rating == "b") {
|
if (rating == "a" || rating == "b") {
|
||||||
estimates.add(
|
estimates.add(
|
||||||
Estimate(
|
Estimate(
|
||||||
estimatedAmount: isPayment ? quote.amountFrom! : quote.amountTo!,
|
estimatedAmount: reversed ? quote.amountFrom! : quote.amountTo!,
|
||||||
fixedRate: quote.fixed,
|
fixedRate: quote.fixed,
|
||||||
reversed: isPayment,
|
reversed: reversed,
|
||||||
exchangeProvider: quote.provider,
|
exchangeProvider: quote.provider,
|
||||||
rateId: response.value!.tradeId,
|
rateId: response.value!.tradeId,
|
||||||
kycRating: quote.kycRating,
|
kycRating: quote.kycRating,
|
||||||
|
@ -236,13 +235,13 @@ class TrocadorExchange extends Exchange {
|
||||||
|
|
||||||
cOrLowerQuotes.sort((a, b) => b.waste.compareTo(a.waste));
|
cOrLowerQuotes.sort((a, b) => b.waste.compareTo(a.waste));
|
||||||
|
|
||||||
for (int i = 0; i < max(3, cOrLowerQuotes.length); i++) {
|
for (int i = 0; i < min(3, cOrLowerQuotes.length); i++) {
|
||||||
final quote = cOrLowerQuotes[i];
|
final quote = cOrLowerQuotes[i];
|
||||||
estimates.add(
|
estimates.add(
|
||||||
Estimate(
|
Estimate(
|
||||||
estimatedAmount: isPayment ? quote.amountFrom! : quote.amountTo!,
|
estimatedAmount: reversed ? quote.amountFrom! : quote.amountTo!,
|
||||||
fixedRate: quote.fixed,
|
fixedRate: quote.fixed,
|
||||||
reversed: isPayment,
|
reversed: reversed,
|
||||||
exchangeProvider: quote.provider,
|
exchangeProvider: quote.provider,
|
||||||
rateId: response.value!.tradeId,
|
rateId: response.value!.tradeId,
|
||||||
kycRating: quote.kycRating,
|
kycRating: quote.kycRating,
|
||||||
|
@ -251,7 +250,8 @@ class TrocadorExchange extends Exchange {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExchangeResponse(
|
return ExchangeResponse(
|
||||||
value: estimates,
|
value: estimates
|
||||||
|
..sort((a, b) => b.estimatedAmount.compareTo(a.estimatedAmount)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue