mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-26 00:58:50 +00:00
exchange rate calculated on send textfield change
This commit is contained in:
parent
ed486f7c16
commit
6d1f0dec8a
1 changed files with 57 additions and 45 deletions
|
@ -69,17 +69,21 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
bool _swapLock = false;
|
||||
|
||||
void sendFieldOnChanged(String value) async {
|
||||
final newFromAmount = Decimal.tryParse(value);
|
||||
if (_sendFocusNode.hasFocus) {
|
||||
final newFromAmount = Decimal.tryParse(value);
|
||||
|
||||
ref.read(exchangeFormStateProvider).fromAmount =
|
||||
newFromAmount ?? Decimal.zero;
|
||||
await ref
|
||||
.read(exchangeFormStateProvider)
|
||||
.setFromAmountAndCalculateToAmount(
|
||||
newFromAmount ?? Decimal.zero, true);
|
||||
|
||||
if (newFromAmount == null) {
|
||||
_receiveController.text =
|
||||
ref.read(prefsChangeNotifierProvider).exchangeRateType ==
|
||||
ExchangeRateType.estimated
|
||||
? "-"
|
||||
: "";
|
||||
if (newFromAmount == null) {
|
||||
_receiveController.text =
|
||||
ref.read(prefsChangeNotifierProvider).exchangeRateType ==
|
||||
ExchangeRateType.estimated
|
||||
? "-"
|
||||
: "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1117,38 +1121,43 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
: ref.read(exchangeFormStateProvider).toAmountString;
|
||||
}
|
||||
|
||||
_sendFocusNode.addListener(() async {
|
||||
if (!_sendFocusNode.hasFocus) {
|
||||
final newFromAmount = Decimal.tryParse(_sendController.text);
|
||||
await ref
|
||||
.read(exchangeFormStateProvider)
|
||||
.setFromAmountAndCalculateToAmount(
|
||||
newFromAmount ?? Decimal.zero, true);
|
||||
|
||||
if (newFromAmount == null) {
|
||||
_receiveController.text =
|
||||
ref.read(prefsChangeNotifierProvider).exchangeRateType ==
|
||||
ExchangeRateType.estimated
|
||||
? "-"
|
||||
: "";
|
||||
}
|
||||
}
|
||||
});
|
||||
_receiveFocusNode.addListener(() async {
|
||||
if (!_receiveFocusNode.hasFocus) {
|
||||
final newToAmount = Decimal.tryParse(_receiveController.text);
|
||||
if (ref.read(prefsChangeNotifierProvider).exchangeRateType !=
|
||||
ExchangeRateType.estimated) {
|
||||
await ref
|
||||
.read(exchangeFormStateProvider)
|
||||
.setToAmountAndCalculateFromAmount(
|
||||
newToAmount ?? Decimal.zero, true);
|
||||
}
|
||||
if (newToAmount == null) {
|
||||
_sendController.text = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
// _sendFocusNode.addListener(() async {
|
||||
// if (!_sendFocusNode.hasFocus) {
|
||||
// final newFromAmount = Decimal.tryParse(_sendController.text);
|
||||
// await ref
|
||||
// .read(exchangeFormStateProvider)
|
||||
// .setFromAmountAndCalculateToAmount(
|
||||
// newFromAmount ?? Decimal.zero, true);
|
||||
//
|
||||
// debugPrint("SendFocusNode has fired");
|
||||
//
|
||||
// if (newFromAmount == null) {
|
||||
// _receiveController.text =
|
||||
// ref.read(prefsChangeNotifierProvider).exchangeRateType ==
|
||||
// ExchangeRateType.estimated
|
||||
// ? "-"
|
||||
// : "";
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// _receiveFocusNode.addListener(() async {
|
||||
// if (!_receiveFocusNode.hasFocus) {
|
||||
// final newToAmount = Decimal.tryParse(_receiveController.text);
|
||||
// if (ref.read(prefsChangeNotifierProvider).exchangeRateType !=
|
||||
// ExchangeRateType.estimated) {
|
||||
// await ref
|
||||
// .read(exchangeFormStateProvider)
|
||||
// .setToAmountAndCalculateFromAmount(
|
||||
// newToAmount ?? Decimal.zero, true);
|
||||
//
|
||||
// debugPrint("ReceiveFocusNode has fired");
|
||||
// }
|
||||
// if (newToAmount == null) {
|
||||
// _sendController.text = "";
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
@ -1164,6 +1173,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
Widget build(BuildContext context) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
||||
// provider for simpleswap; not called rn
|
||||
ref.listen<String>(currentExchangeNameStateProvider, (previous, next) {
|
||||
ref.read(exchangeFormStateProvider).exchange = ref.read(exchangeProvider);
|
||||
});
|
||||
|
@ -1357,13 +1367,15 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
onChanged: onRateTypeChanged,
|
||||
),
|
||||
),
|
||||
if (ref.read(exchangeFormStateProvider).fromAmount != null &&
|
||||
ref.read(exchangeFormStateProvider).fromAmount != Decimal.zero)
|
||||
// these reads should be watch
|
||||
if (ref.watch(exchangeFormStateProvider).fromAmount != null &&
|
||||
ref.watch(exchangeFormStateProvider).fromAmount != Decimal.zero)
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
if (ref.read(exchangeFormStateProvider).fromAmount != null &&
|
||||
ref.read(exchangeFormStateProvider).fromAmount != Decimal.zero)
|
||||
// these reads should be watch
|
||||
if (ref.watch(exchangeFormStateProvider).fromAmount != null &&
|
||||
ref.watch(exchangeFormStateProvider).fromAmount != Decimal.zero)
|
||||
ExchangeProviderOptions(
|
||||
from: ref.watch(exchangeFormStateProvider).fromTicker,
|
||||
to: ref.watch(exchangeFormStateProvider).toTicker,
|
||||
|
|
Loading…
Reference in a new issue