Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements in wallet domain and UI #656

Merged
merged 12 commits into from
Feb 20, 2023
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {

implementation('network:network')
implementation("wallets:electrum")
implementation("wallets:bitcoind")

implementation libs.google.guava
implementation libs.typesafe.config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.application;

enum BitcoinWalletSelection {
BITCOIND,
ELECTRUM,
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.account.AccountService;
import bisq.chat.ChatService;
import bisq.common.application.Service;
import bisq.common.observable.Observable;
import bisq.common.threading.ExecutorFactory;
import bisq.common.util.CompletableFutureUtils;
Expand All @@ -33,11 +34,14 @@
import bisq.settings.SettingsService;
import bisq.support.SupportService;
import bisq.user.UserService;
import bisq.wallets.bitcoind.BitcoinWalletService;
import bisq.wallets.core.WalletService;
import bisq.wallets.electrum.ElectrumWalletService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -66,7 +70,7 @@ public enum State {
}

private final SecurityService securityService;
private final ElectrumWalletService electrumWalletService;
private final Optional<WalletService> walletService;
private final NetworkService networkService;
private final IdentityService identityService;
private final OracleService oracleService;
Expand All @@ -83,8 +87,20 @@ public enum State {
public DefaultApplicationService(String[] args) {
super("default", args);
securityService = new SecurityService(persistenceService);
electrumWalletService = new ElectrumWalletService(ElectrumWalletService.Config.from(getConfig("electrumWallet")),
Path.of(config.getBaseDir()));
com.typesafe.config.Config bitcoinWalletConfig = getConfig("bitcoinWallet");
BitcoinWalletSelection bitcoinWalletSelection = bitcoinWalletConfig.getEnum(BitcoinWalletSelection.class, "bitcoinWalletSelection");
switch (bitcoinWalletSelection) {
case BITCOIND:
walletService = Optional.of(new BitcoinWalletService(BitcoinWalletService.Config.from(bitcoinWalletConfig.getConfig("bitcoind")), getPersistenceService()));
break;
case ELECTRUM:
walletService = Optional.of(new ElectrumWalletService(ElectrumWalletService.Config.from(bitcoinWalletConfig.getConfig("electrum")), Path.of(config.getBaseDir())));
break;
case NONE:
default:
walletService = Optional.empty();
break;
}

networkService = new NetworkService(NetworkServiceConfig.from(config.getBaseDir(), getConfig("network")),
persistenceService,
Expand Down Expand Up @@ -129,7 +145,8 @@ public CompletableFuture<Boolean> initialize() {
setState(State.INITIALIZE_NETWORK);

CompletableFuture<Boolean> networkFuture = networkService.initialize();
CompletableFuture<Boolean> walletFuture = electrumWalletService.initialize();
CompletableFuture<Boolean> walletFuture = walletService.map(Service::initialize)
.orElse(CompletableFuture.completedFuture(true));

networkFuture.whenComplete((r, throwable) -> {
if (throwable != null) {
Expand Down Expand Up @@ -189,7 +206,10 @@ public CompletableFuture<Boolean> shutdown() {
.thenCompose(result -> oracleService.shutdown())
.thenCompose(result -> identityService.shutdown())
.thenCompose(result -> networkService.shutdown())
.thenCompose(result -> electrumWalletService.shutdown())
.thenCompose(result -> {
return walletService.map(Service::shutdown)
.orElse(CompletableFuture.completedFuture(true));
})
.thenCompose(result -> securityService.shutdown())
.orTimeout(10, TimeUnit.SECONDS)
.handle((result, throwable) -> throwable == null)
Expand Down
14 changes: 12 additions & 2 deletions application/src/main/resources/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ application {
}
}

electrumWallet = {
enabled = false
bitcoinWallet = {
// BitcoinWalletSelection enum values: BITCOIND, ELECTRUM, NONE
// BITCOIND currently not supported
bitcoinWalletSelection = NONE
bitcoind = {
network = regtest
}
electrum = {
network = regtest
electrumXServerHost = 127.0.0.1
electrumXServerPort = 50001
}
}
}
1 change: 1 addition & 0 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

implementation("network:network")
implementation("wallets:electrum")
implementation("wallets:bitcoind")

implementation libs.google.guava
implementation libs.bundles.fontawesomefx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ContentController(DefaultApplicationService applicationService) {
super(NavigationTarget.CONTENT);

this.applicationService = applicationService;
model = new ContentModel();
model = new ContentModel(applicationService.getWalletService().isPresent());
view = new ContentView(model, this);
}

Expand All @@ -70,6 +70,9 @@ public void onDeactivate() {

@Override
protected Optional<? extends Controller> createController(NavigationTarget navigationTarget) {
if (navigationTarget == NavigationTarget.WALLET && !model.isWalletEnabled()) {
navigationTarget = NavigationTarget.DASHBOARD;
}
switch (navigationTarget) {
case DASHBOARD: {
return Optional.of(new DashboardController(applicationService));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import bisq.desktop.common.view.NavigationModel;
import bisq.desktop.common.view.NavigationTarget;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j

@Getter
public class ContentModel extends NavigationModel {
public ContentModel() {
private final boolean isWalletEnabled;

public ContentModel(boolean isWalletEnabled) {
this.isWalletEnabled = isWalletEnabled;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import bisq.desktop.common.view.TabModel;

public class WalletModel extends TabModel {

public WalletModel() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import bisq.desktop.common.view.Controller;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.common.view.NavigationTarget;
import bisq.wallets.electrum.ElectrumWalletService;
import bisq.wallets.core.WalletService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -33,21 +33,21 @@ public class WalletDashboardController implements Controller {
@Getter
private final WalletDashboardView view;
private final WalletDashboardModel model;
private final ElectrumWalletService electrumWalletService;
private final WalletService walletService;
private Pin balancePin;

public WalletDashboardController(DefaultApplicationService applicationService) {
electrumWalletService = applicationService.getElectrumWalletService();
walletService = applicationService.getWalletService().orElseThrow();
model = new WalletDashboardModel();
view = new WalletDashboardView(model, this);
}

@Override
public void onActivate() {
balancePin = FxBindings.bind(model.getBalanceAsCoinProperty())
.to(electrumWalletService.getObservableBalanceAsCoin());
.to(walletService.getBalance());

electrumWalletService.getBalance().whenComplete((balance, throwable) -> {
walletService.requestBalance().whenComplete((balance, throwable) -> {
if (throwable == null) {
UIThread.run(() -> model.getBalanceAsCoinProperty().set(balance));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.common.utils.ClipboardUtil;
import bisq.desktop.common.view.Controller;
import bisq.wallets.electrum.ElectrumWalletService;
import bisq.wallets.core.WalletService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -30,17 +30,17 @@ public class WalletReceiveController implements Controller {
@Getter
private final WalletReceiveView view;
private final WalletReceiveModel model;
private final ElectrumWalletService electrumWalletService;
private final WalletService walletService;

public WalletReceiveController(DefaultApplicationService applicationService) {
electrumWalletService = applicationService.getElectrumWalletService();
walletService = applicationService.getWalletService().orElseThrow();
model = new WalletReceiveModel();
view = new WalletReceiveView(model, this);
}

@Override
public void onActivate() {
electrumWalletService.getNewAddress().
walletService.getUnusedAddress().
thenAccept(receiveAddress -> UIThread.run(() -> model.getReceiveAddress().setValue(receiveAddress)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import bisq.desktop.common.utils.validation.MonetaryValidator;
import bisq.desktop.common.view.Controller;
import bisq.desktop.components.overlay.Popup;
import bisq.wallets.electrum.ElectrumWalletService;
import bisq.wallets.core.WalletService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
Expand All @@ -35,13 +35,13 @@ public class WalletSendController implements Controller {
@Getter
private final WalletSendView view;
private final WalletSendModel model;
private final ElectrumWalletService electrumWalletService;
private final WalletService walletService;
private final MonetaryValidator amountValidator = new MonetaryValidator();
private Subscription addressPin;
private Subscription amountPin;

public WalletSendController(DefaultApplicationService applicationService) {
electrumWalletService = applicationService.getElectrumWalletService();
walletService = applicationService.getWalletService().orElseThrow();
model = new WalletSendModel();
view = new WalletSendView(model, this, amountValidator);
}
Expand All @@ -56,7 +56,7 @@ public void onActivate() {
});

//todo check if wallet is encrypted
electrumWalletService.isWalletEncrypted()
walletService.isWalletEncrypted()
.thenAccept(isWalletEncrypted -> UIThread.run(() -> model.getIsPasswordVisible().set(isWalletEncrypted)));
}

Expand All @@ -70,7 +70,7 @@ void onSend() {
//todo
double amount = Double.parseDouble(model.getAmount().get());
String address = model.getAddress().get();
electrumWalletService.sendToAddress(Optional.ofNullable(model.getPassword().get()), address, amount)
walletService.sendToAddress(Optional.ofNullable(model.getPassword().get()), address, amount)
.whenComplete((response, throwable) -> {
if (throwable != null) {
UIThread.run(() -> new Popup().error(throwable.getMessage()).show());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import bisq.application.DefaultApplicationService;
import bisq.desktop.common.view.Controller;
import bisq.wallets.electrum.ElectrumWalletService;
import bisq.wallets.core.WalletService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -28,10 +28,10 @@ public class WalletSettingsController implements Controller {
@Getter
private final WalletSettingsView view;
private final WalletSettingsModel model;
private final ElectrumWalletService electrumWalletService;
private final WalletService walletService;

public WalletSettingsController(DefaultApplicationService applicationService) {
electrumWalletService = applicationService.getElectrumWalletService();
walletService = applicationService.getWalletService().orElseThrow();
model = new WalletSettingsModel();
view = new WalletSettingsView(model, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,36 @@

package bisq.desktop.primary.main.content.wallet.txs;

import bisq.common.monetary.Coin;
import bisq.desktop.components.table.TableItem;
import bisq.presentation.formatters.AmountFormatter;
import bisq.presentation.formatters.DateFormatter;
import bisq.wallets.core.model.Transaction;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
@Getter
@EqualsAndHashCode
public class WalletTransactionListItem implements TableItem {
private final String date;
private final Date date;
private final String dateAsString;
private final String txId;
private final String amount;
private final String confirmations;
private final String amountAsString;
private final String confirmationsAsString;
private final Coin amount;
private final int confirmations;

public WalletTransactionListItem(Transaction transaction) {
date = DateFormatter.formatDateTime(transaction.getDate());
date = transaction.getDate().orElse(new Date());
dateAsString = DateFormatter.formatDateTime(date);
txId = transaction.getTxId();
amount = AmountFormatter.formatAmount(transaction.getAmount());
confirmations = String.valueOf(transaction.getConfirmations());
amount = transaction.getAmount();
amountAsString = AmountFormatter.formatAmount(amount);
confirmations = transaction.getConfirmations();
confirmationsAsString = String.valueOf(confirmations);
}

}
Loading