diff --git a/src/components/tx-flow/flows/AddOwner/ReviewOwner.tsx b/src/components/tx-flow/flows/AddOwner/ReviewOwner.tsx index 464d2bf570..2c802bbbb2 100644 --- a/src/components/tx-flow/flows/AddOwner/ReviewOwner.tsx +++ b/src/components/tx-flow/flows/AddOwner/ReviewOwner.tsx @@ -1,3 +1,4 @@ +import { useCurrentChain } from '@/hooks/useChains' import { useContext, useEffect } from 'react' import { Typography, Divider, Box, SvgIcon, Paper } from '@mui/material' @@ -20,21 +21,24 @@ export const ReviewOwner = ({ params }: { params: AddOwnerFlowProps | ReplaceOwn const { setSafeTx, setSafeTxError } = useContext(SafeTxContext) const { safe } = useSafeInfo() const { chainId } = safe + const chain = useCurrentChain() const { newOwner, removedOwner, threshold } = params useEffect(() => { + if (!chain) return + const promise = removedOwner - ? createSwapOwnerTx({ + ? createSwapOwnerTx(chain, safe.deployed, { newOwnerAddress: newOwner.address, oldOwnerAddress: removedOwner.address, }) - : createAddOwnerTx({ + : createAddOwnerTx(chain, safe.deployed, { ownerAddress: newOwner.address, threshold, }) promise.then(setSafeTx).catch(setSafeTxError) - }, [removedOwner, newOwner, threshold, setSafeTx, setSafeTxError]) + }, [removedOwner, newOwner, threshold, setSafeTx, setSafeTxError, chain, safe.deployed]) const addAddressBookEntryAndSubmit = () => { if (typeof newOwner.name !== 'undefined') { diff --git a/src/services/tx/tx-sender/create.ts b/src/services/tx/tx-sender/create.ts index c53bac7c4c..8fa6735ca9 100644 --- a/src/services/tx/tx-sender/create.ts +++ b/src/services/tx/tx-sender/create.ts @@ -1,4 +1,7 @@ -import type { TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' +import { LATEST_SAFE_VERSION } from '@/config/constants' +import { getReadOnlyGnosisSafeContract } from '@/services/contracts/safeContracts' +import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/dist/src/utils/constants' +import type { ChainInfo, TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' import { getTransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' import type { AddOwnerTxParams, RemoveOwnerTxParams, SwapOwnerTxParams } from '@safe-global/protocol-kit' import type { MetaTransactionData, SafeTransaction, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' @@ -28,14 +31,49 @@ export const createRemoveOwnerTx = async (txParams: RemoveOwnerTxParams): Promis return safeSDK.createRemoveOwnerTx(txParams) } -export const createAddOwnerTx = async (txParams: AddOwnerTxParams): Promise => { +export const createAddOwnerTx = async ( + chain: ChainInfo, + isDeployed: boolean, + txParams: AddOwnerTxParams, +): Promise => { const safeSDK = getAndValidateSafeSDK() - return safeSDK.createAddOwnerTx(txParams) + if (isDeployed) return safeSDK.createAddOwnerTx(txParams) + + const contract = await getReadOnlyGnosisSafeContract(chain, LATEST_SAFE_VERSION) + // @ts-ignore TODO: Fix overload issue + const data = contract.encode('addOwnerWithThreshold', [txParams.ownerAddress, txParams.threshold]) + + const tx = { + to: await safeSDK.getAddress(), + value: '0', + data, + } + + return safeSDK.createTransaction({ + transactions: [tx], + }) } -export const createSwapOwnerTx = async (txParams: SwapOwnerTxParams): Promise => { +export const createSwapOwnerTx = async ( + chain: ChainInfo, + isDeployed: boolean, + txParams: SwapOwnerTxParams, +): Promise => { const safeSDK = getAndValidateSafeSDK() - return safeSDK.createSwapOwnerTx(txParams) + if (isDeployed) return safeSDK.createSwapOwnerTx(txParams) + + const contract = await getReadOnlyGnosisSafeContract(chain, LATEST_SAFE_VERSION) + const data = contract.encode('swapOwner', [SENTINEL_ADDRESS, txParams.oldOwnerAddress, txParams.newOwnerAddress]) + + const tx = { + to: await safeSDK.getAddress(), + value: '0', + data, + } + + return safeSDK.createTransaction({ + transactions: [tx], + }) } export const createUpdateThresholdTx = async (threshold: number): Promise => {