forked from bisq-network/bisq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BtcOfferBookViewModel.java
141 lines (124 loc) · 6.28 KB
/
BtcOfferBookViewModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.main.offer.offerbook;
import bisq.desktop.Navigation;
import bisq.desktop.util.GUIUtil;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.api.CoreApi;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferDirection;
import bisq.core.offer.OfferFilterService;
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.PaymentAccountUtil;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.ClosedTradableManager;
import bisq.core.trade.bsq_swap.BsqSwapTradeManager;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.FormattingUtils;
import bisq.core.util.PriceUtil;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;
import bisq.network.p2p.P2PService;
import com.google.inject.Inject;
import javax.inject.Named;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class BtcOfferBookViewModel extends OfferBookViewModel {
@Inject
public BtcOfferBookViewModel(User user,
OpenOfferManager openOfferManager,
OfferBook offerBook,
Preferences preferences,
WalletsSetup walletsSetup,
P2PService p2PService,
PriceFeedService priceFeedService,
ClosedTradableManager closedTradableManager,
BsqSwapTradeManager bsqSwapTradeManager,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
PriceUtil priceUtil,
OfferFilterService offerFilterService,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter,
BsqFormatter bsqFormatter,
BsqWalletService bsqWalletService, CoreApi coreApi) {
super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi);
}
@Override
void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) {
if (direction == OfferDirection.BUY) {
preferences.setBuyScreenCurrencyCode(code);
} else {
preferences.setSellScreenCurrencyCode(code);
}
}
@Override
protected ObservableList<PaymentMethod> filterPaymentMethods(ObservableList<PaymentMethod> list,
TradeCurrency selectedTradeCurrency) {
return FXCollections.observableArrayList(list.stream()
.filter(paymentMethod -> {
if (showAllTradeCurrenciesProperty.get()) {
return paymentMethod.isFiat();
}
return paymentMethod.isFiat() &&
PaymentAccountUtil.supportsCurrency(paymentMethod, selectedTradeCurrency);
})
.collect(Collectors.toList()));
}
@Override
void fillCurrencies(ObservableList<TradeCurrency> tradeCurrencies,
ObservableList<TradeCurrency> allCurrencies) {
// Used for ignoring filter (show all)
tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, ""));
tradeCurrencies.addAll(preferences.getFiatCurrenciesAsObservable());
tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, ""));
allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, ""));
allCurrencies.addAll(CurrencyUtil.getAllSortedFiatCurrencies());
allCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, ""));
}
@Override
Predicate<OfferBookListItem> getCurrencyAndMethodPredicate(OfferDirection direction,
TradeCurrency selectedTradeCurrency) {
return offerBookListItem -> {
Offer offer = offerBookListItem.getOffer();
boolean directionResult = offer.getDirection() != direction;
boolean currencyResult = (showAllTradeCurrenciesProperty.get() && CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) ||
offer.getCurrencyCode().equals(selectedTradeCurrency.getCode());
boolean paymentMethodResult = showAllPaymentMethods ||
offer.getPaymentMethod().equals(selectedPaymentMethod);
boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook();
return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated;
};
}
@Override
TradeCurrency getDefaultTradeCurrency() {
return GlobalSettings.getDefaultTradeCurrency();
}
@Override
String getCurrencyCodeFromPreferences(OfferDirection direction) {
return direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode();
}
}