Skip to content

Commit

Permalink
feat: update native token amount
Browse files Browse the repository at this point in the history
  • Loading branch information
rick23p committed Aug 1, 2024
1 parent 54021ac commit 7b5d898
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, { FC, useMemo } from 'react';

import { getCurrencyPrecision } from '../../5_pages/PortfolioPage/components/ProtocolSection/ProtocolSection.utils';
import { BITCOIN, ETH } from '../../../constants/currencies';
import { useChainStore } from '../../../hooks/useChainStore';
import { useGetNativeTokenPrice } from '../../../hooks/useGetNativeTokenPrice';
import { isRskChain } from '../../../utils/chain';
import { decimalic } from '../../../utils/math';
import { AmountRenderer } from '../AmountRenderer/AmountRenderer';

Expand All @@ -19,13 +16,7 @@ export const NativeTokenAmount: FC<NativeTokenAmountProps> = ({
dataAttribute,
precision,
}) => {
const { currentChainId } = useChainStore();
const nativeToken = useMemo(
() => (isRskChain(currentChainId) ? BITCOIN : ETH),
[currentChainId],
);

const { price: nativeTokenPrice } = useGetNativeTokenPrice();
const { price: nativeTokenPrice, nativeToken } = useGetNativeTokenPrice();

const value = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const ProtocolData: FC = () => {
<div className="text-xs text-gray-30 mb-2">
{t(pageTranslations.tvlBobNetwork)}
</div>
<div className="text-gray-10 text-sm italic">
<div className="text-gray-10 text-sm">
<NativeTokenAmount usdValue={bobLockedData.total_usd} />
</div>
<div className="text-gray-50 text-sm">
Expand Down
20 changes: 13 additions & 7 deletions apps/frontend/src/hooks/useGetNativeTokenPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import axios from 'axios';

import { RSK_CHAIN_ID } from '../config/chains';

import { BITCOIN, ETH } from '../constants/currencies';
import { COMMON_SYMBOLS } from '../utils/asset';
import { isRskChain } from '../utils/chain';
import { isBobChain } from '../utils/chain';
import { getIndexerUrl } from '../utils/helpers';
import { toWei } from '../utils/math';
import { useCacheCall } from './useCacheCall';
import { getCurrentChain, useCurrentChain } from './useChainStore';
import { useCurrentChain } from './useChainStore';
import { useDollarValue } from './useDollarValue';

export const useGetNativeTokenPrice = () => {
const chainId = useCurrentChain();
const currentChainId = useCurrentChain();

const { value: rBTCPrice } = useCacheCall(
'rbtc-price/indexer',
getCurrentChain(),
RSK_CHAIN_ID,
async () => {
const { data } = await axios.get(getIndexerUrl() + 'tokens', {
params: {
Expand All @@ -38,9 +39,14 @@ export const useGetNativeTokenPrice = () => {
);

const price = useMemo(
() => (isRskChain(chainId) ? rBTCPrice : ethPrice),
[chainId, ethPrice, rBTCPrice],
() => (isBobChain(currentChainId) ? ethPrice : rBTCPrice),
[currentChainId, ethPrice, rBTCPrice],
);

return { price };
const nativeToken = useMemo(
() => (isBobChain(currentChainId) ? ETH : BITCOIN),
[currentChainId],
);

return { price, nativeToken };
};

0 comments on commit 7b5d898

Please sign in to comment.