Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disable submit button for non-owners #2261

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/transactions/ExecuteTxButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ExecuteTxButton = ({

const onClick = (e: SyntheticEvent) => {
e.stopPropagation()
setTxFlow(<ConfirmTxFlow txSummary={txSummary} />)
setTxFlow(<ConfirmTxFlow txSummary={txSummary} />, undefined, false)
}

const onMouseEnter = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/transactions/SignTxButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SignTxButton = ({

const onClick = (e: SyntheticEvent) => {
e.stopPropagation()
setTxFlow(<ConfirmTxFlow txSummary={txSummary} />)
setTxFlow(<ConfirmTxFlow txSummary={txSummary} />, undefined, false)
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/tx-flow/flows/RejectTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type RejectTxProps = {

const RejectTxFlow = ({ txNonce }: RejectTxProps): ReactElement => {
return (
<TxLayout title="Reject transaction" step={0}>
<TxLayout title="Confirm transaction" subtitle="Reject" step={0}>
<RejectTx txNonce={txNonce} />
</TxLayout>
)
Expand Down
44 changes: 25 additions & 19 deletions src/components/tx/SignOrExecuteForm/ExecuteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import { asError } from '@/services/exceptions/utils'
import css from './styles.module.css'
import commonCss from '@/components/tx-flow/common/styles.module.css'
import { TxSecurityContext } from '../security/shared/TxSecurityContext'
import useIsSafeOwner from '@/hooks/useIsSafeOwner'
import NonOwnerError from '@/components/tx/SignOrExecuteForm/NonOwnerError'

const ExecuteForm = ({
safeTx,
txId,
onSubmit,
disableSubmit = false,
origin,
onlyExecute,
}: SignOrExecuteProps & {
safeTx?: SafeTransaction
}): ReactElement => {
Expand All @@ -39,6 +42,7 @@ const ExecuteForm = ({
const [submitError, setSubmitError] = useState<Error | undefined>()

// Hooks
const isOwner = useIsSafeOwner()
const currentChain = useCurrentChain()
const { executeTx } = useTxActions()
const [relays] = useRelaysBySafe()
Expand Down Expand Up @@ -95,12 +99,14 @@ const ExecuteForm = ({
onSubmit()
}

const submitDisabled = !safeTx || !isSubmittable || disableSubmit || isValidExecutionLoading || isExecutionLoop
const cannotPropose = !isOwner && !onlyExecute
const submitDisabled =
!safeTx || !isSubmittable || disableSubmit || isValidExecutionLoading || isExecutionLoop || cannotPropose

return (
<>
<form onSubmit={handleSubmit}>
<div className={classNames({ [css.noBottomBorderRadius]: canRelay })}>
<div className={classNames(css.params, { [css.noBottomBorderRadius]: canRelay })}>
<AdvancedParams
willExecute
params={advancedParams}
Expand All @@ -109,43 +115,43 @@ const ExecuteForm = ({
gasLimitError={gasLimitError}
willRelay={willRelay}
/>
</div>

{canRelay && (
<div className={css.noTopBorder}>
<ExecutionMethodSelector
executionMethod={executionMethod}
setExecutionMethod={setExecutionMethod}
relays={relays}
/>
</div>
)}
{canRelay && (
<div className={css.noTopBorder}>
<ExecutionMethodSelector
executionMethod={executionMethod}
setExecutionMethod={setExecutionMethod}
relays={relays}
/>
</div>
)}
</div>

{/* Error messages */}
{isExecutionLoop ? (
<ErrorMessage className={css.errorWrapper}>
{cannotPropose ? (
<NonOwnerError />
) : isExecutionLoop ? (
<ErrorMessage>
Cannot execute a transaction from the Safe Account itself, please connect a different account.
</ErrorMessage>
) : executionValidationError || gasLimitError ? (
<ErrorMessage error={executionValidationError || gasLimitError} className={css.errorWrapper}>
<ErrorMessage error={executionValidationError || gasLimitError}>
This transaction will most likely fail.{' '}
{isNewExecutableTx
? 'To save gas costs, avoid creating the transaction.'
: 'To save gas costs, reject this transaction.'}
</ErrorMessage>
) : (
submitError && (
<ErrorMessage error={submitError} className={css.errorWrapper}>
Error submitting the transaction. Please try again.
</ErrorMessage>
<ErrorMessage error={submitError}>Error submitting the transaction. Please try again.</ErrorMessage>
)
)}

<Divider className={commonCss.nestedDivider} sx={{ pt: 3 }} />

<CardActions>
{/* Submit button */}
<CheckWallet allowNonOwner={true}>
<CheckWallet allowNonOwner={onlyExecute}>
{(isOk) => (
<Button variant="contained" type="submit" disabled={!isOk || submitDisabled}>
Submit
Expand Down
11 changes: 11 additions & 0 deletions src/components/tx/SignOrExecuteForm/NonOwnerError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ErrorMessage from '@/components/tx/ErrorMessage'

const NonOwnerError = () => {
return (
<ErrorMessage>
You are currently not an owner of this Safe Account and won&apos;t be able to submit this transaction.
</ErrorMessage>
)
}

export default NonOwnerError
13 changes: 4 additions & 9 deletions src/components/tx/SignOrExecuteForm/SignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TxModalContext } from '@/components/tx-flow'
import { asError } from '@/services/exceptions/utils'
import commonCss from '@/components/tx-flow/common/styles.module.css'
import { TxSecurityContext } from '../security/shared/TxSecurityContext'
import css from '@/components/tx/SignOrExecuteForm/styles.module.css'
import NonOwnerError from '@/components/tx/SignOrExecuteForm/NonOwnerError'

const SignForm = ({
safeTx,
Expand Down Expand Up @@ -64,16 +64,11 @@ const SignForm = ({

return (
<form onSubmit={handleSubmit}>
{/* Error messages */}
{isSubmittable && cannotPropose ? (
<ErrorMessage className={css.errorWrapper}>
You are currently not an owner of this Safe Account and won&apos;t be able to submit this transaction.
</ErrorMessage>
{cannotPropose ? (
<NonOwnerError />
) : (
submitError && (
<ErrorMessage error={submitError} className={css.errorWrapper}>
Error submitting the transaction. Please try again.
</ErrorMessage>
<ErrorMessage error={submitError}>Error submitting the transaction. Please try again.</ErrorMessage>
)
)}

Expand Down
8 changes: 4 additions & 4 deletions src/components/tx/SignOrExecuteForm/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
color: var(--color-secondary-dark);
}

.params {
margin-bottom: var(--space-2);
}

.noBottomBorderRadius :global(.MuiPaper-root) {
border-bottom-left-radius: 0 !important;
border-bottom-right-radius: 0 !important;
Expand All @@ -42,10 +46,6 @@
border-top-right-radius: 0 !important;
}

.errorWrapper {
margin-top: var(--space-2) !important;
}

.mobileTxCheckMessages,
.mobileTxCheckMessages:empty {
display: none;
Expand Down
Loading