Skip to content

Commit

Permalink
fix: type errors (excluding tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Aug 1, 2023
1 parent 5ef8c8b commit 0df6caf
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/components/safe-apps/SafeAppLandingPage/AppActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<void>
chain: ChainInfo
app: SafeAppData
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/PendingActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const PendingActionButtons = ({
borderBottomRightRadius: ({ shape }) => shape.borderRadius,
}}
>
<WalletIcon provider={wallet.label} icon={wallet.icon} />
<WalletIcon provider={wallet.walletClientType} />
<Typography variant="body2">{totalToSign}</Typography>
</ButtonBase>
</Tooltip>
Expand Down
11 changes: 6 additions & 5 deletions src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<boolean>(true)
Expand All @@ -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<TransactionDetails[]>(() => {
Expand All @@ -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() }
Expand All @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ 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'
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
Expand All @@ -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)
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -46,7 +46,7 @@ const ReviewSpendingLimitTx = ({
const [submitError, setSubmitError] = useState<Error | undefined>()
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)
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/tx/ExecutionMethodSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export const ExecutionMethodSelector = ({
value={ExecutionMethod.WALLET}
label={
<Typography className={css.radioLabel}>
<WalletIcon provider={wallet?.label || ''} width={20} height={20} icon={wallet?.icon} /> Connected
wallet
<WalletIcon provider={wallet?.walletClientType || ''} width={20} height={20} /> Connected wallet
</Typography>
}
control={<Radio />}
Expand Down
22 changes: 16 additions & 6 deletions src/hooks/messages/useSyncSafeMessageSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +16,7 @@ const useSyncSafeMessageSigner = (
onClose: () => void,
) => {
const [submitError, setSubmitError] = useState<Error | undefined>()
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
Expand All @@ -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
}

Expand All @@ -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) {
Expand All @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useIsValidExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
) => {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useOwnedSafes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedSafesCache>(CACHE_KEY)

useEffect(() => {
Expand Down
14 changes: 7 additions & 7 deletions src/services/safe-messages/safeMsgSender.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,20 +10,20 @@ 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
}): Promise<void> => {
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
Expand Down Expand Up @@ -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<void> => {
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, {
Expand Down

0 comments on commit 0df6caf

Please sign in to comment.