From bec3ace272dac9aaa227883ff90565abd1f3913a Mon Sep 17 00:00:00 2001 From: Antonio Ventilii <32648800+AntonioVentilii@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:49:56 +0100 Subject: [PATCH] feat(frontend): Do not show all-zero state in Hero by default (#3354) # Motivation We have 3 different states for the Hero: A. **Loading**: initial state when the user join. B. **Balance**: state that is shown when the user has at least some token. C. **No-balance**: state that is shown when all the tokens have zero balance or cannot be loaded. The idea is to have only two transitions: from A to B, or from A to C, with no middle glitch. That means that: - for state B, the code shall wait for AT LEAST one positive token balance; - for state C, the code shall wait for all tokens to be zero balance (or not available). So, we create a new derived that monitors all tokens balance to be zero, once all of them are loaded. This is based not only on checking for nullish or zero values, but even to have a minimum number of tokens loaded in the balance store. # Changes - Create store to check for all balances to be zero. - Include condition in the loading context for the Hero: after the exchange is initialized, it can stop loading IF either any token has positive balance OR all tokens have zero balance. - Substitute condition for the Send Button in the Hero: always visible, hidden only when all balances are Zero. - Same for the alternative info string below the USD balance. # Tests I provided some tests for the new util. However, for the stores/derived, I shall do a separate PR, since it requires to mock the `page` store too, and it is not quite trivial. https://github.com/user-attachments/assets/89da6086-04a6-41a2-889f-e5db74333f5d https://github.com/user-attachments/assets/3598a006-ed0d-45fd-9e0c-9cbb8ac7ddbd --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .../exchange/ExchangeBalance.svelte | 4 +- .../src/lib/components/hero/Actions.svelte | 6 +- .../lib/components/hero/HeroContent.svelte | 10 +- .../src/lib/derived/balances.derived.ts | 22 ++++- .../src/lib/derived/network-tokens.derived.ts | 1 + src/frontend/src/lib/utils/balances.utils.ts | 28 ++++++ .../tests/lib/utils/balances.utils.spec.ts | 94 ++++++++++++++++++- src/frontend/src/tests/utils/derived.utils.ts | 9 +- 8 files changed, 164 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/lib/components/exchange/ExchangeBalance.svelte b/src/frontend/src/lib/components/exchange/ExchangeBalance.svelte index 0c633ac7f5..bce74c5315 100644 --- a/src/frontend/src/lib/components/exchange/ExchangeBalance.svelte +++ b/src/frontend/src/lib/components/exchange/ExchangeBalance.svelte @@ -1,6 +1,6 @@