/
LockedListItem.java
146 lines (124 loc) · 4.42 KB
/
LockedListItem.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
142
143
144
145
146
/*
* 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.funds.locked;
import bisq.desktop.util.filtering.FilterableListItem;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.filtering.FilteringUtils;
import bisq.core.btc.listeners.BalanceListener;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletService;
import bisq.core.locale.Res;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.util.coin.CoinFormatter;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import javafx.scene.control.Label;
import lombok.Getter;
import javax.annotation.Nullable;
class LockedListItem implements FilterableListItem {
private final BalanceListener balanceListener;
private final BtcWalletService btcWalletService;
private final CoinFormatter formatter;
@Getter
private final Label balanceLabel;
@Getter
private final Trade trade;
@Getter
private final AddressEntry addressEntry;
@Getter
private final String addressString;
@Nullable
private final Address address;
@Getter
private Coin balance;
@Getter
private String balanceString;
public LockedListItem(Trade trade,
AddressEntry addressEntry,
BtcWalletService btcWalletService,
CoinFormatter formatter) {
this.trade = trade;
this.addressEntry = addressEntry;
this.btcWalletService = btcWalletService;
this.formatter = formatter;
if (trade.getDepositTx() != null && !trade.getDepositTx().getOutputs().isEmpty()) {
address = WalletService.getAddressFromOutput(trade.getDepositTx().getOutput(0));
addressString = address != null ? address.toString() : "";
} else {
address = null;
addressString = "";
}
balanceLabel = new AutoTooltipLabel();
balanceListener = new BalanceListener(address) {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
}
};
btcWalletService.addBalanceListener(balanceListener);
updateBalance();
}
LockedListItem() {
this.trade = null;
this.addressEntry = null;
this.btcWalletService = null;
this.formatter = null;
addressString = null;
address = null;
balanceLabel = null;
balanceListener = null;
}
public void cleanup() {
btcWalletService.removeBalanceListener(balanceListener);
}
private void updateBalance() {
balance = addressEntry.getCoinLockedInMultiSigAsCoin();
balanceString = formatter.formatCoin(this.balance);
balanceLabel.setText(balanceString);
}
public String getDetails() {
return trade != null ?
Res.get("funds.locked.locked", trade.getShortId()) :
Res.get("shared.noDetailsAvailable");
}
public String getDateString() {
return trade != null ?
DisplayUtils.formatDateTime(trade.getDate()) :
Res.get("shared.noDateAvailable");
}
@Override
public boolean match(String filterString) {
if (filterString.isEmpty())
return true;
if (getDetails().contains(filterString)) {
return true;
}
if (getDateString().contains(filterString)) {
return true;
}
if (getAddressString().contains(filterString)) {
return true;
}
if (getBalanceString().contains(filterString)) {
return true;
}
return FilteringUtils.match(getTrade(), filterString);
}
}