Skip to content

Commit

Permalink
Merge pull request #418 from trilitech/multisi-approve-execute
Browse files Browse the repository at this point in the history
Multisi approve execute
  • Loading branch information
ryutamago authored Sep 5, 2023
2 parents 78f8032 + ea1bc2f commit 26b4b68
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe("<ActionButton/>", () => {
<MultisigActionButton
signerAddress={account.address}
pendingApprovals={0}
openSignModal={_ => {}}
operation={pendingOps[0]}
sender={mockMultisigAccount(0)}
/>
Expand All @@ -30,7 +29,6 @@ describe("<ActionButton/>", () => {
<MultisigActionButton
signerAddress={account.address}
pendingApprovals={1}
openSignModal={_ => {}}
operation={pendingOps[0]}
sender={mockMultisigAccount(0)}
/>
Expand All @@ -45,7 +43,6 @@ describe("<ActionButton/>", () => {
<MultisigActionButton
signerAddress={account.address}
pendingApprovals={1}
openSignModal={_ => {}}
operation={operation}
sender={mockMultisigAccount(0)}
/>
Expand All @@ -59,7 +56,6 @@ describe("<ActionButton/>", () => {
<MultisigActionButton
signerAddress={account.address}
pendingApprovals={1}
openSignModal={_ => {}}
operation={operation}
sender={mockMultisigAccount(0)}
/>
Expand All @@ -72,7 +68,6 @@ describe("<ActionButton/>", () => {
<MultisigActionButton
signerAddress={account.address}
pendingApprovals={1}
openSignModal={_ => {}}
operation={pendingOps[0]}
sender={mockMultisigAccount(0)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { CgSandClock } from "react-icons/cg";
import { RxCheckCircled } from "react-icons/rx";
import colors from "../../../../style/colors";
import { IconAndTextBtn } from "../../../IconAndTextBtn";
import { MultisigSignerState } from "./MultisigSignerTileDisplay";

export type MultisigSignerState =
| "awaitingApprovalByExternalSigner"
| "approved"
| "executable"
| "approvable";

export const MultisigActionButton: React.FC<{
signerState: MultisigSignerState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import { MultisigOperation } from "../../../../utils/multisig/types";
import MultisigSignerTile from "./MultisigSignerTile";
import MultisigDecodedOperations from "./MultisigDecodedOperations";
import { MultisigAccount } from "../../../../types/Account";
import ApproveExecuteForm from "../../../ApproveExecuteForm/ApproveExecuteForm";
import { useModal } from "../../../useModal";
import colors from "../../../../style/colors";

export const MultisigPendingAccordionItem: React.FC<{
operation: MultisigOperation;
sender: MultisigAccount;
}> = ({ operation, sender }) => {
const { modalElement, onOpen } = useModal(ApproveExecuteForm);

const { signers, threshold } = sender;
const pendingApprovals = Math.max(threshold - operation.approvals.length, 0);
return (
Expand Down Expand Up @@ -62,15 +58,13 @@ export const MultisigPendingAccordionItem: React.FC<{
key={signer.pkh}
signerAddress={signer}
pendingApprovals={pendingApprovals}
openSignModal={onOpen}
sender={sender}
operation={operation}
/>
))}
</Box>
</AccordionPanel>
</AccordionItem>
{modalElement}
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe("<MultisigSignerTile/>", () => {
pendingApprovals={0}
operation={pendingOps[0]}
sender={mockMultisigAccount(0)}
openSignModal={_ => {}}
/>
);
expect(screen.getByTestId("multisig-signer-button")).toBeInTheDocument();
Expand All @@ -34,7 +33,6 @@ describe("<MultisigSignerTile/>", () => {
pendingApprovals={1}
operation={{ ...pendingOps[0], approvals: [signer.address] }}
sender={mockMultisigAccount(0)}
openSignModal={_ => {}}
/>
);
expect(screen.queryByTestId("multisig-signer-button")).not.toBeInTheDocument();
Expand All @@ -48,7 +46,6 @@ describe("<MultisigSignerTile/>", () => {
pendingApprovals={1}
operation={pendingOps[0]}
sender={account}
openSignModal={_ => {}}
/>
);
expect(screen.queryByTestId("multisig-signer-button")).not.toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import React from "react";
import React, { useContext } from "react";
import { ImplicitAccount, MultisigAccount } from "../../../../types/Account";
import { ImplicitAddress } from "../../../../types/Address";
import { useGetImplicitAccountSafe } from "../../../../utils/hooks/accountHooks";
import { useSelectedNetwork } from "../../../../utils/hooks/assetsHooks";
import { useGetContactName } from "../../../../utils/hooks/contactsHooks";
import { useAsyncActionHandler } from "../../../../utils/hooks/useAsyncActionHandler";
import { MultisigOperation } from "../../../../utils/multisig/types";
import { ParamsWithFee } from "../../../ApproveExecuteForm/types";
import { MultisigSignerTileDisplay, MultisigSignerState } from "./MultisigSignerTileDisplay";
import { MultisigSignerState } from "./MultisigActionButton";
import { makeAccountOperations } from "../../../sendForm/types";
import { estimate } from "../../../../utils/tezos";
import { makeMultisigApproveOrExecuteOperation } from "../../../../types/Operation";
import { estimate } from "../../../../utils/tezos";
import { DynamicModalContext } from "../../../DynamicModal";
import SignPage from "../../../SendFlow/Multisig/SignPage";
import { MultisigSignerTileDisplay } from "./MultisigSignerTileDisplay";

const MultisigSignerTile: React.FC<{
signerAddress: ImplicitAddress;
pendingApprovals: number;
operation: MultisigOperation;
sender: MultisigAccount;
openSignModal: (params: ParamsWithFee) => void;
}> = ({ pendingApprovals, sender, operation, openSignModal, signerAddress }) => {
}> = ({ pendingApprovals, sender, operation, signerAddress }) => {
const getContactName = useGetContactName();
const getImplicitAccount = useGetImplicitAccountSafe();
const { isLoading, handleAsyncAction } = useAsyncActionHandler();
const { openWith } = useContext(DynamicModalContext);
const network = useSelectedNetwork();

const implicitAccount = getImplicitAccount(signerAddress.pkh);
Expand All @@ -35,6 +37,8 @@ const MultisigSignerTile: React.FC<{

const operationIsExecutable = pendingApprovals === 0;

const kind = contactName ? "contact" : signer?.type ?? "unknown";

const onButtonClick = () =>
handleAsyncAction(async () => {
if (!signer) {
Expand All @@ -46,20 +50,22 @@ const MultisigSignerTile: React.FC<{
const executeOrApprove = makeAccountOperations(signer, signer, [
makeMultisigApproveOrExecuteOperation(sender.address, actionType, operation.id),
]);
const suggestedFeeMutez = await estimate(executeOrApprove, network);

openSignModal({
type: actionType,
operation: operation,
sender,
signer,
suggestedFeeMutez: suggestedFeeMutez.toNumber(),
});
const fee = await estimate(executeOrApprove, network);

openWith(
<SignPage
fee={fee}
type={actionType}
signer={signer}
sender={sender}
operation={operation}
/>
);
});

return (
<MultisigSignerTileDisplay
kind={getKind(signer, contactName)}
kind={kind}
pkh={signerAddress.pkh}
label={label}
signerState={getMultisigSignerState({
Expand All @@ -74,14 +80,6 @@ const MultisigSignerTile: React.FC<{
);
};

const getKind = (signerAccount?: ImplicitAccount, contactName?: string) => {
if (contactName) {
return "contact";
}

return signerAccount?.type || "unknown";
};

const getMultisigSignerState = ({
signerAccount,
operationIsExecutable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { AccountType } from "../../../../types/Account";
import { AccountTileBase, LabelAndAddress } from "../../../AccountTile/AccountTileDisplay";
import { getIcon } from "../../../AccountTile/getIcon";
import { AddressKind } from "../../../AccountTile/AddressKind";
import MultisigActionButton from "./MultisigActionButton";

export type MultisigSignerState =
| "awaitingApprovalByExternalSigner"
| "approved"
| "executable"
| "approvable";
import MultisigActionButton, { MultisigSignerState } from "./MultisigActionButton";

export const MultisigSignerTileDisplay: React.FC<{
pkh: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Accordion, Box } from "@chakra-ui/react";
import { range } from "lodash";
import React from "react";
import { MultisigAccount } from "../../../../types/Account";
import { useGetPendingOperations } from "../../../../utils/hooks/multisigHooks";
import { useGetPendingMultisigOperations } from "../../../../utils/hooks/multisigHooks";
import NoItems from "../../../NoItems";
import MultisigPendingAccordionItem from "./MultisigPendingAccordionItem";

export const MultisigPendingAccordion: React.FC<{
account: MultisigAccount;
}> = ({ account }) => {
const getPendingOperations = useGetPendingOperations();
const getPendingOperations = useGetPendingMultisigOperations();
const pendingOperations = getPendingOperations(account);
if (pendingOperations.length === 0) {
return <NoItems text="No multisig pending operations" small />;
Expand Down
26 changes: 0 additions & 26 deletions src/components/ApproveExecuteForm/ApproveExecuteForm.tsx

This file was deleted.

88 changes: 0 additions & 88 deletions src/components/ApproveExecuteForm/SubmitApproveExecute.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/ApproveExecuteForm/types.tsx

This file was deleted.

Loading

0 comments on commit 26b4b68

Please sign in to comment.