valora-inc / wallet

The official repository for the Valora mobile cryptocurrency wallet.
https://valora.xyz
Apache License 2.0
172 stars 85 forks source link

fix(earn): Compute total deposit amount correctly for EarnPoolInfoScreen #6104

Closed finnian0826 closed 2 days ago

finnian0826 commented 5 days ago

Description

totalDepositBalanceInCrypto was being computed incorrectly if there were earningsItems where includedInPoolBalance is true and they are in a different token than the deposit token. Fixed this and added a test, also compute totalDepositBalanceInLocalCurrency using totalDepositBalanceInCrypto rather than doing another filter/reduce.

Test plan

Updated unit tests and added new ones to prevent same bug in the future

Related issues

Backwards compatibility

Current pools don't have any earningItems where includedInPoolBalance is true so no issue, there will be a bug for older versions for Beefy pools though if we separate out compound interest (will show incorrect value).

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

codecov[bot] commented 5 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.73%. Comparing base (515d2e3) to head (73205a2). Report is 9 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/valora-inc/wallet/pull/6104/graphs/tree.svg?width=650&height=150&src=pr&token=ZQBexNu9cz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc)](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc) ```diff @@ Coverage Diff @@ ## main #6104 +/- ## ========================================== - Coverage 88.74% 88.73% -0.02% ========================================== Files 727 727 Lines 30763 30758 -5 Branches 5614 5614 ========================================== - Hits 27301 27292 -9 - Misses 3264 3268 +4 Partials 198 198 ``` | [Files with missing lines](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc) | Coverage Δ | | |---|---|---| | [src/earn/EarnPoolInfoScreen.tsx](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?src=pr&el=tree&filepath=src%2Fearn%2FEarnPoolInfoScreen.tsx&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc#diff-c3JjL2Vhcm4vRWFyblBvb2xJbmZvU2NyZWVuLnRzeA==) | `97.04% <100.00%> (-0.07%)` | :arrow_down: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/valora-inc/wallet/pull/6104/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc). Last update [515d2e3...73205a2](https://app.codecov.io/gh/valora-inc/wallet/pull/6104?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valora-inc).