Skip to content

Commit

Permalink
Add information popups for new signed states (only shown once for use…
Browse files Browse the repository at this point in the history
…r) and minor clean-ups
  • Loading branch information
ripcurlx committed Oct 8, 2019
1 parent 157e668 commit 704ca49
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 57 deletions.
80 changes: 69 additions & 11 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package bisq.core.app;

import bisq.core.account.sign.SignedWitness;
import bisq.core.account.sign.SignedWitnessService;
import bisq.core.account.witness.AccountAgeWitness;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.alert.Alert;
import bisq.core.alert.AlertManager;
Expand All @@ -43,6 +45,7 @@
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.TradeLimits;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.provider.fee.FeeService;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.support.dispute.arbitration.ArbitrationManager;
Expand All @@ -63,6 +66,7 @@
import bisq.network.crypto.EncryptionService;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.peers.keepalive.messages.Ping;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.ClockWatcher;
import bisq.common.Timer;
Expand Down Expand Up @@ -175,7 +179,8 @@ public interface BisqSetupCompleteListener {
private Consumer<String> cryptoSetupFailedHandler, chainFileLockedExceptionHandler,
spvFileCorruptedHandler, lockedUpFundsHandler, daoErrorMessageHandler, daoWarnMessageHandler,
filterWarningHandler, displaySecurityRecommendationHandler, displayLocalhostHandler,
wrongOSArchitectureHandler;
wrongOSArchitectureHandler, displaySignedByArbitratorHandler,
displaySignedByPeerHandler, displayPeerLimitLiftedHandler, displayPeerSignerHandler;
@Setter
@Nullable
private Consumer<Boolean> displayTorNetworkSettingsHandler;
Expand Down Expand Up @@ -339,6 +344,7 @@ private void step5() {
// in MainViewModel
maybeShowSecurityRecommendation();
maybeShowLocalhostRunningInfo();
maybeShowAccountSigningStateInfo();
}


Expand Down Expand Up @@ -579,9 +585,7 @@ private void initWallet() {
if (allBasicServicesInitialized)
checkForLockedUpFunds();
},
() -> {
walletInitialized.set(true);
});
() -> walletInitialized.set(true));
}


