diff --git a/common/src/main/proto/pb.proto b/common/src/main/proto/pb.proto index 8db992f910a..7ba510f4807 100644 --- a/common/src/main/proto/pb.proto +++ b/common/src/main/proto/pb.proto @@ -725,6 +725,7 @@ message PaymentAccountPayload { HalCashAccountPayload hal_cash_account_payload = 24; PromptPayAccountPayload prompt_pay_account_payload = 25; AdvancedCashAccountPayload advanced_cash_account_payload = 26; + InstantCryptoCurrencyAccountPayload instant_crypto_currency_account_payload = 27; } map exclude_from_json_data = 15; } @@ -836,6 +837,10 @@ message CryptoCurrencyAccountPayload { string address = 1; } +message InstantCryptoCurrencyAccountPayload { + string address = 1; +} + message FasterPaymentsAccountPayload { string sort_code = 1; string account_nr = 2; diff --git a/core/src/main/java/bisq/core/payment/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/payment/AccountAgeWitnessService.java index e30617ef8df..e3890d463f6 100644 --- a/core/src/main/java/bisq/core/payment/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/payment/AccountAgeWitnessService.java @@ -126,7 +126,7 @@ public void onUpdatedDataReceived() { private void republishAllFiatAccounts() { if (user.getPaymentAccounts() != null) user.getPaymentAccounts().stream() - .filter(e -> !(e instanceof CryptoCurrencyAccount)) + .filter(e -> !(e instanceof AssetAccount)) .forEach(e -> { // We delay with a random interval of 20-60 sec to ensure to be better connected and don't stress the // P2P network with publishing all at once at startup time. diff --git a/core/src/main/java/bisq/core/payment/AssetAccount.java b/core/src/main/java/bisq/core/payment/AssetAccount.java new file mode 100644 index 00000000000..de7c2e72d2f --- /dev/null +++ b/core/src/main/java/bisq/core/payment/AssetAccount.java @@ -0,0 +1,35 @@ +/* + * 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 . + */ + +package bisq.core.payment; + +import bisq.core.payment.payload.AssetsAccountPayload; +import bisq.core.payment.payload.PaymentMethod; + +public abstract class AssetAccount extends PaymentAccount { + protected AssetAccount(PaymentMethod paymentMethod) { + super(paymentMethod); + } + + public void setAddress(String address) { + ((AssetsAccountPayload) paymentAccountPayload).setAddress(address); + } + + public String getAddress() { + return ((AssetsAccountPayload) paymentAccountPayload).getAddress(); + } +} diff --git a/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java b/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java index ad096d15d99..534157bd1f8 100644 --- a/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java +++ b/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java @@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class CryptoCurrencyAccount extends PaymentAccount { +public final class CryptoCurrencyAccount extends AssetAccount { public CryptoCurrencyAccount() { super(PaymentMethod.BLOCK_CHAINS); @@ -34,12 +34,4 @@ public CryptoCurrencyAccount() { protected PaymentAccountPayload createPayload() { return new CryptoCurrencyAccountPayload(paymentMethod.getId(), id); } - - public void setAddress(String address) { - ((CryptoCurrencyAccountPayload) paymentAccountPayload).setAddress(address); - } - - public String getAddress() { - return ((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress(); - } } diff --git a/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java b/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java new file mode 100644 index 00000000000..17ddf5eca77 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package bisq.core.payment; + +import bisq.core.payment.payload.InstantCryptoCurrencyPayload; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public final class InstantCryptoCurrencyAccount extends AssetAccount { + + public InstantCryptoCurrencyAccount() { + super(PaymentMethod.BLOCK_CHAINS_INSTANT); + } + + @Override + protected PaymentAccountPayload createPayload() { + return new InstantCryptoCurrencyPayload(paymentMethod.getId(), id); + } +} diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java index b35dabc3ff1..ed9462e25dc 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java @@ -74,6 +74,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { return new PromptPayAccount(); case PaymentMethod.ADVANCED_CASH_ID: return new AdvancedCashAccount(); + case PaymentMethod.BLOCK_CHAINS_INSTANT_ID: + return new InstantCryptoCurrencyAccount(); default: throw new RuntimeException("Not supported PaymentMethod: " + paymentMethod); } diff --git a/core/src/main/java/bisq/core/payment/payload/AssetsAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/AssetsAccountPayload.java new file mode 100644 index 00000000000..76d34790e62 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/payload/AssetsAccountPayload.java @@ -0,0 +1,82 @@ +/* + * 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 . + */ + +package bisq.core.payment.payload; + +import bisq.core.locale.Res; + +import java.nio.charset.Charset; + +import java.util.Map; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Nullable; + +@EqualsAndHashCode(callSuper = true) +@ToString +@Setter +@Getter +@Slf4j +public abstract class AssetsAccountPayload extends PaymentAccountPayload { + protected String address = ""; + + protected AssetsAccountPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + protected AssetsAccountPayload(String paymentMethod, + String id, + String address, + long maxTradePeriod, + @Nullable Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + maxTradePeriod, + excludeFromJsonDataMap); + this.address = address; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public String getPaymentDetails() { + return Res.getWithCol("payment.altcoin.receiver.address") + " " + address; + } + + @Override + public String getPaymentDetailsForTradePopup() { + return getPaymentDetails(); + } + + @Override + public byte[] getAgeWitnessInputData() { + return super.getAgeWitnessInputData(address.getBytes(Charset.forName("UTF-8"))); + } +} diff --git a/core/src/main/java/bisq/core/payment/payload/CryptoCurrencyAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/CryptoCurrencyAccountPayload.java index 04dcbe94f9f..a295816f642 100644 --- a/core/src/main/java/bisq/core/payment/payload/CryptoCurrencyAccountPayload.java +++ b/core/src/main/java/bisq/core/payment/payload/CryptoCurrencyAccountPayload.java @@ -17,16 +17,12 @@ package bisq.core.payment.payload; -import bisq.core.locale.Res; - import io.bisq.generated.protobuffer.PB; import com.google.protobuf.Message; import org.springframework.util.CollectionUtils; -import java.nio.charset.Charset; - import java.util.HashMap; import java.util.Map; @@ -43,8 +39,7 @@ @Setter @Getter @Slf4j -public final class CryptoCurrencyAccountPayload extends PaymentAccountPayload { - private String address = ""; +public final class CryptoCurrencyAccountPayload extends AssetsAccountPayload { public CryptoCurrencyAccountPayload(String paymentMethod, String id) { super(paymentMethod, id); @@ -62,9 +57,9 @@ private CryptoCurrencyAccountPayload(String paymentMethod, @Nullable Map excludeFromJsonDataMap) { super(paymentMethod, id, + address, maxTradePeriod, excludeFromJsonDataMap); - this.address = address; } @Override @@ -83,23 +78,4 @@ public static CryptoCurrencyAccountPayload fromProto(PB.PaymentAccountPayload pr CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap())); } - - /////////////////////////////////////////////////////////////////////////////////////////// - // API - /////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public String getPaymentDetails() { - return Res.getWithCol("payment.altcoin.receiver.address") + " " + address; - } - - @Override - public String getPaymentDetailsForTradePopup() { - return getPaymentDetails(); - } - - @Override - public byte[] getAgeWitnessInputData() { - return super.getAgeWitnessInputData(address.getBytes(Charset.forName("UTF-8"))); - } } diff --git a/core/src/main/java/bisq/core/payment/payload/InstantCryptoCurrencyPayload.java b/core/src/main/java/bisq/core/payment/payload/InstantCryptoCurrencyPayload.java new file mode 100644 index 00000000000..bc112d213d2 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/payload/InstantCryptoCurrencyPayload.java @@ -0,0 +1,80 @@ +/* + * 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 . + */ + +package bisq.core.payment.payload; + +import io.bisq.generated.protobuffer.PB; + +import com.google.protobuf.Message; + +import org.springframework.util.CollectionUtils; + +import java.util.HashMap; +import java.util.Map; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Nullable; + +@EqualsAndHashCode(callSuper = true) +@ToString +@Setter +@Getter +@Slf4j +public final class InstantCryptoCurrencyPayload extends AssetsAccountPayload { + + public InstantCryptoCurrencyPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private InstantCryptoCurrencyPayload(String paymentMethod, + String id, + String address, + long maxTradePeriod, + @Nullable Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + address, + maxTradePeriod, + excludeFromJsonDataMap); + } + + @Override + public Message toProtoMessage() { + return getPaymentAccountPayloadBuilder() + .setInstantCryptoCurrencyAccountPayload(PB.InstantCryptoCurrencyAccountPayload.newBuilder() + .setAddress(address)) + .build(); + } + + public static InstantCryptoCurrencyPayload fromProto(PB.PaymentAccountPayload proto) { + return new InstantCryptoCurrencyPayload(proto.getPaymentMethodId(), + proto.getId(), + proto.getInstantCryptoCurrencyAccountPayload().getAddress(), + proto.getMaxTradePeriod(), + CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap())); + } +} diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index 7722dca9ae7..6bfc2f5e69c 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -89,6 +89,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable { public static final String BLOCK_CHAINS_ID = "BLOCK_CHAINS"; public static final String PROMPT_PAY_ID = "PROMPT_PAY"; public static final String ADVANCED_CASH_ID = "ADVANCED_CASH"; + public static final String BLOCK_CHAINS_INSTANT_ID = "BLOCK_CHAINS_INSTANT"; public static PaymentMethod UPHOLD; public static PaymentMethod MONEY_BEAM; @@ -116,6 +117,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable { public static PaymentMethod BLOCK_CHAINS; public static PaymentMethod PROMPT_PAY; public static PaymentMethod ADVANCED_CASH; + public static PaymentMethod BLOCK_CHAINS_INSTANT; // The limit and duration assignment must not be changed as that could break old offers (if amount would be higher // than new trade limit) and violate the maker expectation when he created the offer (duration). @@ -166,7 +168,9 @@ public final class PaymentMethod implements PersistablePayload, Comparable { PROMPT_PAY = new PaymentMethod(PROMPT_PAY_ID, DAY, DEFAULT_TRADE_LIMIT_LOW_RISK), // Altcoins - BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, DEFAULT_TRADE_LIMIT_VERY_LOW_RISK) + BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, DEFAULT_TRADE_LIMIT_VERY_LOW_RISK), + // Altcoins with 1 hour trade period + BLOCK_CHAINS_INSTANT = new PaymentMethod(BLOCK_CHAINS_INSTANT_ID, TimeUnit.HOURS.toMillis(1), DEFAULT_TRADE_LIMIT_VERY_LOW_RISK) )); static { @@ -292,4 +296,8 @@ public int compareTo(@NotNull Object other) { else return 0; } + + public boolean isAsset() { + return this.equals(BLOCK_CHAINS_INSTANT) || this.equals(BLOCK_CHAINS); + } } diff --git a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java index b5cd297bd42..69262e6b5c5 100644 --- a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java @@ -29,6 +29,7 @@ import bisq.core.payment.payload.F2FAccountPayload; import bisq.core.payment.payload.FasterPaymentsAccountPayload; import bisq.core.payment.payload.HalCashAccountPayload; +import bisq.core.payment.payload.InstantCryptoCurrencyPayload; import bisq.core.payment.payload.InteracETransferAccountPayload; import bisq.core.payment.payload.MoneyBeamAccountPayload; import bisq.core.payment.payload.MoneyGramAccountPayload; @@ -132,6 +133,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) { return PromptPayAccountPayload.fromProto(proto); case ADVANCED_CASH_ACCOUNT_PAYLOAD: return AdvancedCashAccountPayload.fromProto(proto); + case INSTANT_CRYPTO_CURRENCY_ACCOUNT_PAYLOAD: + return InstantCryptoCurrencyPayload.fromProto(proto); default: throw new ProtobufferRuntimeException("Unknown proto message case(PB.PaymentAccountPayload). messageCase=" + messageCase); } diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index aeefbae93f7..7751f86a7de 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -2381,6 +2381,11 @@ payment.country=Country payment.extras=Extra requirements payment.email.mobile=Email or mobile no. payment.altcoin.address=Altcoin address +payment.altcoin.tradeInstantCheckbox=Trade instant (within 1 hour) with this Altcoin +payment.altcoin.tradeInstant.popup=For instant trading it is required that both trading peers are online to be able \ + to complete the trade in less than 1 hour.\n\n\ + If you have offers open and you are not available please disable \ + those offers under the 'Portfolio' screen. payment.altcoin=Altcoin payment.select.altcoin=Select or search altcoin payment.secret=Secret question @@ -2579,6 +2584,8 @@ BLOCK_CHAINS=Altcoins PROMPT_PAY=PromptPay # suppress inspection "UnusedProperty" ADVANCED_CASH=Advanced Cash +# suppress inspection "UnusedProperty" +BLOCK_CHAINS_INSTANT=Altcoins Instant # suppress inspection "UnusedProperty" UPHOLD_SHORT=Uphold @@ -2616,6 +2623,9 @@ BLOCK_CHAINS_SHORT=Altcoins PROMPT_PAY_SHORT=PromptPay # suppress inspection "UnusedProperty" ADVANCED_CASH_SHORT=Advanced Cash +# suppress inspection "UnusedProperty" +BLOCK_CHAINS_INSTANT_SHORT=Altcoins Instant + #################################################################### # Validation diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CryptoCurrencyForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AssetsForm.java similarity index 67% rename from desktop/src/main/java/bisq/desktop/components/paymentmethods/CryptoCurrencyForm.java rename to desktop/src/main/java/bisq/desktop/components/paymentmethods/AssetsForm.java index 5b962b5faf2..140ff98c2d4 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CryptoCurrencyForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AssetsForm.java @@ -18,6 +18,7 @@ package bisq.desktop.components.paymentmethods; import bisq.desktop.components.InputTextField; +import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.util.FormBuilder; import bisq.desktop.util.Layout; @@ -27,9 +28,10 @@ import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.payment.AccountAgeWitnessService; -import bisq.core.payment.CryptoCurrencyAccount; +import bisq.core.payment.AssetAccount; +import bisq.core.payment.InstantCryptoCurrencyAccount; import bisq.core.payment.PaymentAccount; -import bisq.core.payment.payload.CryptoCurrencyAccountPayload; +import bisq.core.payment.payload.AssetsAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.validation.AltCoinAddressValidator; import bisq.core.util.BSFormatter; @@ -39,6 +41,7 @@ import org.apache.commons.lang3.StringUtils; +import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; @@ -55,37 +58,41 @@ import static bisq.desktop.util.FormBuilder.addTopLabelTextField; import static bisq.desktop.util.GUIUtil.getComboBoxButtonCell; -public class CryptoCurrencyForm extends PaymentMethodForm { - private final CryptoCurrencyAccount cryptoCurrencyAccount; +public class AssetsForm extends PaymentMethodForm { + private final AssetAccount assetAccount; private final AltCoinAddressValidator altCoinAddressValidator; private final AssetService assetService; private final FilterManager filterManager; private InputTextField addressInputTextField; + private CheckBox tradeInstantCheckBox; + private boolean tradeInstant; public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload, String labelTitle) { addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, labelTitle, - ((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress()); + ((AssetsAccountPayload) paymentAccountPayload).getAddress()); return gridRow; } - public CryptoCurrencyForm(PaymentAccount paymentAccount, - AccountAgeWitnessService accountAgeWitnessService, - AltCoinAddressValidator altCoinAddressValidator, - InputValidator inputValidator, - GridPane gridPane, - int gridRow, - BSFormatter formatter, - AssetService assetService, - FilterManager filterManager) { + public AssetsForm(PaymentAccount paymentAccount, + AccountAgeWitnessService accountAgeWitnessService, + AltCoinAddressValidator altCoinAddressValidator, + InputValidator inputValidator, + GridPane gridPane, + int gridRow, + BSFormatter formatter, + AssetService assetService, + FilterManager filterManager) { super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); - this.cryptoCurrencyAccount = (CryptoCurrencyAccount) paymentAccount; + this.assetAccount = (AssetAccount) paymentAccount; this.altCoinAddressValidator = altCoinAddressValidator; this.assetService = assetService; this.filterManager = filterManager; + + tradeInstant = paymentAccount instanceof InstantCryptoCurrencyAccount; } @Override @@ -94,12 +101,22 @@ public void addFormForAddAccount() { addTradeCurrencyComboBox(); currencyComboBox.setPrefWidth(250); + + tradeInstantCheckBox = FormBuilder.addLabelCheckBox(gridPane, ++gridRow, + Res.get("payment.altcoin.tradeInstantCheckbox"), 10); + tradeInstantCheckBox.setSelected(tradeInstant); + tradeInstantCheckBox.setOnAction(e -> { + tradeInstant = tradeInstantCheckBox.isSelected(); + if (tradeInstant) + new Popup<>().information(Res.get("payment.altcoin.tradeInstant.popup")).show(); + }); + addressInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.altcoin.address")); addressInputTextField.setValidator(altCoinAddressValidator); addressInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - cryptoCurrencyAccount.setAddress(newValue); + assetAccount.setAddress(newValue); updateFromInputs(); }); @@ -107,11 +124,28 @@ public void addFormForAddAccount() { addAccountNameTextFieldWithAutoFillToggleButton(); } + @Override + public PaymentAccount getPaymentAccount() { + if (tradeInstant) { + InstantCryptoCurrencyAccount instantCryptoCurrencyAccount = new InstantCryptoCurrencyAccount(); + instantCryptoCurrencyAccount.init(); + instantCryptoCurrencyAccount.setAccountName(paymentAccount.getAccountName()); + instantCryptoCurrencyAccount.setSaltAsHex(paymentAccount.getSaltAsHex()); + instantCryptoCurrencyAccount.setSalt(paymentAccount.getSalt()); + instantCryptoCurrencyAccount.setSingleTradeCurrency(paymentAccount.getSingleTradeCurrency()); + instantCryptoCurrencyAccount.setSelectedTradeCurrency(paymentAccount.getSelectedTradeCurrency()); + instantCryptoCurrencyAccount.setAddress(assetAccount.getAddress()); + return instantCryptoCurrencyAccount; + } else { + return paymentAccount; + } + } + @Override public void updateFromInputs() { - if (addressInputTextField != null && cryptoCurrencyAccount.getSingleTradeCurrency() != null) + if (addressInputTextField != null && assetAccount.getSingleTradeCurrency() != null) addressInputTextField.setPromptText(Res.get("payment.altcoin.address.dyn", - cryptoCurrencyAccount.getSingleTradeCurrency().getName())); + assetAccount.getSingleTradeCurrency().getName())); super.updateFromInputs(); } @@ -131,14 +165,14 @@ protected void autoFillNameTextField() { public void addFormForDisplayAccount() { gridRowFrom = gridRow; addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), - cryptoCurrencyAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + assetAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), - Res.get(cryptoCurrencyAccount.getPaymentMethod().getId())); + Res.get(assetAccount.getPaymentMethod().getId())); Tuple3 tuple2 = addCompactTopLabelTextField(gridPane, ++gridRow, - Res.get("payment.altcoin.address"), cryptoCurrencyAccount.getAddress()); + Res.get("payment.altcoin.address"), assetAccount.getAddress()); TextField field = tuple2.second; field.setMouseTransparent(false); - final TradeCurrency singleTradeCurrency = cryptoCurrencyAccount.getSingleTradeCurrency(); + final TradeCurrency singleTradeCurrency = assetAccount.getSingleTradeCurrency(); final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : ""; addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.altcoin"), nameAndCode); @@ -147,12 +181,12 @@ public void addFormForDisplayAccount() { @Override public void updateAllInputsValid() { - TradeCurrency selectedTradeCurrency = cryptoCurrencyAccount.getSelectedTradeCurrency(); + TradeCurrency selectedTradeCurrency = assetAccount.getSelectedTradeCurrency(); if (selectedTradeCurrency != null) { altCoinAddressValidator.setCurrencyCode(selectedTradeCurrency.getCode()); allInputsValid.set(isAccountNameValid() - && altCoinAddressValidator.validate(cryptoCurrencyAccount.getAddress()).isValid - && cryptoCurrencyAccount.getSingleTradeCurrency() != null); + && altCoinAddressValidator.validate(assetAccount.getAddress()).isValid + && assetAccount.getSingleTradeCurrency() != null); } } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java index bf602956c81..61d965a7084 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java @@ -31,7 +31,7 @@ import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.payment.AccountAgeWitnessService; -import bisq.core.payment.CryptoCurrencyAccount; +import bisq.core.payment.AssetAccount; import bisq.core.payment.PaymentAccount; import bisq.core.util.BSFormatter; import bisq.core.util.validation.InputValidator; @@ -166,7 +166,7 @@ else if (paymentAccount.getSelectedTradeCurrency() != null) else if (!paymentAccount.getTradeCurrencies().isEmpty()) tradeCurrency = paymentAccount.getTradeCurrencies().get(0); else - tradeCurrency = paymentAccount instanceof CryptoCurrencyAccount ? + tradeCurrency = paymentAccount instanceof AssetAccount ? CurrencyUtil.getAllSortedCryptoCurrencies().get(0) : CurrencyUtil.getDefaultTradeCurrency(); @@ -174,7 +174,7 @@ else if (!paymentAccount.getTradeCurrencies().isEmpty()) final boolean isAddAccountScreen = paymentAccount.getAccountName() == null; final long accountAge = !isAddAccountScreen ? accountAgeWitnessService.getMyAccountAge(paymentAccount.getPaymentAccountPayload()) : 0L; - final String limitationsText = paymentAccount instanceof CryptoCurrencyAccount ? + final String limitationsText = paymentAccount instanceof AssetAccount ? Res.get("payment.maxPeriodAndLimitCrypto", getTimeText(hours), formatter.formatCoinWithCode(Coin.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrency.getCode())))) diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsDataModel.java b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsDataModel.java index d431bcddab1..11fbec3a87b 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsDataModel.java @@ -25,9 +25,8 @@ import bisq.core.locale.TradeCurrency; import bisq.core.offer.OpenOfferManager; import bisq.core.payment.AccountAgeWitnessService; -import bisq.core.payment.CryptoCurrencyAccount; +import bisq.core.payment.AssetAccount; import bisq.core.payment.PaymentAccount; -import bisq.core.payment.payload.PaymentMethod; import bisq.core.trade.TradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -83,7 +82,7 @@ protected void activate() { private void fillAndSortPaymentAccounts() { if (user.getPaymentAccounts() != null) { paymentAccounts.setAll(user.getPaymentAccounts().stream() - .filter(paymentAccount -> paymentAccount.getPaymentMethod().getId().equals(PaymentMethod.BLOCK_CHAINS_ID)) + .filter(paymentAccount -> paymentAccount.getPaymentMethod().isAsset()) .collect(Collectors.toList())); paymentAccounts.sort((o1, o2) -> o1.getCreationDate().compareTo(o2.getCreationDate())); } @@ -117,7 +116,7 @@ public void onSaveNewAccount(PaymentAccount paymentAccount) { }); } - if (!(paymentAccount instanceof CryptoCurrencyAccount)) + if (!(paymentAccount instanceof AssetAccount)) accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload()); } @@ -143,7 +142,7 @@ public void onSelectAccount(PaymentAccount paymentAccount) { public void exportAccounts(Stage stage) { if (user.getPaymentAccounts() != null) { ArrayList accounts = new ArrayList<>(user.getPaymentAccounts().stream() - .filter(paymentAccount -> paymentAccount instanceof CryptoCurrencyAccount) + .filter(paymentAccount -> paymentAccount instanceof AssetAccount) .collect(Collectors.toList())); GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver); } diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java index 732e1a150ae..0a3a2f63369 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java @@ -19,7 +19,7 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.TitledGroupBg; -import bisq.desktop.components.paymentmethods.CryptoCurrencyForm; +import bisq.desktop.components.paymentmethods.AssetsForm; import bisq.desktop.components.paymentmethods.PaymentMethodForm; import bisq.desktop.main.account.content.PaymentAccountsView; import bisq.desktop.main.overlays.popups.Popup; @@ -221,13 +221,13 @@ protected void onSelectAccount(PaymentAccount paymentAccount) { /////////////////////////////////////////////////////////////////////////////////////////// private PaymentMethodForm getPaymentMethodForm(PaymentMethod paymentMethod) { - final PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(paymentMethod); + PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(paymentMethod); paymentAccount.init(); return getPaymentMethodForm(paymentAccount); } private PaymentMethodForm getPaymentMethodForm(PaymentAccount paymentAccount) { - return new CryptoCurrencyForm(paymentAccount, accountAgeWitnessService, altCoinAddressValidator, + return new AssetsForm(paymentAccount, accountAgeWitnessService, altCoinAddressValidator, inputValidator, root, gridRow, formatter, assetService, filterManager); } diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java index 88afc51720b..a60cc95e076 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java @@ -26,9 +26,8 @@ import bisq.core.locale.TradeCurrency; import bisq.core.offer.OpenOfferManager; import bisq.core.payment.AccountAgeWitnessService; -import bisq.core.payment.CryptoCurrencyAccount; +import bisq.core.payment.AssetAccount; import bisq.core.payment.PaymentAccount; -import bisq.core.payment.payload.PaymentMethod; import bisq.core.trade.TradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -85,7 +84,7 @@ protected void activate() { private void fillAndSortPaymentAccounts() { if (user.getPaymentAccounts() != null) { List list = user.getPaymentAccounts().stream() - .filter(paymentAccount -> !paymentAccount.getPaymentMethod().getId().equals(PaymentMethod.BLOCK_CHAINS_ID)) + .filter(paymentAccount -> !paymentAccount.getPaymentMethod().isAsset()) .collect(Collectors.toList()); paymentAccounts.setAll(list); paymentAccounts.sort(Comparator.comparing(PaymentAccount::getCreationDate)); @@ -146,7 +145,7 @@ public void onSelectAccount(PaymentAccount paymentAccount) { public void exportAccounts(Stage stage) { if (user.getPaymentAccounts() != null) { ArrayList accounts = new ArrayList<>(user.getPaymentAccounts().stream() - .filter(paymentAccount -> !(paymentAccount instanceof CryptoCurrencyAccount)) + .filter(paymentAccount -> !(paymentAccount instanceof AssetAccount)) .collect(Collectors.toList())); GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver); } diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index b3564ae0b19..80d76c875c9 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -334,7 +334,7 @@ protected void addNewAccount() { paymentMethodComboBox.setVisibleRowCount(11); paymentMethodComboBox.setPrefWidth(250); List list = PaymentMethod.getPaymentMethods().stream() - .filter(paymentMethod -> !paymentMethod.getId().equals(PaymentMethod.BLOCK_CHAINS_ID)) + .filter(paymentMethod -> !paymentMethod.isAsset()) .collect(Collectors.toList()); paymentMethodComboBox.setItems(FXCollections.observableArrayList(list)); paymentMethodComboBox.setConverter(new StringConverter<>() { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index ab41b1ee552..11ff39e3823 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -25,7 +25,6 @@ import bisq.core.network.MessageState; import bisq.core.offer.Offer; import bisq.core.payment.AccountAgeWitnessService; -import bisq.core.payment.payload.PaymentMethod; import bisq.core.trade.Contract; import bisq.core.trade.Trade; import bisq.core.trade.closed.ClosedTradableManager; @@ -322,7 +321,7 @@ public String getSecurityDeposit() { } public boolean isBlockChainMethod() { - return dataModel.getOffer() != null && dataModel.getOffer().getPaymentMethod().equals(PaymentMethod.BLOCK_CHAINS); + return dataModel.getOffer() != null && dataModel.getOffer().getPaymentMethod().isAsset(); } public int getNumPastTrades(Trade trade) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 7d4eb004485..01c7f17d9a0 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -22,10 +22,10 @@ import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.paymentmethods.AdvancedCashForm; import bisq.desktop.components.paymentmethods.AliPayForm; +import bisq.desktop.components.paymentmethods.AssetsForm; import bisq.desktop.components.paymentmethods.CashDepositForm; import bisq.desktop.components.paymentmethods.ChaseQuickPayForm; import bisq.desktop.components.paymentmethods.ClearXchangeForm; -import bisq.desktop.components.paymentmethods.CryptoCurrencyForm; import bisq.desktop.components.paymentmethods.F2FForm; import bisq.desktop.components.paymentmethods.FasterPaymentsForm; import bisq.desktop.components.paymentmethods.HalCashForm; @@ -56,8 +56,8 @@ import bisq.core.offer.Offer; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaymentAccountUtil; +import bisq.core.payment.payload.AssetsAccountPayload; import bisq.core.payment.payload.CashDepositAccountPayload; -import bisq.core.payment.payload.CryptoCurrencyAccountPayload; import bisq.core.payment.payload.F2FAccountPayload; import bisq.core.payment.payload.FasterPaymentsAccountPayload; import bisq.core.payment.payload.HalCashAccountPayload; @@ -206,7 +206,7 @@ protected void addContent() { Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE).second; field.setCopyWithoutCurrencyPostFix(true); - if (!(paymentAccountPayload instanceof CryptoCurrencyAccountPayload) && + if (!(paymentAccountPayload instanceof AssetsAccountPayload) && !(paymentAccountPayload instanceof F2FAccountPayload)) addTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 1, Res.get("shared.reasonForPayment"), model.dataModel.getReference(), @@ -281,9 +281,10 @@ protected void addContent() { gridRow = F2FForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, model.dataModel.getTrade().getOffer(), 0); break; case PaymentMethod.BLOCK_CHAINS_ID: + case PaymentMethod.BLOCK_CHAINS_INSTANT_ID: String labelTitle = Res.get("portfolio.pending.step2_buyer.sellersAddress", CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode())); - gridRow = CryptoCurrencyForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, labelTitle); + gridRow = AssetsForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, labelTitle); break; case PaymentMethod.PROMPT_PAY_ID: gridRow = PromptPayForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); @@ -495,7 +496,7 @@ private void showPopup() { String id = trade.getShortId(); String paddedId = " " + id + " "; String amount = model.btcFormatter.formatVolumeWithCode(trade.getTradeVolume()); - if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload) { + if (paymentAccountPayload instanceof AssetsAccountPayload) { //noinspection UnusedAssignment message += Res.get("portfolio.pending.step2_buyer.altcoin", CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode()), diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index 312f32e5238..bc1c456e697 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -27,9 +27,9 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; +import bisq.core.payment.payload.AssetsAccountPayload; import bisq.core.payment.payload.BankAccountPayload; import bisq.core.payment.payload.CashDepositAccountPayload; -import bisq.core.payment.payload.CryptoCurrencyAccountPayload; import bisq.core.payment.payload.F2FAccountPayload; import bisq.core.payment.payload.HalCashAccountPayload; import bisq.core.payment.payload.MoneyGramAccountPayload; @@ -183,9 +183,9 @@ protected void addContent() { if (contract != null) { PaymentAccountPayload myPaymentAccountPayload = contract.getSellerPaymentAccountPayload(); PaymentAccountPayload peersPaymentAccountPayload = contract.getBuyerPaymentAccountPayload(); - if (myPaymentAccountPayload instanceof CryptoCurrencyAccountPayload) { - myPaymentDetails = ((CryptoCurrencyAccountPayload) myPaymentAccountPayload).getAddress(); - peersPaymentDetails = ((CryptoCurrencyAccountPayload) peersPaymentAccountPayload).getAddress(); + if (myPaymentAccountPayload instanceof AssetsAccountPayload) { + myPaymentDetails = ((AssetsAccountPayload) myPaymentAccountPayload).getAddress(); + peersPaymentDetails = ((AssetsAccountPayload) peersPaymentAccountPayload).getAddress(); myTitle = Res.get("portfolio.pending.step3_seller.yourAddress", nameByCode); peersTitle = Res.get("portfolio.pending.step3_seller.buyersAddress", nameByCode); isBlockChain = true; @@ -284,7 +284,7 @@ private void onPaymentReceived() { if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) { PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload(); String message = Res.get("portfolio.pending.step3_seller.onPaymentReceived.part1", CurrencyUtil.getNameByCode(model.dataModel.getCurrencyCode())); - if (!(paymentAccountPayload instanceof CryptoCurrencyAccountPayload)) { + if (!(paymentAccountPayload instanceof AssetsAccountPayload)) { if (!(paymentAccountPayload instanceof WesternUnionAccountPayload) && !(paymentAccountPayload instanceof HalCashAccountPayload) && !(paymentAccountPayload instanceof F2FAccountPayload)) { @@ -323,8 +323,8 @@ private void showPopup() { String currencyName = CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode()); String part1 = Res.get("portfolio.pending.step3_seller.part", currencyName); String id = trade.getShortId(); - if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload) { - String address = ((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress(); + if (paymentAccountPayload instanceof AssetsAccountPayload) { + String address = ((AssetsAccountPayload) paymentAccountPayload).getAddress(); String explorerOrWalletString = trade.getOffer().getCurrencyCode().equals("XMR") ? Res.get("portfolio.pending.step3_seller.altcoin.wallet", currencyName) : Res.get("portfolio.pending.step3_seller.altcoin.explorer", currencyName); diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index a97f98ec29f..163cf0481ff 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -532,18 +532,16 @@ protected void updateItem(PaymentMethod item, boolean empty) { public static Callback, ListCell> getPaymentMethodCellFactory() { return p -> new ListCell<>() { @Override - protected void updateItem(PaymentMethod item, boolean empty) { - super.updateItem(item, empty); + protected void updateItem(PaymentMethod method, boolean empty) { + super.updateItem(method, empty); - if (item != null && !empty) { - - String id = item.getId(); + if (method != null && !empty) { + String id = method.getId(); HBox box = new HBox(); box.setSpacing(20); - final boolean isBlockchainPaymentMethod = item.equals(PaymentMethod.BLOCK_CHAINS); Label paymentType = new AutoTooltipLabel( - isBlockchainPaymentMethod ? Res.get("shared.crypto") : Res.get("shared.fiat")); + method.isAsset() ? Res.get("shared.crypto") : Res.get("shared.fiat")); paymentType.getStyleClass().add("currency-label-small"); Label paymentMethod = new AutoTooltipLabel(Res.get(id));