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: preSend amount convert currency display 0 ok-23564 #3608

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions packages/kit/src/components/Format/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useSettings,
useTokenBalanceWithoutFrozen,
} from '../../hooks';
import { useSimpleTokenPriceValue } from '../../hooks/useTokens';
import { useSimpleTokenPriceConvertValue } from '../../hooks/useTokens';
import { getSuggestedDecimals } from '../../utils/priceUtils';
import { formatDecimalZero } from '../../views/Market/utils';

Expand Down Expand Up @@ -229,7 +229,7 @@ export function FormatCurrencyTokenOfAccount({
accountId: string;
networkId: string;
}) {
const priceValue = useSimpleTokenPriceValue({
const priceValue = useSimpleTokenPriceConvertValue({
networkId,
contractAdress: token?.tokenIdOnNetwork,
});
Expand Down
20 changes: 20 additions & 0 deletions packages/kit/src/hooks/useTokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';

import BigNumber from 'bignumber.js';
import { pick } from 'lodash';

import type { Token } from '@onekeyhq/engine/src/types/token';
Expand Down Expand Up @@ -220,3 +221,22 @@ export const useSimpleTokenPriceValue = ({

return price;
};

export const useSimpleTokenPriceConvertValue = ({
networkId,
contractAdress,
}: {
networkId?: string;
contractAdress?: string;
}) => {
const usdPrice = useTokenPrice({
networkId: networkId ?? '',
tokenIdOnNetwork: contractAdress ?? '',
vsCurrency: 'usd',
});
const vsCurrency = useAppSelector((s) => s.settings.selectedFiatMoneySymbol);
const fiatMap = useAppSelector((s) => s.fiatMoney.map);
const fiat = fiatMap[vsCurrency]?.value || 0;
const numberConvert = new BigNumber(fiat).multipliedBy(usdPrice).toNumber();
return numberConvert;
};
4 changes: 2 additions & 2 deletions packages/kit/src/views/Send/utils/usePreSendAmountInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
formatBalanceDisplay,
} from '../../../components/Format';
import { useSettings } from '../../../hooks';
import { useSimpleTokenPriceValue } from '../../../hooks/useTokens';
import { useSimpleTokenPriceConvertValue } from '../../../hooks/useTokens';

export function usePreSendAmountInfo({
tokenInfo,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function usePreSendAmountInfo({
return new RegExp(pattern);
}, [amountInputDecimals]);

const tokenPrice = useSimpleTokenPriceValue({
const tokenPrice = useSimpleTokenPriceConvertValue({
networkId,
contractAdress: tokenInfo?.tokenIdOnNetwork,
});
Expand Down