Expand Down Expand Up @@ -703,9 +707,7 @@ private void initDomainServices() {
voteResultService.getVoteResultExceptions().addListener((ListChangeListener<VoteResultException>) c -> {
c.next();
if (c.wasAdded() && voteResultExceptionHandler != null) {
c.getAddedSubList().forEach(e -> {
voteResultExceptionHandler.accept(e);
});
c.getAddedSubList().forEach(e -> voteResultExceptionHandler.accept(e));
}
});

Expand All @@ -729,9 +731,65 @@ private void maybeShowSecurityRecommendation() {
}

private void maybeShowLocalhostRunningInfo() {
String key = "bitcoinLocalhostNode";
if (bisqEnvironment.isBitcoinLocalhostNodeRunning() && preferences.showAgain(key) &&
displayLocalhostHandler != null)
displayLocalhostHandler.accept(key);
maybeTriggerDisplayHandler("bitcoinLocalhostNode", displayLocalhostHandler, bisqEnvironment.isBitcoinLocalhostNodeRunning());
}

private void maybeShowAccountSigningStateInfo() {
String keySignedByArbitrator = "accountSignedByArbitrator";
String keySignedByPeer = "accountSignedByPeer";
String keyPeerLimitedLifted = "accountLimitLifted";
String keyPeerSigner = "accountPeerSigner";

// check signed witness on startup
checkSigningState(AccountAgeWitnessService.SignState.ARBITRATOR, keySignedByArbitrator, displaySignedByArbitratorHandler);
checkSigningState(AccountAgeWitnessService.SignState.PEER_INITIAL, keySignedByPeer, displaySignedByPeerHandler);
checkSigningState(AccountAgeWitnessService.SignState.PEER_LIMIT_LIFTED, keyPeerLimitedLifted, displayPeerLimitLiftedHandler);
checkSigningState(AccountAgeWitnessService.SignState.PEER_SIGNER, keyPeerSigner, displayPeerSignerHandler);

// check signed witness during runtime
p2PService.getP2PDataStorage().addAppendOnlyDataStoreListener(
payload -> {
maybeTriggerDisplayHandler(keySignedByArbitrator, displaySignedByArbitratorHandler,
isSignedWitnessOfMineWithState(payload, AccountAgeWitnessService.SignState.ARBITRATOR));
maybeTriggerDisplayHandler(keySignedByPeer, displaySignedByPeerHandler,
isSignedWitnessOfMineWithState(payload, AccountAgeWitnessService.SignState.PEER_INITIAL));
maybeTriggerDisplayHandler(keyPeerLimitedLifted, displayPeerLimitLiftedHandler,
isSignedWitnessOfMineWithState(payload, AccountAgeWitnessService.SignState.PEER_LIMIT_LIFTED));
maybeTriggerDisplayHandler(keyPeerSigner, displayPeerSignerHandler,
isSignedWitnessOfMineWithState(payload, AccountAgeWitnessService.SignState.PEER_SIGNER));
});
}

private void checkSigningState(AccountAgeWitnessService.SignState state,
String key, Consumer<String> displayHandler) {
boolean signingStateFound = p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().stream()
.anyMatch(payload -> isSignedWitnessOfMineWithState(payload, state));

maybeTriggerDisplayHandler(key, displayHandler, signingStateFound);
}

private boolean isSignedWitnessOfMineWithState(PersistableNetworkPayload payload,
AccountAgeWitnessService.SignState state) {
if (payload instanceof SignedWitness && user.getPaymentAccounts() != null) {
// We know at this point that it is already added to the signed witness list
// Check if new signed witness is for one of my own accounts

return user.getPaymentAccounts().stream()
.filter(a -> PaymentMethod.hasChargebackRisk(a.getPaymentMethod(), a.getTradeCurrencies()))
.anyMatch(a -> {
AccountAgeWitness myWitness = accountAgeWitnessService.getMyWitness(a.getPaymentAccountPayload());
AccountAgeWitnessService.SignState signState = accountAgeWitnessService.getSignState(myWitness);

return (signState.equals(state));
});
}
return false;
}

private void maybeTriggerDisplayHandler(String key, Consumer<String> displayHandler, boolean signingStateFound) {
if (signingStateFound && preferences.showAgain(key) &&
displayHandler != null) {
displayHandler.accept(key);
}
}
}
14 changes: 11 additions & 3 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ offerbook.warning.sellOfferAndAnyTakerPaymentAccountForOfferMature=This offer ca

offerbook.warning.counterpartyTradeRestrictions=This offer cannot be taken due to counterparty trade restrictions

offerbook.warning.newVersionAnnouncement=We needed to deploy this restriction as a short-term measure for enhanced security.\n\n\
The next software release will provide more robust protection tools so that offers with this risk profile can be traded again.
offerbook.warning.newVersionAnnouncement=With this version of the software trading peers can verify and sign each other to create a network of trusted accounts.\n\n\
By trading with a peer that has already been verified your account will be signed after a successful trade as well and the limits will be lifted after a certain time frame based on the verification method.\n\n\
For more information on account signing, please visit our documentation section on docs.bisq.network/account-signing.

popup.warning.tradeLimitDueAccountAgeRestriction.seller=The allowed trade amount is limited to 0.01 BTC because of security restrictions based on the following criteria:\n\
- The buyers account was created after March 1st 2019\n\
Expand Down Expand Up @@ -1163,7 +1164,7 @@ account.arbitratorRegistration.pubKey=Public key
account.arbitratorRegistration.register=Register
account.arbitratorRegistration.registration={0} registration
account.arbitratorRegistration.revoke=Revoke
account.arbitratorRegistration.info.msg=Please note that you need to stay available for 15 days after revoking as there might be trades which are using you as {0}}. The max. allowed trade period is 8 days and the dispute process might take up to 7 days.
account.arbitratorRegistration.info.msg=Please note that you need to stay available for 15 days after revoking as there might be trades which are using you as {0}. The max. allowed trade period is 8 days and the dispute process might take up to 7 days.
account.arbitratorRegistration.warn.min1Language=You need to set at least 1 language.\nWe added the default language for you.
account.arbitratorRegistration.removedSuccess=You have successfully removed your registration from the Bisq network.
account.arbitratorRegistration.removedFailed=Could not remove registration.{0}
Expand Down Expand Up @@ -2538,6 +2539,13 @@ popup.accountSigning.signAccounts.ECKey.error=Bad arbitrator ECKey

