From d0c02acba1fe4b59776bc94d3dceea358d1cb055 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 22 Jun 2022 11:10:22 -0400 Subject: [PATCH] support sepa instant --- .../core/api/model/PaymentAccountForm.java | 1 + .../java/bisq/core/payment/SepaAccount.java | 4 +- .../bisq/core/payment/SepaInstantAccount.java | 41 +++++++++++++++++-- .../core/payment/payload/PaymentMethod.java | 1 + proto/src/main/proto/pb.proto | 13 +++--- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java index 144baa26..9a741adc 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java @@ -67,6 +67,7 @@ public final class PaymentAccountForm implements PersistablePayload { public enum FormId { REVOLUT, SEPA, + SEPA_INSTANT, TRANSFERWISE, CLEAR_X_CHANGE, SWIFT, diff --git a/core/src/main/java/bisq/core/payment/SepaAccount.java b/core/src/main/java/bisq/core/payment/SepaAccount.java index 2f35ef48..c27a7aff 100644 --- a/core/src/main/java/bisq/core/payment/SepaAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaAccount.java @@ -36,7 +36,7 @@ import org.jetbrains.annotations.NotNull; @EqualsAndHashCode(callSuper = true) public final class SepaAccount extends CountryBasedPaymentAccount implements BankAccount { - private static final List INPUT_FIELD_IDS = List.of( + protected static final List INPUT_FIELD_IDS = List.of( PaymentAccountFormField.FieldId.ACCOUNT_NAME, PaymentAccountFormField.FieldId.HOLDER_NAME, PaymentAccountFormField.FieldId.IBAN, @@ -142,7 +142,7 @@ public final class SepaAccount extends CountryBasedPaymentAccount implements Ban super.validateFormField(form, fieldId, value); } } - + @Override protected PaymentAccountFormField getEmptyFormField(PaymentAccountFormField.FieldId fieldId) { var field = super.getEmptyFormField(fieldId); diff --git a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java index 9102de77..a026d2c6 100644 --- a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java @@ -17,16 +17,18 @@ package bisq.core.payment; +import bisq.core.api.model.PaymentAccountForm; import bisq.core.api.model.PaymentAccountFormField; +import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; import bisq.core.locale.FiatCurrency; import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SepaInstantAccountPayload; - +import bisq.core.payment.validation.SepaIBANValidator; import java.util.List; - +import javax.annotation.Nullable; import lombok.EqualsAndHashCode; import org.jetbrains.annotations.NotNull; @@ -100,13 +102,44 @@ public final class SepaInstantAccount extends CountryBasedPaymentAccount impleme ((SepaInstantAccountPayload) paymentAccountPayload).revertChanges(); } + @Override + public @NotNull List getInputFieldIds() { + return SepaAccount.INPUT_FIELD_IDS; + } + @Override public @NotNull List getSupportedCurrencies() { return SUPPORTED_CURRENCIES; } @Override - public @NotNull List getInputFieldIds() { - throw new RuntimeException("Not implemented"); + @Nullable + public List getSupportedCountries() { + return CountryUtil.getAllSepaCountries(); + } + + @Override + public void validateFormField(PaymentAccountForm form, PaymentAccountFormField.FieldId fieldId, String value) { + switch (fieldId) { + case IBAN: + processValidationResult(new SepaIBANValidator().validate(value)); + break; + default: + super.validateFormField(form, fieldId, value); + } + } + + @Override + protected PaymentAccountFormField getEmptyFormField(PaymentAccountFormField.FieldId fieldId) { + var field = super.getEmptyFormField(fieldId); + switch (fieldId) { + case ACCEPTED_COUNTRY_CODES: + field.setSupportedSepaEuroCountries(CountryUtil.getAllSepaEuroCountries()); + field.setSupportedSepaNonEuroCountries(CountryUtil.getAllSepaNonEuroCountries()); + break; + default: + // no action + } + return field; } } 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 69f03f67..673a672b 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -330,6 +330,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable paymentMethodIds = List.of( REVOLUT_ID, SEPA_ID, + SEPA_INSTANT_ID, TRANSFERWISE_ID, CLEAR_X_CHANGE_ID, SWIFT_ID, diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index e2b05706..1671b940 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -2076,12 +2076,13 @@ message PaymentAccountForm { enum FormId { REVOLUT = 0; SEPA = 1; - TRANSFERWISE = 2; - CLEAR_X_CHANGE = 3; - SWIFT = 4; - F2F = 5; - STRIKE = 6; - MONEY_GRAM = 7; + SEPA_INSTANT = 2; + TRANSFERWISE = 3; + CLEAR_X_CHANGE = 4; + SWIFT = 5; + F2F = 6; + STRIKE = 7; + MONEY_GRAM = 8; } FormId id = 1; repeated PaymentAccountFormField fields = 2;