2022-10-03 18:24:57 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:decimal/decimal.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-04-12 13:42:07 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2023-02-08 19:06:26 +00:00
|
|
|
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
|
|
|
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
|
2023-03-28 23:17:59 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:stackwallet/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_1_view.dart';
|
2022-10-03 19:18:57 +00:00
|
|
|
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_2_view.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_provider_options.dart';
|
|
|
|
import 'package:stackwallet/pages/exchange_view/sub_widgets/rate_type_toggle.dart';
|
2022-11-19 16:01:09 +00:00
|
|
|
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
2022-10-04 17:06:14 +00:00
|
|
|
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2022-11-22 20:42:24 +00:00
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
2022-10-03 19:18:57 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2023-02-08 22:46:30 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-11-18 22:06:29 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
|
2022-11-19 15:20:43 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
2022-11-19 15:20:43 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
2022-11-18 22:06:29 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2022-11-21 17:21:44 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
2022-11-22 20:42:24 +00:00
|
|
|
import 'package:stackwallet/widgets/textfields/exchange_textfield.dart';
|
2022-10-03 19:18:57 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
2022-10-03 18:24:57 +00:00
|
|
|
|
|
|
|
class ExchangeForm extends ConsumerStatefulWidget {
|
2022-10-03 19:18:57 +00:00
|
|
|
const ExchangeForm({
|
|
|
|
Key? key,
|
|
|
|
this.walletId,
|
|
|
|
this.coin,
|
2023-03-28 23:17:59 +00:00
|
|
|
this.contract,
|
2022-10-03 19:18:57 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String? walletId;
|
|
|
|
final Coin? coin;
|
2023-03-28 23:17:59 +00:00
|
|
|
final EthContract? contract;
|
2022-10-03 18:24:57 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ExchangeForm> createState() => _ExchangeFormState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
2022-10-03 19:18:57 +00:00
|
|
|
late final String? walletId;
|
|
|
|
late final Coin? coin;
|
|
|
|
late final bool walletInitiated;
|
|
|
|
|
2022-10-03 18:24:57 +00:00
|
|
|
late final TextEditingController _sendController;
|
|
|
|
late final TextEditingController _receiveController;
|
2022-11-18 22:06:29 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
2022-10-03 18:24:57 +00:00
|
|
|
final FocusNode _sendFocusNode = FocusNode();
|
|
|
|
final FocusNode _receiveFocusNode = FocusNode();
|
|
|
|
|
|
|
|
bool _swapLock = false;
|
|
|
|
|
2023-02-06 19:08:24 +00:00
|
|
|
// todo: check and adjust this value?
|
2023-02-06 22:16:17 +00:00
|
|
|
static const _valueCheckInterval = Duration(milliseconds: 300);
|
|
|
|
|
|
|
|
Future<T> showUpdatingExchangeRate<T>({
|
|
|
|
required Future<T> whileFuture,
|
|
|
|
}) async {
|
|
|
|
unawaited(
|
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (_) => WillPopScope(
|
|
|
|
onWillPop: () async => false,
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.overlay
|
|
|
|
.withOpacity(0.6),
|
|
|
|
child: const CustomLoadingOverlay(
|
|
|
|
message: "Updating exchange rate",
|
|
|
|
eventBus: null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final result = await whileFuture;
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
Navigator.of(context, rootNavigator: isDesktop).pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-02-06 19:08:24 +00:00
|
|
|
|
|
|
|
Timer? _sendFieldOnChangedTimer;
|
2022-10-03 18:24:57 +00:00
|
|
|
void sendFieldOnChanged(String value) async {
|
2022-12-28 23:41:34 +00:00
|
|
|
if (_sendFocusNode.hasFocus) {
|
2023-02-06 19:08:24 +00:00
|
|
|
_sendFieldOnChangedTimer?.cancel();
|
2022-12-28 23:41:34 +00:00
|
|
|
|
2023-02-06 19:08:24 +00:00
|
|
|
_sendFieldOnChangedTimer = Timer(_valueCheckInterval, () async {
|
2023-04-12 13:42:07 +00:00
|
|
|
final newFromAmount = _localizedStringToNum(value);
|
2023-02-06 19:08:24 +00:00
|
|
|
|
|
|
|
await ref
|
|
|
|
.read(exchangeFormStateProvider)
|
|
|
|
.setSendAmountAndCalculateReceiveAmount(newFromAmount, true);
|
|
|
|
});
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 19:08:24 +00:00
|
|
|
Timer? _receiveFieldOnChangedTimer;
|
2023-02-05 20:32:39 +00:00
|
|
|
void receiveFieldOnChanged(String value) async {
|
2023-02-06 19:08:24 +00:00
|
|
|
_receiveFieldOnChangedTimer?.cancel();
|
|
|
|
|
|
|
|
_receiveFieldOnChangedTimer = Timer(_valueCheckInterval, () async {
|
2023-04-12 13:42:07 +00:00
|
|
|
final newToAmount = _localizedStringToNum(value);
|
2023-02-06 19:08:24 +00:00
|
|
|
|
|
|
|
await ref
|
|
|
|
.read(exchangeFormStateProvider)
|
|
|
|
.setReceivingAmountAndCalculateSendAmount(newToAmount, true);
|
|
|
|
});
|
2023-02-05 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 13:42:07 +00:00
|
|
|
Decimal? _localizedStringToNum(String? value) {
|
|
|
|
if (value == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
final numFromLocalised = NumberFormat.decimalPattern(
|
|
|
|
ref.read(localeServiceChangeNotifierProvider).locale)
|
|
|
|
.parse(value);
|
|
|
|
return Decimal.tryParse(numFromLocalised.toString());
|
|
|
|
} catch (_) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 19:06:26 +00:00
|
|
|
Future<AggregateCurrency> _getAggregateCurrency(Currency currency) async {
|
2023-02-08 20:48:09 +00:00
|
|
|
final rateType = ref.read(exchangeFormStateProvider).exchangeRateType;
|
2023-02-08 19:06:26 +00:00
|
|
|
final currencies = await ExchangeDataLoadingService.instance.isar.currencies
|
|
|
|
.filter()
|
|
|
|
.group((q) => rateType == ExchangeRateType.fixed
|
|
|
|
? q
|
|
|
|
.rateTypeEqualTo(SupportedRateType.both)
|
|
|
|
.or()
|
|
|
|
.rateTypeEqualTo(SupportedRateType.fixed)
|
|
|
|
: q
|
|
|
|
.rateTypeEqualTo(SupportedRateType.both)
|
|
|
|
.or()
|
|
|
|
.rateTypeEqualTo(SupportedRateType.estimated))
|
|
|
|
.and()
|
|
|
|
.tickerEqualTo(
|
|
|
|
currency.ticker,
|
|
|
|
caseSensitive: false,
|
|
|
|
)
|
2023-04-10 20:14:03 +00:00
|
|
|
.and()
|
|
|
|
.tokenContractEqualTo(currency.tokenContract)
|
2023-02-08 19:06:26 +00:00
|
|
|
.findAll();
|
|
|
|
|
|
|
|
final items = [Tuple2(currency.exchangeName, currency)];
|
|
|
|
|
|
|
|
for (final currency in currencies) {
|
|
|
|
items.add(Tuple2(currency.exchangeName, currency));
|
|
|
|
}
|
|
|
|
|
|
|
|
return AggregateCurrency(exchangeCurrencyPairs: items);
|
|
|
|
}
|
|
|
|
|
2022-10-03 18:24:57 +00:00
|
|
|
void selectSendCurrency() async {
|
2023-02-08 20:48:09 +00:00
|
|
|
final type = (ref.read(exchangeFormStateProvider).exchangeRateType);
|
2023-02-06 16:27:24 +00:00
|
|
|
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "";
|
2022-10-03 19:18:57 +00:00
|
|
|
|
2023-03-28 23:17:59 +00:00
|
|
|
if (walletInitiated) {
|
|
|
|
if (widget.contract != null &&
|
|
|
|
fromTicker.toLowerCase() == widget.contract!.symbol.toLowerCase()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fromTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
|
|
|
|
// do not allow changing away from wallet coin
|
|
|
|
return;
|
|
|
|
}
|
2023-02-05 20:32:39 +00:00
|
|
|
}
|
2022-10-04 17:06:14 +00:00
|
|
|
|
2023-02-06 21:58:20 +00:00
|
|
|
final selectedCurrency = await _showCurrencySelectionSheet(
|
2023-02-08 19:06:26 +00:00
|
|
|
willChange: ref.read(exchangeFormStateProvider).sendCurrency?.ticker,
|
2023-02-06 16:50:32 +00:00
|
|
|
willChangeIsSend: true,
|
2023-02-08 19:06:26 +00:00
|
|
|
paired: ref.read(exchangeFormStateProvider).receiveCurrency?.ticker,
|
2023-02-05 21:25:35 +00:00
|
|
|
isFixedRate: type == ExchangeRateType.fixed,
|
2023-02-05 20:32:39 +00:00
|
|
|
);
|
2022-12-31 00:26:14 +00:00
|
|
|
|
2023-02-06 21:58:20 +00:00
|
|
|
if (selectedCurrency != null) {
|
2023-02-06 22:16:17 +00:00
|
|
|
await showUpdatingExchangeRate(
|
2023-02-08 19:06:26 +00:00
|
|
|
whileFuture: _getAggregateCurrency(selectedCurrency).then(
|
|
|
|
(aggregateSelected) => ref
|
|
|
|
.read(exchangeFormStateProvider)
|
|
|
|
.updateSendCurrency(aggregateSelected, true)),
|
2023-02-06 21:58:20 +00:00
|
|
|
);
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void selectReceiveCurrency() async {
|
2023-02-06 16:27:24 +00:00
|
|
|
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "";
|
2023-02-05 20:32:39 +00:00
|
|
|
if (walletInitiated &&
|
|
|
|
toTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
|
|
|
|
// do not allow changing away from wallet coin
|
|
|
|
return;
|
|
|
|
}
|
2022-10-04 17:06:14 +00:00
|
|
|
|
2023-02-06 21:58:20 +00:00
|
|
|
final selectedCurrency = await _showCurrencySelectionSheet(
|
2023-02-08 19:06:26 +00:00
|
|
|
willChange: ref.read(exchangeFormStateProvider).receiveCurrency?.ticker,
|
2023-02-06 19:08:24 +00:00
|
|
|
willChangeIsSend: false,
|
2023-02-08 19:06:26 +00:00
|
|
|
paired: ref.read(exchangeFormStateProvider).sendCurrency?.ticker,
|
2023-02-08 20:48:09 +00:00
|
|
|
isFixedRate: ref.read(exchangeFormStateProvider).exchangeRateType ==
|
2023-02-06 21:58:20 +00:00
|
|
|
ExchangeRateType.fixed,
|
2023-02-05 20:32:39 +00:00
|
|
|
);
|
2023-01-02 18:44:33 +00:00
|
|
|
|
2023-02-06 21:58:20 +00:00
|
|
|
if (selectedCurrency != null) {
|
2023-02-06 22:16:17 +00:00
|
|
|
await showUpdatingExchangeRate(
|
2023-02-08 19:06:26 +00:00
|
|
|
whileFuture: _getAggregateCurrency(selectedCurrency).then(
|
|
|
|
(aggregateSelected) => ref
|
|
|
|
.read(exchangeFormStateProvider)
|
|
|
|
.updateReceivingCurrency(aggregateSelected, true)),
|
2023-02-06 21:58:20 +00:00
|
|
|
);
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _swap() async {
|
|
|
|
_swapLock = true;
|
|
|
|
_sendFocusNode.unfocus();
|
|
|
|
_receiveFocusNode.unfocus();
|
|
|
|
|
2023-02-06 22:16:17 +00:00
|
|
|
await showUpdatingExchangeRate(
|
|
|
|
whileFuture:
|
|
|
|
ref.read(exchangeFormStateProvider).swap(shouldNotifyListeners: true),
|
2022-10-03 18:24:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
_swapLock = false;
|
|
|
|
}
|
|
|
|
|
2023-02-06 21:58:20 +00:00
|
|
|
Future<Currency?> _showCurrencySelectionSheet({
|
2023-02-08 19:06:26 +00:00
|
|
|
required String? willChange,
|
|
|
|
required String? paired,
|
2023-02-05 20:32:39 +00:00
|
|
|
required bool isFixedRate,
|
2023-02-06 16:50:32 +00:00
|
|
|
required bool willChangeIsSend,
|
2022-10-03 18:24:57 +00:00
|
|
|
}) async {
|
|
|
|
_sendFocusNode.unfocus();
|
|
|
|
_receiveFocusNode.unfocus();
|
|
|
|
|
2022-11-21 17:21:44 +00:00
|
|
|
final result = isDesktop
|
|
|
|
? await showDialog<Currency?>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return DesktopDialog(
|
|
|
|
maxHeight: 700,
|
|
|
|
maxWidth: 580,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 32,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
"Choose a coin to exchange",
|
|
|
|
style: STextStyles.desktopH3(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const DesktopDialogCloseButton(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 32,
|
|
|
|
right: 32,
|
|
|
|
bottom: 32,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: RoundedWhiteContainer(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
borderColor: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.background,
|
2023-02-05 20:32:39 +00:00
|
|
|
child: ExchangeCurrencySelectionView(
|
2023-02-08 19:06:26 +00:00
|
|
|
willChangeTicker: willChange,
|
|
|
|
pairedTicker: paired,
|
2023-02-05 20:32:39 +00:00
|
|
|
isFixedRate: isFixedRate,
|
2023-02-06 16:50:32 +00:00
|
|
|
willChangeIsSend: willChangeIsSend,
|
2022-11-21 17:21:44 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: await Navigator.of(context).push(
|
|
|
|
MaterialPageRoute<dynamic>(
|
2023-02-05 20:32:39 +00:00
|
|
|
builder: (_) => ExchangeCurrencySelectionView(
|
2023-02-08 19:06:26 +00:00
|
|
|
willChangeTicker: willChange,
|
|
|
|
pairedTicker: paired,
|
2023-02-05 20:32:39 +00:00
|
|
|
isFixedRate: isFixedRate,
|
2023-02-06 16:50:32 +00:00
|
|
|
willChangeIsSend: willChangeIsSend,
|
2022-11-21 17:21:44 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-10-03 18:24:57 +00:00
|
|
|
|
|
|
|
if (mounted && result is Currency) {
|
2023-02-06 21:58:20 +00:00
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return null;
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 16:27:24 +00:00
|
|
|
void onRateTypeChanged(ExchangeRateType newType) async {
|
2022-10-03 18:24:57 +00:00
|
|
|
_receiveFocusNode.unfocus();
|
|
|
|
_sendFocusNode.unfocus();
|
2022-10-04 00:01:04 +00:00
|
|
|
|
2023-02-06 22:16:17 +00:00
|
|
|
await showUpdatingExchangeRate(
|
|
|
|
whileFuture: _onRateTypeChangedFuture(newType),
|
2022-10-04 00:01:04 +00:00
|
|
|
);
|
2023-02-06 22:16:17 +00:00
|
|
|
}
|
2022-10-04 00:01:04 +00:00
|
|
|
|
2023-02-06 22:16:17 +00:00
|
|
|
Future<void> _onRateTypeChangedFuture(ExchangeRateType newType) async {
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.read(exchangeFormStateProvider).exchangeRateType = newType;
|
|
|
|
|
|
|
|
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "-";
|
|
|
|
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "-";
|
2023-02-05 21:11:58 +00:00
|
|
|
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.read(exchangeFormStateProvider).reversed = false;
|
2022-10-04 00:01:04 +00:00
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
if (!(toTicker == "-" || fromTicker == "-")) {
|
2023-02-08 19:06:26 +00:00
|
|
|
// final available = await ExchangeDataLoadingService.instance.isar.pairs
|
|
|
|
// .where()
|
|
|
|
// .exchangeNameEqualTo(
|
|
|
|
// ref.read(currentExchangeNameStateProvider.state).state)
|
|
|
|
// .filter()
|
|
|
|
// .fromEqualTo(fromTicker)
|
|
|
|
// .and()
|
|
|
|
// .toEqualTo(toTicker)
|
|
|
|
// .findAll();
|
|
|
|
await ref.read(exchangeFormStateProvider).refresh();
|
|
|
|
|
|
|
|
// if (available.isNotEmpty) {
|
|
|
|
// final availableCurrencies = await ExchangeDataLoadingService
|
|
|
|
// .instance.isar.currencies
|
|
|
|
// .where()
|
|
|
|
// .exchangeNameEqualTo(
|
|
|
|
// ref.read(currentExchangeNameStateProvider.state).state)
|
|
|
|
// .filter()
|
|
|
|
// .tickerEqualTo(fromTicker)
|
|
|
|
// .or()
|
|
|
|
// .tickerEqualTo(toTicker)
|
|
|
|
// .findAll();
|
|
|
|
//
|
|
|
|
// 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).receiveAmount = newFromAmount;
|
|
|
|
// if (newFromAmount == null) {
|
|
|
|
// _receiveController.text = "";
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// await ref
|
|
|
|
// .read(exchangeFormStateProvider)
|
|
|
|
// .updateReceivingCurrency(to, false);
|
|
|
|
// await ref
|
|
|
|
// .read(exchangeFormStateProvider)
|
|
|
|
// .updateSendCurrency(from, true);
|
|
|
|
//
|
|
|
|
// _receiveController.text =
|
|
|
|
// ref.read(exchangeFormStateProvider).toAmountString.isEmpty
|
|
|
|
// ? "-"
|
|
|
|
// : ref.read(exchangeFormStateProvider).toAmountString;
|
|
|
|
// if (mounted) {
|
|
|
|
// Navigator.of(context, rootNavigator: isDesktop).pop();
|
|
|
|
// }
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
2023-02-05 20:32:39 +00:00
|
|
|
}
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onExchangePressed() async {
|
2023-02-08 20:48:09 +00:00
|
|
|
final rateType = ref.read(exchangeFormStateProvider).exchangeRateType;
|
2023-02-06 16:27:24 +00:00
|
|
|
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "";
|
|
|
|
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "";
|
|
|
|
final sendAmount = ref.read(exchangeFormStateProvider).sendAmount!;
|
2023-05-01 22:26:12 +00:00
|
|
|
final estimate = ref.read(exchangeFormStateProvider).estimates.firstWhere(
|
|
|
|
(e) =>
|
|
|
|
e.exchangeProvider ==
|
|
|
|
ref.read(exchangeFormStateProvider).providerName,
|
|
|
|
);
|
2022-10-03 18:24:57 +00:00
|
|
|
|
2023-02-16 17:40:41 +00:00
|
|
|
if (rateType == ExchangeRateType.fixed && toTicker.toUpperCase() == "WOW") {
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const StackOkDialog(
|
|
|
|
title: "WOW error",
|
|
|
|
message:
|
|
|
|
"Wownero is temporarily disabled as a receiving currency for fixed rate trades due to network issues",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-04 17:06:14 +00:00
|
|
|
String rate;
|
2022-10-03 18:24:57 +00:00
|
|
|
|
2022-10-04 17:06:14 +00:00
|
|
|
switch (rateType) {
|
|
|
|
case ExchangeRateType.estimated:
|
|
|
|
rate =
|
|
|
|
"1 ${fromTicker.toUpperCase()} ~${(estimate.estimatedAmount / sendAmount).toDecimal(scaleOnInfinitePrecision: 8).toStringAsFixed(8)} ${toTicker.toUpperCase()}";
|
|
|
|
break;
|
|
|
|
case ExchangeRateType.fixed:
|
|
|
|
bool? shouldCancel;
|
|
|
|
|
|
|
|
if (estimate.warningMessage != null &&
|
|
|
|
estimate.warningMessage!.isNotEmpty) {
|
|
|
|
shouldCancel = await showDialog<bool?>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true,
|
2022-11-19 15:20:43 +00:00
|
|
|
builder: (_) {
|
|
|
|
if (isDesktop) {
|
|
|
|
return DesktopDialog(
|
|
|
|
maxWidth: 500,
|
|
|
|
maxHeight: 300,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Failed to update trade estimate",
|
|
|
|
style: STextStyles.desktopH3(context),
|
|
|
|
),
|
|
|
|
const DesktopDialogCloseButton(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
Text(
|
|
|
|
estimate.warningMessage!,
|
|
|
|
style: STextStyles.desktopTextSmall(context),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
Text(
|
|
|
|
"Do you want to attempt trade anyways?",
|
|
|
|
style: STextStyles.desktopTextSmall(context),
|
|
|
|
),
|
|
|
|
const Spacer(
|
|
|
|
flex: 2,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: SecondaryButton(
|
|
|
|
label: "Cancel",
|
|
|
|
buttonHeight: ButtonHeight.l,
|
|
|
|
onPressed: () => Navigator.of(
|
|
|
|
context,
|
|
|
|
rootNavigator: true,
|
|
|
|
).pop(true),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 16,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: PrimaryButton(
|
|
|
|
label: "Attempt",
|
|
|
|
buttonHeight: ButtonHeight.l,
|
|
|
|
onPressed: () => Navigator.of(
|
|
|
|
context,
|
|
|
|
rootNavigator: true,
|
|
|
|
).pop(false),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return StackDialog(
|
|
|
|
title: "Failed to update trade estimate",
|
|
|
|
message:
|
|
|
|
"${estimate.warningMessage!}\n\nDo you want to attempt trade anyways?",
|
|
|
|
leftButton: TextButton(
|
|
|
|
style: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-01-24 19:29:12 +00:00
|
|
|
.getSecondaryEnabledButtonStyle(context),
|
2022-11-19 15:20:43 +00:00
|
|
|
child: Text(
|
|
|
|
"Cancel",
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
// notify return to cancel
|
|
|
|
Navigator.of(context).pop(true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
rightButton: TextButton(
|
|
|
|
style: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-01-24 19:29:12 +00:00
|
|
|
.getPrimaryEnabledButtonStyle(context),
|
2022-11-19 15:20:43 +00:00
|
|
|
child: Text(
|
|
|
|
"Attempt",
|
|
|
|
style: STextStyles.button(context),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
// continue and try to attempt trade
|
|
|
|
Navigator.of(context).pop(false);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2022-10-04 17:06:14 +00:00
|
|
|
);
|
|
|
|
}
|
2022-10-03 18:24:57 +00:00
|
|
|
|
2022-10-04 17:06:14 +00:00
|
|
|
if (shouldCancel is bool && shouldCancel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rate =
|
2023-02-06 16:27:24 +00:00
|
|
|
"1 ${fromTicker.toUpperCase()} ~${ref.read(exchangeFormStateProvider).rate!.toStringAsFixed(8)} ${toTicker.toUpperCase()}";
|
2022-10-04 17:06:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-03 18:24:57 +00:00
|
|
|
|
2022-10-04 17:06:14 +00:00
|
|
|
final model = IncompleteExchangeModel(
|
|
|
|
sendTicker: fromTicker.toUpperCase(),
|
|
|
|
receiveTicker: toTicker.toUpperCase(),
|
|
|
|
rateInfo: rate,
|
|
|
|
sendAmount: estimate.reversed ? estimate.estimatedAmount : sendAmount,
|
|
|
|
receiveAmount: estimate.reversed
|
2023-02-06 16:27:24 +00:00
|
|
|
? ref.read(exchangeFormStateProvider).receiveAmount!
|
2022-10-04 17:06:14 +00:00
|
|
|
: estimate.estimatedAmount,
|
|
|
|
rateType: rateType,
|
2023-04-28 20:29:10 +00:00
|
|
|
estimate: estimate,
|
2022-10-04 17:06:14 +00:00
|
|
|
reversed: estimate.reversed,
|
2023-02-09 13:31:31 +00:00
|
|
|
walletInitiated: walletInitiated,
|
2022-10-04 17:06:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
if (walletInitiated) {
|
|
|
|
ref.read(exchangeSendFromWalletIdStateProvider.state).state =
|
|
|
|
Tuple2(walletId!, coin!);
|
2022-11-19 16:01:09 +00:00
|
|
|
if (isDesktop) {
|
2022-11-30 21:15:06 +00:00
|
|
|
ref.read(ssss.state).state = model;
|
2022-11-19 16:01:09 +00:00
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
2022-11-21 22:00:00 +00:00
|
|
|
barrierDismissible: false,
|
2022-11-19 16:01:09 +00:00
|
|
|
builder: (context) {
|
2022-11-30 21:15:06 +00:00
|
|
|
return const DesktopDialog(
|
2022-11-21 15:15:13 +00:00
|
|
|
maxWidth: 720,
|
|
|
|
maxHeight: double.infinity,
|
2022-11-19 16:01:09 +00:00
|
|
|
child: StepScaffold(
|
2022-11-30 21:15:06 +00:00
|
|
|
initialStep: 2,
|
2022-11-19 16:01:09 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
unawaited(
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
Step2View.routeName,
|
|
|
|
arguments: model,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-10-04 17:06:14 +00:00
|
|
|
} else {
|
|
|
|
ref.read(exchangeSendFromWalletIdStateProvider.state).state = null;
|
2022-11-19 16:01:09 +00:00
|
|
|
|
|
|
|
if (isDesktop) {
|
2022-11-30 21:15:06 +00:00
|
|
|
ref.read(ssss.state).state = model;
|
2022-11-19 16:01:09 +00:00
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
2022-11-21 22:00:00 +00:00
|
|
|
barrierDismissible: false,
|
2022-11-19 16:01:09 +00:00
|
|
|
builder: (context) {
|
2022-11-30 21:15:06 +00:00
|
|
|
return const DesktopDialog(
|
2022-11-21 15:15:13 +00:00
|
|
|
maxWidth: 720,
|
|
|
|
maxHeight: double.infinity,
|
2022-11-19 16:01:09 +00:00
|
|
|
child: StepScaffold(
|
2022-11-30 21:15:06 +00:00
|
|
|
initialStep: 1,
|
2022-11-19 16:01:09 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
unawaited(
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
Step1View.routeName,
|
|
|
|
arguments: model,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-10-03 19:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWalletCoin(Coin? coin, bool isSend) {
|
|
|
|
if (coin == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-06 22:16:17 +00:00
|
|
|
String? ticker = isSend
|
|
|
|
? ref.read(exchangeFormStateProvider).fromTicker
|
|
|
|
: ref.read(exchangeFormStateProvider).toTicker;
|
2022-10-03 19:18:57 +00:00
|
|
|
|
|
|
|
if (ticker == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return coin.ticker.toUpperCase() == ticker.toUpperCase();
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_sendController = TextEditingController();
|
|
|
|
_receiveController = TextEditingController();
|
|
|
|
|
2022-10-03 19:18:57 +00:00
|
|
|
walletId = widget.walletId;
|
|
|
|
coin = widget.coin;
|
|
|
|
walletInitiated = walletId != null && coin != null;
|
|
|
|
|
|
|
|
if (walletInitiated) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.read(exchangeFormStateProvider).reset(shouldNotifyListeners: true);
|
2023-03-10 22:47:48 +00:00
|
|
|
ExchangeDataLoadingService.instance
|
|
|
|
.getAggregateCurrency(
|
2023-03-28 23:17:59 +00:00
|
|
|
widget.contract == null ? coin!.ticker : widget.contract!.symbol,
|
2023-03-10 22:47:48 +00:00
|
|
|
ExchangeRateType.estimated,
|
2023-04-10 20:14:03 +00:00
|
|
|
widget.contract == null ? null : widget.contract!.address,
|
2023-03-10 22:47:48 +00:00
|
|
|
)
|
|
|
|
.then((value) {
|
|
|
|
if (value != null) {
|
|
|
|
ref.read(exchangeFormStateProvider).updateSendCurrency(value, true);
|
|
|
|
}
|
|
|
|
});
|
2022-10-03 19:18:57 +00:00
|
|
|
});
|
|
|
|
} else {
|
2022-10-04 00:01:04 +00:00
|
|
|
_sendController.text =
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.read(exchangeFormStateProvider).fromAmountString;
|
2023-02-06 21:50:18 +00:00
|
|
|
_receiveController.text =
|
|
|
|
ref.read(exchangeFormStateProvider).toAmountString;
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
|
|
ref.read(exchangeFormStateProvider).refresh();
|
|
|
|
});
|
2022-10-03 19:18:57 +00:00
|
|
|
}
|
2022-10-03 18:24:57 +00:00
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_receiveController.dispose();
|
|
|
|
_sendController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
|
2023-02-05 21:11:58 +00:00
|
|
|
final rateType = ref.watch(
|
2023-02-08 20:48:09 +00:00
|
|
|
exchangeFormStateProvider.select((value) => value.exchangeRateType));
|
2023-02-05 21:11:58 +00:00
|
|
|
|
2023-02-06 23:49:27 +00:00
|
|
|
final isEstimated = rateType == ExchangeRateType.estimated;
|
2022-10-03 18:24:57 +00:00
|
|
|
|
|
|
|
ref.listen(
|
2023-02-06 16:27:24 +00:00
|
|
|
exchangeFormStateProvider.select((value) => value.toAmountString),
|
|
|
|
(previous, String next) {
|
2022-10-03 18:24:57 +00:00
|
|
|
if (!_receiveFocusNode.hasFocus) {
|
2022-12-26 21:06:51 +00:00
|
|
|
_receiveController.text = isEstimated && next.isEmpty ? "-" : next;
|
2022-10-03 18:24:57 +00:00
|
|
|
if (_swapLock) {
|
2022-10-04 00:01:04 +00:00
|
|
|
_sendController.text =
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.read(exchangeFormStateProvider).fromAmountString;
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ref.listen(
|
2023-02-06 16:27:24 +00:00
|
|
|
exchangeFormStateProvider.select((value) => value.fromAmountString),
|
2022-10-04 00:01:04 +00:00
|
|
|
(previous, String next) {
|
2022-10-03 18:24:57 +00:00
|
|
|
if (!_sendFocusNode.hasFocus) {
|
|
|
|
_sendController.text = next;
|
|
|
|
if (_swapLock) {
|
|
|
|
_receiveController.text = isEstimated
|
2023-02-06 16:27:24 +00:00
|
|
|
? ref.read(exchangeFormStateProvider).toAmountString.isEmpty
|
2022-10-03 18:24:57 +00:00
|
|
|
? "-"
|
2023-02-06 16:27:24 +00:00
|
|
|
: ref.read(exchangeFormStateProvider).toAmountString
|
|
|
|
: ref.read(exchangeFormStateProvider).toAmountString;
|
2022-10-03 18:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"You will send",
|
|
|
|
style: STextStyles.itemSubtitle(context).copyWith(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
|
|
|
),
|
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 10 : 4,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-22 20:42:24 +00:00
|
|
|
ExchangeTextField(
|
2023-02-06 21:45:00 +00:00
|
|
|
key: Key(
|
|
|
|
"exchangeTextFieldKeyFor_${Theme.of(context).extension<StackColors>()!.themeType.name}"),
|
2022-11-22 20:42:24 +00:00
|
|
|
controller: _sendController,
|
|
|
|
focusNode: _sendFocusNode,
|
|
|
|
textStyle: STextStyles.smallMed14(context).copyWith(
|
2022-10-03 18:24:57 +00:00
|
|
|
color: Theme.of(context).extension<StackColors>()!.textDark,
|
|
|
|
),
|
2022-11-22 20:42:24 +00:00
|
|
|
buttonColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
|
|
|
borderRadius: Constants.size.circularBorderRadius,
|
|
|
|
background:
|
|
|
|
Theme.of(context).extension<StackColors>()!.textFieldDefaultBG,
|
2022-10-03 18:24:57 +00:00
|
|
|
onTap: () {
|
|
|
|
if (_sendController.text == "-") {
|
|
|
|
_sendController.text = "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: sendFieldOnChanged,
|
2022-11-22 20:42:24 +00:00
|
|
|
onButtonTap: selectSendCurrency,
|
|
|
|
isWalletCoin: isWalletCoin(coin, true),
|
2023-02-08 17:25:31 +00:00
|
|
|
currency: ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.sendCurrency)),
|
2022-11-22 20:42:24 +00:00
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 10 : 4,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 10 : 4,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
if (ref
|
2023-02-06 16:27:24 +00:00
|
|
|
.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.warning))
|
2022-11-18 22:06:29 +00:00
|
|
|
.isNotEmpty &&
|
2023-02-06 16:27:24 +00:00
|
|
|
!ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.reversed)))
|
2022-11-18 22:06:29 +00:00
|
|
|
Text(
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.warning)),
|
2022-11-18 22:06:29 +00:00
|
|
|
style: STextStyles.errorSmall(context),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-10-03 18:24:57 +00:00
|
|
|
children: [
|
2022-11-18 22:06:29 +00:00
|
|
|
Text(
|
|
|
|
"You will receive",
|
|
|
|
style: STextStyles.itemSubtitle(context).copyWith(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
ConditionalParent(
|
|
|
|
condition: isDesktop,
|
|
|
|
builder: (child) => MouseRegion(
|
|
|
|
cursor: SystemMouseCursors.click,
|
2022-11-23 14:36:27 +00:00
|
|
|
child: child,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-23 14:36:27 +00:00
|
|
|
child: RoundedContainer(
|
|
|
|
padding: isDesktop
|
|
|
|
? const EdgeInsets.all(6)
|
|
|
|
: const EdgeInsets.all(2),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonBackSecondary,
|
|
|
|
radiusMultiplier: 0.75,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () async {
|
|
|
|
await _swap();
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.swap,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark,
|
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
),
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
SizedBox(
|
2022-11-23 14:36:27 +00:00
|
|
|
height: isDesktop ? 10 : 7,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-22 20:42:24 +00:00
|
|
|
ExchangeTextField(
|
2023-02-06 21:45:00 +00:00
|
|
|
key: Key(
|
|
|
|
"exchangeTextFieldKeyFor1_${Theme.of(context).extension<StackColors>()!.themeType.name}"),
|
2022-10-03 18:24:57 +00:00
|
|
|
focusNode: _receiveFocusNode,
|
|
|
|
controller: _receiveController,
|
2022-11-22 20:42:24 +00:00
|
|
|
textStyle: STextStyles.smallMed14(context).copyWith(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.textDark,
|
|
|
|
),
|
|
|
|
buttonColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
|
|
|
borderRadius: Constants.size.circularBorderRadius,
|
|
|
|
background:
|
|
|
|
Theme.of(context).extension<StackColors>()!.textFieldDefaultBG,
|
2022-10-03 18:24:57 +00:00
|
|
|
onTap: () {
|
2023-02-08 20:48:09 +00:00
|
|
|
if (!(ref.read(exchangeFormStateProvider).exchangeRateType ==
|
2022-10-03 18:24:57 +00:00
|
|
|
ExchangeRateType.estimated) &&
|
|
|
|
_receiveController.text == "-") {
|
|
|
|
_receiveController.text = "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: receiveFieldOnChanged,
|
2022-11-22 20:42:24 +00:00
|
|
|
onButtonTap: selectReceiveCurrency,
|
|
|
|
isWalletCoin: isWalletCoin(coin, true),
|
2023-02-08 17:25:31 +00:00
|
|
|
currency: ref.watch(exchangeFormStateProvider
|
|
|
|
.select((value) => value.receiveCurrency)),
|
2023-02-06 19:08:24 +00:00
|
|
|
readOnly: (rateType) == ExchangeRateType.estimated &&
|
2023-02-08 20:22:22 +00:00
|
|
|
ref.watch(exchangeFormStateProvider
|
|
|
|
.select((value) => value.exchange.name)) ==
|
2023-02-06 19:08:24 +00:00
|
|
|
ChangeNowExchange.exchangeName,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
if (ref
|
2023-02-06 16:27:24 +00:00
|
|
|
.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.warning))
|
2022-11-18 22:06:29 +00:00
|
|
|
.isNotEmpty &&
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.reversed)))
|
2022-11-18 22:06:29 +00:00
|
|
|
Text(
|
2023-02-06 16:27:24 +00:00
|
|
|
ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.warning)),
|
2022-11-18 22:06:29 +00:00
|
|
|
style: STextStyles.errorSmall(context),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 20 : 12,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-11-29 15:42:46 +00:00
|
|
|
SizedBox(
|
2023-04-13 20:46:20 +00:00
|
|
|
height: isDesktop ? 60 : 40,
|
2022-11-29 15:42:46 +00:00
|
|
|
child: RateTypeToggle(
|
2023-02-06 21:45:00 +00:00
|
|
|
key: UniqueKey(),
|
2022-11-29 15:42:46 +00:00
|
|
|
onChanged: onRateTypeChanged,
|
|
|
|
),
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
2022-12-28 23:41:34 +00:00
|
|
|
// these reads should be watch
|
2023-02-06 16:27:24 +00:00
|
|
|
if (ref.watch(exchangeFormStateProvider).sendAmount != null &&
|
|
|
|
ref.watch(exchangeFormStateProvider).sendAmount != Decimal.zero)
|
2022-11-18 22:06:29 +00:00
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 20 : 12,
|
2022-10-15 23:56:59 +00:00
|
|
|
),
|
2022-12-28 23:41:34 +00:00
|
|
|
// these reads should be watch
|
2023-02-06 16:27:24 +00:00
|
|
|
if (ref.watch(exchangeFormStateProvider).sendAmount != null &&
|
|
|
|
ref.watch(exchangeFormStateProvider).sendAmount != Decimal.zero)
|
2022-10-15 23:56:59 +00:00
|
|
|
ExchangeProviderOptions(
|
2023-02-06 23:49:27 +00:00
|
|
|
fixedRate: rateType == ExchangeRateType.fixed,
|
2023-02-06 16:27:24 +00:00
|
|
|
reversed: ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.reversed)),
|
2022-10-15 23:56:59 +00:00
|
|
|
),
|
2022-11-18 22:06:29 +00:00
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 20 : 12,
|
2022-10-03 18:24:57 +00:00
|
|
|
),
|
|
|
|
PrimaryButton(
|
2022-11-18 22:06:29 +00:00
|
|
|
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
2023-02-06 16:27:24 +00:00
|
|
|
enabled: ref.watch(
|
|
|
|
exchangeFormStateProvider.select((value) => value.canExchange)),
|
2023-02-05 20:32:39 +00:00
|
|
|
onPressed: onExchangePressed,
|
2023-03-10 22:01:34 +00:00
|
|
|
label: "Swap",
|
2022-10-03 18:24:57 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|