From 00831eb982b80a4785030140323b6829fb406c69 Mon Sep 17 00:00:00 2001 From: Nicolas Lopes Date: Thu, 5 Sep 2024 11:49:45 -0300 Subject: [PATCH] feat: Delete web3 wallets --- user/api.go | 5 +++++ user/client.go | 12 ++++++++++++ user/client_test.go | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/user/api.go b/user/api.go index e1fc182..5f10c6d 100644 --- a/user/api.go +++ b/user/api.go @@ -95,6 +95,11 @@ func DeletePasskey(ctx context.Context, userID, identificationID string) (*clerk return getClient().DeletePasskey(ctx, userID, identificationID) } +// DeleteWeb3Wallet deletes a web3 wallet by its identification ID. +func DeleteWeb3Wallet(ctx context.Context, userID, identificationID string) (*clerk.DeletedResource, error) { + return getClient().DeleteWeb3Wallet(ctx, userID, identificationID) +} + func getClient() *Client { return &Client{ Backend: clerk.GetBackend(), diff --git a/user/client.go b/user/client.go index e09a399..031a9be 100644 --- a/user/client.go +++ b/user/client.go @@ -440,3 +440,15 @@ func (c *Client) DeletePasskey(ctx context.Context, userID, identificationID str err = c.Backend.Call(ctx, req, resource) return resource, err } + +// DeleteWeb3Wallet deletes a web3 wallet by its identification ID. +func (c *Client) DeleteWeb3Wallet(ctx context.Context, userID, identificationID string) (*clerk.DeletedResource, error) { + path, err := clerk.JoinPath(path, userID, "/web3_wallets", identificationID) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodDelete, path) + resource := &clerk.DeletedResource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/user/client_test.go b/user/client_test.go index dbab216..5ef97ca 100644 --- a/user/client_test.go +++ b/user/client_test.go @@ -441,3 +441,22 @@ func TestUserClientDeletePasskey(t *testing.T) { require.NoError(t, err) require.Equal(t, passkeyIdentificationID, passkey.ID) } + +func TestUserClientDeleteWeb3Wallet(t *testing.T) { + t.Parallel() + userID := "user_123" + web3WalletIdentificationID := "idn_345" + config := &clerk.ClientConfig{} + config.HTTPClient = &http.Client{ + Transport: &clerktest.RoundTripper{ + T: t, + Out: json.RawMessage(fmt.Sprintf(`{"id":"%s"}`, web3WalletIdentificationID)), + Method: http.MethodDelete, + Path: "/v1/users/" + userID + "/web3_wallets/" + web3WalletIdentificationID, + }, + } + client := NewClient(config) + web3Wallet, err := client.DeleteWeb3Wallet(context.Background(), userID, web3WalletIdentificationID) + require.NoError(t, err) + require.Equal(t, web3WalletIdentificationID, web3Wallet.ID) +}