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

fix: label main and secondary balances #13462

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bergarces
Copy link
Contributor

@bergarces bergarces commented Feb 12, 2025

Description

It's been reported that setting the primary currency to "Native" was displaying fiat as the main currency and the native currency as secondary. The opposite would happen when setting the primary currency to "Fiat".

This was due to using the wrong nomenclature as the properties of the component responsible for that behaviour (balance was the primary balance and mainBalance was the secondary balance).

The least disruptive behaviour that fixes both the issue and the nomenclature is leaving balance as the primary balance changing the name of mainBalance to secondaryBalance.

This component is used in three different places:

  • Token list items in the home wallet.
  • Balance in the asset overview.
  • Staking balance in the asset overview.

The behaviour for the token list and balance have been fixed to work as the setting suggests. The staking balance has been left as it currently is pending confirmation of whether it needs to follow the same behaviour.

Related issues

Fixes: No open GitHub issue for the ticket

Manual testing steps

  1. Go to Settings -> General -> Primary Currency -> Set to "Native"
  2. Got to Wallet Home page and check assets in the Tokens tab display the native currency as primary and fiat as secondary.
  3. Click on any of the assets to open the asset overview and check that the balance is displayed correctly.
  4. Repeat steps 1, 2 and 3 changing the primary currency to "Fiat"

Screenshots/Recordings

Before

image
image

After

Screenshot_1739377743
Screenshot_1739377733

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-mmi MMI team label Feb 12, 2025
@bergarces bergarces added team-assets and removed team-mmi MMI team labels Feb 12, 2025
@bergarces bergarces force-pushed the fix/MMASSETS-537-mobile-fiat-native-toggle branch 6 times, most recently from d98d06f to 7e60898 Compare February 13, 2025 10:47

interface AssetElementProps {
children?: React.ReactNode;
asset: TokenI;
onPress?: (asset: TokenI) => void;
onLongPress?: ((asset: TokenI) => void) | null;
balance?: string;
mainBalance?: string | null;
Copy link
Contributor Author

@bergarces bergarces Feb 13, 2025

Choose a reason for hiding this comment

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

This is the least disruptive way of fixing the nomenclature without altering behaviour of different components inadvertently.

mainBalance, despite its name, was added after balance and was being used as a secondary balance. By renaming this one and keeping the main balance as balance, it becomes consistent without major changes.

@@ -1,2 +1,2 @@
export const FIAT_BALANCE_TEST_ID = 'fiat-balance-test-id';
export const MAIN_BALANCE_TEST_ID = 'main-balance-test-id';
Copy link
Contributor Author

@bergarces bergarces Feb 13, 2025

Choose a reason for hiding this comment

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

Renaming these test ids for consistency. Snapshots will need updating accordingly.

@@ -101,6 +101,7 @@ const initialState = {
},
settings: {
showTestNetworks: true,
primaryCurrency: 'ETH',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need this to maintain test descriptions and assertions accurate, as otherwise the default is fiat and the TokenListItem component has now been fixed.

@@ -207,7 +207,7 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => {
{hasEthToUnstake && !isLoadingPooledStakesData && (
<AssetElement
asset={asset}
mainBalance={stakedBalanceETH}
secondaryBalance={stakedBalanceETH}
balance={stakedBalanceFiat}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This component is owned by @MetaMask/metamask-staking and is currently displaying fiat balance as the primary and ETH balance as secondary without taking into account the primaryCurrency setting.

Since this is a bug fix for another component, I didn't want to change the behaviour of this one, but it's probably worth checking what it should be.

@bergarces bergarces force-pushed the fix/MMASSETS-537-mobile-fiat-native-toggle branch from 7e60898 to f4773c3 Compare February 13, 2025 11:15
@@ -144,8 +144,8 @@ const Balance = ({ asset, mainBalance, secondaryBalance }: BalanceProps) => {
</Text>
<AssetElement
asset={asset}
mainBalance={mainBalance}
balance={secondaryBalance}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ticket does not specify that we ought to change the behaviour of this component, but I have, given that the same issue applied here.

The way it determines mainBalance and secondaryBalance looks a bit odd (here)

If portfolio view is enabled, it always sets mainBalance as the chain's native currency and secondaryBalance as the fiat.
If portfolio view is NOT enabled, then it sets the mainBalance and secondaryBalance in accordance to the primaryCurrency setting.
They were however being passed the wrong way around, which meant that secondaryBalance was being displayed as the main balance and mainBalance was being displayed as the secondary balance. It should now display as intended.

@bergarces bergarces force-pushed the fix/MMASSETS-537-mobile-fiat-native-toggle branch from f4773c3 to 62f8e82 Compare February 13, 2025 11:44
@bergarces bergarces added the Run Smoke E2E Triggers smoke e2e on Bitrise label Feb 13, 2025
Copy link
Contributor

https://bitrise.io/ Bitrise

🔄🔄🔄 pr_smoke_e2e_pipeline started on Bitrise...🔄🔄🔄

Commit hash: 62f8e82
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/f628c195-9be0-407b-b0f8-cfdd71eeedb7

Note

  • This comment will auto-update when build completes
  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants