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/display small price #1166

Merged
merged 3 commits into from
Feb 26, 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
3 changes: 2 additions & 1 deletion src/pages/UniversalSwap/Component/ChartUsdPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FILTER_TIME_CHART } from 'reducer/type';
import { formatTimeDataChart, getTokenIsStableCoin } from '../helpers';
import { ChartTokenType, useChartUsdPrice } from '../hooks/useChartUsdPrice';
import styles from './ChartUsdPrice.module.scss';
import { parseTokenInfoRawDenom } from '@oraichain/oraidex-common';

export type ChartUsdPropsType = {
filterDay: FILTER_TIME_CHART;
Expand Down Expand Up @@ -42,7 +43,7 @@ const ChartUsdPrice = ({
onMouseLeave
} = useChartUsdPrice(
filterDay,
toTokenDenomIsStable ? currentFromToken?.coinGeckoId : currentToToken?.coinGeckoId,
toTokenDenomIsStable ? parseTokenInfoRawDenom(currentFromToken) : parseTokenInfoRawDenom(currentToToken),
chartTokenType,
onUpdateCurrentItem,
onUpdatePricePercent
Expand Down
4 changes: 3 additions & 1 deletion src/pages/UniversalSwap/Component/HeaderTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const UsdPrice = ({
const headerTabSimple = () => {
return (
<div>
<span>${priceUsd < 10 ** -6 ? minimize(priceUsd.toFixed(12)) : minimize(priceUsd.toString())}</span>
<span>
${priceUsd < 10 ** -6 && priceUsd > 0 ? minimize(priceUsd.toFixed(12)) : minimize(priceUsd.toString())}
</span>
<span
className={cx('percent', isIncrementUsd ? 'increment' : 'decrement', {
hidePercent: chartTokenType === ChartTokenType.Volume
Expand Down
7 changes: 5 additions & 2 deletions src/pages/UniversalSwap/hooks/useChartUsdPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { CoinGeckoId } from '@oraichain/oraidex-common/build/network';
import { oraichainTokens } from 'initCommon';
import { toFixedIfNecessary } from 'pages/Pools/helpers';
import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { FILTER_TIME_CHART } from 'reducer/type';
import axios from 'rest/request';
import { RootState } from 'store/configure';

export enum ChartTokenType {
Price = 'Price',
Expand All @@ -24,13 +26,14 @@ const KeyMapByChartType: Record<ChartTokenType, keyof ChartDataValue> = {

export const useChartUsdPrice = (
type: FILTER_TIME_CHART,
token: CoinGeckoId,
token: string,
chartType: ChartTokenType,
onUpdateCurrentItem?: React.Dispatch<React.SetStateAction<number>>,
onUpdatePricePercent?: React.Dispatch<React.SetStateAction<string | number>>
) => {
const [currentData, setCurrentData] = useState<ChartDataValue[]>([]);
const [changePercent, setChangePercent] = useState<string | number>(0);
const allOraichainTokens = useSelector((state: RootState) => state.token.allOraichainTokens || []);

// TODO: add loading animation later.
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -73,7 +76,7 @@ export const useChartUsdPrice = (
const onChangeRange = async (type: FILTER_TIME_CHART = FILTER_TIME_CHART.DAY) => {
try {
setIsLoading(true);
const tokenOnOraichain = oraichainTokens.find((t) => t.coinGeckoId === token && t.decimals === CW20_DECIMALS);
const tokenOnOraichain = allOraichainTokens.find((t) => t.contractAddress === token || t.denom === token);
const tokenDenom = parseTokenInfoRawDenom(tokenOnOraichain);

const data = await getDataPriceMarket(tokenDenom, type);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/UniversalSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { NetworkFilter, TYPE_TAB_HISTORY, getTokenIsStableCoin, initNetworkFilte
import { ChartTokenType, useChartUsdPrice } from './hooks/useChartUsdPrice';
import styles from './index.module.scss';
import Lottie from 'lottie-react';
import { parseTokenInfoRawDenom } from '@oraichain/oraidex-common';

const cx = cn.bind(styles);

Expand All @@ -45,7 +46,7 @@ const Swap: React.FC = () => {
// get data for mobile
useChartUsdPrice(
FILTER_TIME_CHART.DAY,
tokenTo?.coinGeckoId,
parseTokenInfoRawDenom(tokenTo),
ChartTokenType.Price,
setInitPriceUsd,
setInitPercentChangeUsd
Expand Down
Loading