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

support deleting payment accounts #1136 #1151

Merged
merged 1 commit into from
Jul 16, 2024
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
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
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
Loading