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

Feat/get notifications history #88

Merged
merged 26 commits into from
Jan 8, 2024
Merged

Conversation

devceline
Copy link
Collaborator

@devceline devceline commented Jan 8, 2024

Changes

To achieve this

  • New event handlers were put in place in the engine, mimicking the ones in the client. on,off, once, etc.
  • These are in place to go against the current pub-sub architecture in place, to provide "blocking" functions that resolve once a response is given
  • This is to achieve the spec which takes in params and returns the results in the same function
  • This system will be reused by many other functions, including the refactored subscribe down the line.

Tested

Tested via new integration test that communicates with notify server

How does this new flow work?

image

@devceline devceline marked this pull request as ready for review January 8, 2024 09:47
Copy link

@enesozturk enesozturk left a comment

Choose a reason for hiding this comment

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

Looks good in general, left some feedback

})
);

const issuedAt = Math.round(Date.now() / 1000);

Choose a reason for hiding this comment

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

Suggested change
const issuedAt = Math.round(Date.now() / 1000);
const issuedAtInSeconds = Math.round(Date.now() / 1000);

When we work with dates, or format them into different periods (hrs, seconds, milliseconds, etc.). It's better to select names that indicate what the value is. This will improve further maintenance and also will allow the reviewer to see possible issues on the next lines if he/she knows what the the time period of the variable is in mind


const getNotificationsClaims: NotifyClientTypes.GetNotificationsJwtClaims =
{
act: "notify_get_notifications",

Choose a reason for hiding this comment

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

Suggested change
act: "notify_get_notifications",
action: "notify_get_notifications",

I don't know if this is the right name but I wanted to point out that this field and other fields in this object might be better to have more readable field names. When I read the code, I didn't understand if these values were correctly set without knowing the codebase as a reviewer. I believe we should prever readable field names too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The fields unfortunately have to be compliant with the spec linked above. See the "Authentication" page for details. The reason for the short, 3 letter names is to cut down redundant data on transport, since this all gets encoded into a JWT.

Copy link
Member

Choose a reason for hiding this comment

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

As mentioned below in my other comment this is to be spec compliant: https://github.com/WalletConnect/walletconnect-specs/pull/183/files#diff-02dc8b9dd052b54a577b55ecf0d2b3ad2d58f1df0a0be7ba388fa721ffcbc48eR137

Would have to be agreed at the x-platform level to use longer form but I believe this is the convention for JWT claims

const claims =
this.decodeAndValidateJwtAuth<NotifyClientTypes.GetNotificationsResponseClaims>(
payload.result.auth,
"notify_get_notifications_response"

Choose a reason for hiding this comment

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

Not urgent at this time but since we're using this string in different places and there are different types of values to pass to this function. It might be better to keep these values in a tuple. This would help to maintain them and prevent from possible issues in the future.

type NotifyMessage = {
 GetNotificationResponse: "notify_get_notifications_response",
}

and while using:

this.emit(NotifyMessage.GetNotificationResponse, {...})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This honestly is probably a worthwhile refactor to reduce on the crazy amount of hardcoded strings, but this is not the PR for it. I'll create an issue for this

new Error("getNotificationHistory timed out waiting for a response")
);
// Using five minutes as it is the TTL of wc_getNotificationHistory
// The FIVE_MINUTES const is in seconds, not ms.

Choose a reason for hiding this comment

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

Ref to previous naming comment. Better naming don't require comments as a return

@@ -109,6 +109,17 @@ export declare namespace NotifyClientTypes {
publishedAt: number;
}

interface GetNotificationsJwtClaims extends BaseJwtClaims {
act: "notify_get_notifications";

Choose a reason for hiding this comment

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

Ref to previous naming comment. Better naming don't require comments as a return

Copy link
Member

@bkrem bkrem Jan 8, 2024

Choose a reason for hiding this comment

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

These fields are concretely defined in the spec with these namings, so deviating from them just creates unnecessary mental overhead and remapping, see: https://github.com/WalletConnect/walletconnect-specs/pull/183/files#diff-02dc8b9dd052b54a577b55ecf0d2b3ad2d58f1df0a0be7ba388fa721ffcbc48eR137

Choose a reason for hiding this comment

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

Oh didn't know about it, make sense then, thanks


const getNotificationsClaims: NotifyClientTypes.GetNotificationsJwtClaims =
{
act: "notify_get_notifications",
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned below in my other comment this is to be spec compliant: https://github.com/WalletConnect/walletconnect-specs/pull/183/files#diff-02dc8b9dd052b54a577b55ecf0d2b3ad2d58f1df0a0be7ba388fa721ffcbc48eR137

Would have to be agreed at the x-platform level to use longer form but I believe this is the convention for JWT claims

packages/notify-client/src/controllers/engine.ts Outdated Show resolved Hide resolved
packages/notify-client/src/controllers/engine.ts Outdated Show resolved Hide resolved
@devceline devceline merged commit 9c095e7 into main Jan 8, 2024
1 check passed
@devceline devceline deleted the feat/get-notifications-history branch January 8, 2024 11:37
@devceline devceline mentioned this pull request Jan 9, 2024
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.

Implement getNotificationHistory
3 participants