This commit is contained in:
Serhii 2022-12-26 20:41:21 +02:00
parent d893562dad
commit ca79052914
5 changed files with 79 additions and 88 deletions

View file

@ -82,7 +82,7 @@ class FilterWidget extends StatelessWidget {
final content = item.onChanged != null final content = item.onChanged != null
? Observer( ? Observer(
builder: (_) => StandardCheckbox( builder: (_) => StandardCheckbox(
value: item.value.value, value: item.value(),
caption: item.caption, caption: item.caption,
gradientBackground: true, gradientBackground: true,
borderColor: Theme.of(context).dividerColor, borderColor: Theme.of(context).dividerColor,

View file

@ -8,60 +8,61 @@ part'trade_filter_store.g.dart';
class TradeFilterStore = TradeFilterStoreBase with _$TradeFilterStore; class TradeFilterStore = TradeFilterStoreBase with _$TradeFilterStore;
abstract class TradeFilterStoreBase with Store { abstract class TradeFilterStoreBase with Store {
TradeFilterStoreBase(); TradeFilterStoreBase() : displayXMRTO = true,
displayChangeNow = true,
displaySideShift = true,
displayMorphToken = true,
displaySimpleSwap = true;
Observable<bool> displayXMRTO = Observable(true); @observable
Observable<bool> displayAllTrades = Observable(true); bool displayXMRTO;
Observable<bool> displayChangeNow = Observable(true);
Observable<bool> displaySideShift = Observable(true); @observable
Observable<bool> displayMorphToken = Observable(true); bool displayChangeNow;
Observable<bool> displaySimpleSwap = Observable(true);
@observable
bool displaySideShift;
@observable
bool displayMorphToken;
@observable
bool displaySimpleSwap;
@computed
bool get displayAllTrades => displayChangeNow && displaySideShift && displaySimpleSwap;
@action @action
void toggleDisplayExchange(ExchangeProviderDescription provider) { void toggleDisplayExchange(ExchangeProviderDescription provider) {
switch (provider) { switch (provider) {
case ExchangeProviderDescription.changeNow: case ExchangeProviderDescription.changeNow:
displayAllTrades.value = false; displayChangeNow = !displayChangeNow;
displayChangeNow.value = !displayChangeNow.value;
if (displayChangeNow.value && displaySideShift.value && displaySimpleSwap.value) {
displayAllTrades.value = true;
}
break; break;
case ExchangeProviderDescription.sideShift: case ExchangeProviderDescription.sideShift:
displayAllTrades.value = false; displaySideShift = !displaySideShift;
displaySideShift.value = !displaySideShift.value;
if (displayChangeNow.value && displaySideShift.value && displaySimpleSwap.value) {
displayAllTrades.value = true;
}
break; break;
case ExchangeProviderDescription.simpleSwap: case ExchangeProviderDescription.simpleSwap:
displayAllTrades.value = false; displaySimpleSwap = !displaySimpleSwap;
displaySimpleSwap.value = !displaySimpleSwap.value;
if (displayChangeNow.value && displaySideShift.value && displaySimpleSwap.value) {
displayAllTrades.value = true;
}
break; break;
case ExchangeProviderDescription.xmrto: case ExchangeProviderDescription.xmrto:
displayXMRTO.value = !displayXMRTO.value; displayXMRTO = !displayXMRTO;
break; break;
case ExchangeProviderDescription.morphToken: case ExchangeProviderDescription.morphToken:
displayMorphToken.value = !displayMorphToken.value; displayMorphToken = !displayMorphToken;
break; break;
case ExchangeProviderDescription.all: case ExchangeProviderDescription.all:
displayAllTrades.value = !displayAllTrades.value; if (displayAllTrades) {
if (displayAllTrades.value) { displayChangeNow = false;
displayChangeNow.value = true; displaySideShift = false;
displaySideShift.value = true; displayXMRTO = false;
displayXMRTO.value = true; displayMorphToken = false;
displayMorphToken.value = true; displaySimpleSwap = false;
displaySimpleSwap.value = true; } else {
} displayChangeNow = true;
if (!displayAllTrades.value) { displaySideShift = true;
displayChangeNow.value = false; displayXMRTO = true;
displaySideShift.value = false; displayMorphToken = true;
displayXMRTO.value = false; displaySimpleSwap = true;
displayMorphToken.value = false;
displaySimpleSwap.value = false;
} }
break; break;
} }
@ -70,24 +71,22 @@ abstract class TradeFilterStoreBase with Store {
List<TradeListItem> filtered({required List<TradeListItem> trades, required WalletBase wallet}) { List<TradeListItem> filtered({required List<TradeListItem> trades, required WalletBase wallet}) {
final _trades = final _trades =
trades.where((item) => item.trade.walletId == wallet.id).toList(); trades.where((item) => item.trade.walletId == wallet.id).toList();
final needToFilter = !displayChangeNow.value || !displaySideShift.value final needToFilter = !displayAllTrades;
|| !displayXMRTO.value || !displayMorphToken.value
|| !displaySimpleSwap.value;
return needToFilter return needToFilter
? _trades ? _trades
.where((item) => .where((item) =>
(displayXMRTO.value && (displayXMRTO &&
item.trade.provider == ExchangeProviderDescription.xmrto) || item.trade.provider == ExchangeProviderDescription.xmrto) ||
(displaySideShift.value && (displaySideShift &&
item.trade.provider == ExchangeProviderDescription.sideShift) || item.trade.provider == ExchangeProviderDescription.sideShift) ||
(displayChangeNow.value && (displayChangeNow &&
item.trade.provider == item.trade.provider ==
ExchangeProviderDescription.changeNow) || ExchangeProviderDescription.changeNow) ||
(displayMorphToken.value && (displayMorphToken &&
item.trade.provider == item.trade.provider ==
ExchangeProviderDescription.morphToken) ExchangeProviderDescription.morphToken)
||(displaySimpleSwap.value && ||(displaySimpleSwap &&
item.trade.provider == item.trade.provider ==
ExchangeProviderDescription.simpleSwap)) ExchangeProviderDescription.simpleSwap))
.toList() .toList()

View file

@ -10,11 +10,14 @@ class TransactionFilterStore = TransactionFilterStoreBase
with _$TransactionFilterStore; with _$TransactionFilterStore;
abstract class TransactionFilterStoreBase with Store { abstract class TransactionFilterStoreBase with Store {
TransactionFilterStoreBase(); TransactionFilterStoreBase() : displayIncoming = true,
displayOutgoing = true;
Observable<bool> displayAll = Observable(true); @observable
Observable<bool> displayIncoming = Observable(true); bool displayIncoming;
Observable<bool> displayOutgoing = Observable(true);
@observable
bool displayOutgoing;
@observable @observable
DateTime? startDate; DateTime? startDate;
@ -22,40 +25,30 @@ abstract class TransactionFilterStoreBase with Store {
@observable @observable
DateTime? endDate; DateTime? endDate;
@computed
bool get displayAll => displayIncoming && displayOutgoing;
@action @action
void toggleIAll() { void toggleAll() {
displayAll.value = (!displayAll.value); if (displayAll) {
if (displayAll.value) { displayOutgoing = false;
displayOutgoing.value = true; displayIncoming = false;
displayIncoming.value = true; } else {
} displayOutgoing = true;
if (!displayAll.value) { displayIncoming = true;
displayOutgoing.value = false;
displayIncoming.value = false;
} }
} }
@action @action
void toggleIncoming() { void toggleIncoming() {
displayIncoming.value = (!displayIncoming.value); displayIncoming = !displayIncoming;
if (displayIncoming.value && displayOutgoing.value) {
displayAll.value = true;
}
if (!displayIncoming.value || !displayOutgoing.value) {
displayAll.value = false;
}
} }
@action @action
void toggleOutgoing() { void toggleOutgoing() {
displayOutgoing.value = (!displayOutgoing.value); displayOutgoing = !displayOutgoing;
if (displayIncoming.value && displayOutgoing.value) {
displayAll.value = true;
}
if (!displayIncoming.value || !displayOutgoing.value) {
displayAll.value = false;
}
} }
@action @action
@ -66,8 +59,7 @@ abstract class TransactionFilterStoreBase with Store {
List<TransactionListItem> filtered({required List<TransactionListItem> transactions}) { List<TransactionListItem> filtered({required List<TransactionListItem> transactions}) {
var _transactions = <TransactionListItem>[]; var _transactions = <TransactionListItem>[];
final needToFilter = !displayOutgoing.value || final needToFilter = !displayAll ||
!displayIncoming.value ||
(startDate != null && endDate != null); (startDate != null && endDate != null);
if (needToFilter) { if (needToFilter) {
@ -79,11 +71,11 @@ abstract class TransactionFilterStoreBase with Store {
&& (endDate?.isAfter(item.transaction.date) ?? false); && (endDate?.isAfter(item.transaction.date) ?? false);
} }
if (allowed && (!displayOutgoing.value || !displayIncoming.value)) { if (allowed && (!displayAll)) {
allowed = (displayOutgoing.value && allowed = (displayOutgoing &&
item.transaction.direction == item.transaction.direction ==
TransactionDirection.outgoing) || TransactionDirection.outgoing) ||
(displayIncoming.value && (displayIncoming &&
item.transaction.direction == TransactionDirection.incoming); item.transaction.direction == TransactionDirection.incoming);
} }

View file

@ -59,15 +59,15 @@ abstract class DashboardViewModelBase with Store {
filterItems = { filterItems = {
S.current.transactions: [ S.current.transactions: [
FilterItem( FilterItem(
value: transactionFilterStore.displayAll, value: () => transactionFilterStore.displayAll,
caption: S.current.all_transactions, caption: S.current.all_transactions,
onChanged: transactionFilterStore.toggleIAll), onChanged: transactionFilterStore.toggleAll),
FilterItem( FilterItem(
value: transactionFilterStore.displayIncoming, value: () => transactionFilterStore.displayIncoming,
caption: S.current.incoming, caption: S.current.incoming,
onChanged:transactionFilterStore.toggleIncoming), onChanged:transactionFilterStore.toggleIncoming),
FilterItem( FilterItem(
value: transactionFilterStore.displayOutgoing, value: () => transactionFilterStore.displayOutgoing,
caption: S.current.outgoing, caption: S.current.outgoing,
onChanged: transactionFilterStore.toggleOutgoing), onChanged: transactionFilterStore.toggleOutgoing),
// FilterItem( // FilterItem(
@ -77,22 +77,22 @@ abstract class DashboardViewModelBase with Store {
], ],
S.current.trades: [ S.current.trades: [
FilterItem( FilterItem(
value: tradeFilterStore.displayAllTrades, value: () => tradeFilterStore.displayAllTrades,
caption: S.current.all_trades, caption: S.current.all_trades,
onChanged: () => tradeFilterStore onChanged: () => tradeFilterStore
.toggleDisplayExchange(ExchangeProviderDescription.all)), .toggleDisplayExchange(ExchangeProviderDescription.all)),
FilterItem( FilterItem(
value: tradeFilterStore.displayChangeNow, value: () => tradeFilterStore.displayChangeNow,
caption: ExchangeProviderDescription.changeNow.title, caption: ExchangeProviderDescription.changeNow.title,
onChanged: () => tradeFilterStore onChanged: () => tradeFilterStore
.toggleDisplayExchange(ExchangeProviderDescription.changeNow)), .toggleDisplayExchange(ExchangeProviderDescription.changeNow)),
FilterItem( FilterItem(
value: tradeFilterStore.displaySideShift, value: () => tradeFilterStore.displaySideShift,
caption: ExchangeProviderDescription.sideShift.title, caption: ExchangeProviderDescription.sideShift.title,
onChanged: () => tradeFilterStore onChanged: () => tradeFilterStore
.toggleDisplayExchange(ExchangeProviderDescription.sideShift)), .toggleDisplayExchange(ExchangeProviderDescription.sideShift)),
FilterItem( FilterItem(
value: tradeFilterStore.displaySimpleSwap, value: () => tradeFilterStore.displaySimpleSwap,
caption: ExchangeProviderDescription.simpleSwap.title, caption: ExchangeProviderDescription.simpleSwap.title,
onChanged: () => tradeFilterStore onChanged: () => tradeFilterStore
.toggleDisplayExchange(ExchangeProviderDescription.simpleSwap)), .toggleDisplayExchange(ExchangeProviderDescription.simpleSwap)),

View file

@ -6,7 +6,7 @@ class FilterItem {
required this.caption, required this.caption,
required this.onChanged}); required this.onChanged});
Observable<bool> value; bool Function() value;
String caption; String caption;
Function onChanged; Function onChanged;
} }