diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03dc6..fd36f9494e 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,5 +1,6 @@ /// /// +/// // NOTE: This file should not be edited // see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/src/components/common/BuyCryptoButton/index.tsx b/src/components/common/BuyCryptoButton/index.tsx index e6d26e585c..c039737f09 100644 --- a/src/components/common/BuyCryptoButton/index.tsx +++ b/src/components/common/BuyCryptoButton/index.tsx @@ -20,7 +20,7 @@ const useOnrampAppUrl = (): string | undefined => { const useBuyCryptoHref = (): LinkProps['href'] | undefined => { const query = useSearchParams() - const safe = query.get('safe') + const safe = query?.get('safe') const appUrl = useOnrampAppUrl() return useMemo(() => { diff --git a/src/components/common/SafeTokenWidget/index.tsx b/src/components/common/SafeTokenWidget/index.tsx index d930a116e7..79c4aa10fb 100644 --- a/src/components/common/SafeTokenWidget/index.tsx +++ b/src/components/common/SafeTokenWidget/index.tsx @@ -54,7 +54,7 @@ const SafeTokenWidget = () => { const url = { pathname: AppRoutes.apps.open, - query: { safe: query.get('safe'), appUrl: GOVERNANCE_APP_URL }, + query: { safe: query?.get('safe'), appUrl: GOVERNANCE_APP_URL }, } const canRedeemSep5 = canRedeemSep5Airdrop(allocationData) diff --git a/src/components/tx-flow/index.tsx b/src/components/tx-flow/index.tsx index 46b98a6d60..5927f3796e 100644 --- a/src/components/tx-flow/index.tsx +++ b/src/components/tx-flow/index.tsx @@ -32,7 +32,7 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle const safeId = useChainId() + useSafeAddress() const prevSafeId = useRef(safeId ?? '') const pathname = usePathname() - const prevPathname = useRef(pathname) + const prevPathname = useRef(pathname) const handleModalClose = useCallback(() => { if (shouldWarn.current && !confirmClose()) { diff --git a/src/features/recovery/services/recovery-sender.ts b/src/features/recovery/services/recovery-sender.ts index 3f2b48503c..3b9d42dc3b 100644 --- a/src/features/recovery/services/recovery-sender.ts +++ b/src/features/recovery/services/recovery-sender.ts @@ -5,13 +5,11 @@ import type { OnboardAPI } from '@web3-onboard/core' import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay' import type { TransactionResponse } from 'ethers' -import { createWeb3 } from '@/hooks/wallets/web3' import { didReprice, didRevert } from '@/utils/ethers-utils' import { recoveryDispatch, RecoveryEvent, RecoveryTxType } from './recoveryEvents' import { asError } from '@/services/exceptions/utils' -import { assertWalletChain } from '../../../services/tx/tx-sender/sdk' +import { assertWalletChain, getUncheckedSigner } from '../../../services/tx/tx-sender/sdk' import { isSmartContractWallet } from '@/utils/wallets' -import { UncheckedJsonRpcSigner } from '@/utils/providers/UncheckedJsonRpcSigner' async function getDelayModifierContract({ onboard, @@ -25,14 +23,9 @@ async function getDelayModifierContract({ // Switch signer to chain of Safe const wallet = await assertWalletChain(onboard, chainId) - const provider = createWeb3(wallet.provider) const isSmartContract = await isSmartContractWallet(wallet.chainId, wallet.address) - const originalSigner = await provider.getSigner() - // Use unchecked signer for smart contract wallets as transactions do not necessarily immediately execute - const signer = isSmartContract - ? new UncheckedJsonRpcSigner(provider, await originalSigner.getAddress()) - : originalSigner + const signer = await getUncheckedSigner(wallet.provider) const delayModifier = getModuleInstance(KnownContracts.DELAY, delayModifierAddress, signer).connect(signer) return { diff --git a/src/hooks/useIsSidebarRoute.ts b/src/hooks/useIsSidebarRoute.ts index 1b89b2f606..eba57031a6 100644 --- a/src/hooks/useIsSidebarRoute.ts +++ b/src/hooks/useIsSidebarRoute.ts @@ -26,7 +26,7 @@ const TOGGLE_SIDEBAR_ROUTES = [AppRoutes.apps.open] */ export function useIsSidebarRoute(pathname?: string): [boolean, boolean] { const clientPathname = usePathname() - const route = pathname || clientPathname + const route = pathname || clientPathname || '' const noSidebar = NO_SIDEBAR_ROUTES.includes(route) const toggledSidebar = TOGGLE_SIDEBAR_ROUTES.includes(route) const router = useRouter() diff --git a/src/services/tx/tx-sender/dispatch.ts b/src/services/tx/tx-sender/dispatch.ts index af6d905984..e59b981b78 100644 --- a/src/services/tx/tx-sender/dispatch.ts +++ b/src/services/tx/tx-sender/dispatch.ts @@ -1,4 +1,3 @@ -import { UncheckedJsonRpcSigner } from '@/utils/providers/UncheckedJsonRpcSigner' import { relayTransaction, type SafeInfo, type TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' import type { SafeTransaction, TransactionOptions, TransactionResult } from '@safe-global/safe-core-sdk-types' import { didRevert } from '@/utils/ethers-utils' @@ -17,8 +16,9 @@ import { getUncheckedSafeSDK, assertWalletChain, tryOffChainTxSigning, + getUncheckedSigner, } from './sdk' -import { createWeb3, getUserNonce, getWeb3ReadOnly } from '@/hooks/wallets/web3' +import { getUserNonce, getWeb3ReadOnly } from '@/hooks/wallets/web3' import { type OnboardAPI } from '@web3-onboard/core' import { asError } from '@/services/exceptions/utils' import chains from '@/config/chains' @@ -187,12 +187,11 @@ export const dispatchCustomTxSpeedUp = async ( const eventParams = { txId } const wallet = await assertWalletChain(onboard, chainId) const signerNonce = txOptions.nonce - const web3Provider = createWeb3(wallet.provider) - const signer = await web3Provider.getSigner() // Execute the tx let result: TransactionResponse | undefined try { + const signer = await getUncheckedSigner(wallet.provider) result = await signer.sendTransaction({ to, data, ...txOptions }) txDispatch(TxEvent.EXECUTING, eventParams) } catch (error) { @@ -290,10 +289,9 @@ export const dispatchBatchExecution = async ( if (signerNonce === undefined || signerNonce === null) { signerNonce = await getUserNonce(signerAddress) } - const provider = createWeb3(wallet.provider) - const uncheckedJsonRpcSigner = new UncheckedJsonRpcSigner(provider, (await provider.getSigner()).address) + const signer = await getUncheckedSigner(wallet.provider) - result = await multiSendContract.contract.connect(uncheckedJsonRpcSigner).multiSend(multiSendTxData, overrides) + result = await multiSendContract.contract.connect(signer).multiSend(multiSendTxData, overrides) txIds.forEach((txId) => { txDispatch(TxEvent.EXECUTING, { txId, groupKey }) @@ -341,8 +339,8 @@ export const dispatchSpendingLimitTxExecution = async ( let result: ContractTransactionResponse | undefined try { const wallet = await assertWalletChain(onboard, chainId) - const provider = createWeb3(wallet.provider) - const contract = getSpendingLimitContract(chainId, await provider.getSigner()) + const signer = await getUncheckedSigner(wallet.provider) + const contract = getSpendingLimitContract(chainId, signer) result = await contract.executeAllowanceTransfer( txParams.safeAddress, diff --git a/src/services/tx/tx-sender/sdk.ts b/src/services/tx/tx-sender/sdk.ts index 9379b42b37..26f3ea1ee1 100644 --- a/src/services/tx/tx-sender/sdk.ts +++ b/src/services/tx/tx-sender/sdk.ts @@ -1,7 +1,7 @@ import { getSafeSDK } from '@/hooks/coreSDK/safeCoreSDK' import type Safe from '@safe-global/protocol-kit' import { EthersAdapter, SigningMethod } from '@safe-global/protocol-kit' -import type { JsonRpcSigner } from 'ethers' +import type { Eip1193Provider, JsonRpcSigner } from 'ethers' import { ethers } from 'ethers' import { isWalletRejection, isHardwareWallet, isWalletConnect } from '@/utils/wallets' import { OperationType, type SafeTransaction } from '@safe-global/safe-core-sdk-types' @@ -120,6 +120,11 @@ export const getAssertedChainSigner = async ( return provider.getSigner() } +export const getUncheckedSigner = async (provider: Eip1193Provider) => { + const browserProvider = createWeb3(provider) + return new UncheckedJsonRpcSigner(browserProvider, (await browserProvider.getSigner()).address) +} + /** * https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#UncheckedJsonRpcSigner * This resolves the promise sooner when executing a tx and mocks diff --git a/tsconfig.json b/tsconfig.json index 1fc4f56929..d7d47b0276 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "es2020", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -16,11 +20,31 @@ "incremental": true, "baseUrl": ".", "paths": { - "@/*": ["./src/*"], - "@/public/*": ["./public/*"] + "@/*": [ + "./src/*" + ], + "@/public/*": [ + "./public/*" + ] }, - "plugins": [{ "name": "typescript-plugin-css-modules" }] + "plugins": [ + { + "name": "typescript-plugin-css-modules" + }, + { + "name": "next" + } + ] }, - "include": ["next-env.d.ts", "src/definitions.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules", "src/types/contracts"] + "include": [ + "next-env.d.ts", + "src/definitions.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts" + ], + "exclude": [ + "node_modules", + "src/types/contracts" + ] }