-
Notifications
You must be signed in to change notification settings - Fork 25
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: token version #1137
feat: token version #1137
Conversation
@@ -1,5 +1,6 @@ | |||
use shared::types::custom_token::CustomToken; | |||
use shared::types::token::UserToken; | |||
use shared::types::TokenTimestamp; | |||
|
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.
Suggestion:
If you add these traits to UserToken:
#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct UserToken {
you can do assert_eq!(&one_token_list, &another_token_list, "My lists aren't the same!")
without needing a dedicated comparison function.
If the default definition of Eq
does not suit, it is possible to define a custom one.
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.
Sure we can do that in another PR. Original did not wanted to change the existing struct but, we are passed that now ;)
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Max <[email protected]>
Printing out the token in the assertions of the test requires implementing display. I don't think that's part of this PR, so I've reverted printing out and we can do that in another PR.
|
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.
LGTM. Thanks!
Motivation
Because the UI/UX of custom tokens revolves around enabling and disabling tokens, I think it is worth adding a timestamp (UPDATE: replaced by a version counter following review) to the information to prevent use cases where the user operates on multiple devices simultaneously and would overwrite changes made on one device with those from another.
It may be a not-too-frequent scenario but, given that we are developing this new feature which is not yet live, I think it is the right time to add these kinds of assertions.
That's why this PR adds a
version: Option<u64>
to the existingUserTokens
andCustomTokens
.Notes
In this PR, we are adding new information within a struct of stable memory that already exists on mainnet but, given that we introduce it as an option, it should be backward compatible. There is also a test about it.
Given that the backend sets the version when the entity is saved, it would be handy to return the new entity when setter and add functions are called. However, the Oisy frontend does not currently require it as we are reloading all the user tokens after changes. Therefore, this PR does not change those functions' returns.
For backwards compatibility, I did not modified the existing
remove_from_user_token
function which accept an ID.Did files will be updated in a separate PR that also adapts the frontend code.