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

Default to null balance instead of 0 (show '-' for unknown balance) #916

Merged
merged 8 commits into from
Jul 18, 2022

Conversation

lukaw3d
Copy link
Member

@lukaw3d lukaw3d commented Jul 8, 2022

Fixes #816

Before After
before after

@github-actions
Copy link

github-actions bot commented Jul 8, 2022

MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 17 0 0.04s
✅ GIT git_diff yes no 0.02s
✅ TSX eslint 6 0 0 7.34s
✅ TYPESCRIPT eslint 8 0 0 7.49s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #916 (a533303) into master (fe1790a) will increase coverage by 0.03%.
The diff coverage is 84.61%.

❗ Current head a533303 differs from pull request most recent head 1e764db. Consider uploading reports for the commit 1e764db to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #916      +/-   ##
==========================================
+ Coverage   87.74%   87.77%   +0.03%     
==========================================
  Files          98       97       -1     
  Lines        1640     1628      -12     
  Branches      358      360       +2     
==========================================
- Hits         1439     1429      -10     
+ Misses        201      199       -2     
Flag Coverage Δ
cypress 57.75% <53.84%> (-0.32%) ⬇️
jest 79.07% <84.61%> (+4.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/app/components/AmountFormatter/index.tsx 100.00% <ø> (ø)
...ages/AccountPage/Features/AccountSummary/index.tsx 100.00% <ø> (ø)
src/app/state/account/index.ts 73.68% <0.00%> (-4.10%) ⬇️
src/app/state/account/saga.ts 63.04% <0.00%> (ø)
src/app/pages/AccountPage/index.tsx 97.77% <100.00%> (+2.53%) ⬆️
...e/Features/DelegationList/ActiveDelegationList.tsx 100.00% <100.00%> (ø)
...eatures/DelegationList/DebondingDelegationList.tsx 100.00% <100.00%> (ø)
src/app/state/staking/index.ts 89.28% <100.00%> (+8.51%) ⬆️
src/app/components/Footer/index.tsx 100.00% <0.00%> (ø)
...rc/app/components/MobileFooterNavigation/index.tsx
... and 2 more

@pro-wh
Copy link
Contributor

pro-wh commented Jul 8, 2022

gonna have to ask about this on the issue

src/app/pages/AccountPage/__tests__/index.test.tsx Outdated Show resolved Hide resolved
const history = createMemoryHistory()
history.push('/account/account_address')
const page = renderPage(store, history)
it('with missing delegations', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not create a snapshot for with missing delegations test? Both snapshots creates +2k lines and in most cases they are useless as one snapshot already covers page layout markup and styles.

Copy link
Member Author

@lukaw3d lukaw3d Jul 12, 2022

Choose a reason for hiding this comment

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

Maybe. I would like it capture:

  • "Couldn't load delegations."
  • "API appears to be down"
  • Total balance  -
    Available      100.0
    Staked         -
    Debonding      -
    
  • "Active delegations ()" (so we notice if this breaks. i18n uses "count" to signify plurality, but we give it null)

without sprinkling data-testid everywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to:

expect(page.container).toHaveTextContent('Oasis Scan API appears to be down')
const balance = await screen.findByTestId('account-balance-total')
expect(balance).toHaveTextContent('-')
const balanceSummary = await screen.findByTestId('account-balance-summary')
expect(balanceSummary.textContent).toMatchSnapshot()
const tabs = await screen.findByRole('navigation')
expect(tabs.textContent).toMatchSnapshot()

exports[`<AccountPage /> with missing delegations 1`] = `"Total balance-Available100.0 Staked-Debonding-"`;
exports[`<AccountPage /> with missing delegations 2`] = `"TransactionsActive delegations ()Debonding delegations ()"`;

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, thanks

src/app/state/staking/index.ts Show resolved Hide resolved
@@ -147,13 +151,13 @@ export function AccountPage(props: Props) {
<NavItem
route={`/account/${address}/active-delegations`}
label={t('account.subnavigation.activeDelegations', 'Active delegations ({{count}})', {
count: stake.delegations.length,
count: stake.delegations?.length ?? null!,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to show a label with an empty bracket when nullish coalescing operator returns its right-hand side operand?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it displays Active delegations ()

More effort solutions:

  • add another translation string stake.delegations ? t(account.subnavigation.activeDelegations) : t(account.subnavigation.activeDelegationsNull)
  • use a different field: count is used for plurality and needs to be a number, and null workaround could break. Make that other field a string, so it can be e.g. - too, and update translations

@lukaw3d lukaw3d force-pushed the lw/unknown-null branch 3 times, most recently from 93184ec to a533303 Compare July 13, 2022 21:55
Copy link
Member

@tjanez tjanez left a comment

Choose a reason for hiding this comment

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

I actually prefer - to ?, I think it is prettier and looks more professional.

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.

When backend doesn't give a response, prefer showing ? (for unknown)
4 participants