Skip to content

Commit

Permalink
Merge pull request #6103 from ghubstan/send-pretty-payment-details-to…
Browse files Browse the repository at this point in the history
…-api-client

Send pretty payment details to API clients
  • Loading branch information
ripcurlx authored Mar 13, 2022
2 parents c6293b5 + a399078 commit 64f31f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
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

0 comments on commit 64f31f1

Please sign in to comment.