From 0df6caf3100328ab6369b08621366ae294bfbc58 Mon Sep 17 00:00:00 2001 From: schmanu Date: Tue, 1 Aug 2023 13:21:48 +0200 Subject: [PATCH] fix: type errors (excluding tests) --- .../SafeAppLandingPage/AppActions.tsx | 4 ++-- .../sidebar/PendingActions/index.tsx | 2 +- .../flows/ExecuteBatch/ReviewBatch.tsx | 11 +++++----- .../flows/SafeAppsTx/ReviewSafeAppsTx.tsx | 9 ++++---- .../ReviewSignMessageOnChain.tsx | 9 ++++---- .../TokenTransfer/ReviewSpendingLimitTx.tsx | 16 +++++++++----- .../tx/ExecutionMethodSelector/index.tsx | 3 +-- .../messages/useSyncSafeMessageSigner.ts | 22 ++++++++++++++----- src/hooks/useIsValidExecution.ts | 4 ++-- src/hooks/useOwnedSafes.ts | 3 ++- src/services/safe-messages/safeMsgSender.ts | 14 ++++++------ 11 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/components/safe-apps/SafeAppLandingPage/AppActions.tsx b/src/components/safe-apps/SafeAppLandingPage/AppActions.tsx index b82a002799..cd58891609 100644 --- a/src/components/safe-apps/SafeAppLandingPage/AppActions.tsx +++ b/src/components/safe-apps/SafeAppLandingPage/AppActions.tsx @@ -3,7 +3,7 @@ import type { ChainInfo, SafeAppData } from '@safe-global/safe-gateway-typescrip import { useEffect, useMemo, useState } from 'react' import Link from 'next/link' import type { UrlObject } from 'url' -import type { ConnectedWallet } from '@/hooks/wallets/useOnboard' +import type { ConnectedWallet } from '@privy-io/react-auth' import { useAppSelector } from '@/store' import { selectAllAddressBooks } from '@/store/addressBookSlice' import { selectChains } from '@/store/chainsSlice' @@ -18,7 +18,7 @@ import CreateNewSafeSVG from '@/public/images/open/safe-creation.svg' type Props = { appUrl: string - wallet: ConnectedWallet | null + wallet: ConnectedWallet | null | undefined onConnectWallet: () => Promise chain: ChainInfo app: SafeAppData diff --git a/src/components/sidebar/PendingActions/index.tsx b/src/components/sidebar/PendingActions/index.tsx index d377b22806..03b5743430 100644 --- a/src/components/sidebar/PendingActions/index.tsx +++ b/src/components/sidebar/PendingActions/index.tsx @@ -52,7 +52,7 @@ const PendingActionButtons = ({ borderBottomRightRadius: ({ shape }) => shape.borderRadius, }} > - + {totalToSign} diff --git a/src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx b/src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx index c1277142af..a4abcc515b 100644 --- a/src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx +++ b/src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx @@ -15,7 +15,6 @@ import DecodedTxs from '@/components/tx-flow/flows/ExecuteBatch/DecodedTxs' import { TxSimulation } from '@/components/tx/security/tenderly' import { WrongChainWarning } from '@/components/tx/WrongChainWarning' import { useRelaysBySafe } from '@/hooks/useRemainingRelays' -import useOnboard from '@/hooks/wallets/useOnboard' import { useWeb3 } from '@/hooks/wallets/web3' import { logError, Errors } from '@/services/exceptions' import { dispatchBatchExecution, dispatchBatchExecutionRelay } from '@/services/tx/tx-sender' @@ -31,7 +30,8 @@ import commonCss from '@/components/tx-flow/common/styles.module.css' import { TxModalContext } from '@/components/tx-flow' import useGasPrice from '@/hooks/useGasPrice' import { hasFeature } from '@/utils/chains' -import type { PayableOverrides } from 'ethers' +import { ethers, type PayableOverrides } from 'ethers' +import useWallet from '@/hooks/wallets/useWallet' export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => { const [isSubmittable, setIsSubmittable] = useState(true) @@ -51,7 +51,7 @@ export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => { // Chain has relaying feature and available relays const canRelay = hasRemainingRelays(relays) const willRelay = canRelay && executionMethod === ExecutionMethod.RELAY - const onboard = useOnboard() + const [wallet] = useWallet() const web3 = useWeb3() const [txsWithDetails, error, loading] = useAsync(() => { @@ -75,7 +75,8 @@ export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => { }, [txsWithDetails, multiSendTxs]) const onExecute = async () => { - if (!onboard || !multiSendTxData || !multiSendContract || !txsWithDetails || gasPriceLoading) return + if (!wallet || !wallet.provider || !multiSendTxData || !multiSendContract || !txsWithDetails || gasPriceLoading) + return const overrides: PayableOverrides = isEIP1559 ? { maxFeePerGas: maxFeePerGas?.toString(), maxPriorityFeePerGas: maxPriorityFeePerGas?.toString() } @@ -85,7 +86,7 @@ export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => { txsWithDetails, multiSendContract, multiSendTxData, - onboard, + new ethers.providers.Web3Provider(wallet.provider), safe.chainId, safe.address.value, overrides, diff --git a/src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx b/src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx index d83a5d33ef..2068ee8ca4 100644 --- a/src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx +++ b/src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx @@ -9,7 +9,6 @@ import type { SafeAppsTxParams } from '.' import { trackSafeAppTxCount } from '@/services/safe-apps/track-app-usage-count' import { getTxOrigin } from '@/utils/transactions' import { createMultiSendCallOnlyTx, createTx, dispatchSafeAppsTx } from '@/services/tx/tx-sender' -import useOnboard from '@/hooks/wallets/useOnboard' import useSafeInfo from '@/hooks/useSafeInfo' import useHighlightHiddenTab from '@/hooks/useHighlightHiddenTab' import { SafeTxContext } from '@/components/tx-flow/SafeTxProvider' @@ -17,6 +16,8 @@ import ApprovalEditor from '@/components/tx/ApprovalEditor' import { getInteractionTitle, isTxValid } from '@/components/safe-apps/utils' import ErrorMessage from '@/components/tx/ErrorMessage' import { asError } from '@/services/exceptions/utils' +import useWallet from '@/hooks/wallets/useWallet' +import { ethers } from 'ethers' type ReviewSafeAppsTxProps = { safeAppsTx: SafeAppsTxParams @@ -26,7 +27,7 @@ const ReviewSafeAppsTx = ({ safeAppsTx: { txs, requestId, params, appId, app }, }: ReviewSafeAppsTxProps): ReactElement => { const { safe } = useSafeInfo() - const onboard = useOnboard() + const [wallet] = useWallet() const chain = useCurrentChain() const [txList, setTxList] = useState(txs) const { safeTx, setSafeTx, safeTxError, setSafeTxError } = useContext(SafeTxContext) @@ -51,11 +52,11 @@ const ReviewSafeAppsTx = ({ }, [txList, setSafeTx, setSafeTxError, params]) const handleSubmit = async () => { - if (!safeTx || !onboard) return + if (!safeTx || !wallet || !wallet.provider) return trackSafeAppTxCount(Number(appId)) try { - await dispatchSafeAppsTx(safeTx, requestId, onboard, safe.chainId) + await dispatchSafeAppsTx(safeTx, requestId, new ethers.providers.Web3Provider(wallet.provider), safe.chainId) } catch (error) { setSafeTxError(asError(error)) } diff --git a/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx b/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx index 0d94b49352..98aaf8bf7a 100644 --- a/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx +++ b/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx @@ -19,12 +19,13 @@ import { DecodedMsg } from '@/components/safe-messages/DecodedMsg' import CopyButton from '@/components/common/CopyButton' import { getDecodedMessage } from '@/components/safe-apps/utils' import { createTx, dispatchSafeAppsTx } from '@/services/tx/tx-sender' -import useOnboard from '@/hooks/wallets/useOnboard' import useSafeInfo from '@/hooks/useSafeInfo' import useHighlightHiddenTab from '@/hooks/useHighlightHiddenTab' import { type SafeAppData } from '@safe-global/safe-gateway-typescript-sdk' import { SafeTxContext } from '@/components/tx-flow/SafeTxProvider' import { asError } from '@/services/exceptions/utils' +import useWallet from '@/hooks/wallets/useWallet' +import { ethers } from 'ethers' export type SignMessageOnChainProps = { appId?: number @@ -37,7 +38,7 @@ export type SignMessageOnChainProps = { const ReviewSignMessageOnChain = ({ message, method, requestId }: SignMessageOnChainProps): ReactElement => { const chainId = useChainId() const { safe } = useSafeInfo() - const onboard = useOnboard() + const [wallet] = useWallet() const { safeTx, setSafeTx, setSafeTxError } = useContext(SafeTxContext) useHighlightHiddenTab() @@ -94,9 +95,9 @@ const ReviewSignMessageOnChain = ({ message, method, requestId }: SignMessageOnC ]) const handleSubmit = async () => { - if (!safeTx || !onboard) return + if (!safeTx || !wallet || !wallet.provider) return try { - await dispatchSafeAppsTx(safeTx, requestId, onboard, safe.chainId) + await dispatchSafeAppsTx(safeTx, requestId, new ethers.providers.Web3Provider(wallet.provider), safe.chainId) } catch (error) { setSafeTxError(asError(error)) } diff --git a/src/components/tx-flow/flows/TokenTransfer/ReviewSpendingLimitTx.tsx b/src/components/tx-flow/flows/TokenTransfer/ReviewSpendingLimitTx.tsx index 5a4ba8633c..80d13db779 100644 --- a/src/components/tx-flow/flows/TokenTransfer/ReviewSpendingLimitTx.tsx +++ b/src/components/tx-flow/flows/TokenTransfer/ReviewSpendingLimitTx.tsx @@ -1,6 +1,6 @@ import type { ReactElement, SyntheticEvent } from 'react' import { useContext, useMemo, useState } from 'react' -import type { BigNumberish, BytesLike } from 'ethers' +import { type BigNumberish, type BytesLike, ethers } from 'ethers' import { Button, CardActions, Typography } from '@mui/material' import SendToBlock from '@/components/tx-flow/flows/TokenTransfer/SendToBlock' import { type TokenTransferParams } from '@/components/tx-flow/flows/TokenTransfer/index' @@ -18,11 +18,11 @@ import { useCurrentChain } from '@/hooks/useChains' import { dispatchSpendingLimitTxExecution } from '@/services/tx/tx-sender' import { getTxOptions } from '@/utils/transactions' import { MODALS_EVENTS, trackEvent } from '@/services/analytics' -import useOnboard from '@/hooks/wallets/useOnboard' import { WrongChainWarning } from '@/components/tx/WrongChainWarning' import { asError } from '@/services/exceptions/utils' import TxCard from '@/components/tx-flow/common/TxCard' import { TxModalContext } from '@/components/tx-flow' +import useWallet from '@/hooks/wallets/useWallet' export type SpendingLimitTxParams = { safeAddress: string @@ -46,7 +46,7 @@ const ReviewSpendingLimitTx = ({ const [submitError, setSubmitError] = useState() const { setTxFlow } = useContext(TxModalContext) const currentChain = useCurrentChain() - const onboard = useOnboard() + const [wallet] = useWallet() const { safe, safeAddress } = useSafeInfo() const { balances } = useBalances() const token = balances.items.find((item) => item.tokenInfo.address === params.tokenAddress) @@ -79,7 +79,7 @@ const ReviewSpendingLimitTx = ({ const handleSubmit = async (e: SyntheticEvent) => { e.preventDefault() - if (!onboard) return + if (!wallet || !wallet.provider) return trackEvent(MODALS_EVENTS.USE_SPENDING_LIMIT) @@ -89,7 +89,13 @@ const ReviewSpendingLimitTx = ({ const txOptions = getTxOptions(advancedParams, currentChain) try { - await dispatchSpendingLimitTxExecution(txParams, txOptions, onboard, safe.chainId, safeAddress) + await dispatchSpendingLimitTxExecution( + txParams, + txOptions, + new ethers.providers.Web3Provider(wallet.provider), + safe.chainId, + safeAddress, + ) onSubmit() setTxFlow(undefined) } catch (_err) { diff --git a/src/components/tx/ExecutionMethodSelector/index.tsx b/src/components/tx/ExecutionMethodSelector/index.tsx index 2ac23878c8..c36fb0bdee 100644 --- a/src/components/tx/ExecutionMethodSelector/index.tsx +++ b/src/components/tx/ExecutionMethodSelector/index.tsx @@ -61,8 +61,7 @@ export const ExecutionMethodSelector = ({ value={ExecutionMethod.WALLET} label={ - Connected - wallet + Connected wallet } control={} diff --git a/src/hooks/messages/useSyncSafeMessageSigner.ts b/src/hooks/messages/useSyncSafeMessageSigner.ts index 17bf4a4aa4..eaf48c8eb5 100644 --- a/src/hooks/messages/useSyncSafeMessageSigner.ts +++ b/src/hooks/messages/useSyncSafeMessageSigner.ts @@ -2,9 +2,10 @@ import { asError } from '@/services/exceptions/utils' import { dispatchPreparedSignature } from '@/services/safe-messages/safeMsgNotifications' import { dispatchSafeMsgProposal, dispatchSafeMsgConfirmation } from '@/services/safe-messages/safeMsgSender' import { type EIP712TypedData, type SafeMessage } from '@safe-global/safe-gateway-typescript-sdk' +import { ethers } from 'ethers' import { useEffect, useCallback, useState } from 'react' import useSafeInfo from '../useSafeInfo' -import useOnboard from '../wallets/useOnboard' +import useWallet from '../wallets/useWallet' const useSyncSafeMessageSigner = ( message: SafeMessage | undefined, @@ -15,7 +16,7 @@ const useSyncSafeMessageSigner = ( onClose: () => void, ) => { const [submitError, setSubmitError] = useState() - const onboard = useOnboard() + const [wallet] = useWallet() const { safe } = useSafeInfo() // If the message gets updated in the messageSlice we dispatch it if the signature is complete @@ -27,7 +28,7 @@ const useSyncSafeMessageSigner = ( const onSign = useCallback(async () => { // Error is shown when no wallet is connected, this appeases TypeScript - if (!onboard) { + if (!wallet || !wallet.provider) { return } @@ -36,14 +37,23 @@ const useSyncSafeMessageSigner = ( try { // When collecting the first signature if (!message) { - await dispatchSafeMsgProposal({ onboard, safe, message: decodedMessage, safeAppId }) + await dispatchSafeMsgProposal({ + provider: new ethers.providers.Web3Provider(wallet.provider), + safe, + message: decodedMessage, + safeAppId, + }) // If threshold 1, we do not want to wait for polling if (safe.threshold === 1) { await dispatchPreparedSignature(safe.chainId, safeMessageHash, onClose, requestId) } } else { - await dispatchSafeMsgConfirmation({ onboard, safe, message: decodedMessage }) + await dispatchSafeMsgConfirmation({ + provider: new ethers.providers.Web3Provider(wallet.provider), + safe, + message: decodedMessage, + }) // No requestID => we are in the confirm message dialog and do not need to leave the window open if (!requestId) { @@ -59,7 +69,7 @@ const useSyncSafeMessageSigner = ( } catch (e) { setSubmitError(asError(e)) } - }, [onboard, requestId, message, safe, decodedMessage, safeAppId, safeMessageHash, onClose]) + }, [wallet, requestId, message, safe, decodedMessage, safeAppId, safeMessageHash, onClose]) return { submitError, onSign } } diff --git a/src/hooks/useIsValidExecution.ts b/src/hooks/useIsValidExecution.ts index 6268a6b20b..bee3438f9a 100644 --- a/src/hooks/useIsValidExecution.ts +++ b/src/hooks/useIsValidExecution.ts @@ -7,7 +7,7 @@ import ContractErrorCodes from '@/services/contracts/ContractErrorCodes' import { type SafeInfo } from '@safe-global/safe-gateway-typescript-sdk' import { createWeb3, useWeb3ReadOnly } from '@/hooks/wallets/web3' import { type JsonRpcProvider } from '@ethersproject/providers' -import { type ConnectedWallet } from '@/services/onboard' +import type { ConnectedWallet, EIP1193Provider } from '@privy-io/react-auth' import { getCurrentGnosisSafeContract } from '@/services/contracts/safeContracts' import useSafeInfo from '@/hooks/useSafeInfo' import useWallet from '@/hooks/wallets/useWallet' @@ -23,7 +23,7 @@ const isContractError = (error: EthersError) => { // Monkey patch the signerProvider to proxy requests to the "readonly" provider if on the wrong chain // This is ONLY used to check the validity of a transaction in `useIsValidExecution` const getPatchedSignerProvider = ( - wallet: ConnectedWallet, + wallet: ConnectedWallet & { provider: EIP1193Provider }, chainId: SafeInfo['chainId'], readOnlyProvider: JsonRpcProvider, ) => { diff --git a/src/hooks/useOwnedSafes.ts b/src/hooks/useOwnedSafes.ts index 66db1772b8..ea3d7a7cfa 100644 --- a/src/hooks/useOwnedSafes.ts +++ b/src/hooks/useOwnedSafes.ts @@ -16,7 +16,8 @@ type OwnedSafesCache = { const useOwnedSafes = (): OwnedSafesCache['walletAddress'] => { const chainId = useChainId() - const { address: walletAddress } = useWallet() || {} + const [wallet] = useWallet() + const { address: walletAddress } = wallet || {} const [ownedSafesCache, setOwnedSafesCache] = useLocalStorage(CACHE_KEY) useEffect(() => { diff --git a/src/services/safe-messages/safeMsgSender.ts b/src/services/safe-messages/safeMsgSender.ts index 47f0983268..d64659ee6f 100644 --- a/src/services/safe-messages/safeMsgSender.ts +++ b/src/services/safe-messages/safeMsgSender.ts @@ -1,7 +1,7 @@ import { proposeSafeMessage, confirmSafeMessage } from '@safe-global/safe-gateway-typescript-sdk' import type { SafeInfo, SafeMessage } from '@safe-global/safe-gateway-typescript-sdk' import { isObjectEIP712TypedData } from '@safe-global/safe-apps-sdk' -import type { OnboardAPI } from '@web3-onboard/core' +import type { Web3Provider } from '@ethersproject/providers' import { safeMsgDispatch, SafeMsgEvent } from './safeMsgEvents' import { generateSafeMessageHash, tryOffChainMsgSigning } from '@/utils/safe-messages' @@ -10,12 +10,12 @@ import { getAssertedChainSigner } from '@/services/tx/tx-sender/sdk' import { asError } from '../exceptions/utils' export const dispatchSafeMsgProposal = async ({ - onboard, + provider, safe, message, safeAppId, }: { - onboard: OnboardAPI + provider: Web3Provider safe: SafeInfo message: SafeMessage['message'] safeAppId?: number @@ -23,7 +23,7 @@ export const dispatchSafeMsgProposal = async ({ const messageHash = generateSafeMessageHash(safe, message) try { - const signer = await getAssertedChainSigner(onboard, safe.chainId) + const signer = await getAssertedChainSigner(provider, safe.chainId) const signature = await tryOffChainMsgSigning(signer, safe, message) let normalizedMessage = message @@ -51,18 +51,18 @@ export const dispatchSafeMsgProposal = async ({ } export const dispatchSafeMsgConfirmation = async ({ - onboard, + provider, safe, message, }: { - onboard: OnboardAPI + provider: Web3Provider safe: SafeInfo message: SafeMessage['message'] }): Promise => { const messageHash = generateSafeMessageHash(safe, message) try { - const signer = await getAssertedChainSigner(onboard, safe.chainId) + const signer = await getAssertedChainSigner(provider, safe.chainId) const signature = await tryOffChainMsgSigning(signer, safe, message) await confirmSafeMessage(safe.chainId, messageHash, {