-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
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. |
|
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 |
There was a problem hiding this comment.
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
|
Noticing a couple things:
Screen.Recording.2025-04-24.at.11.22.08.AM.mov
|
There was a problem hiding this 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.
|
TODO: update title with cp-7.46.0 |
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( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) * |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = () => { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
closing in favor of #14892 |
This is happening also in extension; for evms too; both values are computed differently; |
Description
Adds asset list 24h price change
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist