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

update webhook bugfix #288

Closed
wants to merge 1 commit into from
Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## [0.8.1] - 2024-10-09
### Fixed
Comment on lines +5 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## [0.8.1] - 2024-10-09
### Fixed
## [0.8.1] - 2024-10-09
### Fixed

- Fixed a bug that overwrites existing webhook notification URI when only updating a webhook's addresses

## [0.8.0] - 2024-10-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
maxWorkers: 1,
coverageThreshold: {
"./src/coinbase/**": {
branches: 77,
branches: 75,
functions: 85,
statements: 85,
lines: 85,
Expand Down
7 changes: 5 additions & 2 deletions src/coinbase/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ export class Webhook {
notificationUri,
eventTypeFilter,
}: UpdateWebhookOptions): Promise<Webhook> {
const finalNotificationUri = notificationUri ?? this.getNotificationURI();
const finalEventTypeFilter = eventTypeFilter ?? this.getEventTypeFilter();

const result = await Coinbase.apiClients.webhook!.updateWebhook(this.getId()!, {
notification_uri: notificationUri,
notification_uri: finalNotificationUri,
event_filters: this.getEventFilters()!,
event_type_filter: eventTypeFilter,
event_type_filter: finalEventTypeFilter,
});
Comment on lines 191 to 195
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of those props required on the request? What about not sending it, if user hasn't sent on the SDK function param? It would be ideal to the API request to mimic what user intended, this could also possibly prevent issues in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because on the CDP side this is a PUT endpoint, so we have to provide all these parameters when calling it. These parameters are as good as required, although not labeled as "required".


this.model = result.data;
Expand Down
4 changes: 4 additions & 0 deletions src/tests/webhook_test.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add 1 more test where we update the event type filter and not the notification URI.

Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ describe("Webhook", () => {
expect(Coinbase.apiClients.webhook!.updateWebhook).toHaveBeenCalledWith("test-id", {
notification_uri: "https://new-url.com/callback",
event_filters: [{ contract_address: "0x...", from_address: "0x...", to_address: "0x..." }],
event_type_filter: {
addresses: ["0xa55C5950F7A3C42Fa5799B2Cac0e455774a07382"],
wallet_id: "w1",
},
});

expect(webhook.getNotificationURI()).toBe("https://new-url.com/callback");
Expand Down
Loading