popup.accountSigning.success.headline=Congratulations
popup.accountSigning.success.description=All {0} payment accounts were successfully signed!
popup.accountSigning.generalInformation=You'll find the signing state of all your accounts in the account section.\n\n\
For further information please visit docs.bisq.network/account-signing.html.
popup.accountSigning.signedByArbitrator=One of your payment accounts has been verified and signed by an arbitrator. Trading with this account will automatically sign your trading peer''s account after a successful trade.\n\n{0}
popup.accountSigning.signedByPeer=One of your payment accounts has been verified and signed by a trading peer. You''re initial limit will be lifted within 30 days from now. \
After 60 days you are able to sign other accounts as well.\n\n{0}
popup.accountSigning.peerLimitLifted=The initial limit for one of your accounts has been lifted.\n\n{0}
popup.accountSigning.peerSigner=One of your accounts is mature enough to sign other payment accounts as well.\n\n{0}

####################################################################
# Notifications
Expand Down
101 changes: 58 additions & 43 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import bisq.core.app.BisqSetup;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.payment.AliPayAccount;
Expand All @@ -56,7 +57,6 @@
import bisq.core.user.DontShowAgainLookup;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;

import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.P2PService;
Expand Down Expand Up @@ -87,6 +87,7 @@

import java.util.Comparator;
import java.util.Date;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
Expand Down Expand Up @@ -119,7 +120,6 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
@Getter
private final TorNetworkSettingsWindow torNetworkSettingsWindow;
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
private final BSFormatter formatter;

@Getter
private BooleanProperty showAppScreen = new SimpleBooleanProperty();
Expand Down Expand Up @@ -158,8 +158,7 @@ public MainViewModel(BisqSetup bisqSetup,
BisqEnvironment bisqEnvironment,
AccountAgeWitnessService accountAgeWitnessService,
TorNetworkSettingsWindow torNetworkSettingsWindow,
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler,
BSFormatter formatter) {
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
this.bisqSetup = bisqSetup;
this.walletsSetup = walletsSetup;
this.user = user;
Expand All @@ -180,7 +179,6 @@ public MainViewModel(BisqSetup bisqSetup,
this.accountAgeWitnessService = accountAgeWitnessService;
this.torNetworkSettingsWindow = torNetworkSettingsWindow;
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
this.formatter = formatter;

TxIdTextField.setPreferences(preferences);

Expand Down Expand Up @@ -288,33 +286,26 @@ private void setupHandlers() {
tacWindow.onAction(acceptedHandler::run).show();
}, 1));

bisqSetup.setCryptoSetupFailedHandler(msg -> {
UserThread.execute(() -> new Popup<>().warning(msg)
.useShutDownButton()
.useReportBugButton()
.show());
});
bisqSetup.setCryptoSetupFailedHandler(msg -> UserThread.execute(() ->
new Popup<>().warning(msg)
.useShutDownButton()
.useReportBugButton()
.show()));
bisqSetup.setDisplayTorNetworkSettingsHandler(show -> {
if (show)
torNetworkSettingsWindow.show();
else
torNetworkSettingsWindow.hide();
});
bisqSetup.setSpvFileCorruptedHandler(msg -> {
new Popup<>().warning(msg)
.actionButtonText(Res.get("settings.net.reSyncSPVChainButton"))
.onAction(() -> GUIUtil.reSyncSPVChain(walletsSetup, preferences))
.show();
});
bisqSetup.setVoteResultExceptionHandler(voteResultException -> {
log.warn(voteResultException.toString());
});
bisqSetup.setSpvFileCorruptedHandler(msg -> new Popup<>().warning(msg)
.actionButtonText(Res.get("settings.net.reSyncSPVChainButton"))
.onAction(() -> GUIUtil.reSyncSPVChain(walletsSetup, preferences))
.show());
bisqSetup.setVoteResultExceptionHandler(voteResultException -> log.warn(voteResultException.toString()));

