mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-26 00:58:50 +00:00
verify paired currency selection list options are valid
This commit is contained in:
parent
f174efcec0
commit
3fde042c8e
2 changed files with 40 additions and 0 deletions
lib/pages/exchange_view
|
@ -27,12 +27,14 @@ class ExchangeCurrencySelectionView extends StatefulWidget {
|
|||
required this.willChange,
|
||||
required this.paired,
|
||||
required this.isFixedRate,
|
||||
required this.willChangeIsSend,
|
||||
}) : super(key: key);
|
||||
|
||||
final String exchangeName;
|
||||
final Currency? willChange;
|
||||
final Currency? paired;
|
||||
final bool isFixedRate;
|
||||
final bool willChangeIsSend;
|
||||
|
||||
@override
|
||||
State<ExchangeCurrencySelectionView> createState() =>
|
||||
|
@ -46,6 +48,34 @@ class _ExchangeCurrencySelectionViewState
|
|||
final isDesktop = Util.isDesktop;
|
||||
|
||||
late List<Currency> _currencies;
|
||||
late final List<Pair> pairs;
|
||||
|
||||
List<Pair> getAvailablePairs() {
|
||||
final filter = ExchangeDataLoadingService.instance.isar.pairs
|
||||
.where()
|
||||
.exchangeNameEqualTo(widget.exchangeName)
|
||||
.filter()
|
||||
.group((q) => widget.isFixedRate
|
||||
? q
|
||||
.rateTypeEqualTo(SupportedRateType.both)
|
||||
.or()
|
||||
.rateTypeEqualTo(SupportedRateType.fixed)
|
||||
: q
|
||||
.rateTypeEqualTo(SupportedRateType.both)
|
||||
.or()
|
||||
.rateTypeEqualTo(SupportedRateType.estimated));
|
||||
|
||||
if (widget.paired != null) {
|
||||
return filter
|
||||
.and()
|
||||
.group((q) => widget.willChangeIsSend
|
||||
? q.toEqualTo(widget.paired!.ticker, caseSensitive: false)
|
||||
: q.fromEqualTo(widget.paired!.ticker, caseSensitive: false))
|
||||
.findAllSync();
|
||||
} else {
|
||||
return filter.findAllSync();
|
||||
}
|
||||
}
|
||||
|
||||
void filter(String text) {
|
||||
setState(() {
|
||||
|
@ -53,6 +83,10 @@ class _ExchangeCurrencySelectionViewState
|
|||
.where()
|
||||
.exchangeNameEqualTo(widget.exchangeName)
|
||||
.filter()
|
||||
.anyOf<String, Currency>(
|
||||
pairs.map((e) => widget.willChangeIsSend ? e.to : e.from),
|
||||
(q, ticker) => q.tickerEqualTo(ticker),
|
||||
)
|
||||
.group((q) => widget.isFixedRate
|
||||
? q
|
||||
.rateTypeEqualTo(SupportedRateType.both)
|
||||
|
@ -85,6 +119,7 @@ class _ExchangeCurrencySelectionViewState
|
|||
@override
|
||||
void initState() {
|
||||
_searchController = TextEditingController();
|
||||
pairs = getAvailablePairs();
|
||||
|
||||
final query = ExchangeDataLoadingService.instance.isar.currencies
|
||||
.where()
|
||||
|
|
|
@ -112,6 +112,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
|
||||
await _showCurrencySelectionSheet(
|
||||
willChange: ref.read(exchangeFormStateProvider).sendCurrency,
|
||||
willChangeIsSend: true,
|
||||
paired: ref.read(exchangeFormStateProvider).receiveCurrency,
|
||||
isFixedRate: type == ExchangeRateType.fixed,
|
||||
onSelected: (selectedCurrency) => ref
|
||||
|
@ -158,6 +159,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
|
||||
await _showCurrencySelectionSheet(
|
||||
willChange: ref.read(exchangeFormStateProvider).receiveCurrency,
|
||||
willChangeIsSend: false,
|
||||
paired: ref.read(exchangeFormStateProvider).sendCurrency,
|
||||
isFixedRate: type == ExchangeRateType.fixed,
|
||||
onSelected: (selectedCurrency) => ref
|
||||
|
@ -229,6 +231,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
required Currency? willChange,
|
||||
required Currency? paired,
|
||||
required bool isFixedRate,
|
||||
required bool willChangeIsSend,
|
||||
required void Function(Currency) onSelected,
|
||||
}) async {
|
||||
_sendFocusNode.unfocus();
|
||||
|
@ -281,6 +284,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
willChange: willChange,
|
||||
paired: paired,
|
||||
isFixedRate: isFixedRate,
|
||||
willChangeIsSend: willChangeIsSend,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -300,6 +304,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
willChange: willChange,
|
||||
paired: paired,
|
||||
isFixedRate: isFixedRate,
|
||||
willChangeIsSend: willChangeIsSend,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue