From d27bf0e4452afb7f3aa4bc676fd7bb02586f0921 Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Wed, 21 Aug 2024 13:00:49 +0200 Subject: [PATCH] Fix or surpress strict type errors --- .../keychain/src/components/ErrorBoundary.tsx | 8 ++--- .../keychain/src/components/Execute/Fees.tsx | 6 ++-- packages/keychain/src/components/Funding.tsx | 3 +- .../keychain/src/components/SignMessage.tsx | 4 +++ .../keychain/src/components/Transaction.tsx | 2 +- .../src/components/bridge/BridgeEth.tsx | 9 +++-- .../src/components/bridge/TransferButton.tsx | 3 +- .../components/connect/Authenticate/index.tsx | 2 +- .../src/components/connect/CreateSession.tsx | 2 +- .../keychain/src/components/connect/Login.tsx | 13 ++++--- .../src/components/connect/Signup.tsx | 11 ++++-- .../layout/Footer/TransactionSummary.tsx | 2 +- .../src/components/layout/Footer/index.tsx | 4 +-- packages/keychain/src/errors.ts | 10 ++++++ packages/keychain/src/hooks/account.ts | 11 ++++-- packages/keychain/src/hooks/connection.tsx | 34 +++++++++++++++---- packages/keychain/src/hooks/deploy.ts | 7 ++-- packages/keychain/src/hooks/policy.ts | 6 ++++ packages/keychain/src/hooks/theme.tsx | 6 ++-- packages/keychain/src/hooks/transaction.ts | 2 +- packages/keychain/src/pages/pending.tsx | 4 +++ .../keychain/src/pages/slot/session/index.tsx | 3 ++ packages/keychain/src/utils/account.ts | 4 +++ .../keychain/src/utils/connection/connect.ts | 2 +- .../keychain/src/utils/connection/execute.ts | 4 ++- .../keychain/src/utils/connection/index.ts | 4 +-- .../keychain/src/utils/connection/probe.ts | 4 +-- packages/keychain/src/utils/controller.ts | 10 ++++-- packages/keychain/src/utils/url.ts | 4 +++ 29 files changed, 138 insertions(+), 46 deletions(-) diff --git a/packages/keychain/src/components/ErrorBoundary.tsx b/packages/keychain/src/components/ErrorBoundary.tsx index ac7c87609..d7e97bf3a 100644 --- a/packages/keychain/src/components/ErrorBoundary.tsx +++ b/packages/keychain/src/components/ErrorBoundary.tsx @@ -1,4 +1,4 @@ -import React, { PropsWithChildren } from "react"; +import React, { ErrorInfo, PropsWithChildren } from "react"; import { Container, Content, Footer } from "./layout"; import { AlertIcon, ExternalIcon } from "@cartridge/ui"; import { Button, HStack, Link, Text } from "@chakra-ui/react"; @@ -10,16 +10,16 @@ export class ErrorBoundary extends React.Component< PropsWithChildren, { error?: Error } > { - constructor(props) { + constructor(props: PropsWithChildren) { super(props); this.state = {}; } - static getDerivedStateFromError(error) { + static getDerivedStateFromError(error: Error) { return { error }; } - componentDidCatch(error, errorInfo) { + componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.log({ error, errorInfo }); } diff --git a/packages/keychain/src/components/Execute/Fees.tsx b/packages/keychain/src/components/Execute/Fees.tsx index 99319581b..8f61b228e 100644 --- a/packages/keychain/src/components/Execute/Fees.tsx +++ b/packages/keychain/src/components/Execute/Fees.tsx @@ -19,10 +19,10 @@ export function Fees({ }>(); useEffect(() => { - if (!fees) { - return; - } async function compute() { + if (!fees) { + return; + } setFormattedFee( fees.max > 10000000000000n ? { diff --git a/packages/keychain/src/components/Funding.tsx b/packages/keychain/src/components/Funding.tsx index 056527f76..c9bb6963a 100644 --- a/packages/keychain/src/components/Funding.tsx +++ b/packages/keychain/src/components/Funding.tsx @@ -146,7 +146,8 @@ function FundingInner({ onComplete }: FundingInnerProps) { try { const transaction_hash = await deploySelf(ETH_MIN_PREFUND); onComplete(transaction_hash); - } catch (e) { + } catch (_e) { + const e = _e as Error; if (e.message && e.message.includes("DuplicateTx")) { onComplete(); return; diff --git a/packages/keychain/src/components/SignMessage.tsx b/packages/keychain/src/components/SignMessage.tsx index c040893c5..2b6b5e5ec 100644 --- a/packages/keychain/src/components/SignMessage.tsx +++ b/packages/keychain/src/components/SignMessage.tsx @@ -31,12 +31,15 @@ export function SignMessage({ ) => { for (const typeMember of messageType) { if (typeMember.type === "felt*") { + // @ts-expect-error TODO(#602): Fix type const stringArray: Array = initial[typeMember.name].map( (hex: string) => shortString.decodeShortString(hex), ); + // @ts-expect-error TODO(#602): Fix type initial[typeMember.name] = stringArray.join(""); } else if (typeMember.type !== "felt" && typeMember.type !== "string") { convertFeltArraysToString( + // @ts-expect-error TODO(#602): Fix type initial[typeMember.name], typedData.types[typeMember.type], ); @@ -69,6 +72,7 @@ export function SignMessage({ const ptName = messageData.primaryType; const pt = messageData.types[ptName]; const values = (typeName: string) => { + // @ts-expect-error TODO(#602): Fix type const v = messageData.message[typeName]; if (typeof v === "object") { return Object.entries(v).map(([key, value]) => { diff --git a/packages/keychain/src/components/Transaction.tsx b/packages/keychain/src/components/Transaction.tsx index f30cc0b6d..da3f94bc1 100644 --- a/packages/keychain/src/components/Transaction.tsx +++ b/packages/keychain/src/components/Transaction.tsx @@ -21,7 +21,7 @@ export interface TransactionProps { name: string; hash: string; chainId: constants.StarknetChainId; - finalized?: (TransactionState) => void; + finalized?: (txState: TransactionState) => void; } export function Transaction({ diff --git a/packages/keychain/src/components/bridge/BridgeEth.tsx b/packages/keychain/src/components/bridge/BridgeEth.tsx index 8dc495b5b..072947aae 100644 --- a/packages/keychain/src/components/bridge/BridgeEth.tsx +++ b/packages/keychain/src/components/bridge/BridgeEth.tsx @@ -76,6 +76,7 @@ export function BridgeEth({ if (chainId === constants.StarknetChainId.SN_MAIN) { const { data } = await fetchEthPrice(); const usdeth = parseFloat(data.price.amount); + // @ts-expect-error TODO(#602): Fix type const inputValue = parseFloat(debouncedValue); const cost = inputValue * usdeth; const dollarUSLocale = Intl.NumberFormat("en-US"); @@ -87,7 +88,9 @@ export function BridgeEth({ } function validateValue(): boolean { + // @ts-expect-error TODO(#602): Fix type const inputValue = parseFloat(debouncedValue); + // @ts-expect-error TODO(#602): Fix type const balance = parseFloat(ethBalance); if (inputValue > balance) { return false; @@ -218,6 +221,7 @@ export function BridgeEth({ { if (error === null) { + // @ts-expect-error TODO(#602): Fix type setErrorMessage(null); return; } else if (error.name === "ChainMismatchError") { @@ -282,13 +287,13 @@ const { chains, publicClient } = configureChains( [mainnet, sepolia], [ alchemyProvider({ - apiKey: process.env.NEXT_PUBLIC_ETH_RPC_MAINNET.replace( + apiKey: process.env.NEXT_PUBLIC_ETH_RPC_MAINNET!.replace( /^.+\/v2\//, "$`", ), }), alchemyProvider({ - apiKey: process.env.NEXT_PUBLIC_ETH_RPC_SEPOLIA.replace( + apiKey: process.env.NEXT_PUBLIC_ETH_RPC_SEPOLIA!.replace( /^.+\/v2\//, "$`", ), diff --git a/packages/keychain/src/components/bridge/TransferButton.tsx b/packages/keychain/src/components/bridge/TransferButton.tsx index 89d771aba..74d185ab4 100644 --- a/packages/keychain/src/components/bridge/TransferButton.tsx +++ b/packages/keychain/src/components/bridge/TransferButton.tsx @@ -77,10 +77,11 @@ export function TransferButton({ abi: EthL1BridgeABI, functionName: "deposit", args: [parseEther(value?.length ? value : "0"), BigInt(account.address)], + // @ts-expect-error TODO(#602): Fix type overrides: { value: value && l2Fee ? parseEther(value) + BigInt(l2Fee) : undefined, }, - enabled: !disabled && value && !!l2Fee, + enabled: !disabled && !!value && !!l2Fee, }); const { data, write } = useContractWrite(config); diff --git a/packages/keychain/src/components/connect/Authenticate/index.tsx b/packages/keychain/src/components/connect/Authenticate/index.tsx index 6bdba75f3..11299b247 100644 --- a/packages/keychain/src/components/connect/Authenticate/index.tsx +++ b/packages/keychain/src/components/connect/Authenticate/index.tsx @@ -42,7 +42,7 @@ export function Authenticate({ } }, [onSuccess, action, name]); - if (!isSupported) { + if (!isSupported && !!message) { return ; } diff --git a/packages/keychain/src/components/connect/CreateSession.tsx b/packages/keychain/src/components/connect/CreateSession.tsx index 564178dbf..5571971a6 100644 --- a/packages/keychain/src/components/connect/CreateSession.tsx +++ b/packages/keychain/src/components/connect/CreateSession.tsx @@ -26,7 +26,7 @@ export function CreateSession({ await controller.approve(origin, expiresAt, policies, maxFees); onConnect(policies); } catch (e) { - setError(e); + setError(e as Error); setIsConnecting(false); } }, [controller, origin, expiresAt, policies, maxFees, onConnect]); diff --git a/packages/keychain/src/components/connect/Login.tsx b/packages/keychain/src/components/connect/Login.tsx index ba1ca7c2f..35fce589d 100644 --- a/packages/keychain/src/components/connect/Login.tsx +++ b/packages/keychain/src/components/connect/Login.tsx @@ -4,7 +4,6 @@ import { Container, Footer, Content, useLayout } from "components/layout"; import { useCallback, useEffect, useState } from "react"; import Controller from "utils/controller"; import { LoginMode, LoginProps } from "./types"; -import { useAnalytics } from "hooks/analytics"; import { fetchAccount, validateUsernameFor } from "./utils"; import { RegistrationLink } from "./RegistrationLink"; import { useControllerTheme } from "hooks/theme"; @@ -39,11 +38,13 @@ function Form({ }: LoginProps) { const { footer } = useLayout(); const { origin, policies, chainId, rpcUrl, setController } = useConnection(); - const { event: log } = useAnalytics(); const [isLoading, setIsLoading] = useState(false); const [expiresAt] = useState(3000000000n); const [error, setError] = useState(); - const [usernameField, setUsernameField] = useState({ + const [usernameField, setUsernameField] = useState<{ + value: string; + error?: string; + }>({ value: prefilledName, error: undefined, }); @@ -63,9 +64,11 @@ function Form({ const { account: { + // @ts-expect-error TODO(#602): Fix type credentials: { webauthn: [{ id: credentialId, publicKey }], }, + // @ts-expect-error TODO(#602): Fix type contractAddress: address, }, } = await fetchAccount(usernameField.value); @@ -93,7 +96,8 @@ function Form({ if (onSuccess) { onSuccess(); } - } catch (e) { + } catch (_e) { + const e = _e as Error; setError(e); } @@ -106,7 +110,6 @@ function Form({ policies, expiresAt, mode, - log, onSuccess, setController, ]); diff --git a/packages/keychain/src/components/connect/Signup.tsx b/packages/keychain/src/components/connect/Signup.tsx index 9b6fcfa21..3261bc763 100644 --- a/packages/keychain/src/components/connect/Signup.tsx +++ b/packages/keychain/src/components/connect/Signup.tsx @@ -27,7 +27,10 @@ export function Signup({ const { deployRequest } = useDeploy(); const [error, setError] = useState(); const [isRegistering, setIsRegistering] = useState(false); - const [usernameField, setUsernameField] = useState({ + const [usernameField, setUsernameField] = useState<{ + value: string; + error?: string; + }>({ value: prefilledName, error: undefined, }); @@ -106,7 +109,7 @@ export function Signup({ refetchOnWindowFocus: false, staleTime: 10000000, cacheTime: 10000000, - refetchInterval: (data) => (!data ? 1000 : undefined), + refetchInterval: (data) => (!data ? 1000 : false), onSuccess: async (data) => { try { if ( @@ -118,9 +121,11 @@ export function Signup({ const { account: { + // @ts-expect-error TODO(#602): Fix type credentials: { webauthn: [{ id: credentialId, publicKey }], }, + // @ts-expect-error TODO(#602): Fix type contractAddress: address, }, } = data; @@ -142,7 +147,7 @@ export function Signup({ onSuccess(); } } catch (e) { - setError(e); + setError(e as Error); } }, }, diff --git a/packages/keychain/src/components/layout/Footer/TransactionSummary.tsx b/packages/keychain/src/components/layout/Footer/TransactionSummary.tsx index 4b1653217..c06464650 100644 --- a/packages/keychain/src/components/layout/Footer/TransactionSummary.tsx +++ b/packages/keychain/src/components/layout/Footer/TransactionSummary.tsx @@ -8,7 +8,7 @@ export function TransactionSummary({ }: { isSlot: boolean; createSession: boolean; - hostname: string; + hostname?: string; }) { return ( diff --git a/packages/keychain/src/components/layout/Footer/index.tsx b/packages/keychain/src/components/layout/Footer/index.tsx index abb049401..f53ba1904 100644 --- a/packages/keychain/src/components/layout/Footer/index.tsx +++ b/packages/keychain/src/components/layout/Footer/index.tsx @@ -1,6 +1,6 @@ import { HStack, IconButton, Spacer, Text, VStack } from "@chakra-ui/react"; import { CartridgeLogo, WedgeUpIcon } from "@cartridge/ui"; -import React, { useEffect, useMemo, useRef } from "react"; +import React, { MutableRefObject, useEffect, useMemo, useRef } from "react"; import { FOOTER_HEIGHT, PORTAL_WINDOW_HEIGHT, @@ -82,7 +82,7 @@ export function Footer({ }} backgroundColor="var(--chakra-colors-solid-bg)" overflow="hidden" - ref={ref} + ref={ref as MutableRefObject} > { - if (!hasPlatformAuthenticator || navigator.userAgent.indexOf("Win") != -1) + if (!hasPlatformAuthenticator || navigator.userAgent.indexOf("Win") != -1) { + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.authenticatorSelection.authenticatorAttachment = "cross-platform"; - else + } else { + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.authenticatorSelection.authenticatorAttachment = undefined; + } + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.user.id = Buffer.from(name); + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.challenge = base64url.toBuffer( + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.challenge as unknown as string, ); + // @ts-expect-error TODO(#602): Fix type beginRegistration.publicKey.rp.id = process.env.NEXT_PUBLIC_RP_ID; const credentials = (await navigator.credentials.create( beginRegistration, diff --git a/packages/keychain/src/hooks/connection.tsx b/packages/keychain/src/hooks/connection.tsx index 8aec2ace1..9ee26c6d0 100644 --- a/packages/keychain/src/hooks/connection.tsx +++ b/packages/keychain/src/hooks/connection.tsx @@ -23,8 +23,11 @@ import { RpcProvider, CallData, constants, shortString } from "starknet"; import { Policy, Prefund, ResponseCodes } from "@cartridge/controller"; import { mergeDefaultETHPrefund } from "utils/token"; import { isIframe } from "components/connect/utils"; +import { ControllerNotReady } from "errors"; -const ConnectionContext = createContext(undefined); +const ConnectionContext = createContext( + undefined, +); type ConnectionContextValue = { context: ConnectionCtx; @@ -36,7 +39,7 @@ type ConnectionContextValue = { policies: Policy[]; prefunds: Prefund[]; hasPrefundRequest: boolean; - error: Error; + error?: Error; setContext: (context: ConnectionCtx) => void; setController: (controller: Controller) => void; cancel: () => void; @@ -95,6 +98,7 @@ export function ConnectionProvider({ children }: PropsWithChildren) { if (!parent) return; try { + // @ts-expect-error TODO(#602): Fix type context.resolve({ code: ResponseCodes.CANCELED, message: "User aborted", @@ -206,6 +210,10 @@ export function ConnectionProvider({ children }: PropsWithChildren) { const setDelegateTransaction = useCallback( (context: ConnectionCtx, delegateAddress: string) => { + if (!controller) { + throw new ControllerNotReady(); + } + setContext({ origin: context.origin, transactions: [ @@ -224,11 +232,15 @@ export function ConnectionProvider({ children }: PropsWithChildren) { }, } as ExecuteCtx); }, - [controller?.address, openSettings], + [controller, openSettings], ); const setExternalOwnerTransaction = useCallback( (context: ConnectionCtx, externalOwnerAddress: string) => { + if (!controller) { + throw new ControllerNotReady(); + } + setContext({ origin: context.origin, transactions: [ @@ -247,11 +259,15 @@ export function ConnectionProvider({ children }: PropsWithChildren) { }, } as ExecuteCtx); }, - [controller?.address, openSettings], + [controller, openSettings], ); const removeExternalOwnerTransaction = useCallback( (context: ConnectionCtx, externalOwnerAddress: string) => { + if (!controller) { + throw new ControllerNotReady(); + } + setContext({ origin: context.origin, transactions: [ @@ -270,17 +286,23 @@ export function ConnectionProvider({ children }: PropsWithChildren) { }, } as ExecuteCtx); }, - [controller?.address, openSettings], + [controller, openSettings], ); return ( Promise }>; export function useConnection() { - const ctx = useContext(ConnectionContext); + const ctx = useContext(ConnectionContext); if (!ctx) { throw new Error("ConnectionProvider must be placed"); } diff --git a/packages/keychain/src/hooks/deploy.ts b/packages/keychain/src/hooks/deploy.ts index 061e7c501..04b3ea134 100644 --- a/packages/keychain/src/hooks/deploy.ts +++ b/packages/keychain/src/hooks/deploy.ts @@ -59,7 +59,8 @@ export const useDeploy = (): DeployInterface => { setIsDeployed(true); return hash.deployAccount; - } catch (e) { + } catch (_e) { + const e = _e as Error; if (!e.message.includes("account already deployed")) { throw e; } @@ -81,7 +82,8 @@ export const useDeploy = (): DeployInterface => { setIsDeployed(true); return transaction_hash; - } catch (e) { + } catch (_e) { + const e = _e as Error; if (!e.message.includes("account already deployed")) { throw e; } @@ -93,6 +95,7 @@ export const useDeploy = (): DeployInterface => { ); return { + // @ts-expect-error TODO(#602): Fix type deployRequest, deploySelf, isDeploying, diff --git a/packages/keychain/src/hooks/policy.ts b/packages/keychain/src/hooks/policy.ts index 854d8daf5..52c5514d8 100644 --- a/packages/keychain/src/hooks/policy.ts +++ b/packages/keychain/src/hooks/policy.ts @@ -43,15 +43,20 @@ export function useUrlPolicys(): { const requestDict = {}; requests.forEach((policy) => { + // @ts-expect-error TODO(#602): Fix type requestDict[policy.target] = requestDict[policy.target] || []; + // @ts-expect-error TODO(#602): Fix type requestDict[policy.target].push(policy.method); }); + // @ts-expect-error TODO(#602): Fix type const promises = []; Object.keys(requestDict).forEach((target) => { + // @ts-expect-error TODO(#602): Fix type promises.push(getValidPolicys(requestDict[target], target)); }); + // @ts-expect-error TODO(#602): Fix type Promise.all(promises) .then((policies) => { policies = policies.flat(); @@ -63,6 +68,7 @@ export function useUrlPolicys(): { }); }, [router]); + // @ts-expect-error TODO(#602): Fix type return { isValidating, chainId, validPolicys, invalidPolicys, origin }; } diff --git a/packages/keychain/src/hooks/theme.tsx b/packages/keychain/src/hooks/theme.tsx index 855bed59d..aa2588cee 100644 --- a/packages/keychain/src/hooks/theme.tsx +++ b/packages/keychain/src/hooks/theme.tsx @@ -15,7 +15,9 @@ import { ProviderProps, } from "react"; -const ControllerThemeContext = createContext(undefined); +const ControllerThemeContext = createContext( + undefined, +); export function ControllerThemeProvider({ value, @@ -35,7 +37,7 @@ export function ControllerThemeProvider({ } export function useControllerTheme() { - const ctx = useContext(ControllerThemeContext); + const ctx = useContext(ControllerThemeContext); if (!ctx) { throw new Error("ControllerThemeProvider must be placed"); } diff --git a/packages/keychain/src/hooks/transaction.ts b/packages/keychain/src/hooks/transaction.ts index c3bc1378d..e7f33b9d4 100644 --- a/packages/keychain/src/hooks/transaction.ts +++ b/packages/keychain/src/hooks/transaction.ts @@ -8,7 +8,7 @@ export type Transaction = { }; export function useUrlTxns(): { - chainId: constants.StarknetChainId; + chainId?: constants.StarknetChainId; txns: Transaction[]; } { const router = useRouter(); diff --git a/packages/keychain/src/pages/pending.tsx b/packages/keychain/src/pages/pending.tsx index cc7afc58e..cebf9e49c 100644 --- a/packages/keychain/src/pages/pending.tsx +++ b/packages/keychain/src/pages/pending.tsx @@ -28,6 +28,10 @@ function Pending() { //pending }, [txnResults, txns]); + if (!chainId) { + return null; + } + return ( diff --git a/packages/keychain/src/pages/slot/session/index.tsx b/packages/keychain/src/pages/slot/session/index.tsx index ddbb2ed42..d35657139 100644 --- a/packages/keychain/src/pages/slot/session/index.tsx +++ b/packages/keychain/src/pages/slot/session/index.tsx @@ -87,9 +87,11 @@ function CreateSession() { .then((res) => { const { account: { + // @ts-expect-error TODO(#602): Fix type credentials: { webauthn: [{ id: credentialId, publicKey }], }, + // @ts-expect-error TODO(#602): Fix type contractAddress: address, }, } = res; @@ -121,6 +123,7 @@ function CreateSession() { let calls = policies.map((policy) => { return { contractAddress: policy.target, + // @ts-expect-error TODO(#602): Fix type entrypoint: hash.getSelector(policy.method), calldata: [], } as Call; diff --git a/packages/keychain/src/utils/account.ts b/packages/keychain/src/utils/account.ts index 568fa708e..fab0ee915 100644 --- a/packages/keychain/src/utils/account.ts +++ b/packages/keychain/src/utils/account.ts @@ -120,11 +120,13 @@ class Account extends BaseAccount { ): Promise { this.ensureDeployed(); + // @ts-expect-error TODO(#602): Fix type details.nonce = details.nonce ?? (await super.getNonce("pending")); const res = await this.cartridge.execute(normalizeCalls(calls), details); Storage.update(this.selector, { + // @ts-expect-error TODO(#602): Fix type nonce: num.toHex(BigInt(details.nonce) + 1n), }); @@ -162,11 +164,13 @@ class Account extends BaseAccount { hash: BigNumberish, signature: Signature, ): Promise { + // @ts-expect-error TODO(#602): Fix type if (BigInt(signature[0]) === 0n) { return ec.starkCurve.verify( // @ts-expect-error TODO: fix overload type mismatch signature, BigInt(hash).toString(), + // @ts-expect-error TODO(#602): Fix type signature[0], ); } diff --git a/packages/keychain/src/utils/connection/connect.ts b/packages/keychain/src/utils/connection/connect.ts index 0b0afb6b7..9025a9c9a 100644 --- a/packages/keychain/src/utils/connection/connect.ts +++ b/packages/keychain/src/utils/connection/connect.ts @@ -32,7 +32,7 @@ export function connectFactory({ } export function disconnectFactory( - setController: (controller: Controller) => void, + setController: (controller?: Controller) => void, ) { return (controller: Controller) => { controller.delete(); diff --git a/packages/keychain/src/utils/connection/execute.ts b/packages/keychain/src/utils/connection/execute.ts index b0e85dd5d..ec64dc280 100644 --- a/packages/keychain/src/utils/connection/execute.ts +++ b/packages/keychain/src/utils/connection/execute.ts @@ -60,6 +60,7 @@ export function executeFactory({ } const { nonce, maxFee } = await getInvocationDetails( + // @ts-expect-error TODO(#602): Fix type transactionsDetail, account, calls, @@ -74,7 +75,7 @@ export function executeFactory({ } catch (e) { return { code: ResponseCodes.NOT_ALLOWED, - message: e.message, + message: (e as Error).message, }; } }; @@ -94,6 +95,7 @@ async function tryPaymaster( account: Account, calls: Call[], paymaster: PaymasterOptions, + // @ts-expect-error TODO(#602): Fix type ): Promise { try { const transaction_hash = await account.cartridge.executeFromOutside( diff --git a/packages/keychain/src/utils/connection/index.ts b/packages/keychain/src/utils/connection/index.ts index 9ea5a44c0..b9aa37137 100644 --- a/packages/keychain/src/utils/connection/index.ts +++ b/packages/keychain/src/utils/connection/index.ts @@ -26,8 +26,8 @@ export function connectToController({ setOrigin: (origin: string) => void; setRpcUrl: (url: string) => void; setPolicies: (policies: Policy[]) => void; - setContext: (ctx: ConnectionCtx) => void; - setController: (controller: Controller) => void; + setContext: (ctx?: ConnectionCtx) => void; + setController: (controller?: Controller) => void; }) { return connectToParent({ methods: { diff --git a/packages/keychain/src/utils/connection/probe.ts b/packages/keychain/src/utils/connection/probe.ts index 8381248a4..d7bfc1ca7 100644 --- a/packages/keychain/src/utils/connection/probe.ts +++ b/packages/keychain/src/utils/connection/probe.ts @@ -5,11 +5,11 @@ export function probeFactory({ setController, setRpcUrl, }: { - setController: (controller: Controller) => void; + setController: (controller?: Controller) => void; setRpcUrl: (rpcUrl: string) => void; }) { return (origin: string) => - (rpcUrl?: string): Promise => { + (rpcUrl: string): Promise => { const controller = Controller.fromStore(origin); if (!controller) { return Promise.reject({ diff --git a/packages/keychain/src/utils/controller.ts b/packages/keychain/src/utils/controller.ts index 2905db956..e7ccdda25 100644 --- a/packages/keychain/src/utils/controller.ts +++ b/packages/keychain/src/utils/controller.ts @@ -28,6 +28,7 @@ export default class Controller { public username: string; public chainId: string; public rpcUrl: string; + // @ts-expect-error TODO(#602): Fix type public signer: SignerInterface; protected publicKey: string; protected credentialId: string; @@ -61,9 +62,10 @@ export default class Controller { rpcUrl, address, username, + // @ts-expect-error TODO(#602): Fix type this.signer, { - rpId: process.env.NEXT_PUBLIC_RP_ID, + rpId: process.env.NEXT_PUBLIC_RP_ID!, credentialId, publicKey, }, @@ -119,7 +121,10 @@ export default class Controller { Storage.set("version", VERSION); Storage.set( - selectors[VERSION].admin(this.address, process.env.NEXT_PUBLIC_ADMIN_URL), + selectors[VERSION].admin( + this.address, + process.env.NEXT_PUBLIC_ADMIN_URL!, + ), {}, ); Storage.set(selectors[VERSION].active(), { @@ -165,6 +170,7 @@ export default class Controller { const { username, publicKey, credentialId } = controller; if (version !== VERSION) { + // @ts-expect-error TODO(#602): Fix type migrations[version][VERSION](address); } diff --git a/packages/keychain/src/utils/url.ts b/packages/keychain/src/utils/url.ts index 02a31cc6d..f319628f9 100644 --- a/packages/keychain/src/utils/url.ts +++ b/packages/keychain/src/utils/url.ts @@ -102,7 +102,9 @@ export const PopupCenter = ( targetWidth = mobile() ? null : w, targetHeight = mobile() ? null : h, V = screenX < 0 ? window.screen.width + screenX : screenX, + // @ts-expect-error TODO(#602): Fix type left = parseInt(String(V + (outerWidth - targetWidth) / 2), 10), + // @ts-expect-error TODO(#602): Fix type right = parseInt(String(screenY + (outerHeight - targetHeight) / 2.5), 10), features = []; if (targetWidth !== null) { @@ -117,7 +119,9 @@ export const PopupCenter = ( var newWindow = window.open(url, title, features.join(",")); + // @ts-expect-error TODO(#602): Fix type if (window.focus) { + // @ts-expect-error TODO(#602): Fix type newWindow.focus(); }