Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Aug 26, 2024
1 parent 7e1a6b8 commit 8c3d68e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,68 +171,6 @@ exports[`<ApproveInfo /> renders component for approve request 1`] = `
</div>
</div>
</div>
<div
class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md"
data-testid="advanced-details-data-section"
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
>
<p
class="mm-box mm-text mm-text--body-md-medium mm-box--color-inherit"
>
Data
</p>
</div>
<div
class="mm-box"
>
<svg
class="preloader__icon"
fill="none"
height="20"
viewBox="0 0 16 16"
width="20"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M8 13.7143C4.84409 13.7143 2.28571 11.1559 2.28571 8C2.28571 4.84409 4.84409 2.28571 8 2.28571C11.1559 2.28571 13.7143 4.84409 13.7143 8C13.7143 11.1559 11.1559 13.7143 8 13.7143ZM8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16Z"
fill="var(--color-primary-muted)"
fill-rule="evenodd"
/>
<mask
height="16"
id="mask0"
mask-type="alpha"
maskUnits="userSpaceOnUse"
width="16"
x="0"
y="0"
>
<path
clip-rule="evenodd"
d="M8 13.7143C4.84409 13.7143 2.28571 11.1559 2.28571 8C2.28571 4.84409 4.84409 2.28571 8 2.28571C11.1559 2.28571 13.7143 4.84409 13.7143 8C13.7143 11.1559 11.1559 13.7143 8 13.7143ZM8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16Z"
fill="var(--color-primary-default)"
fill-rule="evenodd"
/>
</mask>
<g
mask="url(#mask0)"
>
<path
d="M6.85718 17.9999V11.4285V8.28564H-4.85711V17.9999H6.85718Z"
fill="var(--color-primary-default)"
/>
</g>
</svg>
</div>
</div>
</div>
<div
class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md"
data-testid="gas-fee-section"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ describe('useApproveTokenSimulation', () => {
});

it('returns the token id for NFT', async () => {
const useIsNFTMock = jest
.fn()
.mockImplementation(() => ({ isNFT: true, decimals: '18' }));
const useIsNFTMock = jest.fn().mockImplementation(() => ({ isNFT: true }));

const useDecodedTransactionDataMock = jest.fn().mockImplementation(() => ({
pending: false,
Expand Down Expand Up @@ -93,9 +91,7 @@ describe('useApproveTokenSimulation', () => {
});

it('returns "UNLIMITED MESSAGE" token amount for fungible tokens approvals equal or over the total number of tokens in circulation', async () => {
const useIsNFTMock = jest
.fn()
.mockImplementation(() => ({ isNFT: false, decimals: '18' }));
const useIsNFTMock = jest.fn().mockImplementation(() => ({ isNFT: false }));

const useDecodedTransactionDataMock = jest.fn().mockImplementation(() => ({
pending: false,
Expand All @@ -110,7 +106,7 @@ describe('useApproveTokenSimulation', () => {
},
{
type: 'uint256',
value: 10 ** 18,
value: 10 ** 15,
},
],
},
Expand All @@ -135,7 +131,7 @@ describe('useApproveTokenSimulation', () => {

expect(result.current).toMatchInlineSnapshot(`
{
"formattedTokenNum": "1,000,000,000,000,000,000",
"formattedTokenNum": "1,000,000,000,000,000",
"pending": undefined,
"tokenAmount": "UNLIMITED MESSAGE",
"value": {
Expand All @@ -149,7 +145,7 @@ describe('useApproveTokenSimulation', () => {
},
{
"type": "uint256",
"value": 1000000000000000000,
"value": 1000000000000000,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@ import { useIsNFT } from './use-is-nft';

export const UNLIMITED_MSG = 'UNLIMITED MESSAGE';

function isSpendingCapUnlimited(
tokenDecimals: string,
decodedSpendingCap: number,
) {
const totalCirculatingSupplyBigNumber = new BigNumber(10).pow(
Number(tokenDecimals),
);

// convert `decodedSpendingCap` to Big Number because numbers lose precision above
// `Number.MAX_SAFE_INTEGER`
const spendingCapBigNumber = new BigNumber(decodedSpendingCap);

return spendingCapBigNumber.greaterThanOrEqualTo(
totalCirculatingSupplyBigNumber,
);
const UNLIMITED_THRESHOLD = 10 ** 15;

function isSpendingCapUnlimited(decodedSpendingCap: number) {
return decodedSpendingCap >= UNLIMITED_THRESHOLD;
}

export const useApproveTokenSimulation = (transactionMeta: TransactionMeta) => {
const locale = useSelector(getIntlLocale);

const { isNFT, pending: isNFTPending, decimals } = useIsNFT(transactionMeta);
const { isNFT, pending: isNFTPending } = useIsNFT(transactionMeta);

const decodedResponse = useDecodedTransactionData();

Expand All @@ -41,11 +30,7 @@ export const useApproveTokenSimulation = (transactionMeta: TransactionMeta) => {
: new Intl.NumberFormat(locale).format(decodedSpendingCap);

let tokenAmount;
if (
!isNFT &&
decimals !== undefined &&
isSpendingCapUnlimited(decimals, decodedSpendingCap)
) {
if (!isNFT && isSpendingCapUnlimited(decodedSpendingCap)) {
tokenAmount = UNLIMITED_MSG;
} else {
tokenAmount = `${tokenPrefix}${formattedTokenNum}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import { TokenStandard } from '../../../../../../../../shared/constants/transaction';
import {
CONTRACT_INTERACTION_SENDER_ADDRESS,
genUnapprovedContractInteractionConfirmation,
Expand All @@ -7,7 +8,6 @@ import mockState from '../../../../../../../../test/data/mock-state.json';
import { renderHookWithProvider } from '../../../../../../../../test/lib/render-helpers';
import { getTokenStandardAndDetails } from '../../../../../../../store/actions';
import { useIsNFT } from './use-is-nft';
import { TokenStandard } from '../../../../../../../../shared/constants/transaction';

jest.mock('../../../../../../../store/actions', () => ({
...jest.requireActual('../../../../../../../store/actions'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { getTokenStandardAndDetails } from '../../../../../../../store/actions';

export const useIsNFT = (
transactionMeta: TransactionMeta,
): { isNFT: boolean; pending: boolean; decimals: string | undefined } => {
): { isNFT: boolean; pending: boolean } => {
const { value, pending } = useAsyncResult(async () => {
return await getTokenStandardAndDetails(
transactionMeta?.txParams?.to as string,
);
}, [transactionMeta]);

const isNFT = value?.standard !== TokenStandard.ERC20;
const decimals = value?.decimals;

return { pending, isNFT, decimals };
return { pending, isNFT };
};

0 comments on commit 8c3d68e

Please sign in to comment.