forked from bisq-network/bisq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preferences.java
962 lines (760 loc) · 39.1 KB
/
Preferences.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
/*
* 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.core.user;
import bisq.core.btc.nodes.LocalBitcoinNode;
import bisq.core.btc.nodes.BtcNodes;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;
import bisq.core.setup.CoreNetworkCapabilities;
import bisq.network.p2p.network.BridgeAddressProvider;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.storage.Storage;
import bisq.common.util.Utilities;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
@Singleton
public final class Preferences implements PersistedDataHost, BridgeAddressProvider {
private static final ArrayList<BlockChainExplorer> BTC_MAIN_NET_EXPLORERS = new ArrayList<>(Arrays.asList(
new BlockChainExplorer("Blockstream.info", "https://blockstream.info/tx/", "https://blockstream.info/address/"),
new BlockChainExplorer("Blockstream.info Tor V3", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/tx/", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/address/"),
new BlockChainExplorer("mempool.space", "https://mempool.space/tx/", "https://mempool.space/explorer/address/"),
new BlockChainExplorer("mempool.space Tor V2", "http://mempooltxrqf4re5.onion/tx/", "http://mempooltxrqf4re5.onion/explorer/address/"),
new BlockChainExplorer("OXT", "https://oxt.me/transaction/", "https://oxt.me/address/"),
new BlockChainExplorer("Bitaps", "https://bitaps.com/", "https://bitaps.com/"),
new BlockChainExplorer("Blockcypher", "https://live.blockcypher.com/btc/tx/", "https://live.blockcypher.com/btc/address/"),
new BlockChainExplorer("Tradeblock", "https://tradeblock.com/bitcoin/tx/", "https://tradeblock.com/bitcoin/address/"),
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/transactions/", "https://www.biteasy.com/addresses/"),
new BlockChainExplorer("Blockonomics", "https://www.blockonomics.co/api/tx?txid=", "https://www.blockonomics.co/#/search?q="),
new BlockChainExplorer("Chainflyer", "http://chainflyer.bitflyer.jp/Transaction/", "http://chainflyer.bitflyer.jp/Address/"),
new BlockChainExplorer("Smartbit", "https://www.smartbit.com.au/tx/", "https://www.smartbit.com.au/address/"),
new BlockChainExplorer("SoChain. Wow.", "https://chain.so/tx/BTC/", "https://chain.so/address/BTC/"),
new BlockChainExplorer("Blockchain.info", "https://blockchain.info/tx/", "https://blockchain.info/address/"),
new BlockChainExplorer("Insight", "https://insight.bitpay.com/tx/", "https://insight.bitpay.com/address/")
));
private static final ArrayList<BlockChainExplorer> BTC_TEST_NET_EXPLORERS = new ArrayList<>(Arrays.asList(
new BlockChainExplorer("Blockstream.info", "https://blockstream.info/testnet/tx/", "https://blockstream.info/testnet/address/"),
new BlockChainExplorer("Blockstream.info Tor V3", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/tx/", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/address/"),
new BlockChainExplorer("Blockcypher", "https://live.blockcypher.com/btc-testnet/tx/", "https://live.blockcypher.com/btc-testnet/address/"),
new BlockChainExplorer("Blocktrail", "https://www.blocktrail.com/tBTC/tx/", "https://www.blocktrail.com/tBTC/address/"),
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/testnet/transactions/", "https://www.biteasy.com/testnet/addresses/"),
new BlockChainExplorer("Smartbit", "https://testnet.smartbit.com.au/tx/", "https://testnet.smartbit.com.au/address/"),
new BlockChainExplorer("SoChain. Wow.", "https://chain.so/tx/BTCTEST/", "https://chain.so/address/BTCTEST/")
));
private static final ArrayList<BlockChainExplorer> BTC_DAO_TEST_NET_EXPLORERS = new ArrayList<>(Collections.singletonList(
new BlockChainExplorer("BTC DAO-testnet explorer", "https://bisq.network/explorer/btc/dao_testnet/tx/", "https://bisq.network/explorer/btc/dao_testnet/address/")
));
public static final ArrayList<BlockChainExplorer> BSQ_MAIN_NET_EXPLORERS = new ArrayList<>(Arrays.asList(
new BlockChainExplorer("bsq.ninja (@wiz)", "https://bsq.ninja/tx.html?tx=", "https://bsq.ninja/Address.html?addr="),
new BlockChainExplorer("bsq.sqrrm.net (@sqrrm)", "https://bsq.sqrrm.net/tx.html?tx=", "https://bsq.sqrrm.net/Address.html?addr="),
new BlockChainExplorer("bsq.bisq.services (@devinbileck)", "https://bsq.bisq.services/tx.html?tx=", "https://bsq.bisq.services/Address.html?addr="),
new BlockChainExplorer("bsq.vante.me (@mrosseel)", "https://bsq.vante.me/tx.html?tx=", "https://bsq.vante.me/Address.html?addr="),
new BlockChainExplorer("bsq.emzy.de (@emzy)", "https://bsq.emzy.de/tx.html?tx=", "https://bsq.emzy.de/Address.html?addr="),
new BlockChainExplorer("bsq.bisq.cc (@m52go)", "https://bsq.bisq.cc/tx.html?tx=", "https://bsq.bisq.cc/Address.html?addr=")
));
// payload is initialized so the default values are available for Property initialization.
@Setter
@Delegate(excludes = ExcludesDelegateMethods.class)
private PreferencesPayload prefPayload = new PreferencesPayload();
private boolean initialReadDone = false;
@Getter
private final BooleanProperty useAnimationsProperty = new SimpleBooleanProperty(prefPayload.isUseAnimations());
@Getter
private final IntegerProperty cssThemeProperty = new SimpleIntegerProperty(prefPayload.getCssTheme());
private final ObservableList<FiatCurrency> fiatCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableList<CryptoCurrency> cryptoCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableList<TradeCurrency> tradeCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableMap<String, Boolean> dontShowAgainMapAsObservable = FXCollections.observableHashMap();
private final Storage<PreferencesPayload> storage;
private final Config config;
private final LocalBitcoinNode localBitcoinNode;
private final String btcNodesFromOptions, referralIdFromOptions,
rpcUserFromOptions, rpcPwFromOptions;
private final int blockNotifyPortFromOptions;
private final boolean fullDaoNodeFromOptions;
@Getter
private final BooleanProperty useStandbyModeProperty = new SimpleBooleanProperty(prefPayload.isUseStandbyMode());
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("WeakerAccess")
@Inject
public Preferences(Storage<PreferencesPayload> storage,
Config config,
LocalBitcoinNode localBitcoinNode,
@Named(Config.BTC_NODES) String btcNodesFromOptions,
@Named(Config.REFERRAL_ID) String referralId,
@Named(Config.FULL_DAO_NODE) boolean fullDaoNode,
@Named(Config.RPC_USER) String rpcUser,
@Named(Config.RPC_PASSWORD) String rpcPassword,
@Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort) {
this.storage = storage;
this.config = config;
this.localBitcoinNode = localBitcoinNode;
this.btcNodesFromOptions = btcNodesFromOptions;
this.referralIdFromOptions = referralId;
this.fullDaoNodeFromOptions = fullDaoNode;
this.rpcUserFromOptions = rpcUser;
this.rpcPwFromOptions = rpcPassword;
this.blockNotifyPortFromOptions = rpcBlockNotificationPort;
useAnimationsProperty.addListener((ov) -> {
prefPayload.setUseAnimations(useAnimationsProperty.get());
GlobalSettings.setUseAnimations(prefPayload.isUseAnimations());
persist();
});
cssThemeProperty.addListener((ov) -> {
prefPayload.setCssTheme(cssThemeProperty.get());
persist();
});
useStandbyModeProperty.addListener((ov) -> {
prefPayload.setUseStandbyMode(useStandbyModeProperty.get());
persist();
});
fiatCurrenciesAsObservable.addListener((javafx.beans.Observable ov) -> {
prefPayload.getFiatCurrencies().clear();
prefPayload.getFiatCurrencies().addAll(fiatCurrenciesAsObservable);
prefPayload.getFiatCurrencies().sort(TradeCurrency::compareTo);
persist();
});
cryptoCurrenciesAsObservable.addListener((javafx.beans.Observable ov) -> {
prefPayload.getCryptoCurrencies().clear();
prefPayload.getCryptoCurrencies().addAll(cryptoCurrenciesAsObservable);
prefPayload.getCryptoCurrencies().sort(TradeCurrency::compareTo);
persist();
});
fiatCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
cryptoCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
}
@Override
public void readPersisted() {
PreferencesPayload persisted = storage.initAndGetPersistedWithFileName("PreferencesPayload", 100);
BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
TradeCurrency preferredTradeCurrency;
if (persisted != null) {
prefPayload = persisted;
GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
GlobalSettings.setUseAnimations(prefPayload.isUseAnimations());
preferredTradeCurrency = checkNotNull(prefPayload.getPreferredTradeCurrency(), "preferredTradeCurrency must not be null");
setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(prefPayload.getFiatCurrencies());
setCryptoCurrencies(prefPayload.getCryptoCurrencies());
setBsqBlockChainExplorer(prefPayload.getBsqBlockChainExplorer());
} else {
prefPayload = new PreferencesPayload();
prefPayload.setUserLanguage(GlobalSettings.getLocale().getLanguage());
prefPayload.setUserCountry(CountryUtil.getDefaultCountry());
GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
preferredTradeCurrency = checkNotNull(CurrencyUtil.getCurrencyByCountryCode(prefPayload.getUserCountry().code),
"preferredTradeCurrency must not be null");
prefPayload.setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(CurrencyUtil.getMainFiatCurrencies());
setCryptoCurrencies(CurrencyUtil.getMainCryptoCurrencies());
switch (baseCurrencyNetwork.getCurrencyCode()) {
case "BTC":
setBlockChainExplorerMainNet(BTC_MAIN_NET_EXPLORERS.get(0));
setBlockChainExplorerTestNet(BTC_TEST_NET_EXPLORERS.get(0));
break;
default:
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
}
prefPayload.setDirectoryChooserPath(Utilities.getSystemHomeDirectory());
prefPayload.setOfferBookChartScreenCurrencyCode(preferredTradeCurrency.getCode());
prefPayload.setTradeChartsScreenCurrencyCode(preferredTradeCurrency.getCode());
prefPayload.setBuyScreenCurrencyCode(preferredTradeCurrency.getCode());
prefPayload.setSellScreenCurrencyCode(preferredTradeCurrency.getCode());
}
// We don't want to pass Preferences to all popups where the don't show again checkbox is used, so we use
// that static lookup class to avoid static access to the Preferences directly.
DontShowAgainLookup.setPreferences(this);
GlobalSettings.setDefaultTradeCurrency(preferredTradeCurrency);
// set all properties
useAnimationsProperty.set(prefPayload.isUseAnimations());
useStandbyModeProperty.set(prefPayload.isUseStandbyMode());
cssThemeProperty.set(prefPayload.getCssTheme());
// if no valid Bitcoin block explorer is set, select the 1st valid Bitcoin block explorer
ArrayList<BlockChainExplorer> btcExplorers = getBlockChainExplorers();
if (!blockExplorerExists(btcExplorers, getBlockChainExplorer()))
setBlockChainExplorer(btcExplorers.get(0));
// if no valid BSQ block explorer is set, randomly select a valid BSQ block explorer
ArrayList<BlockChainExplorer> bsqExplorers = getBsqBlockChainExplorers();
if (!blockExplorerExists(bsqExplorers, getBsqBlockChainExplorer()))
setBsqBlockChainExplorer(bsqExplorers.get((new Random()).nextInt(bsqExplorers.size())));
tradeCurrenciesAsObservable.addAll(prefPayload.getFiatCurrencies());
tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies());
dontShowAgainMapAsObservable.putAll(getDontShowAgainMap());
// Override settings with options if set
if (config.useTorForBtcOptionSetExplicitly)
setUseTorForBitcoinJ(config.useTorForBtc);
if (btcNodesFromOptions != null && !btcNodesFromOptions.isEmpty()) {
if (getBitcoinNodes() != null && !getBitcoinNodes().equals(btcNodesFromOptions)) {
log.warn("The Bitcoin node(s) from the program argument and the one(s) persisted in the UI are different. " +
"The Bitcoin node(s) {} from the program argument will be used.", btcNodesFromOptions);
}
setBitcoinNodes(btcNodesFromOptions);
setBitcoinNodesOptionOrdinal(BtcNodes.BitcoinNodesOption.CUSTOM.ordinal());
}
if (referralIdFromOptions != null && !referralIdFromOptions.isEmpty())
setReferralId(referralIdFromOptions);
if (prefPayload.getIgnoreDustThreshold() < Restrictions.getMinNonDustOutput().value) {
setIgnoreDustThreshold(600);
}
// For users from old versions the 4 flags a false but we want to have it true by default
// PhoneKeyAndToken is also null so we can use that to enable the flags
if (prefPayload.getPhoneKeyAndToken() == null) {
setUseSoundForMobileNotifications(true);
setUseTradeNotifications(true);
setUseMarketNotifications(true);
setUsePriceNotifications(true);
}
// We set the capability in CoreNetworkCapabilities if the program argument is set.
// If we have set it in the preferences view we handle it here.
CoreNetworkCapabilities.maybeApplyDaoFullMode(config);
initialReadDone = true;
persist();
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void dontShowAgain(String key, boolean dontShowAgain) {
prefPayload.getDontShowAgainMap().put(key, dontShowAgain);
persist();
dontShowAgainMapAsObservable.put(key, dontShowAgain);
}
public void resetDontShowAgain() {
prefPayload.getDontShowAgainMap().clear();
persist();
dontShowAgainMapAsObservable.clear();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Setter
///////////////////////////////////////////////////////////////////////////////////////////
public void setUseAnimations(boolean useAnimations) {
this.useAnimationsProperty.set(useAnimations);
}
public void setCssTheme(boolean useDarkMode) {
this.cssThemeProperty.set(useDarkMode ? 1 : 0);
}
public void addFiatCurrency(FiatCurrency tradeCurrency) {
if (!fiatCurrenciesAsObservable.contains(tradeCurrency))
fiatCurrenciesAsObservable.add(tradeCurrency);
}
public void removeFiatCurrency(FiatCurrency tradeCurrency) {
if (tradeCurrenciesAsObservable.size() > 1) {
fiatCurrenciesAsObservable.remove(tradeCurrency);
if (prefPayload.getPreferredTradeCurrency() != null &&
prefPayload.getPreferredTradeCurrency().equals(tradeCurrency))
setPreferredTradeCurrency(tradeCurrenciesAsObservable.get(0));
} else {
log.error("you cannot remove the last currency");
}
}
public void addCryptoCurrency(CryptoCurrency tradeCurrency) {
if (!cryptoCurrenciesAsObservable.contains(tradeCurrency))
cryptoCurrenciesAsObservable.add(tradeCurrency);
}
public void removeCryptoCurrency(CryptoCurrency tradeCurrency) {
if (tradeCurrenciesAsObservable.size() > 1) {
cryptoCurrenciesAsObservable.remove(tradeCurrency);
if (prefPayload.getPreferredTradeCurrency() != null &&
prefPayload.getPreferredTradeCurrency().equals(tradeCurrency))
setPreferredTradeCurrency(tradeCurrenciesAsObservable.get(0));
} else {
log.error("you cannot remove the last currency");
}
}
public void setBlockChainExplorer(BlockChainExplorer blockChainExplorer) {
if (Config.baseCurrencyNetwork().isMainnet())
setBlockChainExplorerMainNet(blockChainExplorer);
else
setBlockChainExplorerTestNet(blockChainExplorer);
}
public void setTacAccepted(boolean tacAccepted) {
prefPayload.setTacAccepted(tacAccepted);
persist();
}
public void setTacAcceptedV120(boolean tacAccepted) {
prefPayload.setTacAcceptedV120(tacAccepted);
persist();
}
private void persist() {
if (initialReadDone)
storage.queueUpForSave(prefPayload);
}
public void setUserLanguage(@NotNull String userLanguageCode) {
prefPayload.setUserLanguage(userLanguageCode);
if (prefPayload.getUserCountry() != null && prefPayload.getUserLanguage() != null)
GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
persist();
}
public void setUserCountry(@NotNull Country userCountry) {
prefPayload.setUserCountry(userCountry);
if (prefPayload.getUserLanguage() != null)
GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), userCountry.code));
persist();
}
public void setPreferredTradeCurrency(TradeCurrency preferredTradeCurrency) {
if (preferredTradeCurrency != null) {
prefPayload.setPreferredTradeCurrency(preferredTradeCurrency);
GlobalSettings.setDefaultTradeCurrency(preferredTradeCurrency);
persist();
}
}
public void setUseTorForBitcoinJ(boolean useTorForBitcoinJ) {
prefPayload.setUseTorForBitcoinJ(useTorForBitcoinJ);
persist();
}
public void setShowOwnOffersInOfferBook(boolean showOwnOffersInOfferBook) {
prefPayload.setShowOwnOffersInOfferBook(showOwnOffersInOfferBook);
persist();
}
public void setMaxPriceDistanceInPercent(double maxPriceDistanceInPercent) {
prefPayload.setMaxPriceDistanceInPercent(maxPriceDistanceInPercent);
persist();
}
public void setBackupDirectory(String backupDirectory) {
prefPayload.setBackupDirectory(backupDirectory);
persist();
}
public void setAutoSelectArbitrators(boolean autoSelectArbitrators) {
prefPayload.setAutoSelectArbitrators(autoSelectArbitrators);
persist();
}
public void setUsePercentageBasedPrice(boolean usePercentageBasedPrice) {
prefPayload.setUsePercentageBasedPrice(usePercentageBasedPrice);
persist();
}
public void setTagForPeer(String fullAddress, String tag) {
prefPayload.getPeerTagMap().put(fullAddress, tag);
persist();
}
public void setOfferBookChartScreenCurrencyCode(String offerBookChartScreenCurrencyCode) {
prefPayload.setOfferBookChartScreenCurrencyCode(offerBookChartScreenCurrencyCode);
persist();
}
public void setBuyScreenCurrencyCode(String buyScreenCurrencyCode) {
prefPayload.setBuyScreenCurrencyCode(buyScreenCurrencyCode);
persist();
}
public void setSellScreenCurrencyCode(String sellScreenCurrencyCode) {
prefPayload.setSellScreenCurrencyCode(sellScreenCurrencyCode);
persist();
}
public void setIgnoreTradersList(List<String> ignoreTradersList) {
prefPayload.setIgnoreTradersList(ignoreTradersList);
persist();
}
public void setDirectoryChooserPath(String directoryChooserPath) {
prefPayload.setDirectoryChooserPath(directoryChooserPath);
persist();
}
public void setTradeChartsScreenCurrencyCode(String tradeChartsScreenCurrencyCode) {
prefPayload.setTradeChartsScreenCurrencyCode(tradeChartsScreenCurrencyCode);
persist();
}
public void setTradeStatisticsTickUnitIndex(int tradeStatisticsTickUnitIndex) {
prefPayload.setTradeStatisticsTickUnitIndex(tradeStatisticsTickUnitIndex);
persist();
}
public void setSortMarketCurrenciesNumerically(boolean sortMarketCurrenciesNumerically) {
prefPayload.setSortMarketCurrenciesNumerically(sortMarketCurrenciesNumerically);
persist();
}
public void setBitcoinNodes(String bitcoinNodes) {
prefPayload.setBitcoinNodes(bitcoinNodes);
persist();
}
public void setUseCustomWithdrawalTxFee(boolean useCustomWithdrawalTxFee) {
prefPayload.setUseCustomWithdrawalTxFee(useCustomWithdrawalTxFee);
persist();
}
public void setWithdrawalTxFeeInBytes(long withdrawalTxFeeInBytes) {
prefPayload.setWithdrawalTxFeeInBytes(withdrawalTxFeeInBytes);
persist();
}
public void setBuyerSecurityDepositAsPercent(double buyerSecurityDepositAsPercent, PaymentAccount paymentAccount) {
double max = Restrictions.getMaxBuyerSecurityDepositAsPercent();
double min = Restrictions.getMinBuyerSecurityDepositAsPercent();
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
prefPayload.setBuyerSecurityDepositAsPercentForCrypto(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
else
prefPayload.setBuyerSecurityDepositAsPercent(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
persist();
}
public void setSelectedPaymentAccountForCreateOffer(@Nullable PaymentAccount paymentAccount) {
prefPayload.setSelectedPaymentAccountForCreateOffer(paymentAccount);
persist();
}
public void setPayFeeInBtc(boolean payFeeInBtc) {
prefPayload.setPayFeeInBtc(payFeeInBtc);
persist();
}
private void setFiatCurrencies(List<FiatCurrency> currencies) {
fiatCurrenciesAsObservable.setAll(currencies.stream()
.map(fiatCurrency -> new FiatCurrency(fiatCurrency.getCurrency()))
.distinct().collect(Collectors.toList()));
}
private void setCryptoCurrencies(List<CryptoCurrency> currencies) {
cryptoCurrenciesAsObservable.setAll(currencies.stream().distinct().collect(Collectors.toList()));
}
public void setBsqBlockChainExplorer(BlockChainExplorer bsqBlockChainExplorer) {
prefPayload.setBsqBlockChainExplorer(bsqBlockChainExplorer);
persist();
}
private void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet) {
prefPayload.setBlockChainExplorerTestNet(blockChainExplorerTestNet);
persist();
}
private void setBlockChainExplorerMainNet(BlockChainExplorer blockChainExplorerMainNet) {
prefPayload.setBlockChainExplorerMainNet(blockChainExplorerMainNet);
persist();
}
public void setResyncSpvRequested(boolean resyncSpvRequested) {
prefPayload.setResyncSpvRequested(resyncSpvRequested);
// We call that before shutdown so we dont want a delay here
storage.queueUpForSave(prefPayload, 1);
}
public void setBridgeAddresses(List<String> bridgeAddresses) {
prefPayload.setBridgeAddresses(bridgeAddresses);
// We call that before shutdown so we dont want a delay here
storage.queueUpForSave(prefPayload, 1);
}
// Only used from PB but keep it explicit as it may be used from the client and then we want to persist
public void setPeerTagMap(Map<String, String> peerTagMap) {
prefPayload.setPeerTagMap(peerTagMap);
persist();
}
public void setBridgeOptionOrdinal(int bridgeOptionOrdinal) {
prefPayload.setBridgeOptionOrdinal(bridgeOptionOrdinal);
persist();
}
public void setTorTransportOrdinal(int torTransportOrdinal) {
prefPayload.setTorTransportOrdinal(torTransportOrdinal);
persist();
}
public void setCustomBridges(String customBridges) {
prefPayload.setCustomBridges(customBridges);
persist();
}
public void setBitcoinNodesOptionOrdinal(int bitcoinNodesOptionOrdinal) {
prefPayload.setBitcoinNodesOptionOrdinal(bitcoinNodesOptionOrdinal);
persist();
}
public void setReferralId(String referralId) {
prefPayload.setReferralId(referralId);
persist();
}
public void setPhoneKeyAndToken(String phoneKeyAndToken) {
prefPayload.setPhoneKeyAndToken(phoneKeyAndToken);
persist();
}
public void setUseSoundForMobileNotifications(boolean value) {
prefPayload.setUseSoundForMobileNotifications(value);
persist();
}
public void setUseTradeNotifications(boolean value) {
prefPayload.setUseTradeNotifications(value);
persist();
}
public void setUseMarketNotifications(boolean value) {
prefPayload.setUseMarketNotifications(value);
persist();
}
public void setUsePriceNotifications(boolean value) {
prefPayload.setUsePriceNotifications(value);
persist();
}
public void setUseStandbyMode(boolean useStandbyMode) {
this.useStandbyModeProperty.set(useStandbyMode);
}
public void setTakeOfferSelectedPaymentAccountId(String value) {
prefPayload.setTakeOfferSelectedPaymentAccountId(value);
persist();
}
public void setDaoFullNode(boolean value) {
// We only persist if we have not set the program argument
if (config.fullDaoNodeOptionSetExplicitly) {
prefPayload.setDaoFullNode(value);
persist();
}
}
public void setRpcUser(String value) {
// We only persist if we have not set the program argument
if (!rpcUserFromOptions.isEmpty()) {
prefPayload.setRpcUser(value);
persist();
}
prefPayload.setRpcUser(value);
persist();
}
public void setRpcPw(String value) {
// We only persist if we have not set the program argument
if (rpcPwFromOptions.isEmpty()) {
prefPayload.setRpcPw(value);
persist();
}
}
public void setBlockNotifyPort(int value) {
// We only persist if we have not set the program argument
if (blockNotifyPortFromOptions == Config.UNSPECIFIED_PORT) {
prefPayload.setBlockNotifyPort(value);
persist();
}
}
public void setIgnoreDustThreshold(int value) {
prefPayload.setIgnoreDustThreshold(value);
persist();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter
///////////////////////////////////////////////////////////////////////////////////////////
public BooleanProperty useAnimationsProperty() {
return useAnimationsProperty;
}
public ObservableList<FiatCurrency> getFiatCurrenciesAsObservable() {
return fiatCurrenciesAsObservable;
}
public ObservableList<CryptoCurrency> getCryptoCurrenciesAsObservable() {
return cryptoCurrenciesAsObservable;
}
public ObservableList<TradeCurrency> getTradeCurrenciesAsObservable() {
return tradeCurrenciesAsObservable;
}
public ObservableMap<String, Boolean> getDontShowAgainMapAsObservable() {
return dontShowAgainMapAsObservable;
}
public BlockChainExplorer getBlockChainExplorer() {
BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
switch (baseCurrencyNetwork) {
case BTC_MAINNET:
return prefPayload.getBlockChainExplorerMainNet();
case BTC_TESTNET:
case BTC_REGTEST:
return prefPayload.getBlockChainExplorerTestNet();
case BTC_DAO_TESTNET:
return BTC_DAO_TEST_NET_EXPLORERS.get(0);
case BTC_DAO_BETANET:
return prefPayload.getBlockChainExplorerMainNet();
case BTC_DAO_REGTEST:
return BTC_DAO_TEST_NET_EXPLORERS.get(0);
default:
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
}
}
public ArrayList<BlockChainExplorer> getBlockChainExplorers() {
BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
switch (baseCurrencyNetwork) {
case BTC_MAINNET:
return BTC_MAIN_NET_EXPLORERS;
case BTC_TESTNET:
case BTC_REGTEST:
return BTC_TEST_NET_EXPLORERS;
case BTC_DAO_TESTNET:
return BTC_DAO_TEST_NET_EXPLORERS;
case BTC_DAO_BETANET:
return BTC_MAIN_NET_EXPLORERS;
case BTC_DAO_REGTEST:
return BTC_DAO_TEST_NET_EXPLORERS;
default:
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
}
}
public ArrayList<BlockChainExplorer> getBsqBlockChainExplorers() { return BSQ_MAIN_NET_EXPLORERS; }
public boolean showAgain(String key) {
return !prefPayload.getDontShowAgainMap().containsKey(key) || !prefPayload.getDontShowAgainMap().get(key);
}
public boolean getUseTorForBitcoinJ() {
// We override the useTorForBitcoinJ and set it to false if we will use a
// localhost Bitcoin node or if we are not on mainnet, unless the useTorForBtc
// parameter is explicitly provided. On testnet there are very few Bitcoin tor
// nodes and we don't provide tor nodes.
if ((!Config.baseCurrencyNetwork().isMainnet()
|| localBitcoinNode.willUse())
&& !config.useTorForBtcOptionSetExplicitly)
return false;
else
return prefPayload.isUseTorForBitcoinJ();
}
public double getBuyerSecurityDepositAsPercent(PaymentAccount paymentAccount) {
double value = PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount) ?
prefPayload.getBuyerSecurityDepositAsPercentForCrypto() : prefPayload.getBuyerSecurityDepositAsPercent();
if (value < Restrictions.getMinBuyerSecurityDepositAsPercent()) {
value = Restrictions.getMinBuyerSecurityDepositAsPercent();
setBuyerSecurityDepositAsPercent(value, paymentAccount);
}
return value == 0 ? Restrictions.getDefaultBuyerSecurityDepositAsPercent() : value;
}
//TODO remove and use isPayFeeInBtc instead
public boolean getPayFeeInBtc() {
return prefPayload.isPayFeeInBtc();
}
@Override
@Nullable
public List<String> getBridgeAddresses() {
return prefPayload.getBridgeAddresses();
}
public long getWithdrawalTxFeeInBytes() {
return Math.max(prefPayload.getWithdrawalTxFeeInBytes(), Config.baseCurrencyNetwork().getDefaultMinFeePerByte());
}
public boolean isDaoFullNode() {
if (config.fullDaoNodeOptionSetExplicitly) {
return fullDaoNodeFromOptions;
} else {
return prefPayload.isDaoFullNode();
}
}
public String getRpcUser() {
if (!rpcUserFromOptions.isEmpty()) {
return rpcUserFromOptions;
} else {
return prefPayload.getRpcUser();
}
}
public String getRpcPw() {
if (!rpcPwFromOptions.isEmpty()) {
return rpcPwFromOptions;
} else {
return prefPayload.getRpcPw();
}
}
public int getBlockNotifyPort() {
if (blockNotifyPortFromOptions != Config.UNSPECIFIED_PORT) {
try {
return blockNotifyPortFromOptions;
} catch (Throwable ignore) {
return 0;
}
} else {
return prefPayload.getBlockNotifyPort();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void updateTradeCurrencies(ListChangeListener.Change<? extends TradeCurrency> change) {
change.next();
if (change.wasAdded() && change.getAddedSize() == 1 && initialReadDone)
tradeCurrenciesAsObservable.add(change.getAddedSubList().get(0));
else if (change.wasRemoved() && change.getRemovedSize() == 1 && initialReadDone)
tradeCurrenciesAsObservable.remove(change.getRemoved().get(0));
}
private boolean blockExplorerExists(ArrayList<BlockChainExplorer> explorers,
BlockChainExplorer explorer)
{
if (explorer != null && explorers != null && explorers.size() > 0)
for (int i = 0; i < explorers.size(); i++)
if (explorers.get(i).name.equals(explorer.name))
return true;
return false;
}
private interface ExcludesDelegateMethods {
void setTacAccepted(boolean tacAccepted);
void setUseAnimations(boolean useAnimations);
void setCssTheme(int cssTheme);
void setUserLanguage(@NotNull String userLanguageCode);
void setUserCountry(@NotNull Country userCountry);
void setPreferredTradeCurrency(TradeCurrency preferredTradeCurrency);
void setUseTorForBitcoinJ(boolean useTorForBitcoinJ);
void setShowOwnOffersInOfferBook(boolean showOwnOffersInOfferBook);
void setMaxPriceDistanceInPercent(double maxPriceDistanceInPercent);
void setBackupDirectory(String backupDirectory);
void setAutoSelectArbitrators(boolean autoSelectArbitrators);
void setUsePercentageBasedPrice(boolean usePercentageBasedPrice);
void setTagForPeer(String hostName, String tag);
void setOfferBookChartScreenCurrencyCode(String offerBookChartScreenCurrencyCode);
void setBuyScreenCurrencyCode(String buyScreenCurrencyCode);
void setSellScreenCurrencyCode(String sellScreenCurrencyCode);
void setIgnoreTradersList(List<String> ignoreTradersList);
void setDirectoryChooserPath(String directoryChooserPath);
void setTradeChartsScreenCurrencyCode(String tradeChartsScreenCurrencyCode);
void setTradeStatisticsTickUnitIndex(int tradeStatisticsTickUnitIndex);
void setSortMarketCurrenciesNumerically(boolean sortMarketCurrenciesNumerically);
void setBitcoinNodes(String bitcoinNodes);
void setUseCustomWithdrawalTxFee(boolean useCustomWithdrawalTxFee);
void setWithdrawalTxFeeInBytes(long withdrawalTxFeeInBytes);
void setSelectedPaymentAccountForCreateOffer(@Nullable PaymentAccount paymentAccount);
void setBsqBlockChainExplorer(BlockChainExplorer bsqBlockChainExplorer);
void setPayFeeInBtc(boolean payFeeInBtc);
void setFiatCurrencies(List<FiatCurrency> currencies);
void setCryptoCurrencies(List<CryptoCurrency> currencies);
void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet);
void setBlockChainExplorerMainNet(BlockChainExplorer blockChainExplorerMainNet);
void setResyncSpvRequested(boolean resyncSpvRequested);
void setDontShowAgainMap(Map<String, Boolean> dontShowAgainMap);
void setPeerTagMap(Map<String, String> peerTagMap);
void setBridgeAddresses(List<String> bridgeAddresses);
void setBridgeOptionOrdinal(int bridgeOptionOrdinal);
void setTorTransportOrdinal(int torTransportOrdinal);
void setCustomBridges(String customBridges);
void setBitcoinNodesOptionOrdinal(int bitcoinNodesOption);
void setReferralId(String referralId);
void setPhoneKeyAndToken(String phoneKeyAndToken);
void setUseSoundForMobileNotifications(boolean value);
void setUseTradeNotifications(boolean value);
void setUseMarketNotifications(boolean value);
void setUsePriceNotifications(boolean value);
List<String> getBridgeAddresses();
long getWithdrawalTxFeeInBytes();
void setUseStandbyMode(boolean useStandbyMode);
void setTakeOfferSelectedPaymentAccountId(String value);
void setIgnoreDustThreshold(int value);
void setBuyerSecurityDepositAsPercent(double buyerSecurityDepositAsPercent);
double getBuyerSecurityDepositAsPercent();
void setDaoFullNode(boolean value);
void setRpcUser(String value);
void setRpcPw(String value);
void setBlockNotifyPort(int value);
boolean isDaoFullNode();
String getRpcUser();
String getRpcPw();
int getBlockNotifyPort();
void setTacAcceptedV120(boolean tacAccepted);
}
}