-
Notifications
You must be signed in to change notification settings - Fork 150
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
fix!: change the response for vesting-info #717
Conversation
This PR will be followed up by #709 |
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.
Tiny nit
: Array.isArray(vesting.unwrap()) | ||
? vesting.unwrap() | ||
: [vesting.unwrap()], |
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.
Would like to avoid double unwrap here, but not sure what a good way would be, TS would likely scream about something like:
: Array.isArray(vesting.unwrap()) | |
? vesting.unwrap() | |
: [vesting.unwrap()], | |
: Array.isArray(vesting = vesting.unwrap()) | |
? vesting | |
: [vesting], |
Could use a different variable for the unwrapped value (declared before the return, assigned in place)? 🤔
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.
Ahh very good point. I should have noticed that earlier when I tried to abstract the vesting.unwrap()
before calling vesting.isNone
which caused me issues.
Good call. Going to declare 2 variables, one for the bool value, and the other to unwrap vesting
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.
So I actually changed it quiet a bit to isolate each case more, it avoids unwrapping if isNone
is true
and also avoids unwrapping multiple times as well.
if (vesting.isNone) { | ||
return { | ||
at, | ||
vesting: [], | ||
}; | ||
} else { | ||
const unwrapVesting = vesting.unwrap(); | ||
|
||
return { | ||
at, | ||
vesting: Array.isArray(unwrapVesting) ? unwrapVesting : [unwrapVesting], | ||
}; |
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.
Optimizing for clarity, I like it.
BREAKING CHANGE
With runtime v9110, the vesting-info response now returns an array for
vesting
, with theVestingInfo
type now beingVec<PalletVestingVestingInfo>
. Sidecar previously returned responses under thevesting
key as objects, therefore when there was no information the response was an empty object.This is now changed as the response will default to an empty array when there is no vesting-info on the account, and the past responses that were objects, will now be wrapped in an array.
Examples:
Before:
After