mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Add bonds for selecting bond id
This commit is contained in:
parent
68e2389c30
commit
6077cca35f
@ -35,17 +35,16 @@ import bisq.core.btc.wallet.BsqBalanceListener;
|
|||||||
import bisq.core.btc.wallet.BsqWalletService;
|
import bisq.core.btc.wallet.BsqWalletService;
|
||||||
import bisq.core.btc.wallet.WalletsSetup;
|
import bisq.core.btc.wallet.WalletsSetup;
|
||||||
import bisq.core.dao.DaoFacade;
|
import bisq.core.dao.DaoFacade;
|
||||||
|
import bisq.core.dao.bonding.Bond;
|
||||||
import bisq.core.dao.bonding.BondingConsensus;
|
import bisq.core.dao.bonding.BondingConsensus;
|
||||||
|
import bisq.core.dao.bonding.Bonds;
|
||||||
import bisq.core.dao.bonding.lockup.LockupType;
|
import bisq.core.dao.bonding.lockup.LockupType;
|
||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
import bisq.core.util.BsqFormatter;
|
import bisq.core.util.BsqFormatter;
|
||||||
import bisq.core.util.validation.IntegerValidator;
|
import bisq.core.util.validation.IntegerValidator;
|
||||||
import bisq.core.util.validation.StringValidator;
|
|
||||||
|
|
||||||
import bisq.network.p2p.P2PService;
|
import bisq.network.p2p.P2PService;
|
||||||
|
|
||||||
import bisq.common.util.Utilities;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.InsufficientMoneyException;
|
import org.bitcoinj.core.InsufficientMoneyException;
|
||||||
|
|
||||||
@ -80,13 +79,12 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
private final BsqValidator bsqValidator;
|
private final BsqValidator bsqValidator;
|
||||||
private final DaoFacade daoFacade;
|
private final DaoFacade daoFacade;
|
||||||
private final IntegerValidator timeInputTextFieldValidator;
|
private final IntegerValidator timeInputTextFieldValidator;
|
||||||
private final StringValidator bondIdValidator;
|
|
||||||
|
|
||||||
private int gridRow = 0;
|
private int gridRow = 0;
|
||||||
private InputTextField amountInputTextField;
|
private InputTextField amountInputTextField;
|
||||||
private InputTextField timeInputTextField;
|
private InputTextField timeInputTextField;
|
||||||
private ComboBox<LockupType> lockupTypeComboBox;
|
private ComboBox<LockupType> lockupTypeComboBox;
|
||||||
private InputTextField bondIdInputTextField;
|
private ComboBox<Bond> bondsComboBox;
|
||||||
private Button lockupButton;
|
private Button lockupButton;
|
||||||
private ChangeListener<Boolean> focusOutListener;
|
private ChangeListener<Boolean> focusOutListener;
|
||||||
private ChangeListener<String> inputTextFieldListener;
|
private ChangeListener<String> inputTextFieldListener;
|
||||||
@ -117,9 +115,6 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
timeInputTextFieldValidator = new IntegerValidator();
|
timeInputTextFieldValidator = new IntegerValidator();
|
||||||
timeInputTextFieldValidator.setMinValue(BondingConsensus.getMinLockTime());
|
timeInputTextFieldValidator.setMinValue(BondingConsensus.getMinLockTime());
|
||||||
timeInputTextFieldValidator.setMaxValue(BondingConsensus.getMaxLockTime());
|
timeInputTextFieldValidator.setMaxValue(BondingConsensus.getMaxLockTime());
|
||||||
|
|
||||||
bondIdValidator = new StringValidator();
|
|
||||||
bondIdValidator.setLength(20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -133,13 +128,13 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
amountInputTextField.setPromptText(Res.get("dao.bonding.lock.setAmount", bsqFormatter.formatCoinWithCode(Restrictions.getMinNonDustOutput())));
|
amountInputTextField.setPromptText(Res.get("dao.bonding.lock.setAmount", bsqFormatter.formatCoinWithCode(Restrictions.getMinNonDustOutput())));
|
||||||
amountInputTextField.setValidator(bsqValidator);
|
amountInputTextField.setValidator(bsqValidator);
|
||||||
|
|
||||||
timeInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("dao.bonding.lock.time"), Layout.GRID_GAP).second;
|
timeInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("dao.bonding.lock.time")).second;
|
||||||
timeInputTextField.setPromptText(Res.get("dao.bonding.lock.setTime",
|
timeInputTextField.setPromptText(Res.get("dao.bonding.lock.setTime",
|
||||||
String.valueOf(BondingConsensus.getMinLockTime()), String.valueOf(BondingConsensus.getMaxLockTime())));
|
String.valueOf(BondingConsensus.getMinLockTime()), String.valueOf(BondingConsensus.getMaxLockTime())));
|
||||||
timeInputTextField.setValidator(timeInputTextFieldValidator);
|
timeInputTextField.setValidator(timeInputTextFieldValidator);
|
||||||
|
|
||||||
lockupTypeComboBox = addLabelComboBox(root, ++gridRow,
|
lockupTypeComboBox = addLabelComboBox(root, ++gridRow, Res.get("dao.bonding.lock.type")).second;
|
||||||
Res.getWithCol("dao.bonding.lock.type"), Layout.GRID_GAP).second;
|
lockupTypeComboBox.setPromptText(Res.get("list.currency.select"));
|
||||||
lockupTypeComboBox.setConverter(new StringConverter<LockupType>() {
|
lockupTypeComboBox.setConverter(new StringConverter<LockupType>() {
|
||||||
@Override
|
@Override
|
||||||
public String toString(LockupType lockupType) {
|
public String toString(LockupType lockupType) {
|
||||||
@ -152,14 +147,21 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
lockupTypeComboBox.setItems(FXCollections.observableArrayList(Arrays.asList(LockupType.values())));
|
lockupTypeComboBox.setItems(FXCollections.observableArrayList(Arrays.asList(LockupType.values())));
|
||||||
lockupTypeComboBox.getSelectionModel().selectFirst();
|
|
||||||
|
|
||||||
bondIdInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("dao.bonding.lock.bondId"), Layout.GRID_GAP).second;
|
bondsComboBox = addLabelComboBox(root, ++gridRow, Res.get("dao.bonding.lock.bonds")).second;
|
||||||
bondIdInputTextField.setPromptText(Res.get("dao.bonding.lock.setBondId"));
|
bondsComboBox.setPromptText(Res.get("list.currency.select"));
|
||||||
|
bondsComboBox.setConverter(new StringConverter<Bond>() {
|
||||||
|
@Override
|
||||||
|
public String toString(Bond bond) {
|
||||||
|
return bond.toDisplayString();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO atm it does not make sense to validate as we dont use real data
|
@Override
|
||||||
// data should get derived anyway sfrom human readable sources
|
public Bond fromString(String string) {
|
||||||
//bondIdInputTextField.setValidator(bondIdValidator);
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bondsComboBox.setItems(FXCollections.observableArrayList(Bonds.getBonds()));
|
||||||
|
|
||||||
lockupButton = addButtonAfterGroup(root, ++gridRow, Res.get("dao.bonding.lock.lockupButton"));
|
lockupButton = addButtonAfterGroup(root, ++gridRow, Res.get("dao.bonding.lock.lockupButton"));
|
||||||
lockupButton.setOnAction((event) -> {
|
lockupButton.setOnAction((event) -> {
|
||||||
@ -169,11 +171,11 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
LockupType type = lockupTypeComboBox.getValue();
|
LockupType type = lockupTypeComboBox.getValue();
|
||||||
//TODO use mapping to human readable input
|
//TODO use mapping to human readable input
|
||||||
Optional<byte[]> hashOfBondId;
|
Optional<byte[]> hashOfBondId;
|
||||||
if (type == LockupType.BONDED_ROLE)
|
if (type == LockupType.BONDED_ROLE) {
|
||||||
hashOfBondId = Optional.of(Utilities.decodeFromHex(bondIdInputTextField.getText()));
|
hashOfBondId = Optional.of(bondsComboBox.getSelectionModel().getSelectedItem().getHash());
|
||||||
else
|
} else {
|
||||||
hashOfBondId = Optional.empty();
|
hashOfBondId = Optional.empty();
|
||||||
|
}
|
||||||
new Popup<>().headLine(Res.get("dao.bonding.lock.sendFunds.headline"))
|
new Popup<>().headLine(Res.get("dao.bonding.lock.sendFunds.headline"))
|
||||||
.confirmation(Res.get("dao.bonding.lock.sendFunds.details",
|
.confirmation(Res.get("dao.bonding.lock.sendFunds.details",
|
||||||
bsqFormatter.formatCoinWithCode(lockupAmount),
|
bsqFormatter.formatCoinWithCode(lockupAmount),
|
||||||
@ -256,7 +258,9 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
|
|||||||
|
|
||||||
private void updateButtonState() {
|
private void updateButtonState() {
|
||||||
lockupButton.setDisable(!bsqValidator.validate(amountInputTextField.getText()).isValid ||
|
lockupButton.setDisable(!bsqValidator.validate(amountInputTextField.getText()).isValid ||
|
||||||
!timeInputTextFieldValidator.validate(timeInputTextField.getText()).isValid);
|
!timeInputTextFieldValidator.validate(timeInputTextField.getText()).isValid ||
|
||||||
|
bondsComboBox.getSelectionModel().getSelectedItem() == null ||
|
||||||
|
lockupTypeComboBox.getSelectionModel().getSelectedItem() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleError(Throwable throwable) {
|
private void handleError(Throwable throwable) {
|
||||||
|
@ -28,6 +28,8 @@ import bisq.desktop.util.validation.BsqValidator;
|
|||||||
|
|
||||||
import bisq.core.btc.wallet.BsqWalletService;
|
import bisq.core.btc.wallet.BsqWalletService;
|
||||||
import bisq.core.dao.DaoFacade;
|
import bisq.core.dao.DaoFacade;
|
||||||
|
import bisq.core.dao.bonding.Bond;
|
||||||
|
import bisq.core.dao.bonding.Bonds;
|
||||||
import bisq.core.dao.state.blockchain.Tx;
|
import bisq.core.dao.state.blockchain.Tx;
|
||||||
import bisq.core.dao.state.ext.Param;
|
import bisq.core.dao.state.ext.Param;
|
||||||
import bisq.core.dao.voting.proposal.Proposal;
|
import bisq.core.dao.voting.proposal.Proposal;
|
||||||
@ -40,8 +42,6 @@ import bisq.core.dao.voting.proposal.param.ChangeParamProposal;
|
|||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
import bisq.core.util.BsqFormatter;
|
import bisq.core.util.BsqFormatter;
|
||||||
|
|
||||||
import bisq.common.util.Utilities;
|
|
||||||
|
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
@ -60,6 +60,7 @@ import javafx.collections.ObservableList;
|
|||||||
|
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -217,9 +218,9 @@ public class ProposalDisplay {
|
|||||||
confiscateBondComboBox.setItems(lockupAndUnlockingBondIds);
|
confiscateBondComboBox.setItems(lockupAndUnlockingBondIds);
|
||||||
confiscateBondComboBox.setConverter(new StringConverter<byte[]>() {
|
confiscateBondComboBox.setConverter(new StringConverter<byte[]>() {
|
||||||
@Override
|
@Override
|
||||||
public String toString(byte[] id) {
|
public String toString(byte[] hashOfBondId) {
|
||||||
//TODO map to some human readable data source
|
Optional<Bond> bond = Bonds.getBond(hashOfBondId);
|
||||||
return Utilities.bytesAsHexString(id);
|
return bond.isPresent() ? bond.get().toDisplayString() : "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user