diff --git a/src/components/AccountCard/ApproveExecuteForm/types.tsx b/src/components/AccountCard/ApproveExecuteForm/types.tsx
deleted file mode 100644
index 35beb6e98..000000000
--- a/src/components/AccountCard/ApproveExecuteForm/types.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { ApproveOrExecute } from "../../../utils/tezos/types";
-import { MultisigOperation } from "../../../utils/multisig/types";
-import { ContractAddress, ImplicitAddress } from "../../../types/Address";
-
-export type ParamsWithFee = ApproveExecuteParams & { suggestedFeeMutez: number };
-
-export type ApproveExecuteParams = {
- type: ApproveOrExecute;
- operation: MultisigOperation;
- signer: ImplicitAddress;
- multisigAddress: ContractAddress;
-};
diff --git a/src/components/AccountCard/ApproveExecuteForm/useApproveOrExecuteModal.tsx b/src/components/AccountCard/ApproveExecuteForm/useApproveOrExecuteModal.tsx
deleted file mode 100644
index 2607ca6b1..000000000
--- a/src/components/AccountCard/ApproveExecuteForm/useApproveOrExecuteModal.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import { useToast } from "@chakra-ui/react";
-import { useState } from "react";
-import ApproveExecuteForm from "./ApproveExecuteForm";
-import { useGetPk } from "../../../utils/hooks/accountHooks";
-import { useSelectedNetwork } from "../../../utils/hooks/assetsHooks";
-import { estimateMultisigApproveOrExecute } from "../../../utils/tezos";
-import { ApproveExecuteParams } from "./types";
-import { useModal } from "./useModal";
-
-export const useApproveOrExecuteModdal = () => {
- const { modalElement, onOpen } = useModal(ApproveExecuteForm);
- const toast = useToast();
- const [isLoading, setIsLoading] = useState(false);
- const network = useSelectedNetwork();
- const getPk = useGetPk();
-
- const approveOrExecute = async (params: ApproveExecuteParams) => {
- setIsLoading(true);
- try {
- const pk = getPk(params.signer.pkh);
- const { suggestedFeeMutez } = await estimateMultisigApproveOrExecute(
- {
- type: params.type,
- contract: params.multisigAddress,
- operationId: params.operation.id,
- },
- pk,
- params.signer.pkh,
- network
- );
- onOpen({ ...params, suggestedFeeMutez });
- } catch (error: any) {
- console.warn("Failed simulation", error);
- toast({ title: "Failed simulation", description: error.message, status: "warning" });
- }
-
- setIsLoading(false);
- };
-
- return { modalElement, isLoading, approveOrExecute };
-};
diff --git a/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.test.tsx b/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.test.tsx
index 6d75fd37b..8d8157749 100644
--- a/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.test.tsx
+++ b/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.test.tsx
@@ -1,76 +1,80 @@
-import { mockImplicitAccount } from "../../../../mocks/factories";
+import { mockImplicitAccount, mockMultisigAccount } from "../../../../mocks/factories";
import { render, screen } from "../../../../mocks/testUtils";
import store from "../../../../utils/redux/store";
import MultisigActionButton from "./MultisigSignerTile";
import accountsSlice from "../../../../utils/redux/slices/accountsSlice";
+import { pendingOps } from "../../../../mocks/multisig";
const { add } = accountsSlice.actions;
+const account = mockImplicitAccount(0);
describe("", () => {
it("should display execute for non-pending operation with signer included in the owned account", () => {
- const account = mockImplicitAccount(0);
store.dispatch(add([account]));
render(
{}}
+ openSignModal={_ => {}}
+ operation={pendingOps[0]}
+ account={mockMultisigAccount(0)}
/>
);
expect(screen.getByTestId("multisig-signer-button")).toHaveTextContent("Execute");
});
it("should display approve for pending operation with signer included in the owned account", () => {
- const account = mockImplicitAccount(0);
store.dispatch(add([account]));
render(
{}}
+ openSignModal={_ => {}}
+ operation={pendingOps[0]}
+ account={mockMultisigAccount(0)}
/>
);
expect(screen.getByTestId("multisig-signer-button")).toHaveTextContent("Approve");
});
it("should show approved for pending operation with signers included in the account that already approved", () => {
- const account = mockImplicitAccount(0);
store.dispatch(add([account]));
+ const operation = { ...pendingOps[0], approvals: [account.address] };
render(
{}}
+ openSignModal={_ => {}}
+ operation={operation}
+ account={mockMultisigAccount(0)}
/>
);
expect(screen.getByTestId("multisig-signer-approved")).toHaveTextContent("Approved");
});
it("should show approved for operation with signers not in the account", () => {
- const account = mockImplicitAccount(0);
+ const operation = { ...pendingOps[0], approvals: [account.address] };
render(
{}}
+ openSignModal={_ => {}}
+ operation={operation}
+ account={mockMultisigAccount(0)}
/>
);
expect(screen.getByTestId("multisig-signer-approved-or-waiting")).toHaveTextContent("Approved");
});
it("should show Awaiting approval for operation with signers not owned by the user account that hasn't approved", () => {
- const account = mockImplicitAccount(0);
render(
{}}
+ openSignModal={_ => {}}
+ operation={pendingOps[0]}
+ account={mockMultisigAccount(0)}
/>
);
expect(screen.getByTestId("multisig-signer-approved-or-waiting")).toHaveTextContent(
diff --git a/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.tsx b/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.tsx
index 2c63c5bd5..b95820347 100644
--- a/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.tsx
+++ b/src/components/AccountCard/AssetsPannel/MultisigPendingAccordion/MultisigActionButton.tsx
@@ -5,20 +5,32 @@ import { RxCheckCircled } from "react-icons/rx";
import colors from "../../../../style/colors";
import { ImplicitAddress } from "../../../../types/Address";
import { useGetImplicitAccount } from "../../../../utils/hooks/accountHooks";
-import { ApproveOrExecute } from "../../../../utils/tezos/types";
+import { useSelectedNetwork } from "../../../../utils/hooks/assetsHooks";
+import { estimateMultisigApproveOrExecute } from "../../../../utils/tezos";
import { IconAndTextBtn } from "../../../IconAndTextBtn";
+import { ParamsWithFee } from "../../../ApproveExecuteForm/types";
+import { MultisigOperation } from "../../../../utils/multisig/types";
+import { MultisigAccount } from "../../../../types/Account";
export const MultisigActionButton: React.FC<{
- signer: ImplicitAddress; // TODO: change to ImplicitAccount
- approvers: ImplicitAddress[]; // TODO: change to ImplicitAccount
+ signerAddress: ImplicitAddress;
pendingApprovals: number;
- onClickApproveOrExecute: (a: ApproveOrExecute) => void;
- isLoading?: boolean;
-}> = ({ signer, approvers, pendingApprovals, onClickApproveOrExecute, isLoading = false }) => {
+ operation: MultisigOperation;
+ account: MultisigAccount;
+ openSignModal: (params: ParamsWithFee) => void;
+}> = ({
+ signerAddress,
+ account: { address: multisigAddress },
+ operation,
+ pendingApprovals,
+ openSignModal,
+}) => {
const getImplicitAccount = useGetImplicitAccount();
+ const network = useSelectedNetwork();
+ const signer = getImplicitAccount(signerAddress.pkh);
+ const signerInOwnedAccounts = !!signer;
- const signerInOwnedAccounts = !!getImplicitAccount(signer.pkh);
- const approvedBySigner = !!approvers.find(approver => approver === signer);
+ const approvedBySigner = !!operation.approvals.find(approver => approver === signerAddress);
const operationIsExecutable = pendingApprovals === 0;
if (!signerInOwnedAccounts) {
@@ -47,13 +59,28 @@ export const MultisigActionButton: React.FC<{
);
}
+ const onButtonClick = async () => {
+ const actionType = operationIsExecutable ? "execute" : "approve";
+ const { suggestedFeeMutez } = await estimateMultisigApproveOrExecute(
+ {
+ type: actionType,
+ contract: multisigAddress,
+ operationId: operation.id,
+ },
+ signer,
+ network
+ );
+ openSignModal({
+ type: actionType,
+ operation: operation,
+ multisigAddress,
+ signer,
+ suggestedFeeMutez,
+ });
+ };
+
return (
-