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 broken USD rate lookup #5444

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/text/AssetChangeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ interface Props {
* asset
**/
export const AssetChangeTextUi4 = React.memo(({ wallet, tokenId, style }: Props) => {
const { assetToFiatRate, usdToWalletFiatRate, assetToYestFiatRate } = useTokenDisplayData({
const { assetToFiatRate, usdToWalletFiatRate, assetToYestUsdRate } = useTokenDisplayData({
tokenId,
wallet
})

const theme = useTheme()
const { percentString, deltaColorStyle } = getPercentDeltaString(assetToFiatRate, assetToYestFiatRate, usdToWalletFiatRate, theme)
const { percentString, deltaColorStyle } = getPercentDeltaString(assetToFiatRate, assetToYestUsdRate, usdToWalletFiatRate, theme)
const textStyle = React.useMemo<TextStyle>(
() => ({
color: deltaColorStyle,
Expand All @@ -41,8 +41,8 @@ export const AssetChangeTextUi4 = React.memo(({ wallet, tokenId, style }: Props)
return <EdgeText style={textStyle}>{percentString}</EdgeText>
})

const getPercentDeltaString = (assetToFiatRate: string, assetToYestFiatRate: string, usdToWalletFiatRate: string, theme: Theme) => {
const yesterdayExchangeRate = mul(assetToYestFiatRate, usdToWalletFiatRate)
const getPercentDeltaString = (assetToFiatRate: string, assetToYestUsdRate: string, usdToWalletFiatRate: string, theme: Theme) => {
const yesterdayExchangeRate = mul(assetToYestUsdRate, usdToWalletFiatRate)
const yesterdayDelta = sub(assetToFiatRate, yesterdayExchangeRate)

// Use 0 as delta if either exchange rate is missing or 0
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useTokenDisplayData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useTokenDisplayData = (props: { tokenId: EdgeTokenId; wallet: EdgeC
// BASE / QUOTE = PRICE, where:
// - 'Fiat' is the QUOTE, defined by the wallet's fiatCurrencyCode
// - 'Yest' is an index for a historical price from 24 hours ago.
const usdFiatPrice = useSelector(state => getExchangeRate(state, currencyCode, isoFiatCurrencyCode))
const usdToWalletFiatRate = useSelector(state => getExchangeRate(state, 'iso:USD', isoFiatCurrencyCode))
const assetFiatPrice = useCurrencyFiatRate({
currencyCode,
isoFiatCurrencyCode
Expand All @@ -46,8 +46,8 @@ export const useTokenDisplayData = (props: { tokenId: EdgeTokenId; wallet: EdgeC
fiatDenomination,
isoFiatCurrencyCode,
assetToFiatRate: !zeroString(assetFiatPrice) ? assetFiatPrice : '0',
usdToWalletFiatRate: !zeroString(usdFiatPrice) ? usdFiatPrice : '0',
assetToYestFiatRate: !zeroString(assetFiatYestPrice) ? assetFiatYestPrice : '0'
usdToWalletFiatRate: !zeroString(usdToWalletFiatRate) ? usdToWalletFiatRate : '0',
assetToYestUsdRate: !zeroString(assetFiatYestPrice) ? assetFiatYestPrice : '0'
}
}

Expand Down
Loading