diff --git a/CHANGELOG.md b/CHANGELOG.md index add44b41..cd622325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## [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 diff --git a/jest.config.js b/jest.config.js index 2642a5f3..40a4c63a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,7 +10,7 @@ module.exports = { maxWorkers: 1, coverageThreshold: { "./src/coinbase/**": { - branches: 77, + branches: 75, functions: 85, statements: 85, lines: 85, diff --git a/src/coinbase/webhook.ts b/src/coinbase/webhook.ts index c9bf3d15..b6a109d1 100644 --- a/src/coinbase/webhook.ts +++ b/src/coinbase/webhook.ts @@ -185,10 +185,13 @@ export class Webhook { notificationUri, eventTypeFilter, }: UpdateWebhookOptions): Promise { + 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, }); this.model = result.data; diff --git a/src/tests/webhook_test.ts b/src/tests/webhook_test.ts index 10139643..3408c7ea 100644 --- a/src/tests/webhook_test.ts +++ b/src/tests/webhook_test.ts @@ -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");