Skip to content

fix: add percent change for 24h on asset list #14839

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

Closed
wants to merge 27 commits into from

Conversation

sahar-fehri
Copy link
Contributor

@sahar-fehri sahar-fehri commented Apr 24, 2025

Description

Adds asset list 24h price change

Related issues

Fixes:

Manual testing steps

  1. Switch to a Solana account
  2. You should be able to see the 24h percent change on the asset list and aggregated balance

Screenshots/Recordings

Before

After

Screenshot 2025-04-24 at 15 44 55

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.

@sahar-fehri sahar-fehri added Run Smoke E2E Triggers smoke e2e on Bitrise no-changelog Indicates no external facing user changes, therefore no changelog documentation needed labels Apr 24, 2025
Copy link
Contributor

github-actions bot commented Apr 24, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 5427bd4
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/4adb105c-b3a3-46ad-bc01-5a2724c65d2a

Note

  • 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

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

return !isTestNet(chainId) && isEvmAccountType(account.type);
///: END:ONLY_INCLUDE_IF

// Note: This code marked as unreachable however when the above block gets removed after code fencing this return becomes necessary
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this because now we also display 24h change for non EVM

@sahar-fehri sahar-fehri added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 24, 2025
@sahar-fehri sahar-fehri marked this pull request as ready for review April 24, 2025 17:17
@sahar-fehri sahar-fehri requested review from a team as code owners April 24, 2025 17:17
Copy link
Contributor

github-actions bot commented Apr 24, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: b0b6244
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/6f7bca76-0d19-406a-9c76-81692f2a561a

Note

  • 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

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@gambinish
Copy link
Contributor

Noticing a couple things:

  1. The percent change on the main token list is different than the AssetOverview screen. Is this expected?
Screen.Recording.2025-04-24.at.11.22.08.AM.mov
  1. For USDC, I'm noticing that it's -0.00%. This seems like an odd display value. On AssetOverview we are showing a different value of +0.00%. Which is correct? Neither seems logical, and I wonder what the intended behavior should be. Maybe we can use formatWithThreshold to display -<0.01% in red when the difference is below the smallest display value (say -0.00001%). We could also do something similar if the trend is upwards, and display +<0.01% in green.

gambinish
gambinish previously approved these changes Apr 24, 2025
Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

Approving since my comments aren't technically regressions, and this is the existing behavior.

We should probably revisit this in the future.

@sahar-fehri sahar-fehri added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 24, 2025
@sahar-fehri
Copy link
Contributor Author

TODO: update title with cp-7.46.0

Base automatically changed from feat/solana-token-details-2 to main April 24, 2025 22:53
@gambinish gambinish dismissed their stale review April 24, 2025 22:53

The base branch was changed.

@owencraston
Copy link
Contributor

In testing this seemed to work fairly well but I am noticing a few things. Namely the fact that the percentage change is different on the token list vs the asset overview. I tested with eth accounts and noticed this is the case as well.

nonEvmChainId,
);

const nonEvmFiatBalancesArray = Object.entries(
Copy link
Contributor

Choose a reason for hiding this comment

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

Both this and nonEvmAccountBalance should be memoized. The Object.entries will eagerly create a new object on every render which can trigger more re renders. Instead we can warp these two in a useMemo.

const nonEvmChainId = useSelector(selectSelectedNonEvmNetworkChainId);

const nonEvmAccountBalance = getMultichainNetworkAggregatedBalance(
account as unknown as InternalAccount,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the casting is unnecessary here. If not we should explicit mark the return type of this selector to be InternalAccount.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make the return type explicit in the selector;
Although i think i might need to still cast because the return type is InternalAccount | undefined

const amountChange = totalNonEvmBalance - totalNonEvmBalance1dAgo;

const percentageChange =
((totalNonEvmBalance - totalNonEvmBalance1dAgo) / totalNonEvmBalance1dAgo) *
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make sure that the totalNonEvmBalance1dAgo is greater than 0 in order to avoid a divide by 0 issue? I believe if the value is 0 we will see infinity. Is this a valid case or am I being paranoid?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also can we just reuse the amountChange var from above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point; i can add a check but i think that to be in that case everything would have to be zero
if
const totalNonEvmBalance1dAgo = getNonEvmTotalFiat1dAgo();
is zero then totalNonEvmBalance is also zero in which case we return null

  if (!totalNonEvmBalance) {
    return null;
  }

);
};

export default NonEvmAggregatedPercentage;
Copy link
Contributor

Choose a reason for hiding this comment

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

lets wrap this whole thing in a React.memo

@@ -255,7 +278,10 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
)),
[handleSelectTimePeriod, timePeriod],
);
const itemAddress = safeToChecksumAddress(asset.address);

const itemAddress = isEvmSelected
Copy link
Contributor

@owencraston owencraston Apr 25, 2025

Choose a reason for hiding this comment

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

In see we are doing lots of this across the app. Perhaps we can turn this into a util.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't touched this component i think you see this change now because the branch i was branched off of was merged; good point though can add a TODO seems like it would not be a small refactor ^^

);

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const allMultichainAssetsRates = useSelector(selectMultichainAssetsRates);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets make sure this selector is a deep equal selector. I did not verify that it is/is not. Just wanted to mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update this, i also think this was not originally modifed in this PR but worth improving 🙏

fiatAmount: Number(amount),
}));

const getNonEvmTotalFiat1dAgo = () => {
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 also memoize this?

<View style={styles.wrapper}>
<SensitiveText
isHidden={privacyMode}
length="10"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the length always going to be 10?

percentageTextColor = TextColor.Alternative;
}

const formattedPercentage = isValidAmount(percentageChange)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should move these into utils.

@sahar-fehri
Copy link
Contributor Author

closing in favor of #14892

@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2025
@sahar-fehri
Copy link
Contributor Author

hings. Namely the fact that the p

This is happening also in extension; for evms too; both values are computed differently;
One mainly from price-api (historical prices endpoint) (the one on the asset details)
While the percentage on the aggregated balance view is computed based on the user's balance and the market data we get from price api.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no-changelog Indicates no external facing user changes, therefore no changelog documentation needed Run Smoke E2E Triggers smoke e2e on Bitrise team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants