Search in sources :

Example 1 with WalletHistoryClearedEvent

use of com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent in project sparrow by sparrowwallet.

the class CoinTreeTable method getDefaultPlaceholder.

protected Node getDefaultPlaceholder(Wallet wallet) {
    StackPane stackPane = new StackPane();
    stackPane.getChildren().add(AppServices.isConnecting() ? new Label("Loading transactions...") : new Label("No transactions"));
    if (Config.get().getServerType() == ServerType.BITCOIN_CORE && !AppServices.isConnecting()) {
        Hyperlink hyperlink = new Hyperlink();
        hyperlink.setTranslateY(30);
        hyperlink.setOnAction(event -> {
            WalletBirthDateDialog dlg = new WalletBirthDateDialog(wallet.getBirthDate());
            Optional<Date> optDate = dlg.showAndWait();
            if (optDate.isPresent()) {
                Storage storage = AppServices.get().getOpenWallets().get(wallet);
                Wallet pastWallet = wallet.copy();
                wallet.setBirthDate(optDate.get());
                // Trigger background save of birthdate
                EventManager.get().post(new WalletDataChangedEvent(wallet));
                // Trigger full wallet rescan
                wallet.clearHistory();
                EventManager.get().post(new WalletHistoryClearedEvent(wallet, pastWallet, storage.getWalletId(wallet)));
            }
        });
        if (wallet.getBirthDate() == null) {
            hyperlink.setText("Scan for previous transactions?");
        } else {
            DateFormat dateFormat = new SimpleDateFormat(DateStringConverter.FORMAT_PATTERN);
            hyperlink.setText("Scan for transactions earlier than " + dateFormat.format(wallet.getBirthDate()) + "?");
        }
        stackPane.getChildren().add(hyperlink);
    }
    stackPane.setAlignment(Pos.CENTER);
    return stackPane;
}
Also used : WalletHistoryClearedEvent(com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent) Storage(com.sparrowwallet.sparrow.io.Storage) Wallet(com.sparrowwallet.drongo.wallet.Wallet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Label(javafx.scene.control.Label) WalletDataChangedEvent(com.sparrowwallet.sparrow.event.WalletDataChangedEvent) SimpleDateFormat(java.text.SimpleDateFormat) StackPane(javafx.scene.layout.StackPane) Date(java.util.Date) Hyperlink(javafx.scene.control.Hyperlink)

Aggregations

Wallet (com.sparrowwallet.drongo.wallet.Wallet)1 WalletDataChangedEvent (com.sparrowwallet.sparrow.event.WalletDataChangedEvent)1 WalletHistoryClearedEvent (com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent)1 Storage (com.sparrowwallet.sparrow.io.Storage)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Hyperlink (javafx.scene.control.Hyperlink)1 Label (javafx.scene.control.Label)1 StackPane (javafx.scene.layout.StackPane)1