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. |
39f5b8f to
2d899f2
Compare
1e81c7e to
1a842fc
Compare
|
Added DONOTMERGE based on Alex's PR description, which could be lost in the rest of the text |
93813d6 to
e7af0ca
Compare
3a10ca4 to
c4a8d27
Compare
92abc5f to
8953502
Compare
| > | ||
| <h2> | ||
| <span className="asset-list-item__token-value">{primary}</span> | ||
| <span className="asset-list-item__token-symbol">{tokenSymbol}</span> |
There was a problem hiding this comment.
In some other places, we intentionally put the symbol and the value in separate elements so that we can use CSS to ellipse long values without obscuring the symbol. That seems like it would be useful here too 🤔 But that said I can't see any evidence of such a strategy being used here.
c4ed806 to
d56f07a
Compare
05618c8 to
649f696
Compare
94e0f59 to
a3c576c
Compare
a3c576c to
e6f5674
Compare
brad-decker
left a comment
There was a problem hiding this comment.
There's a number of issues with this PR due to conversionRate possibly being undefined where it was never assumed to be undefined before. Might want to hardcode the selector to return undefined to figure out what should be displayed in these cases. I've left a number of feedback items here too. I also started a thread in the design team channel to discuss how we should handle the changes to make assets display fiat as the "primary" display value when the appropriate setting is set.
| "@metamask/contract-metadata": "^1.26.0", | ||
| "@metamask/controllers": "^9.0.0", | ||
| "@metamask/eth-ledger-bridge-keyring": "^0.6.0", | ||
| "@metamask/controllers": "^10.0.0", |
There was a problem hiding this comment.
NIT: the positional change here is unnecessary and breaks alphabetical order.
| onClick, | ||
| tokenAddress, | ||
| tokenSymbol, | ||
| primarySymbol, |
There was a problem hiding this comment.
[req]
instead of primary/primarySymbol etc
what if we had:
primaryAsset.amount and primaryAsset.symbol and primaryAsset.isFiat ( also primaryAsset.decimals and primaryAsset.address and primaryAsset.image )?
similarily
secondaryAsset.amount amd secondaryAsset.symbol
I think this could go a long way in reducing confusion in this component and make clearer what primary/secondary means. I still don't like these words as a data descriptor. They are being described as how they usually appear in our UI which leads to the confusion that needs to have flags for reversing their meaning. That's a conversation for another PR I think 😬
There was a problem hiding this comment.
actually after reviewing this bit:
const tokenSymbol = useMemo(
() => (primaryIsFiat ? secondarySymbol : primarySymbol),
[primaryIsFiat, secondarySymbol, primarySymbol],
);
I'm more confused.
the asset row exists to display a specific asset, the user's preferences do not change that. primary in this case is meant to describe the larger, more dominant value whereas secondary is the one under it that is smaller and supports the former.
I think we should go with something like this:
asset: PropTypes.shape({
amount: PropTypes.string.isRequired,
symbol: PropTypes.string.isRequired,
decimals: PropTypes.number,
address: PropTypes.string,
image: PropTypes.string,
}).isRequired,
conversionAsset: PropTypes.shape({
amount: PropTypes.string.isRequired,
symbol: PropTypes.string.isRequired,
}),
conversionIsPrimary: propTypes.bool,
we can then always rely on the distinction that asset is the asset we are rendering. conversion is clearer as well than secondary, especially with the combination of conversionIsPrimary. We also do not extend the problem of treating the "secondary" asset as fiat when it could be other crypto. I probably haven't thought this all the way through, so feel free to mutate it to make sense but I think this is much easier to reason about when trying to support this component moving forward.
There was a problem hiding this comment.
Re the last comment, the conversionRate should be null when not available? and I'm not seeing that behavior where some tokens are USD and others are with their symbols...?
Regarding the shape you suggest for primary/secondary -> asset/conversionAsset, I agree it is an improvement. I'll move forward with that for now.
There was a problem hiding this comment.
ah sorry, you have to set "primary" currency as "Fiat" in settings to see this. I did update the getConversionRate selector to return null instead of undefined and same result.
| <span className="asset-list-item__secondary-value"> | ||
| {secondary} | ||
| </span> | ||
| <span className="asset-list-item__secondary-symbol"> |
There was a problem hiding this comment.
I think your intention may have been to utilize the token-value styles to ellipse long text here. If that's the case you need to add the class to those styles.
ui/selectors/custom-gas.js
Outdated
| const isMainnet = getIsMainnet(state); | ||
| const showFiat = isMainnet || Boolean(showFiatInTestnets); | ||
| const { conversionRate } = state.metamask; | ||
| const showFiat = Boolean((isMainnet || showFiatInTestnets) && conversionRate); |
There was a problem hiding this comment.
can this use the getShouldShowFiat selector now?
| const currentCurrency = useSelector(getCurrentCurrency); | ||
| const userPrefersShownFiat = useSelector(getShouldShowFiat); | ||
| const showFiat = overrides.showFiat ?? userPrefersShownFiat; | ||
| const showFiat = overrides?.showFiat ?? userPrefersShownFiat; |
There was a problem hiding this comment.
This file throws an error when getConversionRate is hardwired to return undefined, because it doesn't check if this is available before trying to compute values.
| conversionRate, | ||
| numberOfDecimals: 2, | ||
| }); | ||
| const fiatTransactionAmount = conversionRate |
ui/hooks/useEthFiatAmount.js
Outdated
| const currentCurrency = useSelector(getCurrentCurrency); | ||
| const userPrefersShownFiat = useSelector(getShouldShowFiat); | ||
| const showFiat = overrides.showFiat ?? userPrefersShownFiat; | ||
| const showFiat = Boolean(overrides.showFiat ?? userPrefersShownFiat); |
There was a problem hiding this comment.
this boolean needs to be updated to take into account the possibility of conversionRate not being present.
| chainId, | ||
| nativeCurrencySymbol, | ||
| }) { | ||
| const showInFiat = Boolean(nativeCurrencySymbol && conversionRate); |
e352bd8 to
42fc1e5
Compare
|
The core of this PR was extracted and merged. The remaining pieces will be added in subsequent PRs. |



Fixes: #9492
Explanation: In cases where a user has not entered a symbol ticker for a custom RPC network (or our conversion rate API doesn't recognize the asset), don't currently update our conversionRate in state and use the conversion rate from the previously used network with a valild conversion rate. Moreover, in useCurrencyDisplay (where we apply the conversion for most UI elements where the value of a secondary currency is required) we haven't had a clear conditional separation of values that require conversion (Secondary currencies / Fiat) and those that do not (Primary Currency / native assets).
This PR, in tandem with this one allows conversionRates to be null when we cannot calculate them. In such cases we do not show a converted secondary currency (even if the user has selected to show conversions in testnets). This prevents us from showing inaccurate conversions. It also adds logic to avoid applying conversion rates to primary currencies which results in some of the more alarming bugs (show in video in linked PR above).
tldr: when reviewing start at useCurrencyDisplay.js
Additional work here:
Work to follow:
currentCurrencyandnativeCurrencytogether and clean up the impossible to reason about logic that lives in components like currency-input.component and token-input.component.currentCurrencyandnativeCurrencytopreferredCurrencyandnetworkCurrencyrespectively per this thread. If you have thoughts on this please include comments here?Manual testing steps:
Show Conversion on Testnetson.