mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
commit
394409ac28
3 changed files with 331 additions and 334 deletions
|
@ -7,7 +7,7 @@ import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.d
|
|||
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
|
||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||
import 'package:stackwallet/services/exchange/exchange.dart';
|
||||
import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
||||
// import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
|
||||
class ExchangeFormState extends ChangeNotifier {
|
||||
|
@ -53,8 +53,8 @@ class ExchangeFormState extends ChangeNotifier {
|
|||
return _from?.ticker;
|
||||
case ExchangeRateType.fixed:
|
||||
switch (exchange?.name) {
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
return _from?.ticker;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// return _from?.ticker;
|
||||
case ChangeNowExchange.exchangeName:
|
||||
return market?.from;
|
||||
default:
|
||||
|
@ -69,8 +69,8 @@ class ExchangeFormState extends ChangeNotifier {
|
|||
return _to?.ticker;
|
||||
case ExchangeRateType.fixed:
|
||||
switch (exchange?.name) {
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
return _to?.ticker;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// return _to?.ticker;
|
||||
case ChangeNowExchange.exchangeName:
|
||||
return market?.to;
|
||||
default:
|
||||
|
@ -296,9 +296,9 @@ class ExchangeFormState extends ChangeNotifier {
|
|||
}
|
||||
|
||||
Future<void> updateRanges({required bool shouldNotifyListeners}) async {
|
||||
if (exchange?.name == SimpleSwapExchange.exchangeName) {
|
||||
reversed = false;
|
||||
}
|
||||
// if (exchange?.name == SimpleSwapExchange.exchangeName) {
|
||||
// reversed = false;
|
||||
// }
|
||||
final _fromTicker = reversed ? toTicker : fromTicker;
|
||||
final _toTicker = reversed ? fromTicker : toTicker;
|
||||
if (_fromTicker == null || _toTicker == null) {
|
||||
|
@ -340,9 +340,9 @@ class ExchangeFormState extends ChangeNotifier {
|
|||
required bool shouldNotifyListeners,
|
||||
required bool reversed,
|
||||
}) async {
|
||||
if (exchange?.name == SimpleSwapExchange.exchangeName) {
|
||||
reversed = false;
|
||||
}
|
||||
// if (exchange?.name == SimpleSwapExchange.exchangeName) {
|
||||
// reversed = false;
|
||||
// }
|
||||
final amount = reversed ? toAmount : fromAmount;
|
||||
if (fromTicker == null ||
|
||||
toTicker == null ||
|
||||
|
|
|
@ -20,7 +20,7 @@ import 'package:stackwallet/pages/exchange_view/sub_widgets/rate_type_toggle.dar
|
|||
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||
import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
||||
// import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -101,11 +101,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
currencies =
|
||||
ref.read(availableChangeNowCurrenciesProvider).currencies;
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
currencies = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRateCurrencies;
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// currencies = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRateCurrencies;
|
||||
// break;
|
||||
default:
|
||||
currencies = [];
|
||||
}
|
||||
|
@ -170,17 +170,17 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
},
|
||||
);
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
await _showFloatingRateSelectionSheet(
|
||||
currencies: ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.fixedRateCurrencies,
|
||||
excludedTicker:
|
||||
ref.read(exchangeFormStateProvider).toTicker ?? "-",
|
||||
fromTicker: fromTicker,
|
||||
onSelected: (from) =>
|
||||
ref.read(exchangeFormStateProvider).updateFrom(from, true));
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// await _showFloatingRateSelectionSheet(
|
||||
// currencies: ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .fixedRateCurrencies,
|
||||
// excludedTicker:
|
||||
// ref.read(exchangeFormStateProvider).toTicker ?? "-",
|
||||
// fromTicker: fromTicker,
|
||||
// onSelected: (from) =>
|
||||
// ref.read(exchangeFormStateProvider).updateFrom(from, true));
|
||||
// break;
|
||||
default:
|
||||
// TODO show error?
|
||||
}
|
||||
|
@ -204,11 +204,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
currencies =
|
||||
ref.read(availableChangeNowCurrenciesProvider).currencies;
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
currencies = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRateCurrencies;
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// currencies = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRateCurrencies;
|
||||
// break;
|
||||
default:
|
||||
currencies = [];
|
||||
}
|
||||
|
@ -272,17 +272,17 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
},
|
||||
);
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
await _showFloatingRateSelectionSheet(
|
||||
currencies: ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.fixedRateCurrencies,
|
||||
excludedTicker:
|
||||
ref.read(exchangeFormStateProvider).fromTicker ?? "",
|
||||
fromTicker: ref.read(exchangeFormStateProvider).fromTicker ?? "",
|
||||
onSelected: (to) =>
|
||||
ref.read(exchangeFormStateProvider).updateTo(to, true));
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// await _showFloatingRateSelectionSheet(
|
||||
// currencies: ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .fixedRateCurrencies,
|
||||
// excludedTicker:
|
||||
// ref.read(exchangeFormStateProvider).fromTicker ?? "",
|
||||
// fromTicker: ref.read(exchangeFormStateProvider).fromTicker ?? "",
|
||||
// onSelected: (to) =>
|
||||
// ref.read(exchangeFormStateProvider).updateTo(to, true));
|
||||
// break;
|
||||
default:
|
||||
// TODO show error?
|
||||
}
|
||||
|
@ -374,12 +374,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
case ChangeNowExchange.exchangeName:
|
||||
allPairs = ref.read(availableChangeNowCurrenciesProvider).pairs;
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
allPairs = ref.read(exchangeFormStateProvider).exchangeType ==
|
||||
ExchangeRateType.fixed
|
||||
? ref.read(availableSimpleswapCurrenciesProvider).fixedRatePairs
|
||||
: ref.read(availableSimpleswapCurrenciesProvider).floatingRatePairs;
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// allPairs = ref.read(exchangeFormStateProvider).exchangeType ==
|
||||
// ExchangeRateType.fixed
|
||||
// ? ref.read(availableSimpleswapCurrenciesProvider).fixedRatePairs
|
||||
// : ref.read(availableSimpleswapCurrenciesProvider).floatingRatePairs;
|
||||
// break;
|
||||
default:
|
||||
allPairs = [];
|
||||
}
|
||||
|
@ -486,18 +486,18 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
.currencies
|
||||
.where((e) => e.ticker.toUpperCase() == ticker.toUpperCase());
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
possibleCurrencies = [
|
||||
...ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.fixedRateCurrencies
|
||||
.where((e) => e.ticker.toUpperCase() == ticker.toUpperCase()),
|
||||
...ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRateCurrencies
|
||||
.where((e) => e.ticker.toUpperCase() == ticker.toUpperCase()),
|
||||
];
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// possibleCurrencies = [
|
||||
// ...ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .fixedRateCurrencies
|
||||
// .where((e) => e.ticker.toUpperCase() == ticker.toUpperCase()),
|
||||
// ...ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRateCurrencies
|
||||
// .where((e) => e.ticker.toUpperCase() == ticker.toUpperCase()),
|
||||
// ];
|
||||
// break;
|
||||
default:
|
||||
possibleCurrencies = [];
|
||||
}
|
||||
|
@ -655,12 +655,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
.pairs
|
||||
.where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
available = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRatePairs
|
||||
.where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// available = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRatePairs
|
||||
// .where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
// break;
|
||||
default:
|
||||
available = [];
|
||||
}
|
||||
|
@ -675,13 +675,13 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
.where(
|
||||
(e) => e.ticker == fromTicker || e.ticker == toTicker);
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
availableCurrencies = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRateCurrencies
|
||||
.where(
|
||||
(e) => e.ticker == fromTicker || e.ticker == toTicker);
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// availableCurrencies = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRateCurrencies
|
||||
// .where(
|
||||
// (e) => e.ticker == fromTicker || e.ticker == toTicker);
|
||||
// break;
|
||||
default:
|
||||
availableCurrencies = [];
|
||||
}
|
||||
|
@ -763,47 +763,47 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
return;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
final available = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRatePairs
|
||||
.where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
if (available.isNotEmpty) {
|
||||
final availableCurrencies = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.fixedRateCurrencies
|
||||
.where(
|
||||
(e) => e.ticker == fromTicker || e.ticker == toTicker);
|
||||
if (availableCurrencies.length > 1) {
|
||||
final from = availableCurrencies
|
||||
.firstWhere((e) => e.ticker == fromTicker);
|
||||
final to = availableCurrencies
|
||||
.firstWhere((e) => e.ticker == toTicker);
|
||||
|
||||
final newFromAmount = Decimal.tryParse(_sendController.text);
|
||||
ref.read(exchangeFormStateProvider).fromAmount =
|
||||
newFromAmount ?? Decimal.zero;
|
||||
if (newFromAmount == null) {
|
||||
_receiveController.text = "";
|
||||
}
|
||||
|
||||
await ref.read(exchangeFormStateProvider).updateTo(to, false);
|
||||
await ref
|
||||
.read(exchangeFormStateProvider)
|
||||
.updateFrom(from, true);
|
||||
|
||||
_receiveController.text =
|
||||
ref.read(exchangeFormStateProvider).toAmountString.isEmpty
|
||||
? "-"
|
||||
: ref.read(exchangeFormStateProvider).toAmountString;
|
||||
if (mounted) {
|
||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// final available = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRatePairs
|
||||
// .where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
// if (available.isNotEmpty) {
|
||||
// final availableCurrencies = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .fixedRateCurrencies
|
||||
// .where(
|
||||
// (e) => e.ticker == fromTicker || e.ticker == toTicker);
|
||||
// if (availableCurrencies.length > 1) {
|
||||
// final from = availableCurrencies
|
||||
// .firstWhere((e) => e.ticker == fromTicker);
|
||||
// final to = availableCurrencies
|
||||
// .firstWhere((e) => e.ticker == toTicker);
|
||||
//
|
||||
// final newFromAmount = Decimal.tryParse(_sendController.text);
|
||||
// ref.read(exchangeFormStateProvider).fromAmount =
|
||||
// newFromAmount ?? Decimal.zero;
|
||||
// if (newFromAmount == null) {
|
||||
// _receiveController.text = "";
|
||||
// }
|
||||
//
|
||||
// await ref.read(exchangeFormStateProvider).updateTo(to, false);
|
||||
// await ref
|
||||
// .read(exchangeFormStateProvider)
|
||||
// .updateFrom(from, true);
|
||||
//
|
||||
// _receiveController.text =
|
||||
// ref.read(exchangeFormStateProvider).toAmountString.isEmpty
|
||||
// ? "-"
|
||||
// : ref.read(exchangeFormStateProvider).toAmountString;
|
||||
// if (mounted) {
|
||||
// Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
default:
|
||||
//
|
||||
}
|
||||
|
@ -844,12 +844,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
.pairs
|
||||
.where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
break;
|
||||
case SimpleSwapExchange.exchangeName:
|
||||
availableFloatingPairs = ref
|
||||
.read(availableSimpleswapCurrenciesProvider)
|
||||
.floatingRatePairs
|
||||
.where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
break;
|
||||
// case SimpleSwapExchange.exchangeName:
|
||||
// availableFloatingPairs = ref
|
||||
// .read(availableSimpleswapCurrenciesProvider)
|
||||
// .floatingRatePairs
|
||||
// .where((e) => e.to == toTicker && e.from == fromTicker);
|
||||
// break;
|
||||
default:
|
||||
availableFloatingPairs = [];
|
||||
}
|
||||
|
@ -1176,12 +1176,9 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
exchangeFormStateProvider.select((value) => value.toAmountString),
|
||||
(previous, String next) {
|
||||
if (!_receiveFocusNode.hasFocus) {
|
||||
_receiveController.text = isEstimated &&
|
||||
ref.watch(exchangeProvider).name ==
|
||||
SimpleSwapExchange.exchangeName &&
|
||||
next.isEmpty
|
||||
? "-"
|
||||
: next;
|
||||
// ref.watch(exchangeProvider).name ==
|
||||
// SimpleSwapExchange.exchangeName &&
|
||||
_receiveController.text = isEstimated && next.isEmpty ? "-" : next;
|
||||
//todo: check if print needed
|
||||
// debugPrint("RECEIVE AMOUNT LISTENER ACTIVATED");
|
||||
if (_swapLock) {
|
||||
|
@ -1335,9 +1332,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
exchangeFormStateProvider.select((value) => value.toTicker)),
|
||||
readOnly: ref.watch(prefsChangeNotifierProvider
|
||||
.select((value) => value.exchangeRateType)) ==
|
||||
ExchangeRateType.estimated ||
|
||||
ref.watch(exchangeProvider).name ==
|
||||
SimpleSwapExchange.exchangeName,
|
||||
ExchangeRateType.estimated,
|
||||
// ||
|
||||
// ref.watch(exchangeProvider).name ==
|
||||
// SimpleSwapExchange.exchangeName,
|
||||
),
|
||||
if (ref
|
||||
.watch(
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:stackwallet/providers/providers.dart';
|
|||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||
import 'package:stackwallet/services/exchange/exchange.dart';
|
||||
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
||||
import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -250,207 +249,207 @@ class ExchangeProviderOptions extends ConsumerWidget {
|
|||
height: 1,
|
||||
color: Theme.of(context).extension<StackColors>()!.background,
|
||||
),
|
||||
if (!isDesktop)
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
ConditionalParent(
|
||||
condition: isDesktop,
|
||||
builder: (child) => MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: child,
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (ref.read(currentExchangeNameStateProvider.state).state !=
|
||||
SimpleSwapExchange.exchangeName) {
|
||||
ref.read(currentExchangeNameStateProvider.state).state =
|
||||
SimpleSwapExchange.exchangeName;
|
||||
ref.read(exchangeFormStateProvider).exchange =
|
||||
Exchange.fromName(ref
|
||||
.read(currentExchangeNameStateProvider.state)
|
||||
.state);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: Padding(
|
||||
padding: isDesktop
|
||||
? const EdgeInsets.all(16)
|
||||
: const EdgeInsets.all(0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: Radio(
|
||||
activeColor: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.radioButtonIconEnabled,
|
||||
value: SimpleSwapExchange.exchangeName,
|
||||
groupValue: ref
|
||||
.watch(currentExchangeNameStateProvider.state)
|
||||
.state,
|
||||
onChanged: (value) {
|
||||
if (value is String) {
|
||||
ref
|
||||
.read(currentExchangeNameStateProvider.state)
|
||||
.state = value;
|
||||
ref.read(exchangeFormStateProvider).exchange =
|
||||
Exchange.fromName(ref
|
||||
.read(currentExchangeNameStateProvider
|
||||
.state)
|
||||
.state);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 14,
|
||||
),
|
||||
SvgPicture.asset(
|
||||
Assets.exchange.simpleSwap,
|
||||
width: isDesktop ? 32 : 24,
|
||||
height: isDesktop ? 32 : 24,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
SimpleSwapExchange.exchangeName,
|
||||
style: STextStyles.titleBold12(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textDark2,
|
||||
),
|
||||
),
|
||||
if (from != null &&
|
||||
to != null &&
|
||||
toAmount != null &&
|
||||
toAmount! > Decimal.zero &&
|
||||
fromAmount != null &&
|
||||
fromAmount! > Decimal.zero)
|
||||
FutureBuilder(
|
||||
future: SimpleSwapExchange().getEstimate(
|
||||
from!,
|
||||
to!,
|
||||
// reversed ? toAmount! : fromAmount!,
|
||||
fromAmount!,
|
||||
fixedRate,
|
||||
// reversed,
|
||||
false,
|
||||
),
|
||||
builder: (context,
|
||||
AsyncSnapshot<ExchangeResponse<Estimate>>
|
||||
snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
final estimate = snapshot.data?.value;
|
||||
if (estimate != null) {
|
||||
Decimal rate = (estimate.estimatedAmount /
|
||||
fromAmount!)
|
||||
.toDecimal(
|
||||
scaleOnInfinitePrecision: 12);
|
||||
|
||||
Coin coin;
|
||||
try {
|
||||
coin =
|
||||
coinFromTickerCaseInsensitive(to!);
|
||||
} catch (_) {
|
||||
coin = Coin.bitcoin;
|
||||
}
|
||||
return Text(
|
||||
"1 ${from!.toUpperCase()} ~ ${Format.localizedStringAsFixed(
|
||||
value: rate,
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale),
|
||||
),
|
||||
decimalPlaces:
|
||||
Constants.decimalPlacesForCoin(
|
||||
coin),
|
||||
)} ${to!.toUpperCase()}",
|
||||
style:
|
||||
STextStyles.itemSubtitle12(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"$runtimeType failed to fetch rate for SimpleSwap: ${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 (!(from != null &&
|
||||
// to != null &&
|
||||
// (reversed
|
||||
// ? toAmount != null && toAmount! > Decimal.zero
|
||||
// : fromAmount != null &&
|
||||
// fromAmount! > Decimal.zero)))
|
||||
if (!(from != null &&
|
||||
to != 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 (!isDesktop)
|
||||
// const SizedBox(
|
||||
// height: 16,
|
||||
// ),
|
||||
// ConditionalParent(
|
||||
// condition: isDesktop,
|
||||
// builder: (child) => MouseRegion(
|
||||
// cursor: SystemMouseCursors.click,
|
||||
// child: child,
|
||||
// ),
|
||||
// child: GestureDetector(
|
||||
// onTap: () {
|
||||
// if (ref.read(currentExchangeNameStateProvider.state).state !=
|
||||
// SimpleSwapExchange.exchangeName) {
|
||||
// // ref.read(currentExchangeNameStateProvider.state).state =
|
||||
// // SimpleSwapExchange.exchangeName;
|
||||
// ref.read(exchangeFormStateProvider).exchange =
|
||||
// Exchange.fromName(ref
|
||||
// .read(currentExchangeNameStateProvider.state)
|
||||
// .state);
|
||||
// }
|
||||
// },
|
||||
// child: Container(
|
||||
// color: Colors.transparent,
|
||||
// child: Padding(
|
||||
// padding: isDesktop
|
||||
// ? const EdgeInsets.all(16)
|
||||
// : const EdgeInsets.all(0),
|
||||
// child: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// SizedBox(
|
||||
// width: 20,
|
||||
// height: 20,
|
||||
// child: Radio(
|
||||
// activeColor: Theme.of(context)
|
||||
// .extension<StackColors>()!
|
||||
// .radioButtonIconEnabled,
|
||||
// value: SimpleSwapExchange.exchangeName,
|
||||
// groupValue: ref
|
||||
// .watch(currentExchangeNameStateProvider.state)
|
||||
// .state,
|
||||
// onChanged: (value) {
|
||||
// if (value is String) {
|
||||
// ref
|
||||
// .read(currentExchangeNameStateProvider.state)
|
||||
// .state = value;
|
||||
// ref.read(exchangeFormStateProvider).exchange =
|
||||
// Exchange.fromName(ref
|
||||
// .read(currentExchangeNameStateProvider
|
||||
// .state)
|
||||
// .state);
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// width: 14,
|
||||
// ),
|
||||
// // SvgPicture.asset(
|
||||
// // Assets.exchange.simpleSwap,
|
||||
// // width: isDesktop ? 32 : 24,
|
||||
// // height: isDesktop ? 32 : 24,
|
||||
// // ),
|
||||
// // const SizedBox(
|
||||
// // width: 10,
|
||||
// // ),
|
||||
// // Expanded(
|
||||
// // child: Column(
|
||||
// // mainAxisAlignment: MainAxisAlignment.start,
|
||||
// // mainAxisSize: MainAxisSize.min,
|
||||
// // crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// // children: [
|
||||
// // Text(
|
||||
// // SimpleSwapExchange.exchangeName,
|
||||
// // style: STextStyles.titleBold12(context).copyWith(
|
||||
// // color: Theme.of(context)
|
||||
// // .extension<StackColors>()!
|
||||
// // .textDark2,
|
||||
// // ),
|
||||
// // ),
|
||||
// // if (from != null &&
|
||||
// // to != null &&
|
||||
// // toAmount != null &&
|
||||
// // toAmount! > Decimal.zero &&
|
||||
// // fromAmount != null &&
|
||||
// // fromAmount! > Decimal.zero)
|
||||
// // FutureBuilder(
|
||||
// // future: SimpleSwapExchange().getEstimate(
|
||||
// // from!,
|
||||
// // to!,
|
||||
// // // reversed ? toAmount! : fromAmount!,
|
||||
// // fromAmount!,
|
||||
// // fixedRate,
|
||||
// // // reversed,
|
||||
// // false,
|
||||
// // ),
|
||||
// // builder: (context,
|
||||
// // AsyncSnapshot<ExchangeResponse<Estimate>>
|
||||
// // snapshot) {
|
||||
// // if (snapshot.connectionState ==
|
||||
// // ConnectionState.done &&
|
||||
// // snapshot.hasData) {
|
||||
// // final estimate = snapshot.data?.value;
|
||||
// // if (estimate != null) {
|
||||
// // Decimal rate = (estimate.estimatedAmount /
|
||||
// // fromAmount!)
|
||||
// // .toDecimal(
|
||||
// // scaleOnInfinitePrecision: 12);
|
||||
// //
|
||||
// // Coin coin;
|
||||
// // try {
|
||||
// // coin =
|
||||
// // coinFromTickerCaseInsensitive(to!);
|
||||
// // } catch (_) {
|
||||
// // coin = Coin.bitcoin;
|
||||
// // }
|
||||
// // return Text(
|
||||
// // "1 ${from!.toUpperCase()} ~ ${Format.localizedStringAsFixed(
|
||||
// // value: rate,
|
||||
// // locale: ref.watch(
|
||||
// // localeServiceChangeNotifierProvider
|
||||
// // .select(
|
||||
// // (value) => value.locale),
|
||||
// // ),
|
||||
// // decimalPlaces:
|
||||
// // Constants.decimalPlacesForCoin(
|
||||
// // coin),
|
||||
// // )} ${to!.toUpperCase()}",
|
||||
// // style:
|
||||
// // STextStyles.itemSubtitle12(context)
|
||||
// // .copyWith(
|
||||
// // color: Theme.of(context)
|
||||
// // .extension<StackColors>()!
|
||||
// // .textSubtitle1,
|
||||
// // ),
|
||||
// // );
|
||||
// // } else {
|
||||
// // Logging.instance.log(
|
||||
// // "$runtimeType failed to fetch rate for SimpleSwap: ${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 (!(from != null &&
|
||||
// // // to != null &&
|
||||
// // // (reversed
|
||||
// // // ? toAmount != null && toAmount! > Decimal.zero
|
||||
// // // : fromAmount != null &&
|
||||
// // // fromAmount! > Decimal.zero)))
|
||||
// // if (!(from != null &&
|
||||
// // to != 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,
|
||||
// // ),
|
||||
// // ),
|
||||
// // ],
|
||||
// // ),
|
||||
// // ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue