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

Fix(Balances): make decimals non-nullable #2291

Merged
merged 5 commits into from
Jan 27, 2025
Merged

Fix(Balances): make decimals non-nullable #2291

merged 5 commits into from
Jan 27, 2025

Conversation

katspaugh
Copy link
Member

Summary

Token decimals being always a number has been the assumption on the client for quite some time and a lot of code would have to be changed if we were to start treating it as nullable.

Changes

So I've adjusted the OpenAPI type and also added a fallback value (although it's probably never null in reality).

@katspaugh katspaugh requested a review from a team as a code owner January 24, 2025 15:10
Comment on lines 201 to 205
token: {
...balance.token,
decimals:
balance.token?.decimals ?? SafeBalancesApi.DEFAULT_DECIMALS,
},
Copy link
Member

Choose a reason for hiding this comment

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

As there are multiple IBalanceApis, we should assign the default value during validation. It then doesn't need to be done in both places and will solve the MultisigTransactionExecutionDetailsMapper CI error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, thanks for the pointer!

const token = tokenBuilder().build();
// @ts-expect-error - inferred type doesn't allow optional properties
delete token.decimals;

const result = TokenSchema.safeParse(token);

expect(result.success && result.data.decimals).toBe(null);
expect(result.success && result.data.decimals).toBe(18);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would add a new const is test named DEFAULT_DECIMALS.

@katspaugh katspaugh merged commit 4d3c894 into main Jan 27, 2025
18 checks passed
@katspaugh katspaugh deleted the decimals branch January 27, 2025 08:28
katspaugh added a commit that referenced this pull request Jan 28, 2025
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