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

add better typing for standalone balances #1475

Merged
merged 2 commits into from
Sep 11, 2024
Merged

Conversation

piyalbasu
Copy link
Contributor

Motivation:

I added blockaidData to the BE's balances which caused the balances we get from the BE to be out of sync with the balances we get using a custom network. This should have raised type errors throughout the app, but it did not because we used a lot of casting as any with balances to work our way out of some tricky type issues.

I'm removing the use of any when dealing with balances so we have a strongly typed (and more predictable) format for balances

const v: any = resp.balances[k];
if (v.liquidity_pool_id) {
const v = resp.balances[k];
if (v.liquidityPoolId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed this key to be camelcase rather than snake

@piyalbasu piyalbasu marked this pull request as draft September 10, 2024 20:29
const { balances, subentry_count, num_sponsored, num_sponsoring } =
accountDetails;

const displayableBalances = Object.values(balances).reduce(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using reduce made it hard for TS to typecheck the different balance types. Switching to a for loop for more clarity.

Also, at some point balances must have changed from an object to an array. No need to do this Object.values conversion

reserves: lp.reserves,
};
delete balances[k].liquidity_pool_id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

initially, we assigned liquidity_pool_id's value to liquidityPoolId and then deleted the old liquidity_pool_id. I'm just simplifying the logic in makeDisplayableBalances so we don't need to do this anymore

@piyalbasu piyalbasu marked this pull request as ready for review September 11, 2024 18:24
@piyalbasu piyalbasu merged commit 616d03d into release/5.23.2 Sep 11, 2024
3 checks passed
@piyalbasu piyalbasu deleted the remove-balance-any branch September 11, 2024 19:03
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.

2 participants