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

Add domain logic for push notifications #1778

Merged
merged 42 commits into from
Aug 6, 2024
Merged

Add domain logic for push notifications #1778

merged 42 commits into from
Aug 6, 2024

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Jul 22, 2024

Summary

This adds the relative logic to the domain for enqueuing notifications to subscribers when the relevant hook event is received.

It leverages the NotificationsDatasource to getSubscribersWithTokensBySafe for the relative TransactionEventType and enqueueNotifications accordingly.

Changes

  • Add INotificationsRepositoryV2 behind a feature flag:
    • enqueueNotification
    • upsertSubscriptions
    • getSafeSubscription
    • getSubscribersWithTokensBySafe
    • deleteSubscription
    • deleteDevice
  • Extend HooksRepository with onEventEnqueueNotifications with respective entities.
  • Add transaction_hash query to getIncomingTransfers and propagate changes/add tests.
  • Locate previously domain-relative logic for notifications in domain, e.g. entities and builders.
  • Add approriate test coverage.

Comment on lines 47 to 122
if (safe && safe.owners.includes(args.account)) {
authorizedSafesToSubscribe.push(safeToSubscribe);
continue;
}

const delegates = await this.delegatesRepository
.getDelegates({
chainId: safeToSubscribe.chainId,
safeAddress: safeToSubscribe.address,
delegate: args.account,
})
.catch(() => null);

// Upsert delegate
if (
delegates &&
delegates.results.some(({ delegate }) => delegate === args.account)
Copy link
Member Author

@iamacook iamacook Jul 23, 2024

Choose a reason for hiding this comment

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

These checks need to be disucssed as it is still unclear whether we allow anyone to subscribe to queue-related events. I'd suggest we keep with owner/delegate only and adjust later if needed as it's a small adjustment if necessary.

@iamacook iamacook self-assigned this Jul 24, 2024
@hectorgomezv hectorgomezv added the in review Someone is reviewing this Pull Request label Jul 26, 2024
Comment on lines 636 to 640
subscribers.map((subscriber) => {
return messageConfirmationBuilder()
.with('owner', subscriber.subscriber)
.build();
}),
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should we also test the scenario where a subset of the subscribers have signed? I think currently all the test escenarios are all-or-none signatures.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 663d901.

continue;
}

throw new UnauthorizedException();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should we log this error (the account signer not being a owner/delegate of one of the target Safes), wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 663d901.

@hectorgomezv hectorgomezv removed the in review Someone is reviewing this Pull Request label Jul 26, 2024
@hectorgomezv
Copy link
Member

I think this PR needs a rebase onto the source branch 🙂

hectorgomezv
hectorgomezv previously approved these changes Aug 5, 2024
Base automatically changed from notifications-database to main August 6, 2024 07:41
@iamacook iamacook dismissed hectorgomezv’s stale review August 6, 2024 07:41

The base branch was changed.

@hectorgomezv hectorgomezv self-requested a review August 6, 2024 08:43
@iamacook iamacook merged commit f1b3053 into main Aug 6, 2024
16 checks passed
@iamacook iamacook deleted the notifications-domain branch August 6, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants