Skip to content

Commit

Permalink
fix: Permit dataTree should not enforce ERC20 18 digit decimals if to…
Browse files Browse the repository at this point in the history
…ken is not ERC20
  • Loading branch information
digiwand committed Oct 29, 2024
1 parent b649acf commit 90778b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { useSelector } from 'react-redux';
import { isValidAddress } from 'ethereumjs-util';

Expand All @@ -14,11 +14,11 @@ import {
import { ConfirmInfoSection } from '../../../../../../components/app/confirm/info/row/section';
import { useI18nContext } from '../../../../../../hooks/useI18nContext';
import { SignatureRequestType } from '../../../../types/confirm';
import { useGetTokenStandardAndDetails } from '../../../../hooks/useGetTokenStandardAndDetails';
import {
isOrderSignatureRequest,
isPermitSignatureRequest,
} from '../../../../utils';
import { fetchErc20Decimals } from '../../../../utils/token';
import { useConfirmContext } from '../../../../context/confirm';
import { selectUseTransactionSimulations } from '../../../../selectors/preferences';
import { ConfirmInfoRowTypedSignData } from '../../row/typed-sign-data/typedSignData';
Expand All @@ -30,7 +30,6 @@ const TypedSignInfo: React.FC = () => {
const useTransactionSimulations = useSelector(
selectUseTransactionSimulations,
);
const [decimals, setDecimals] = useState<number>(0);

if (!currentConfirmation?.msgParams) {
return null;
Expand All @@ -43,18 +42,10 @@ const TypedSignInfo: React.FC = () => {

const isPermit = isPermitSignatureRequest(currentConfirmation);
const isOrder = isOrderSignatureRequest(currentConfirmation);
const chainId = currentConfirmation.chainId as string;

useEffect(() => {
(async () => {
if (!isPermit && !isOrder) {
return;
}
const tokenDecimals = await fetchErc20Decimals(verifyingContract);
setDecimals(tokenDecimals);
})();
}, [verifyingContract]);
const tokenContract = isPermit || isOrder ? verifyingContract : undefined;
const { decimalsNumber } = useGetTokenStandardAndDetails(tokenContract);

const chainId = currentConfirmation.chainId as string;
const msgData = currentConfirmation.msgParams?.data as string;

return (
Expand Down Expand Up @@ -95,7 +86,7 @@ const TypedSignInfo: React.FC = () => {
>
<ConfirmInfoRowTypedSignData
data={msgData}
tokenDecimals={decimals}
tokenDecimals={decimalsNumber}
chainId={chainId}
/>
</ConfirmInfoRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import {
* @returns
*/
export const useGetTokenStandardAndDetails = (
tokenAddress: Hex | string | undefined,
tokenAddress?: Hex | string | undefined,
) => {
if (!tokenAddress) {
return { decimalsNumber: undefined };
}

const { value: details } = useAsyncResult<TokenDetailsERC20>(
async () =>
(await memoizedGetTokenStandardAndDetails(
Expand Down

0 comments on commit 90778b0

Please sign in to comment.