Skip to content

Commit

Permalink
Do not show block if relaying not enabled at all
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 10, 2023
1 parent 79edddc commit 8db5a5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/components/tx/SignOrExecuteForm/ExecuteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ const ExecuteForm = ({
// Check that the transaction is executable
const isExecutionLoop = useIsExecutionLoop()

// We default to relay, but the option is only shown if we canRelay
const [executionMethod, setExecutionMethod] = useState(ExecutionMethod.RELAY)

// SC wallets can relay fully signed transactions
const [canRelay] = useWalletCanRelay(safeTx)
const [canWalletRelay] = useWalletCanRelay(safeTx)
// We default to relay
const [executionMethod, setExecutionMethod] = useState(
canWalletRelay ? ExecutionMethod.RELAY : ExecutionMethod.WALLET,
)
// The transaction can/will be relayed
const willRelay = canRelay && executionMethod === ExecutionMethod.RELAY
const willRelay = executionMethod === ExecutionMethod.RELAY
const hasRelays = !!relays?.remaining

// Estimate gas limit
Expand Down Expand Up @@ -111,7 +112,7 @@ const ExecuteForm = ({
return (
<>
<form onSubmit={handleSubmit}>
<div className={classNames(css.params, { [css.noBottomBorderRadius]: canRelay })}>
<div className={classNames(css.params, { [css.noBottomBorderRadius]: canWalletRelay })}>
<AdvancedParams
willExecute
params={advancedParams}
Expand All @@ -121,7 +122,7 @@ const ExecuteForm = ({
willRelay={willRelay}
/>

{canRelay && (
{canWalletRelay && (
<div className={css.noTopBorder}>
<ExecutionMethodSelector
executionMethod={executionMethod}
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useWalletCanRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import useWallet from '@/hooks/wallets/useWallet'
import { isSmartContractWallet } from '@/utils/wallets'
import { Errors, logError } from '@/services/exceptions'
import { type SafeTransaction } from '@safe-global/safe-core-sdk-types'
import { FEATURES, hasFeature } from '@/utils/chains'
import { useCurrentChain } from './useChains'

const useWalletCanRelay = (tx: SafeTransaction | undefined) => {
const { safe } = useSafeInfo()
const wallet = useWallet()
const chain = useCurrentChain()
const isFeatureEnabled = chain && hasFeature(chain, FEATURES.RELAYING)
const hasEnoughSignatures = tx && tx.signatures.size >= safe.threshold

return useAsync(() => {
if (!tx || !wallet) return
if (!isFeatureEnabled || !tx || !wallet) return

return isSmartContractWallet(wallet)
.then((isSCWallet) => {
Expand All @@ -23,7 +27,7 @@ const useWalletCanRelay = (tx: SafeTransaction | undefined) => {
logError(Errors._106, err.message)
return false
})
}, [hasEnoughSignatures, tx, wallet])
}, [isFeatureEnabled, hasEnoughSignatures, tx, wallet])
}

export default useWalletCanRelay

0 comments on commit 8db5a5e

Please sign in to comment.