Skip to content

Commit

Permalink
comment feedback - various
Browse files Browse the repository at this point in the history
- removes unneeded assignments
  • Loading branch information
Da-Colon committed Aug 9, 2024
1 parent 8368953 commit f47857b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
55 changes: 28 additions & 27 deletions src/components/Proposals/MultisigProposalDetails/TxActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,27 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
const [contractCall, contractCallPending] = useTransaction();
const { loadSafeMultisigProposals } = useSafeMultisigProposals();
const baseContracts = useSafeContracts();
if (user.votingWeight === 0n) return <></>;
if (user.votingWeight === 0n) return null;

const multisigTx = proposal.transaction;

if (!multisigTx) return null;
if (!proposal.transaction) return null;

const signTransaction = async () => {
if (
!signerOrProvider ||
!safe?.address ||
(multisigTx.data && !isHex(multisigTx.data)) ||
!proposal.transaction ||
(proposal.transaction.data && !isHex(proposal.transaction.data)) ||
!safeAPI
) {
return;
}
try {
const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
value: BigInt(multisigTx.value),
data: multisigTx.data as Hex | undefined,
operation: multisigTx.operation as 0 | 1,
...proposal.transaction,
to: getAddress(proposal.transaction.to),
value: BigInt(proposal.transaction.value),
data: proposal.transaction.data as Hex | undefined,
operation: proposal.transaction.operation as 0 | 1,
});

asyncRequest({
Expand All @@ -97,22 +96,23 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
const timelockTransaction = async () => {
try {
if (
!multisigTx.confirmations ||
!proposal.transaction ||
!proposal.transaction.confirmations ||
!baseContracts ||
!freezeGuardContractAddress ||
(multisigTx.data && !isHex(multisigTx.data))
(proposal.transaction.data && !isHex(proposal.transaction.data))
) {
return;
}
const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
value: BigInt(multisigTx.value),
data: multisigTx.data as Hex | undefined,
operation: multisigTx.operation as 0 | 1,
...proposal.transaction,
to: getAddress(proposal.transaction.to),
value: BigInt(proposal.transaction.value),
data: proposal.transaction.data as Hex | undefined,
operation: proposal.transaction.operation as 0 | 1,
});
const signatures = buildSignatureBytes(
multisigTx.confirmations.map(confirmation => {
proposal.transaction.confirmations.map(confirmation => {
if (!isHex(confirmation.signature)) {
throw new Error('Confirmation signature is malfunctioned');
}
Expand Down Expand Up @@ -157,24 +157,25 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
try {
if (
!signerOrProvider ||
!proposal.transaction ||
!safe?.address ||
!multisigTx.confirmations ||
(multisigTx.data && !isHex(multisigTx.data))
!proposal.transaction.confirmations ||
(proposal.transaction.data && !isHex(proposal.transaction.data))
) {
return;
}
const safeContract = GnosisSafeL2__factory.connect(safe.address, signerOrProvider);

const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
value: BigInt(multisigTx.value),
data: multisigTx.data as Hex | undefined,
operation: multisigTx.operation as 0 | 1,
...proposal.transaction,
to: getAddress(proposal.transaction.to),
value: BigInt(proposal.transaction.value),
data: proposal.transaction.data as Hex | undefined,
operation: proposal.transaction.operation as 0 | 1,
});

const signatures = buildSignatureBytes(
multisigTx.confirmations.map(confirmation => {
proposal.transaction.confirmations.map(confirmation => {
if (!isHex(confirmation.signature)) {
throw new Error('Confirmation signature is malfunctioned');
}
Expand Down Expand Up @@ -256,7 +257,7 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
pageTitle: 'executeTitle',
},
};
const isActiveNonce = !!safe && multisigTx.nonce === safe.nonce;
const isActiveNonce = !!safe && proposal.transaction.nonce === safe.nonce;
const isButtonDisabled =
isSubmitDisabled ||
isPending ||
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/DAO/proposal/useGetMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ const useGetMultisigMetadata = (proposal: FractalProposal | null | undefined) =>

if (!proposal.transaction) return;

const transaction = proposal.transaction;

// transactionType either isn't SafeMultisigTransactionResponse, or
// there is no dataDecoded field on it
if (!transaction?.dataDecoded) return;
if (!proposal.transaction?.dataDecoded) return;

// find the last transaction in the multiSend batch, which *should* be the metadata
// transaction, which contains the IPFS hash as its data array
const dataDecoded: DataDecoded = JSON.parse(JSON.stringify(transaction.dataDecoded));
const dataDecoded: DataDecoded = JSON.parse(JSON.stringify(proposal.transaction.dataDecoded));
const transactions: Transaction[] = dataDecoded.parameters[0]?.valueDecoded;

if (!transactions) return;
Expand Down
8 changes: 3 additions & 5 deletions src/hooks/utils/useSafeTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ export const useSafeTransactions = () => {
return activity;
}

const multiSigTransaction = activity.transaction;

let state;
if (multiSigTransaction.isExecuted) {
if (activity.transaction.isExecuted) {
state = FractalProposalState.EXECUTED;
} else if (isRejected(activityArr, multiSigTransaction)) {
} else if (isRejected(activityArr, activity.transaction)) {
state = FractalProposalState.REJECTED;
} else if (isApproved(multiSigTransaction)) {
} else if (isApproved(activity.transaction)) {
state = FractalProposalState.EXECUTABLE;
} else {
state = FractalProposalState.ACTIVE;
Expand Down
6 changes: 2 additions & 4 deletions src/utils/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export async function getTxTimelockedTimestamp(
freezeGuard: MultisigFreezeGuard,
provider: Providers,
) {
const multiSigTransaction = activity.transaction;

if (!multiSigTransaction?.confirmations) {
if (!activity.transaction?.confirmations) {
throw new Error(
'Error getting transaction timelocked timestamp - invalid format of multisig transaction',
);
}
const signatures = buildSignatureBytes(
multiSigTransaction.confirmations.map(confirmation => {
activity.transaction.confirmations.map(confirmation => {
if (!isHex(confirmation.signature)) {
throw new Error('Confirmation signature is malfunctioned');
}
Expand Down

0 comments on commit f47857b

Please sign in to comment.