Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Fix: show non-owner execution warning only on tx creation #3416

Merged
merged 4 commits into from
Feb 9, 2022
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
8 changes: 5 additions & 3 deletions src/components/ReviewInfoText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ export const ReviewInfoText = ({
You're about to {transactionAction} a transaction and will have to confirm it with your currently
connected wallet.
</Paragraph>
{txEstimationExecutionStatus === EstimationStatus.FAILURE && (
<TransactionFailText isExecution={isExecution} />
)}
</>
)}
<TransactionFailText
estimationStatus={txEstimationExecutionStatus}
isExecution={isExecution}
isCreation={isCreation}
/>
</ReviewInfoTextWrapper>
)
}
23 changes: 17 additions & 6 deletions src/components/TransactionFailText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSelector } from 'react-redux'
import { currentSafeThreshold } from 'src/logic/safe/store/selectors'
import { shouldSwitchWalletChain } from 'src/logic/wallets/store/selectors'
import { grantedSelector } from 'src/routes/safe/container/selector'
import { EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'

const styles = createStyles({
executionWarningRow: {
Expand All @@ -24,14 +25,24 @@ const useStyles = makeStyles(styles)

type TransactionFailTextProps = {
isExecution: boolean
isCreation: boolean
estimationStatus: EstimationStatus
}

export const TransactionFailText = ({ isExecution }: TransactionFailTextProps): React.ReactElement | null => {
export const TransactionFailText = ({
isExecution,
isCreation,
estimationStatus,
}: TransactionFailTextProps): React.ReactElement | null => {
const classes = useStyles()
const threshold = useSelector(currentSafeThreshold)
const isWrongChain = useSelector(shouldSwitchWalletChain)
const isGranted = useSelector(grantedSelector)

if (estimationStatus !== EstimationStatus.FAILURE && !(isCreation && !isGranted)) {
return null
}

let errorDesc = 'To save gas costs, avoid creating the transaction.'
if (isExecution) {
errorDesc =
Expand All @@ -40,11 +51,11 @@ export const TransactionFailText = ({ isExecution }: TransactionFailTextProps):
: `To save gas costs, avoid executing the transaction.`
}

const error = isGranted
? `This transaction will most likely fail. ${errorDesc}`
: isWrongChain
? 'Your wallet is connected to the wrong chain.'
: "You are currently not an owner of this Safe and won't be able to submit this transaction."
const defaultMsg = `This transaction will most likely fail. ${errorDesc}`
const notOwnerMsg = `You are currently not an owner of this Safe and won't be able to submit this transaction.`
const wrongChainMsg = 'Your wallet is connected to the wrong chain.'

const error = isGranted ? defaultMsg : isWrongChain ? wrongChainMsg : isCreation ? notOwnerMsg : defaultMsg

return (
<Row align="center">
Expand Down