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

style(frontend): fixes display of token balances #3234

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

BonomoAlessandro
Copy link
Collaborator

@BonomoAlessandro BonomoAlessandro commented Oct 30, 2024

Motivation

There should be a consistent way to display the token balance and the usd balance.

Token card:

  • If token balance and usd balance are defined, both should be displayed.
  • If token balance is undefined and usd balance is defined, n/a should be displayed for the balance and -. for the usd balance.
  • If token balance is defined and usd balance is undefined, the usd balance should be displayed as n/a.
  • If token balance and usd balance are undefined, the balance should be displayed as n/a and the usd balance as -.

Token view:
When the usd balance is not defined, the text $ value is not available should be displayed.

Changes

  • displayed values

Tests

before:

token card

balance and usdBalance defined:
image

balance null and usdBalance defined:
image

balance defined and usdBalance undefined:
image

balance and usdBalance undefined:
image

token view

usd balance defined:
image

usd balance undefined:
image

after:

token card

balance and usdBalance defined:
image

balance null and usdBalance defined:
image

balance defined and usdBalance undefined:
image

balance and usdBalance undefined:
image

token view

usd balance defined:
image

usd balance undefined:
image

@BonomoAlessandro BonomoAlessandro changed the title fixes display of token balances style(frontend): fixes display of token balances Oct 30, 2024
@BonomoAlessandro BonomoAlessandro marked this pull request as ready for review October 30, 2024 09:19
@BonomoAlessandro BonomoAlessandro requested a review from a team as a code owner October 30, 2024 09:19
@AntonioVentilii-DFINITY
Copy link
Contributor

AntonioVentilii-DFINITY commented Oct 30, 2024

So, this PR I think is not correct: it was decided that when the USD balance is undefined (not loaded yet) it should be shown as missing, since it indicates that we don't have a price feed. In fact, if you try to do that with a non-null token amount, you will see that the token amount is for example 4 and the USD amount is 0, and that is not correct.

Same thing for the balance: if the balance is undefined (not loaded) is one thing, while if it is null (missing) is another

May you please double-check with the requirements?

@BonomoAlessandro
Copy link
Collaborator Author

The token card looks now like this:

balance and usdBalance defined:
image

balance null and usdBalance defined:
image

balance defined and usdBalance undefined:
image

balance null and usdBalance undefined:
image

@BonomoAlessandro
Copy link
Collaborator Author

The Token view looks like this:

usdBalance defined:
image

usdBalance undefined:
image

@BonomoAlessandro
Copy link
Collaborator Author

@AntonioVentilii-DFINITY pls review

<TokenExchangeBalance
balance={token?.balance}
usdBalance={token?.usdBalance}
nullishBalanceMessage="$ value is not available"
Copy link
Collaborator

Choose a reason for hiding this comment

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

i18n ?

value: ZERO,
unitName: data.decimals
}).replace('0', '-')}
<span>n/a</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@@ -5,17 +5,15 @@

export let balance: TokenFinancialData['balance'];
export let usdBalance: TokenFinancialData['usdBalance'];
export let nullishBalanceMessage = '-';
Copy link
Collaborator

Choose a reason for hiding this comment

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

why a prop? I think you can use directly inside the component since that is its usage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be a prop because by default, this property will display - when the value is null or undefined. However, for the Hero element, it should display '$ value is not available' instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am still not convinced about this, i would prefer to default is as undefined and the use coalescing to overwrite it with '-'

BonomoAlessandro and others added 4 commits November 6, 2024 09:35
# Conflicts:
#	src/frontend/src/lib/components/hero/Balance.svelte
#	src/frontend/src/lib/i18n/en.json
@BonomoAlessandro
Copy link
Collaborator Author

@AntonioVentilii-DFINITY pls review

@AntonioVentilii
Copy link
Collaborator

@BonomoAlessandro may you please update the description and the screenshots?

</script>

<output class="break-all">
{#if nonNullish(balance) && nonNullish(usdBalance)}
{formatUSD({ value: usdBalance })}
{:else if isNullish(balance)}
<span class:animate-pulse={isNullish(balance)}>{nullishBalanceMessage}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need the condition here anymore, right? it will always be true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No this is still needed. The if above checks if the balance AND usdBalance is non nullish. In case that the balance is defined but the usdbalance is nullish this check also failes and the third option will take place.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but animate-pulse={isNullish(balance)} will always be true, since it's inside if isNullish(balance)}

@@ -5,17 +5,15 @@

export let balance: TokenFinancialData['balance'];
export let usdBalance: TokenFinancialData['usdBalance'];
export let nullishBalanceMessage = '-';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am still not convinced about this, i would prefer to default is as undefined and the use coalescing to overwrite it with '-'

options: { minFraction: 0, maxFraction: 0 }
}).replace('0', '-')}
</span>
<span class:animate-pulse={isNullish(balance)}>{$i18n.tokens.balance.error.not_applicable}</span
Copy link
Collaborator

Choose a reason for hiding this comment

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

personally, I would not like to see a bunch of 'n/a' on the screen... especially in the ICP network, I don't know if it gives a good impression to the users, @StefanBerger-DFINITY

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@AntonioVentilii at the moment it is defined like this. I guess in case of a change it would be solved with another bug ticket.

value: ZERO,
unitName: data.decimals
}).replace('0', '-')}
<span>{$i18n.tokens.balance.error.not_applicable}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

here will be the same, but there are less tokens where this is true; maybe here just greyed out?

Copy link
Collaborator Author

@BonomoAlessandro BonomoAlessandro Nov 13, 2024

Choose a reason for hiding this comment

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

same as my comment above

@BonomoAlessandro
Copy link
Collaborator Author

@AntonioVentilii Description is updated and the not needed isNullish check is removed.

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