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

Send pretty payment details to API clients #6103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
Expand Down Expand Up @@ -76,6 +77,11 @@ public class TakeBuyBTCOfferWithNationalBankAcctTest extends AbstractTradeTest {
private static PaymentAccount alicesPaymentAccount;
private static PaymentAccount bobsPaymentAccount;

@BeforeAll
public static void setUp() {
setUp(false);
}

@Test
@Order(1)
public void testTakeAlicesBuyOffer(final TestInfo testInfo) {
Expand Down Expand Up @@ -156,13 +162,19 @@ public void testBankAcctDetailsIncludedInContracts(final TestInfo testInfo) {
assertNotNull(alicesPaymentAccount);
assertNotNull(bobsPaymentAccount);

var alicesContract = aliceClient.getTrade(tradeId).getContractAsJson();
verifyJsonContractIncludesBankAccountDetails(alicesContract, alicesPaymentAccount);
verifyJsonContractIncludesBankAccountDetails(alicesContract, bobsPaymentAccount);

var bobsContract = bobClient.getTrade(tradeId).getContractAsJson();
verifyJsonContractIncludesBankAccountDetails(bobsContract, alicesPaymentAccount);
verifyJsonContractIncludesBankAccountDetails(bobsContract, bobsPaymentAccount);
var alicesTrade = aliceClient.getTrade(tradeId);
assertNotEquals("", alicesTrade.getContract().getMakerPaymentAccountPayload().getPaymentDetails());
assertNotEquals("", alicesTrade.getContract().getTakerPaymentAccountPayload().getPaymentDetails());
var alicesContractJson = alicesTrade.getContractAsJson();
verifyJsonContractIncludesBankAccountDetails(alicesContractJson, alicesPaymentAccount);
verifyJsonContractIncludesBankAccountDetails(alicesContractJson, bobsPaymentAccount);

var bobsTrade = bobClient.getTrade(tradeId);
assertNotEquals("", bobsTrade.getContract().getMakerPaymentAccountPayload().getPaymentDetails());
assertNotEquals("", bobsTrade.getContract().getTakerPaymentAccountPayload().getPaymentDetails());
var bobsContractJson = bobsTrade.getContractAsJson();
verifyJsonContractIncludesBankAccountDetails(bobsContractJson, alicesPaymentAccount);
verifyJsonContractIncludesBankAccountDetails(bobsContractJson, bobsPaymentAccount);
}

@Test
Expand Down Expand Up @@ -207,7 +219,7 @@ public void testBobsConfirmPaymentReceived(final TestInfo testInfo) {

@Test
@Order(5)
public void testKeepFunds(final TestInfo testInfo) {
public void testCloseTrade(final TestInfo testInfo) {
try {
genBtcBlocksThenWait(1, 1_000);

Expand Down
2 changes: 1 addition & 1 deletion apitest/src/test/java/bisq/apitest/scenario/TradeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testTakeBuyBTCOfferWithNationalBankAcct(final TestInfo testInfo) {
test.testBankAcctDetailsIncludedInContracts(testInfo);
test.testAlicesConfirmPaymentStarted(testInfo);
test.testBobsConfirmPaymentReceived(testInfo);
test.testKeepFunds(testInfo);
test.testCloseTrade(testInfo);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ public class PaymentAccountPayloadInfo implements Payload {
private final String paymentMethodId;
@Nullable
private final String address;
@Nullable
private final String paymentDetails;

public PaymentAccountPayloadInfo(String id,
String paymentMethodId,
@Nullable String address) {
@Nullable String address,
@Nullable String paymentDetails) {
this.id = id;
this.paymentMethodId = paymentMethodId;
this.address = address;
this.paymentDetails = paymentDetails;
}

public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(
Expand All @@ -57,21 +61,30 @@ public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(
else if (paymentAccountPayload instanceof InstantCryptoCurrencyPayload)
address = Optional.of(((InstantCryptoCurrencyPayload) paymentAccountPayload).getAddress());

String prettyPaymentDetails = paymentAccountPayload.getPaymentDetailsForTradePopup();
Optional<String> paymentDetails = prettyPaymentDetails.isBlank()
? Optional.empty()
: Optional.of(prettyPaymentDetails);

return new PaymentAccountPayloadInfo(paymentAccountPayload.getId(),
paymentAccountPayload.getPaymentMethodId(),
address.orElse(""));
address.orElse(""),
paymentDetails.orElse(""));
}

// For transmitting TradeInfo messages when the contract or the contract's payload is not yet available.
public static Supplier<PaymentAccountPayloadInfo> emptyPaymentAccountPayload = () ->
new PaymentAccountPayloadInfo("", "", "");
new PaymentAccountPayloadInfo("", "", "", "");

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

public static PaymentAccountPayloadInfo fromProto(bisq.proto.grpc.PaymentAccountPayloadInfo proto) {
return new PaymentAccountPayloadInfo(proto.getId(), proto.getPaymentMethodId(), proto.getAddress());
return new PaymentAccountPayloadInfo(proto.getId(),
proto.getPaymentMethodId(),
proto.getAddress(),
proto.getPaymentDetails());
}

@Override
Expand All @@ -80,6 +93,7 @@ public bisq.proto.grpc.PaymentAccountPayloadInfo toProtoMessage() {
.setId(id)
.setPaymentMethodId(paymentMethodId)
.setAddress(address != null ? address : "")
.setPaymentDetails(paymentDetails != null ? paymentDetails : "")
.build();
}
}
1 change: 1 addition & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ message PaymentAccountPayloadInfo {
string id = 1; // The unique identifier of the payment account.
string payment_method_id = 2; // The unique identifier of the payment method.
string address = 3; // The optional altcoin wallet address associated with the (altcoin) payment account.
string payment_details = 4; // The optional payment details, if available.
}

message TxFeeRateInfo {
Expand Down