bisqSetup.setChainFileLockedExceptionHandler(msg -> {
new Popup<>().warning(msg)
.useShutDownButton()
.show();
});
bisqSetup.setChainFileLockedExceptionHandler(msg -> new Popup<>().warning(msg)
.useShutDownButton()
.show());
bisqSetup.setLockedUpFundsHandler(msg -> new Popup<>().warning(msg).show());
bisqSetup.setShowFirstPopupIfResyncSPVRequestedHandler(this::showFirstPopupIfResyncSPVRequested);
bisqSetup.setRequestWalletPasswordHandler(aesKeyHandler -> walletPasswordWindow
Expand All @@ -335,9 +326,7 @@ private void setupHandlers() {
bisqSetup.setDisplayAlertHandler(alert -> new DisplayAlertMessageWindow()
.alertMessage(alert)
.closeButtonText(Res.get("shared.close"))
.onClose(() -> {
user.setDisplayedAlert(alert);
})
.onClose(() -> user.setDisplayedAlert(alert))
.show());
bisqSetup.setDisplayPrivateNotificationHandler(privateNotification ->
new Popup<>().headLine(Res.get("popup.privateNotification.headline"))
Expand All @@ -361,16 +350,46 @@ private void setupHandlers() {
popupQueue.add(popup);
}
});
bisqSetup.setDisplaySignedByArbitratorHandler(key -> {
if (!DevEnv.isDevMode()) {
preferences.dontShowAgain(key, true);
new Popup<>().information(Res.get("popup.accountSigning.signedByArbitrator",
Res.get("popup.accountSigning.generalInformation")))
.show();
}
});
bisqSetup.setDisplaySignedByPeerHandler(key -> {
if (!DevEnv.isDevMode()) {
preferences.dontShowAgain(key, true);
new Popup<>().information(Res.get("popup.accountSigning.signedByPeer",
Res.get("popup.accountSigning.generalInformation")))
.show();
}
});
bisqSetup.setDisplayPeerLimitLiftedHandler(key -> {
if (!DevEnv.isDevMode()) {
preferences.dontShowAgain(key, true);
new Popup<>().information(Res.get("popup.accountSigning.peerLimitLifted",
Res.get("popup.accountSigning.generalInformation")))
.show();
}
});
bisqSetup.setDisplayPeerSignerHandler(key -> {
if (!DevEnv.isDevMode()) {
preferences.dontShowAgain(key, true);
new Popup<>().information(Res.get("popup.accountSigning.peerSigner",
Res.get("popup.accountSigning.generalInformation")))
.show();
}
});

bisqSetup.setWrongOSArchitectureHandler(msg -> new Popup<>().warning(msg).show());

corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> {
new Popup<>()
.warning(Res.get("popup.warning.incompatibleDB", files.toString(),
bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY)))
.useShutDownButton()
.show();
});
corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> new Popup<>()
.warning(Res.get("popup.warning.incompatibleDB", files.toString(),
bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY)))
.useShutDownButton()
.show());

tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> new Popup<>()
.warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage))
Expand All @@ -379,9 +398,7 @@ private void setupHandlers() {
bisqSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());
daoPresentation.getBsqSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());

bisqSetup.setFilterWarningHandler(warning -> {
new Popup<>().warning(warning).show();
});
bisqSetup.setFilterWarningHandler(warning -> new Popup<>().warning(warning).show());
}

private void setupP2PNumPeersWatcher() {
Expand Down Expand Up @@ -483,7 +500,9 @@ public void onUpdatedDataReceived() {
cryptoCurrencyAccount.init();
cryptoCurrencyAccount.setAccountName("ETH dummy");// Don't translate only for dev
cryptoCurrencyAccount.setAddress("0x" + new Random().nextInt(1000000));
cryptoCurrencyAccount.setSingleTradeCurrency(CurrencyUtil.getCryptoCurrency("ETH").get());
Optional<CryptoCurrency> eth = CurrencyUtil.getCryptoCurrency("ETH");
eth.ifPresent(cryptoCurrencyAccount::setSingleTradeCurrency);

user.addPaymentAccount(cryptoCurrencyAccount);
}
}
Expand Down Expand Up @@ -593,10 +612,6 @@ BooleanProperty getIsFiatCurrencyPriceFeedSelected() {
return marketPricePresentation.getIsFiatCurrencyPriceFeedSelected();
}

BooleanProperty getIsCryptoCurrencyPriceFeedSelected() {
return marketPricePresentation.getIsCryptoCurrencyPriceFeedSelected();
}

BooleanProperty getIsExternallyProvidedPrice() {
return marketPricePresentation.getIsExternallyProvidedPrice();
}
Expand Down

0 comments on commit 704ca49

Please sign in to comment.