From 4ee8adeed3d21c5579c130c3a3d3d8817a22506e Mon Sep 17 00:00:00 2001 From: Howard Braham Date: Mon, 16 Sep 2024 22:56:07 -0400 Subject: [PATCH] fix lint:tsc --- .../nfts/nft-details/nft-full-image.tsx | 5 ++- .../account-list-menu.test.tsx | 1 - .../pages/connections/connections.test.tsx | 32 ++++++++----------- .../pages/connections/connections.tsx | 7 ++-- ui/pages/asset/asset.tsx | 9 ++++-- ui/pages/bridge/index.tsx | 1 - .../confirmations/confirm/stories/utils.tsx | 2 +- 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ui/components/app/assets/nfts/nft-details/nft-full-image.tsx b/ui/components/app/assets/nfts/nft-details/nft-full-image.tsx index 64e2a3191c0e..f280749a1a35 100644 --- a/ui/components/app/assets/nfts/nft-details/nft-full-image.tsx +++ b/ui/components/app/assets/nfts/nft-details/nft-full-image.tsx @@ -30,7 +30,10 @@ export default function NftFullImage() { const nfts = useSelector(getNfts); const nft = nfts.find( ({ address, tokenId }: { address: string; tokenId: string }) => - isEqualCaseInsensitive(address, asset) && id === tokenId.toString(), + address && + asset && + isEqualCaseInsensitive(address, asset) && + id === tokenId.toString(), ); const { image, imageOriginal, name, tokenId } = nft; diff --git a/ui/components/multichain/account-list-menu/account-list-menu.test.tsx b/ui/components/multichain/account-list-menu/account-list-menu.test.tsx index 0f6b64f557f2..7a849577dfa4 100644 --- a/ui/components/multichain/account-list-menu/account-list-menu.test.tsx +++ b/ui/components/multichain/account-list-menu/account-list-menu.test.tsx @@ -105,7 +105,6 @@ describe('AccountListMenu', () => { jest .spyOn(reactRouterDom, 'useHistory') .mockImplementation() - // @ts-expect-error mocking history return .mockReturnValue({ push: historyPushMock }); }); diff --git a/ui/components/multichain/pages/connections/connections.test.tsx b/ui/components/multichain/pages/connections/connections.test.tsx index a9b37e585ae3..0840e3a2f9ed 100644 --- a/ui/components/multichain/pages/connections/connections.test.tsx +++ b/ui/components/multichain/pages/connections/connections.test.tsx @@ -1,13 +1,12 @@ import React from 'react'; -import { Router, Route } from 'react-router-dom'; // Import Router and Route -import { createMemoryHistory } from 'history'; +import { MemoryRouter, Route } from 'react-router-dom'; +import mockState from '../../../../../test/data/mock-state.json'; import { fireEvent, renderWithProvider, waitFor, } from '../../../../../test/jest'; import configureStore from '../../../../store/store'; -import mockState from '../../../../../test/data/mock-state.json'; import { Connections } from './connections'; describe('Connections Content', () => { @@ -88,15 +87,14 @@ describe('Connections Content', () => { }); it('should render correctly', () => { - const history = createMemoryHistory(); - history.push('/connect/https%3A%2F%2Fmetamask.github.io'); - const { container, getByTestId } = renderWithProvider( - + - , + , connectedStore, ); expect(container).toMatchSnapshot(); @@ -104,30 +102,28 @@ describe('Connections Content', () => { }); it('it should render Disconnect all Account button of the page', () => { - const history = createMemoryHistory(); - history.push('/connect/https%3A%2F%2Fmetamask.github.io'); - const { getByText } = renderWithProvider( - + - , + , connectedStore, ); expect(getByText('Disconnect all accounts')).toBeInTheDocument(); }); it('it should trigger disconnect all accounts modal flow when disconnect all accounts button is clicked', async () => { - const history = createMemoryHistory(); - history.push('/connect/https%3A%2F%2Fmetamask.github.io'); - const { getByText, getByTestId } = renderWithProvider( - + - , + , connectedStore, ); diff --git a/ui/components/multichain/pages/connections/connections.tsx b/ui/components/multichain/pages/connections/connections.tsx index ae1f5b88193e..10404eb75331 100644 --- a/ui/components/multichain/pages/connections/connections.tsx +++ b/ui/components/multichain/pages/connections/connections.tsx @@ -85,10 +85,9 @@ export const Connections = () => { setShowDisconnectedAllAccountsUpdatedToast, ] = useState(false); - const urlParams: { origin: string } = useParams(); - const securedOrigin = decodeURIComponent(urlParams.origin); + const urlParams = useParams<{ origin: string }>(); + const activeTabOrigin = decodeURIComponent(urlParams.origin || ''); - const activeTabOrigin: string = securedOrigin; // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any const subjectMetadata: { [key: string]: any } = useSelector( @@ -246,7 +245,7 @@ export const Connections = () => { textAlign={TextAlign.Center} ellipsis > - {getURLHost(securedOrigin)} + {getURLHost(activeTabOrigin)} diff --git a/ui/pages/asset/asset.tsx b/ui/pages/asset/asset.tsx index 975ff2e5cc25..e931279113b0 100644 --- a/ui/pages/asset/asset.tsx +++ b/ui/pages/asset/asset.tsx @@ -20,13 +20,16 @@ const Asset = () => { const nfts = useSelector(getNfts); const { asset, id } = useParams<{ asset: string; id: string }>(); - const token = tokens.find(({ address }: { address: string }) => - isEqualCaseInsensitive(address, asset), + const token = tokens.find( + ({ address }: { address: string }) => + asset && isEqualCaseInsensitive(address, asset), ); const nft = nfts.find( ({ address, tokenId }: { address: string; tokenId: string }) => - isEqualCaseInsensitive(address, asset) && id === tokenId.toString(), + asset && + isEqualCaseInsensitive(address, asset) && + id === tokenId.toString(), ); useEffect(() => { diff --git a/ui/pages/bridge/index.tsx b/ui/pages/bridge/index.tsx index f216a52ec71d..780a19bd71f4 100644 --- a/ui/pages/bridge/index.tsx +++ b/ui/pages/bridge/index.tsx @@ -40,7 +40,6 @@ const CrossChainSwap = () => { const redirectToDefaultRoute = async () => { history.push({ pathname: DEFAULT_ROUTE, - // @ts-expect-error - property 'state' does not exist on type PartialPath. state: { stayOnHomePage: true }, }); dispatch(clearSwapsState()); diff --git a/ui/pages/confirmations/confirm/stories/utils.tsx b/ui/pages/confirmations/confirm/stories/utils.tsx index dd194d574109..9c68a392cbd7 100644 --- a/ui/pages/confirmations/confirm/stories/utils.tsx +++ b/ui/pages/confirmations/confirm/stories/utils.tsx @@ -46,7 +46,7 @@ export function ConfirmStoryTemplate( }`, ]} > - } /> + } /> );