Skip to content

Commit

Permalink
fix: do not propose transaction for contrafactual safes
Browse files Browse the repository at this point in the history
  • Loading branch information
clovisdasilvaneto committed Sep 17, 2024
1 parent 4148903 commit ac79864
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/components/tx/SignOrExecuteForm/SignOrExecuteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import ConfirmationView from '../confirmation-views'
export type SubmitCallback = (txId: string, isExecuted?: boolean) => void

export type SignOrExecuteProps = {
txId: string
txId?: string
onSubmit?: SubmitCallback
children?: ReactNode
isExecutable?: boolean
Expand Down Expand Up @@ -141,7 +141,7 @@ export const SignOrExecuteForm = ({
</ErrorBoundary>
)}

{props.txDetails && <ConfirmationView isCreation={isCreation} txDetails={props.txDetails} safeTx={safeTx} />}
<ConfirmationView isCreation={isCreation} txDetails={props.txDetails} safeTx={safeTx} />

{!isCounterfactualSafe && !props.isRejection && <BlockaidBalanceChanges />}
</TxCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { render } from '@/tests/test-utils'
import { fireEvent } from '@testing-library/react'
import { encodeBytes32String } from 'ethers'
import { Status } from 'zodiac-roles-deployments'
import {
DetailedExecutionInfoType,
SettingsInfoType,
TransactionInfoType,
} from '@safe-global/safe-gateway-typescript-sdk'
import { createMockTransactionDetails } from '@/tests/transactions'

let isSafeOwner = true
// mock useIsSafeOwner
Expand All @@ -14,6 +20,96 @@ jest.mock('@/hooks/useIsSafeOwner', () => ({
default: jest.fn(() => isSafeOwner),
}))

const txDetails = createMockTransactionDetails({
txInfo: {
type: TransactionInfoType.SETTINGS_CHANGE,
humanDescription: 'Add new owner 0xd8dA...6045 with threshold 1',
dataDecoded: {
method: 'addOwnerWithThreshold',
parameters: [
{
name: 'owner',
type: 'address',
value: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
},
{
name: '_threshold',
type: 'uint256',
value: '1',
},
],
},
settingsInfo: {
type: SettingsInfoType.ADD_OWNER,
owner: {
value: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
name: 'Nevinha',
logoUri: 'http://something.com',
},
threshold: 1,
},
},
txData: {
hexData:
'0x0d582f13000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000000001',
dataDecoded: {
method: 'addOwnerWithThreshold',
parameters: [
{
name: 'owner',
type: 'address',
value: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
},
{
name: '_threshold',
type: 'uint256',
value: '1',
},
],
},
to: {
value: '0xE20CcFf2c38Ef3b64109361D7b7691ff2c7D5f67',
name: '',
},
value: '0',
operation: 0,
trustedDelegateCallTarget: false,
addressInfoIndex: {
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045': {
value: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
name: 'MetaMultiSigWallet',
},
},
},
detailedExecutionInfo: {
type: DetailedExecutionInfoType.MULTISIG,
submittedAt: 1726064794013,
nonce: 4,
safeTxGas: '0',
baseGas: '0',
gasPrice: '0',
gasToken: '0x0000000000000000000000000000000000000000',
refundReceiver: {
value: '0x0000000000000000000000000000000000000000',
name: 'MetaMultiSigWallet',
},
safeTxHash: '0x96a96c11b8d013ff5d7a6ce960b22e961046cfa42eff422ac71c1daf6adef2e0',
signers: [
{
value: '0xDa5e9FA404881Ff36DDa97b41Da402dF6430EE6b',
name: '',
},
],
confirmationsRequired: 1,
confirmations: [],
rejectors: [],
trusted: false,
proposer: {
value: '0xDa5e9FA404881Ff36DDa97b41Da402dF6430EE6b',
name: '',
},
},
})
describe('SignOrExecute', () => {
beforeEach(() => {
isSafeOwner = true
Expand All @@ -22,6 +118,7 @@ describe('SignOrExecute', () => {
it('should display a safeTxError', () => {
const { getByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
onSubmit={jest.fn()}
safeTxError={new Error('Safe transaction error')}
Expand All @@ -41,6 +138,7 @@ describe('SignOrExecute', () => {

const { getByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTx={safeTxBuilder().build()}
onSubmit={jest.fn()}
Expand All @@ -61,6 +159,7 @@ describe('SignOrExecute', () => {

const { getByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -80,6 +179,7 @@ describe('SignOrExecute', () => {

const { queryByTestId } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -101,6 +201,7 @@ describe('SignOrExecute', () => {

const { queryByTestId } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -122,6 +223,7 @@ describe('SignOrExecute', () => {

const { queryByTestId } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -141,6 +243,7 @@ describe('SignOrExecute', () => {

const { queryByTestId } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -160,6 +263,7 @@ describe('SignOrExecute', () => {

const { queryByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand All @@ -176,6 +280,7 @@ describe('SignOrExecute', () => {

const { getByTestId, getByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand Down Expand Up @@ -204,6 +309,7 @@ describe('SignOrExecute', () => {
it('should not display safeTxError message for valid transactions', () => {
const { queryByText } = render(
<SignOrExecuteForm
txDetails={txDetails}
txId="0x012312"
safeTxError={undefined}
safeTx={safeTxBuilder().build()}
Expand Down
9 changes: 5 additions & 4 deletions src/components/tx/SignOrExecuteForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useProposeTx } from './hooks'
import { useContext } from 'react'
import ErrorBoundary from '@/components/common/ErrorBoundary'
import TxCard from '@/components/tx-flow/common/TxCard'
import useSafeInfo from '@/hooks/useSafeInfo'

type SignOrExecuteExtendedProps = Omit<SignOrExecuteProps, 'txId'> & {
onSubmit?: SubmitCallback
Expand All @@ -24,17 +25,17 @@ type SignOrExecuteExtendedProps = Omit<SignOrExecuteProps, 'txId'> & {

const SignOrExecute = (props: SignOrExecuteExtendedProps) => {
const { safeTx } = useContext(SafeTxContext)

const [txDetails, error, isLoading] = useProposeTx(safeTx, props.txId, props.origin)
const { safe } = useSafeInfo()
const [txDetails, error, isLoading] = useProposeTx(safe.deployed ? safeTx : undefined, props.txId, props.origin)

return error ? (
<TxCard>
<ErrorBoundary error={error} componentStack="SignOrExecuteForm/index" />
</TxCard>
) : isLoading || !safeTx || !txDetails ? (
) : isLoading || !safeTx || (!txDetails && safe.deployed) ? (
<SignOrExecuteSkeleton />
) : (
<SignOrExecuteForm {...props} isCreation={!props.txId} txId={props.txId || txDetails.txId} txDetails={txDetails} />
<SignOrExecuteForm {...props} isCreation={!props.txId} txId={props.txId || txDetails?.txId} txDetails={txDetails} />
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const safeTxWithNativeData = {
data: '0x',
},
}
console.log(safeTxWithNativeData)
describe('ConfirmationView', () => {
it('should display a confirmation screen for a SETTINGS_CHANGE transaction', () => {
const { container, getByTestId } = render(
Expand Down
19 changes: 11 additions & 8 deletions src/components/tx/confirmation-views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { NarrowConfirmationViewProps } from './types'
import SettingsChange from './SettingsChange'

type ConfirmationViewProps = {
txDetails: TransactionDetails
txDetails?: TransactionDetails
safeTx?: SafeTransaction
txId?: string
isBatch?: boolean
Expand All @@ -26,22 +26,25 @@ const getConfirmationViewComponent = (txType: TransactionInfoType, props: Narrow
}

const ConfirmationView = (props: ConfirmationViewProps) => {
const { txInfo, txId } = props.txDetails
const { txId } = props.txDetails || {}
const [decodedData] = useDecodeTx(props.safeTx)

const ConfirmationViewComponent = useMemo(
() =>
getConfirmationViewComponent(txInfo.type, {
txDetails: props.txDetails,
txInfo,
}),
[props.txDetails, txInfo],
props.txDetails
? getConfirmationViewComponent(props.txDetails.txInfo.type, {
txDetails: props.txDetails,
txInfo: props.txDetails.txInfo,
})
: undefined,
[props.txDetails],
)
const showTxDetails = txId && !props.isCreation && props.txDetails && !isCustomTxInfo(props.txDetails.txInfo)

return (
<>
{ConfirmationViewComponent || (showTxDetails && <TxData txDetails={props.txDetails} imitation={false} trusted />)}
{ConfirmationViewComponent ||
(showTxDetails && props.txDetails && <TxData txDetails={props.txDetails} imitation={false} trusted />)}

{decodedData && <ConfirmationOrder decodedData={decodedData} toAddress={props.safeTx?.data.to ?? ''} />}

Expand Down

0 comments on commit ac79864

Please sign in to comment.