Skip to content

Commit

Permalink
support deleting payment accounts #1136
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 16, 2024
1 parent 690f38e commit 66eb7e2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/haveno/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ public PaymentAccount createCryptoCurrencyPaymentAccount(String accountName,
tradeInstant);
}

public void deletePaymentAccount(String paymentAccountId) {
paymentAccountsService.deletePaymentAccount(paymentAccountId);
}

public List<PaymentMethod> getCryptoCurrencyPaymentMethods() {
return paymentAccountsService.getCryptoCurrencyPaymentMethods();
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/haveno/core/api/CorePaymentAccountsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ synchronized PaymentAccount createCryptoCurrencyPaymentAccount(String accountNam
return cryptoCurrencyAccount;
}

synchronized void deletePaymentAccount(String paymentAccountId) {
accountService.checkAccountOpen();
PaymentAccount paymentAccount = getPaymentAccount(paymentAccountId);
if (paymentAccount == null) throw new IllegalArgumentException(format("Payment account with id %s not found", paymentAccountId));
user.removePaymentAccount(paymentAccount);
log.info("Deleted payment account with id {} and payment method {}.",
paymentAccount.getId(),
paymentAccount.getPaymentAccountPayload().getPaymentMethodId());
}

// TODO Support all alt coin payment methods supported by UI.
// The getCryptoCurrencyPaymentMethods method below will be
// callable from the CLI when more are supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import haveno.proto.grpc.CreateCryptoCurrencyPaymentAccountRequest;
import haveno.proto.grpc.CreatePaymentAccountReply;
import haveno.proto.grpc.CreatePaymentAccountRequest;
import haveno.proto.grpc.DeletePaymentAccountReply;
import haveno.proto.grpc.DeletePaymentAccountRequest;
import haveno.proto.grpc.GetCryptoCurrencyPaymentMethodsReply;
import haveno.proto.grpc.GetCryptoCurrencyPaymentMethodsRequest;
import haveno.proto.grpc.GetPaymentAccountFormReply;
Expand Down Expand Up @@ -160,6 +162,19 @@ public void createCryptoCurrencyPaymentAccount(CreateCryptoCurrencyPaymentAccoun
}
}

@Override
public void deletePaymentAccount(DeletePaymentAccountRequest req,
StreamObserver<DeletePaymentAccountReply> responseObserver) {
try {
coreApi.deletePaymentAccount(req.getPaymentAccountId());
var reply = DeletePaymentAccountReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}
}

@Override
public void getCryptoCurrencyPaymentMethods(GetCryptoCurrencyPaymentMethodsRequest req,
StreamObserver<GetCryptoCurrencyPaymentMethodsReply> responseObserver) {
Expand Down
9 changes: 9 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ service PaymentAccounts {
}
rpc CreateCryptoCurrencyPaymentAccount (CreateCryptoCurrencyPaymentAccountRequest) returns (CreateCryptoCurrencyPaymentAccountReply) {
}
rpc DeletePaymentAccount (DeletePaymentAccountRequest) returns (DeletePaymentAccountReply) {
}
rpc GetCryptoCurrencyPaymentMethods (GetCryptoCurrencyPaymentMethodsRequest) returns (GetCryptoCurrencyPaymentMethodsReply) {
}
rpc ValidateFormField (ValidateFormFieldRequest) returns (ValidateFormFieldReply) {
Expand Down Expand Up @@ -639,6 +641,13 @@ message CreateCryptoCurrencyPaymentAccountRequest {
bool trade_instant = 4;
}

message DeletePaymentAccountRequest {
string payment_account_id = 1;
}

message DeletePaymentAccountReply {
}

message CreateCryptoCurrencyPaymentAccountReply {
PaymentAccount payment_account = 1;
}
Expand Down

0 comments on commit 66eb7e2

Please sign in to comment.