-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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, {...})
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
Co-authored-by: Ben Kremer <[email protected]>
Changes
getNoticationHistory
per spec.getNotificationHistory
#89getMessageHistory
anddeleteNotifyMessage
To achieve this
on
,off
,once
, etc.subscribe
down the line.Tested
Tested via new integration test that communicates with notify server
How does this new flow work?