From 567c1b5b80b953ee49206e06b590f0a389f9eccd Mon Sep 17 00:00:00 2001 From: Sergey Kintsel Date: Wed, 26 Jul 2023 12:16:54 +0100 Subject: [PATCH 1/4] Remove RawOperation leftovers --- .../CSVFileUploader/CSVFileUploadForm.tsx | 4 +- src/multisig/multisigUtils.test.ts | 2 +- src/types/RawOperation.ts | 40 ------------------- src/utils/tezos/helpers.test.ts | 2 +- src/utils/tezos/helpers.ts | 2 +- 5 files changed, 5 insertions(+), 45 deletions(-) delete mode 100644 src/types/RawOperation.ts diff --git a/src/components/CSVFileUploader/CSVFileUploadForm.tsx b/src/components/CSVFileUploader/CSVFileUploadForm.tsx index 8b50f5001..fc542a093 100644 --- a/src/components/CSVFileUploader/CSVFileUploadForm.tsx +++ b/src/components/CSVFileUploader/CSVFileUploadForm.tsx @@ -16,7 +16,7 @@ import { import Papa, { ParseResult } from "papaparse"; import { FormProvider, useForm } from "react-hook-form"; import { ImplicitAccount } from "../../types/Account"; -import { RawOperation } from "../../types/RawOperation"; +import { Operation } from "../../types/Operation"; import { useGetImplicitAccount } from "../../utils/hooks/accountHooks"; import { useBatchIsSimulating, @@ -58,7 +58,7 @@ const CSVFileUploadForm = ({ onClose }: { onClose: () => void }) => { throw new Error("Error loading csv file."); } - const operations: RawOperation[] = []; + const operations: Operation[] = []; for (let i = 0; i < rows.data.length; i++) { const row = rows.data[i]; try { diff --git a/src/multisig/multisigUtils.test.ts b/src/multisig/multisigUtils.test.ts index bcef1496a..eb76ec196 100644 --- a/src/multisig/multisigUtils.test.ts +++ b/src/multisig/multisigUtils.test.ts @@ -1,6 +1,6 @@ import { mockContractAddress, mockImplicitAddress } from "../mocks/factories"; import { ContractAddress, ImplicitAddress, parseContractPkh } from "../types/Address"; -import { FA12Operation, FA2Operation } from "../types/RawOperation"; +import { FA12Operation, FA2Operation } from "../types/Operation"; import { makeFA12TransactionParameter, makeFA2TransactionParameter } from "../utils/tezos"; import { FA12_TRANSFER_ARG_TYPES, diff --git a/src/types/RawOperation.ts b/src/types/RawOperation.ts deleted file mode 100644 index 7f2ff0be3..000000000 --- a/src/types/RawOperation.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { BigMapAbstraction, TransferParams } from "@taquito/taquito"; -import { BigNumber } from "bignumber.js"; -import { Address, ContractAddress, ImplicitAddress } from "./Address"; - -export type MultisigStorage = { - last_op_id: BigNumber; - pending_ops: BigMapAbstraction; - threshold: BigNumber; - owner: Address; - metadata: BigMapAbstraction; - signers: Address[]; -}; - -export type TezOperation = { - type: "tez"; - recipient: Address; - amount: string; - parameter?: TransferParams["parameter"]; -}; - -export type FA2Operation = { - type: "fa2"; - sender: Address; - recipient: Address; - contract: ContractAddress; - tokenId: string; - amount: string; -}; - -export type FA12Operation = Omit & { - type: "fa1.2"; - tokenId: "0"; -}; - -export type Delegation = { - type: "delegation"; - recipient: ImplicitAddress | undefined; -}; - -export type RawOperation = TezOperation | FA12Operation | FA2Operation | Delegation; diff --git a/src/utils/tezos/helpers.test.ts b/src/utils/tezos/helpers.test.ts index c0d6f83c0..0368214e7 100644 --- a/src/utils/tezos/helpers.test.ts +++ b/src/utils/tezos/helpers.test.ts @@ -1,7 +1,7 @@ import { InMemorySigner } from "@taquito/signer"; import axios from "axios"; import { mockContractAddress, mockImplicitAddress } from "../../mocks/factories"; -import { FA12Operation, FA2Operation } from "../../types/RawOperation"; +import { FA12Operation, FA2Operation } from "../../types/Operation"; import { tzktUrls } from "./consts"; import { addressExists, diff --git a/src/utils/tezos/helpers.ts b/src/utils/tezos/helpers.ts index eaf9b105e..287b68f25 100644 --- a/src/utils/tezos/helpers.ts +++ b/src/utils/tezos/helpers.ts @@ -5,7 +5,7 @@ import { Curves, InMemorySigner } from "@taquito/signer"; import { TezosToolkit, TransferParams } from "@taquito/taquito"; import axios from "axios"; import { shuffle } from "lodash"; -import { FA12Operation, FA2Operation } from "../../types/RawOperation"; +import { FA12Operation, FA2Operation } from "../../types/Operation"; import { SignerConfig } from "../../types/SignerConfig"; import { TezosNetwork } from "../../types/TezosNetwork"; import { PublicKeyPair } from "../restoreAccounts"; From 8b721c75c89518c2cfeefdfbaa1bfa1425d7926e Mon Sep 17 00:00:00 2001 From: Sergey Kintsel Date: Wed, 26 Jul 2023 12:58:08 +0100 Subject: [PATCH 2/4] Add sender to the Delegation operation type It is required by taquito that we specify the sender (source) for delegation operations. This way we can have a unified type that is ready to be consumed by taquito's API --- .../MultisigActionButton.test.tsx | 10 ++--- .../MultisigActionButton.tsx | 14 ++---- .../MultisigDecodedOperationItem.test.tsx | 4 +- .../MultisigDecodedOperations.tsx | 6 ++- .../MultisigPendingAccordionItem.test.tsx | 8 ++-- .../MultisigPendingAccordionItem.tsx | 10 ++--- .../MultisigSignerTile.test.tsx | 6 +-- .../MultisigSignerTile.tsx | 2 +- .../MultisigPendingAccordion/index.tsx | 6 +-- .../ApproveExecuteForm/ApproveExecuteForm.tsx | 3 +- .../SubmitApproveExecute.tsx | 30 ++++++------- src/components/ApproveExecuteForm/types.tsx | 5 +-- .../sendForm/components/SignButton.tsx | 14 +++--- src/components/sendForm/steps/FillStep.tsx | 1 + src/components/sendForm/steps/SubmitStep.tsx | 2 +- src/integration/tezos.integration.test.ts | 3 ++ src/mocks/factories.ts | 1 + src/multisig/decode/decodeLambda.test.ts | 43 ++++++++++++------- src/multisig/decode/decodeLambda.ts | 32 +++++++++----- src/multisig/multisigUtils.test.ts | 10 ++++- src/types/Operation.ts | 1 + .../BeaconRequestNotification.tsx | 9 ++-- .../panels/SignPayloadRequestPanel.tsx | 2 +- 23 files changed, 124 insertions(+), 98 deletions(-) diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.test.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.test.tsx index 8d8157749..677e63e04 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.test.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.test.tsx @@ -18,7 +18,7 @@ describe("", () => { pendingApprovals={0} openSignModal={_ => {}} operation={pendingOps[0]} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} /> ); expect(screen.getByTestId("multisig-signer-button")).toHaveTextContent("Execute"); @@ -32,7 +32,7 @@ describe("", () => { pendingApprovals={1} openSignModal={_ => {}} operation={pendingOps[0]} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} /> ); expect(screen.getByTestId("multisig-signer-button")).toHaveTextContent("Approve"); @@ -47,7 +47,7 @@ describe("", () => { pendingApprovals={1} openSignModal={_ => {}} operation={operation} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} /> ); expect(screen.getByTestId("multisig-signer-approved")).toHaveTextContent("Approved"); @@ -61,7 +61,7 @@ describe("", () => { pendingApprovals={1} openSignModal={_ => {}} operation={operation} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} /> ); expect(screen.getByTestId("multisig-signer-approved-or-waiting")).toHaveTextContent("Approved"); @@ -74,7 +74,7 @@ describe("", () => { pendingApprovals={1} openSignModal={_ => {}} operation={pendingOps[0]} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} /> ); expect(screen.getByTestId("multisig-signer-approved-or-waiting")).toHaveTextContent( diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.tsx index b95820347..6bfc33ef2 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigActionButton.tsx @@ -16,15 +16,9 @@ export const MultisigActionButton: React.FC<{ signerAddress: ImplicitAddress; pendingApprovals: number; operation: MultisigOperation; - account: MultisigAccount; + sender: MultisigAccount; openSignModal: (params: ParamsWithFee) => void; -}> = ({ - signerAddress, - account: { address: multisigAddress }, - operation, - pendingApprovals, - openSignModal, -}) => { +}> = ({ signerAddress, sender, operation, pendingApprovals, openSignModal }) => { const getImplicitAccount = useGetImplicitAccount(); const network = useSelectedNetwork(); const signer = getImplicitAccount(signerAddress.pkh); @@ -64,7 +58,7 @@ export const MultisigActionButton: React.FC<{ const { suggestedFeeMutez } = await estimateMultisigApproveOrExecute( { type: actionType, - contract: multisigAddress, + contract: sender.address, operationId: operation.id, }, signer, @@ -73,7 +67,7 @@ export const MultisigActionButton: React.FC<{ openSignModal({ type: actionType, operation: operation, - multisigAddress, + sender, signer, suggestedFeeMutez, }); diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperationItem.test.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperationItem.test.tsx index 2d3e26729..1a7a1b4f3 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperationItem.test.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperationItem.test.tsx @@ -16,7 +16,9 @@ beforeEach(() => { describe("", () => { it("displays delegate", () => { render( - + ); expect(screen.getByTestId("decoded-item-delegate")).toHaveTextContent("Undelegate"); diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperations.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperations.tsx index af2d9250d..d68cefea3 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperations.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperations.tsx @@ -10,13 +10,15 @@ import { } from "@chakra-ui/react"; import { parseRawMichelson } from "../../../../multisig/decode/decodeLambda"; import { UnrecognizedMichelsonError } from "../../../../multisig/decode/UnrecognizedMichelsonError"; +import { MultisigAccount } from "../../../../types/Account"; import MultisigDecodedOperationItem from "./MultisigDecodedOperationItem"; const MultisigDecodedOperations: React.FC<{ rawActions: string; -}> = ({ rawActions }) => { + sender: MultisigAccount; +}> = ({ rawActions, sender }) => { try { - const operations = parseRawMichelson(rawActions); + const operations = parseRawMichelson(rawActions, sender); return ( {operations.map((operation, i) => ( diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.test.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.test.tsx index f9661781d..d8537505b 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.test.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.test.tsx @@ -33,7 +33,7 @@ describe("", () => { render( ", () => { render( ", () => { render( - + ); const firstPendingOp = screen.getByTestId("multisig-pending-operation-" + pendingOps[0].id); @@ -145,7 +145,7 @@ describe("", () => { const approvablePendingOp: MultisigOperation = { ...pendingOps[0], approvals: [] }; render( - + ); const firstPendingOp = screen.getByTestId("multisig-pending-operation-" + pendingOps[0].id); diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.tsx index bf3b449a1..665ad13fc 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigPendingAccordionItem.tsx @@ -19,11 +19,11 @@ import colors from "../../../../style/colors"; export const MultisigPendingAccordionItem: React.FC<{ operation: MultisigOperation; - account: MultisigAccount; -}> = ({ operation, account }) => { + sender: MultisigAccount; +}> = ({ operation, sender }) => { const { modalElement, onOpen } = useModal(ApproveExecuteForm); - const { signers, threshold } = account; + const { signers, threshold } = sender; const pendingApprovals = Math.max(threshold - operation.approvals.length, 0); return ( - + Pending Approvals: @@ -63,7 +63,7 @@ export const MultisigPendingAccordionItem: React.FC<{ signerAddress={signer} pendingApprovals={pendingApprovals} openSignModal={onOpen} - account={account} + sender={sender} operation={operation} /> ))} diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.test.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.test.tsx index 898f86ba3..d40ed96a2 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.test.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.test.tsx @@ -20,7 +20,7 @@ describe("", () => { signerAddress={signer.address} pendingApprovals={0} operation={pendingOps[0]} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} openSignModal={_ => {}} /> ); @@ -33,7 +33,7 @@ describe("", () => { signerAddress={signer.address} pendingApprovals={1} operation={{ ...pendingOps[0], approvals: [signer.address] }} - account={mockMultisigAccount(0)} + sender={mockMultisigAccount(0)} openSignModal={_ => {}} /> ); @@ -47,7 +47,7 @@ describe("", () => { signerAddress={mockImplicitAccount(1).address} pendingApprovals={1} operation={pendingOps[0]} - account={account} + sender={account} openSignModal={_ => {}} /> ); diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.tsx index ca91713d3..458a1b42c 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigSignerTile.tsx @@ -15,7 +15,7 @@ const MultisigSignerTile: React.FC<{ signerAddress: ImplicitAddress; pendingApprovals: number; operation: MultisigOperation; - account: MultisigAccount; + sender: MultisigAccount; openSignModal: (params: ParamsWithFee) => void; }> = props => { const signer = props.signerAddress; diff --git a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/index.tsx b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/index.tsx index 8c10d966e..a4b898b31 100644 --- a/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/index.tsx +++ b/src/components/AccountCard/AssetsPanel/MultisigPendingAccordion/index.tsx @@ -18,11 +18,7 @@ export const MultisigPendingAccordion: React.FC<{ {pendingOperations.map(operation => ( - + ))} diff --git a/src/components/ApproveExecuteForm/ApproveExecuteForm.tsx b/src/components/ApproveExecuteForm/ApproveExecuteForm.tsx index 3fe1e01bc..f0649d652 100644 --- a/src/components/ApproveExecuteForm/ApproveExecuteForm.tsx +++ b/src/components/ApproveExecuteForm/ApproveExecuteForm.tsx @@ -15,12 +15,11 @@ const ApproveExecuteForm: React.FC<{ params: ParamsWithFee }> = ({ params }) => if (history.currentStep.type === "submit") { return ( { history.goToStep({ type: "success", hash }); }} - signerAccount={params.signer} /> ); } diff --git a/src/components/ApproveExecuteForm/SubmitApproveExecute.tsx b/src/components/ApproveExecuteForm/SubmitApproveExecute.tsx index bc184ab9f..1445de8fa 100644 --- a/src/components/ApproveExecuteForm/SubmitApproveExecute.tsx +++ b/src/components/ApproveExecuteForm/SubmitApproveExecute.tsx @@ -12,7 +12,6 @@ import { useToast, } from "@chakra-ui/react"; import SignButton from "../sendForm/components/SignButton"; -import { ImplicitAccount } from "../../types/Account"; import { ParamsWithFee } from "./types"; import { prettyTezAmount } from "../../utils/format"; import MultisigDecodedOperations from "../AccountCard/AssetsPanel/MultisigPendingAccordion/MultisigDecodedOperations"; @@ -22,11 +21,9 @@ import { ApproveOrExecute } from "../../utils/tezos/types"; import { TezosNetwork } from "../../types/TezosNetwork"; import { TezosToolkit } from "@taquito/taquito"; -type Props = { - signerAccount: ImplicitAccount; +type Props = ParamsWithFee & { onSuccess: (hash: string) => void; network: TezosNetwork; - params: ParamsWithFee; }; const TITLE: Record = { @@ -37,8 +34,11 @@ const TITLE: Record = { export const SubmitApproveOrExecuteForm: React.FC = ({ network, onSuccess, - signerAccount, - params, + signer, + sender, + suggestedFeeMutez, + operation, + type: actionType, }) => { const toast = useToast(); @@ -46,9 +46,9 @@ export const SubmitApproveOrExecuteForm: React.FC = ({ try { const result = await approveOrExecuteMultisigOperation( { - contract: params.multisigAddress, - operationId: params.operation.id, - type: params.type, + contract: sender.address, + operationId: operation.id, + type: actionType, }, tezosToolkit ); @@ -62,30 +62,30 @@ export const SubmitApproveOrExecuteForm: React.FC = ({ return ( - {TITLE[params.type]} + {TITLE[actionType]} - {TITLE[params.type]} + {TITLE[actionType]} Signer: - + - + Fee - {prettyTezAmount(String(params.suggestedFeeMutez))} + {prettyTezAmount(String(suggestedFeeMutez))} - + ); diff --git a/src/components/ApproveExecuteForm/types.tsx b/src/components/ApproveExecuteForm/types.tsx index 6134f21e9..0838b6420 100644 --- a/src/components/ApproveExecuteForm/types.tsx +++ b/src/components/ApproveExecuteForm/types.tsx @@ -1,7 +1,6 @@ import { ApproveOrExecute } from "../../utils/tezos/types"; import { MultisigOperation } from "../../utils/multisig/types"; -import { ContractAddress } from "../../types/Address"; -import { ImplicitAccount } from "../../types/Account"; +import { ImplicitAccount, MultisigAccount } from "../../types/Account"; export type ParamsWithFee = ApproveExecuteParams & { suggestedFeeMutez: number }; @@ -9,5 +8,5 @@ export type ApproveExecuteParams = { type: ApproveOrExecute; operation: MultisigOperation; signer: ImplicitAccount; - multisigAddress: ContractAddress; + sender: MultisigAccount; }; diff --git a/src/components/sendForm/components/SignButton.tsx b/src/components/sendForm/components/SignButton.tsx index 9ed686ec7..f7fe99639 100644 --- a/src/components/sendForm/components/SignButton.tsx +++ b/src/components/sendForm/components/SignButton.tsx @@ -23,9 +23,9 @@ import { makeToolkit } from "../../../utils/tezos"; const SignButton: React.FC<{ onSubmit: (tezosToolkit: TezosToolkit) => Promise; - signerAccount: ImplicitAccount; + signer: ImplicitAccount; network: TezosNetwork; -}> = ({ signerAccount, network, onSubmit }) => { +}> = ({ signer, network, onSubmit }) => { const { register, handleSubmit, @@ -52,7 +52,7 @@ const SignButton: React.FC<{ const onMnemonicSign = async ({ password }: { password: string }) => { return handleSign(async () => { - const secretKey = await getSecretKey(signerAccount as MnemonicAccount, password); + const secretKey = await getSecretKey(signer as MnemonicAccount, password); return makeToolkit({ type: "mnemonic", secretKey, network }); }); }; @@ -65,14 +65,14 @@ const SignButton: React.FC<{ handleSign(() => makeToolkit({ type: "ledger", - account: signerAccount as LedgerAccount, + account: signer as LedgerAccount, network, }) ); return ( - {signerAccount.type === AccountType.MNEMONIC && ( + {signer.type === AccountType.MNEMONIC && ( <> Password: @@ -100,8 +100,8 @@ const SignButton: React.FC<{ )} - {signerAccount.type === AccountType.SOCIAL && } - {signerAccount.type === AccountType.LEDGER && ( + {signer.type === AccountType.SOCIAL && } + {signer.type === AccountType.LEDGER && ( diff --git a/src/components/sendForm/steps/FillStep.tsx b/src/components/sendForm/steps/FillStep.tsx index 4585ab2e9..3f8ef44e1 100644 --- a/src/components/sendForm/steps/FillStep.tsx +++ b/src/components/sendForm/steps/FillStep.tsx @@ -427,6 +427,7 @@ export const FillStep: React.FC<{ onSubmit={formValues => { const delegation: Delegation = { type: "delegation", + sender: parsePkh(sender), recipient: formValues.baker !== undefined ? parseImplicitPkh(formValues.baker) : undefined, }; diff --git a/src/components/sendForm/steps/SubmitStep.tsx b/src/components/sendForm/steps/SubmitStep.tsx index 20ba13d40..3c9e1f66c 100644 --- a/src/components/sendForm/steps/SubmitStep.tsx +++ b/src/components/sendForm/steps/SubmitStep.tsx @@ -95,7 +95,7 @@ export const SubmitStep: React.FC<{ - + diff --git a/src/integration/tezos.integration.test.ts b/src/integration/tezos.integration.test.ts index 9fa6a1ef7..34021a47a 100644 --- a/src/integration/tezos.integration.test.ts +++ b/src/integration/tezos.integration.test.ts @@ -37,6 +37,7 @@ describe("Tezos utils", () => { }, { type: "delegation", + sender: sender.address, recipient: pkh1, }, { @@ -253,6 +254,7 @@ describe("Tezos utils", () => { [ { type: "delegation", + sender: sender.address, recipient: parseImplicitPkh("tz1fXRwGcgoz81Fsksx9L2rVD5wE6CpTMkLz"), }, ], @@ -273,6 +275,7 @@ describe("Tezos utils", () => { }, { type: "delegation", + sender: sender.address, recipient: parseImplicitPkh("tz1fXRwGcgoz81Fsksx9L2rVD5wE6CpTMkLz"), }, ], diff --git a/src/mocks/factories.ts b/src/mocks/factories.ts index bef131e76..a6ab6bbd7 100644 --- a/src/mocks/factories.ts +++ b/src/mocks/factories.ts @@ -329,6 +329,7 @@ export const mockNftTransfer = (index: number): Operation => { export const mockDelegationTransfer = (index: number): Operation => { return { type: "delegation", + sender: mockImplicitAddress(index), recipient: mockImplicitAddress(index + 1), }; }; diff --git a/src/multisig/decode/decodeLambda.test.ts b/src/multisig/decode/decodeLambda.test.ts index 7f4a56d0c..197ed28bb 100644 --- a/src/multisig/decode/decodeLambda.test.ts +++ b/src/multisig/decode/decodeLambda.test.ts @@ -2,6 +2,9 @@ import { decode, parseRawMichelson } from "./decodeLambda"; import type { MichelsonV1Expression } from "@taquito/rpc"; import { parseContractPkh, parseImplicitPkh } from "../../types/Address"; import { UnrecognizedMichelsonError } from "./UnrecognizedMichelsonError"; +import { mockMultisigAccount } from "../../mocks/factories"; + +const multisig = mockMultisigAccount(0); describe("decodeLambda", () => { test("invalid michelsonJSON batch (no head)", () => { @@ -17,7 +20,7 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(() => decode(singleTezNoHead)).toThrowError(/Invalid literal value/i); + expect(() => decode(singleTezNoHead, multisig)).toThrowError(/Invalid literal value/i); }); test("simple tez", () => { @@ -34,7 +37,7 @@ describe("decodeLambda", () => { { prim: "TRANSFER_TOKENS" }, { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { amount: "910000", recipient: parseImplicitPkh("tz1Te4MXuNYxyyuPqmAQdnKwkD8ZgSF9M7d6"), @@ -66,7 +69,7 @@ describe("decodeLambda", () => { { prim: "TRANSFER_TOKENS" }, { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { type: "tez", amount: "5", @@ -185,7 +188,7 @@ describe("decodeLambda", () => { { prim: "TRANSFER_TOKENS" }, { prim: "CONS" }, ]; - const result = decode(input); + const result = decode(input, multisig); const expected = [ { amount: "1", @@ -223,7 +226,7 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { amount: "20000", recipient: parseImplicitPkh("tz1Te4MXuNYxyyuPqmAQdnKwkD8ZgSF9M7d6"), @@ -366,7 +369,7 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { amount: "600000", recipient: parseImplicitPkh("tz1Te4MXuNYxyyuPqmAQdnKwkD8ZgSF9M7d6"), @@ -458,7 +461,7 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { amount: "300", contract: parseContractPkh("KT1UCPcXExqEYRnfoXWYvBkkn5uPjn8TBTEe"), @@ -663,7 +666,7 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ + expect(decode(input, multisig)).toEqual([ { amount: "100000", recipient: parseImplicitPkh("tz1Te4MXuNYxyyuPqmAQdnKwkD8ZgSF9M7d6"), @@ -723,7 +726,7 @@ describe("decodeLambda", () => { "bye", ]; - expect(() => decode(input as MichelsonV1Expression[])).toThrow(); + expect(() => decode(input as MichelsonV1Expression[], multisig)).toThrow(); }); test("remove delegate", () => { @@ -735,7 +738,9 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([{ type: "delegation" }]); + expect(decode(input, multisig)).toEqual([ + { type: "delegation", sender: multisig.address, recipient: undefined }, + ]); }); test("set delegate", () => { @@ -751,8 +756,12 @@ describe("decodeLambda", () => { { prim: "CONS" }, ]; - expect(decode(input)).toEqual([ - { type: "delegation", recipient: parseImplicitPkh("tz1RuHDSj9P7mNNhfKxsyLGRDahTX5QD1DdP") }, + expect(decode(input, multisig)).toEqual([ + { + type: "delegation", + sender: multisig.address, + recipient: parseImplicitPkh("tz1RuHDSj9P7mNNhfKxsyLGRDahTX5QD1DdP"), + }, ]); }); @@ -780,13 +789,13 @@ describe("decodeLambda", () => { }, ]; - expect(() => decode(unrecognizableMichelson)).toThrow(UnrecognizedMichelsonError); + expect(() => decode(unrecognizableMichelson, multisig)).toThrow(UnrecognizedMichelsonError); }); test("parseRawMichelson decodes raw michelson", () => { const rawMichelson = '[{"prim":"DROP"},{"prim":"NIL","args":[{"prim":"operation"}]},{"prim":"PUSH","args":[{"prim":"key_hash"},{"bytes":"00e09454275ac1a764ca6f8b1f52a2eeff1fd4fe0e"}]},{"prim":"IMPLICIT_ACCOUNT"},{"prim":"PUSH","args":[{"prim":"mutez"},{"int":"350000000000"}]},{"prim":"UNIT"},{"prim":"TRANSFER_TOKENS"},{"prim":"CONS"},{"prim":"PUSH","args":[{"prim":"address"},{"bytes":"01d7270a1dd9a8b9ee6b48380fb60dc36a7cd521bb007472616e73666572"}]},{"prim":"CONTRACT","args":[{"prim":"pair","args":[{"prim":"address","annots":[":from"]},{"prim":"pair","args":[{"prim":"address","annots":[":to"]},{"prim":"nat","annots":[":value"]}]}]}]},[{"prim":"IF_NONE","args":[[{"prim":"UNIT"},{"prim":"FAILWITH"}],[]]}],{"prim":"PUSH","args":[{"prim":"mutez"},{"int":"0"}]},{"prim":"PUSH","args":[{"prim":"pair","args":[{"prim":"address","annots":[":from"]},{"prim":"pair","args":[{"prim":"address","annots":[":to"]},{"prim":"nat","annots":[":value"]}]}]},{"prim":"Pair","args":[{"bytes":"0156637790cdb23bc0a4c57d069d2e3577e5ed89a600"},{"prim":"Pair","args":[{"bytes":"0000e09454275ac1a764ca6f8b1f52a2eeff1fd4fe0e"},{"int":"2"}]}]}]},{"prim":"TRANSFER_TOKENS"},{"prim":"CONS"},{"prim":"PUSH","args":[{"prim":"address"},{"bytes":"01fc1beb979d7c8da00d6e5e22c297bcf541834607007472616e73666572"}]},{"prim":"CONTRACT","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"address","annots":["%from_"]},{"prim":"list","annots":["%txs"],"args":[{"prim":"pair","args":[{"prim":"address","annots":["%to_"]},{"prim":"pair","args":[{"prim":"nat","annots":["%token_id"]},{"prim":"nat","annots":["%amount"]}]}]}]}]}]}]},[{"prim":"IF_NONE","args":[[{"prim":"UNIT"},{"prim":"FAILWITH"}],[]]}],{"prim":"PUSH","args":[{"prim":"mutez"},{"int":"0"}]},{"prim":"PUSH","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"address","annots":["%from_"]},{"prim":"list","annots":["%txs"],"args":[{"prim":"pair","args":[{"prim":"address","annots":["%to_"]},{"prim":"pair","args":[{"prim":"nat","annots":["%token_id"]},{"prim":"nat","annots":["%amount"]}]}]}]}]}]},[{"prim":"Pair","args":[{"bytes":"0156637790cdb23bc0a4c57d069d2e3577e5ed89a600"},[{"prim":"Pair","args":[{"bytes":"0000e09454275ac1a764ca6f8b1f52a2eeff1fd4fe0e"},{"prim":"Pair","args":[{"int":"0"},{"int":"3"}]}]}]]}]]},{"prim":"TRANSFER_TOKENS"},{"prim":"CONS"}]'; - expect(parseRawMichelson(rawMichelson)).toEqual([ + expect(parseRawMichelson(rawMichelson, multisig)).toEqual([ { amount: "350000000000", recipient: { @@ -837,12 +846,14 @@ describe("decodeLambda", () => { const unrecognizableRawMichelson = '[{"prim":"DROP"},{"prim":"NIL","args":[{"prim":"operation"}]},{"prim":"PUSH","args":[{"prim":"address"},{"bytes":"0156cb5559a8d8c945944e71edec63dd04a8e76b87007472616e73666572"}]},{"prim":"CONTRACT","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"address","annots":["%from_"]},{"prim":"list","annots":["%txs"],"args":[{"prim":"pair","args":[{"prim":"address","annots":["%to_"]},{"prim":"pair","args":[{"prim":"nat","annots":["%token_id"]},{"prim":"nat","annots":["%amount"]}]}]}]}]}]}]},{"prim":"IF_NONE","args":[[{"prim":"UNIT"},{"prim":"FAILWITH"}],[{"prim":"PUSH","args":[{"prim":"mutez"},{"int":"1"}]},{"prim":"PUSH","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"address","annots":["%from_"]},{"prim":"list","annots":["%txs"],"args":[{"prim":"pair","args":[{"prim":"address","annots":["%to_"]},{"prim":"pair","args":[{"prim":"nat","annots":["%token_id"]},{"prim":"nat","annots":["%amount"]}]}]}]}]}]},[{"prim":"Pair","args":[{"bytes":"018e368c2083bdaef3199bae317d6c967c21d947b300"},[{"prim":"Pair","args":[{"bytes":"000057c264d6d7f7257cd3d8096150b0d8be60577ca7"},{"prim":"Pair","args":[{"int":"6"},{"int":"1"}]}]}]]}]]},{"prim":"TRANSFER_TOKENS"},{"prim":"CONS"}]]}]'; - expect(() => parseRawMichelson(unrecognizableRawMichelson)).toThrow(UnrecognizedMichelsonError); + expect(() => parseRawMichelson(unrecognizableRawMichelson, multisig)).toThrow( + UnrecognizedMichelsonError + ); }); test("parseRawMichelson should throw syntax error", () => { const invalidJsonString = "{a:"; - expect(() => parseRawMichelson(invalidJsonString)).toThrow(SyntaxError); + expect(() => parseRawMichelson(invalidJsonString, multisig)).toThrow(SyntaxError); }); }); diff --git a/src/multisig/decode/decodeLambda.ts b/src/multisig/decode/decodeLambda.ts index 77b1dba91..70274fd91 100644 --- a/src/multisig/decode/decodeLambda.ts +++ b/src/multisig/decode/decodeLambda.ts @@ -12,6 +12,7 @@ import { import type { MichelsonV1Expression } from "@taquito/rpc"; import { parseContractPkh, parseImplicitPkh, parsePkh } from "../../types/Address"; import { UnrecognizedMichelsonError } from "./UnrecognizedMichelsonError"; +import { MultisigAccount } from "../../types/Account"; const convertToPkh = (addressBytes: string): string => { if (addressBytes.length === 42) { @@ -94,17 +95,24 @@ const parseFa1 = (michelson: MichelsonV1Expression[]): Operation => { }; }; -const parseSetDelegate = (michelson: MichelsonV1Expression[]): Operation => { +const parseSetDelegate = ( + michelson: MichelsonV1Expression[], + account: MultisigAccount +): Operation => { const parseResult = setDelegateSchema.parse(michelson); return { type: "delegation", + sender: account.address, recipient: parseImplicitPkh(convertToPkh(parseResult[0].args[1].bytes)), }; }; -const parseRemoveDelegate = (_michelson: MichelsonV1Expression[]): Operation => { - return { type: "delegation", recipient: undefined }; +const parseRemoveDelegate = ( + _michelson: MichelsonV1Expression[], + account: MultisigAccount +): Operation => { + return { type: "delegation", sender: account.address, recipient: undefined }; }; const parsings = [ @@ -116,7 +124,11 @@ const parsings = [ { schema: removeDelegateSchema, parsingFn: parseRemoveDelegate }, ]; -const parse = (michelson: MichelsonV1Expression[], acc: Operation[] = []): Operation[] => { +const parse = ( + michelson: MichelsonV1Expression[], + account: MultisigAccount, + acc: Operation[] = [] +): Operation[] => { if (michelson.length === 0) { return acc; } @@ -128,8 +140,8 @@ const parse = (michelson: MichelsonV1Expression[], acc: Operation[] = []): Opera continue; } - const parsed = parsingFn(parseResult.data); - return parse(michelson.slice(schema.items.length), [...acc, ...[parsed].flat()]); + const parsed = parsingFn(parseResult.data, account); + return parse(michelson.slice(schema.items.length), account, [...acc, ...[parsed].flat()]); } throw new UnrecognizedMichelsonError(`${JSON.stringify(michelson[0])}`); @@ -139,13 +151,13 @@ const assertHead = (michelson: MichelsonV1Expression[]) => { batchHeadSchema.parse(michelson.slice(0, 2)); }; -export const decode = (michelson: MichelsonV1Expression[]) => { +export const decode = (michelson: MichelsonV1Expression[], account: MultisigAccount) => { assertHead(michelson); - return parse(michelson.slice(2)); + return parse(michelson.slice(2), account); }; -export const parseRawMichelson = (rawMichelson: string): Operation[] => { +export const parseRawMichelson = (rawMichelson: string, account: MultisigAccount): Operation[] => { const michelson: MichelsonV1Expression[] = JSON.parse(rawMichelson); - return decode(michelson); + return decode(michelson, account); }; diff --git a/src/multisig/multisigUtils.test.ts b/src/multisig/multisigUtils.test.ts index eb76ec196..40552bf54 100644 --- a/src/multisig/multisigUtils.test.ts +++ b/src/multisig/multisigUtils.test.ts @@ -91,6 +91,7 @@ describe("makeLambda", () => { it("can set a delegate", () => { const result = makeLambda({ type: "delegation", + sender: multisigContractAddress, recipient: mockImplicitAddress(0), }); expect(result).toEqual([ @@ -101,7 +102,11 @@ describe("makeLambda", () => { }); it("can unset a delegate", () => { - const result = makeLambda({ type: "delegation", recipient: undefined }); + const result = makeLambda({ + type: "delegation", + sender: multisigContractAddress, + recipient: undefined, + }); expect(result).toEqual([ { prim: "DROP" }, @@ -162,9 +167,10 @@ describe("makeBatchLambda", () => { fa12Operation, { type: "delegation", + sender: multisigContractAddress, recipient: mockImplicitAddress(1), }, - { type: "delegation", recipient: undefined }, + { type: "delegation", sender: multisigContractAddress, recipient: undefined }, ]); const expected = [ diff --git a/src/types/Operation.ts b/src/types/Operation.ts index db35b7b3c..88e4f3da4 100644 --- a/src/types/Operation.ts +++ b/src/types/Operation.ts @@ -34,6 +34,7 @@ export type FA12Operation = Omit & { export type Delegation = { type: "delegation"; + sender: Address; recipient: ImplicitAddress | undefined; }; diff --git a/src/utils/beacon/BeaconNotification/BeaconRequestNotification.tsx b/src/utils/beacon/BeaconNotification/BeaconRequestNotification.tsx index 9013ff35f..a232be47b 100644 --- a/src/utils/beacon/BeaconNotification/BeaconRequestNotification.tsx +++ b/src/utils/beacon/BeaconNotification/BeaconRequestNotification.tsx @@ -142,7 +142,7 @@ export const BeaconNotification: React.FC<{ } }; -const beaconToUmamiOperation = (operation: PartialTezosOperation, sender: string) => { +const beaconToUmamiOperation = (operation: PartialTezosOperation, sourceAddress: string) => { if (operation.kind === TezosOperationType.TRANSACTION) { const result: Operation = { type: "tez", @@ -157,6 +157,7 @@ const beaconToUmamiOperation = (operation: PartialTezosOperation, sender: string if (operation.kind === TezosOperationType.DELEGATION) { const result: Operation = { type: "delegation", + sender: parsePkh(sourceAddress), recipient: operation.delegate !== undefined ? parseImplicitPkh(operation.delegate) : undefined, }; @@ -167,12 +168,10 @@ const beaconToUmamiOperation = (operation: PartialTezosOperation, sender: string throw new Error(`Unsupported operation: ${operation.kind}`); }; -const buildTransfers = (o: OperationRequestOutput) => { - const { operationDetails } = o; - +const buildTransfers = ({ operationDetails, sourceAddress }: OperationRequestOutput) => { if (operationDetails.length === 0) { throw new Error("Empty operation details!"); } - return operationDetails.map(operation => beaconToUmamiOperation(operation, o.sourceAddress)); + return operationDetails.map(operation => beaconToUmamiOperation(operation, sourceAddress)); }; diff --git a/src/utils/beacon/BeaconNotification/panels/SignPayloadRequestPanel.tsx b/src/utils/beacon/BeaconNotification/panels/SignPayloadRequestPanel.tsx index a77adbcf8..d34d9dbe1 100644 --- a/src/utils/beacon/BeaconNotification/panels/SignPayloadRequestPanel.tsx +++ b/src/utils/beacon/BeaconNotification/panels/SignPayloadRequestPanel.tsx @@ -54,7 +54,7 @@ const SignPayloadRequestPanel: React.FC<{ {request.payload} - + ); From efa13d0a300dc944416a3c3728f8899d5993d535 Mon Sep 17 00:00:00 2001 From: Sergey Kintsel Date: Wed, 26 Jul 2023 13:15:10 +0100 Subject: [PATCH 3/4] Make taquito batch params builder not use sender We are using the sender from the delegate. Also, this function is not async anymore --- src/components/sendForm/SendForm.test.tsx | 6 --- src/components/sendForm/util/execution.ts | 12 ++--- src/components/sendForm/util/simulation.ts | 2 +- src/integration/tezos.integration.test.ts | 6 +-- .../multisigSandbox2.integration.test.ts | 5 -- src/utils/redux/slices/assetsSlice.test.ts | 1 - .../redux/thunks/estimateAndUpdateBatch.ts | 2 +- src/utils/tezos/estimate.ts | 5 +- src/utils/tezos/operations.ts | 4 +- src/utils/tezos/params.ts | 51 +++++-------------- src/views/batch/BatchView.test.tsx | 1 - src/views/batch/batchUtils.ts | 5 +- 12 files changed, 26 insertions(+), 74 deletions(-) diff --git a/src/components/sendForm/SendForm.test.tsx b/src/components/sendForm/SendForm.test.tsx index cadecbdfc..b80dd2de4 100644 --- a/src/components/sendForm/SendForm.test.tsx +++ b/src/components/sendForm/SendForm.test.tsx @@ -306,7 +306,6 @@ describe("", () => { recipient: mockImplicitAddress(7), }, ], - mockImplicitAccount(1), MOCK_TEZOS_TOOLKIT ); }); @@ -378,7 +377,6 @@ describe("", () => { }, ], mockImplicitAccount(2), - mockImplicitAccount(2), "mainnet" ); @@ -417,7 +415,6 @@ describe("", () => { tokenId: mockFA2.tokenId, }, ], - mockImplicitAccount(2), MOCK_TEZOS_TOOLKIT ); }); @@ -489,7 +486,6 @@ describe("", () => { }, ], mockImplicitAccount(2), - mockImplicitAccount(2), "mainnet" ); @@ -527,7 +523,6 @@ describe("", () => { tokenId: "0", }, ], - mockImplicitAccount(2), MOCK_TEZOS_TOOLKIT ); }); @@ -611,7 +606,6 @@ describe("", () => { tokenId: nft.token?.tokenId, }, ], - mockImplicitAccount(1), MOCK_TEZOS_TOOLKIT ); }); diff --git a/src/components/sendForm/util/execution.ts b/src/components/sendForm/util/execution.ts index 4f2c75bde..b3f89a60a 100644 --- a/src/components/sendForm/util/execution.ts +++ b/src/components/sendForm/util/execution.ts @@ -1,6 +1,6 @@ import { TezosToolkit } from "@taquito/taquito"; import { makeBatchLambda } from "../../../multisig/multisigUtils"; -import { ImplicitAccount, MultisigAccount } from "../../../types/Account"; +import { MultisigAccount } from "../../../types/Account"; import { Operation } from "../../../types/Operation"; import { proposeMultisigLambda, submitBatch } from "../../../utils/tezos"; import { FormOperations } from "../types"; @@ -15,12 +15,8 @@ const makeProposeOperation = async ( return proposeMultisigLambda({ contract: sender.address, lambdaActions }, tezosToolkit); }; -const makeTransferImplicit = async ( - operations: Operation[], - sender: ImplicitAccount, - tezosToolkit: TezosToolkit -) => { - return submitBatch(operations, sender, tezosToolkit).then(({ opHash }) => ({ hash: opHash })); +const makeTransferImplicit = async (operations: Operation[], tezosToolkit: TezosToolkit) => { + return submitBatch(operations, tezosToolkit).then(({ opHash }) => ({ hash: opHash })); }; export const makeTransfer = (op: FormOperations, tezosToolkit: TezosToolkit) => { @@ -29,7 +25,7 @@ export const makeTransfer = (op: FormOperations, tezosToolkit: TezosToolkit) => const transfer = op.type === "proposal" ? makeProposeOperation(transferToDisplay, op.sender, tezosToolkit) - : makeTransferImplicit(transferToDisplay, op.signer, tezosToolkit); + : makeTransferImplicit(transferToDisplay, tezosToolkit); return transfer; }; diff --git a/src/components/sendForm/util/simulation.ts b/src/components/sendForm/util/simulation.ts index 9cb2d0a0d..4d8525363 100644 --- a/src/components/sendForm/util/simulation.ts +++ b/src/components/sendForm/util/simulation.ts @@ -36,5 +36,5 @@ export const makeSimulation = async (operation: FormOperations, network: TezosNe } const implicitOps = operation.content; - return estimateBatch(implicitOps, operation.signer, operation.signer, network).then(getTotalFee); + return estimateBatch(implicitOps, operation.signer, network).then(getTotalFee); }; diff --git a/src/integration/tezos.integration.test.ts b/src/integration/tezos.integration.test.ts index 34021a47a..3795be2ef 100644 --- a/src/integration/tezos.integration.test.ts +++ b/src/integration/tezos.integration.test.ts @@ -65,7 +65,7 @@ describe("Tezos utils", () => { tokenId: ghostFA2.tokenId, }, ]; - const result = await operationsToBatchParams(input, sender); + const result = operationsToBatchParams(input); expect(result).toEqual([ { amount: 3, @@ -220,7 +220,6 @@ describe("Tezos utils", () => { }, ], sender, - sender, TezosNetwork.GHOSTNET ); for (let i = 0; i < ghostnetResult.length; i += 1) { @@ -242,7 +241,6 @@ describe("Tezos utils", () => { }, ], sender, - sender, TezosNetwork.MAINNET ); expect(mainnetResult).toHaveLength(2); @@ -259,7 +257,6 @@ describe("Tezos utils", () => { }, ], sender, - sender, TezosNetwork.MAINNET ); expect(mainnetResult).toHaveLength(1); @@ -280,7 +277,6 @@ describe("Tezos utils", () => { }, ], sender, - sender, TezosNetwork.MAINNET ); await expect(estimation).rejects.toThrow(/tez.subtraction_underflow/i); diff --git a/src/multisig/multisigSandbox2.integration.test.ts b/src/multisig/multisigSandbox2.integration.test.ts index 236de42d1..82d6dce3a 100644 --- a/src/multisig/multisigSandbox2.integration.test.ts +++ b/src/multisig/multisigSandbox2.integration.test.ts @@ -52,11 +52,6 @@ describe("multisig Sandbox", () => { recipient: MULTISIG_GHOSTNET_1, }, ], - { - ...mockImplicitAccount(0), - address: parseImplicitPkh(await devAccount2.publicKeyHash()), - pk: await devAccount2.publicKey(), - }, await makeToolkit({ type: "mnemonic", secretKey: devAccount2Sk, diff --git a/src/utils/redux/slices/assetsSlice.test.ts b/src/utils/redux/slices/assetsSlice.test.ts index cdd3b1473..02a801ef3 100644 --- a/src/utils/redux/slices/assetsSlice.test.ts +++ b/src/utils/redux/slices/assetsSlice.test.ts @@ -355,7 +355,6 @@ describe("Assets reducer", () => { expect(estimateBatchMock).toHaveBeenCalledWith( transfers, mockImplicitAccount(1), - mockImplicitAccount(1), TezosNetwork.MAINNET ); expect(store.getState().assets.batches[mockImplicitAddress(1).pkh]?.isSimulating).toEqual( diff --git a/src/utils/redux/thunks/estimateAndUpdateBatch.ts b/src/utils/redux/thunks/estimateAndUpdateBatch.ts index 5ba5833b9..84e912401 100644 --- a/src/utils/redux/thunks/estimateAndUpdateBatch.ts +++ b/src/utils/redux/thunks/estimateAndUpdateBatch.ts @@ -26,7 +26,7 @@ export const estimateAndUpdateBatch = ( dispatch(batchSimulationStart({ pkh: sender.address.pkh })); try { - const items = await operationsToBatchItems(operations, sender, signer, network); + const items = await operationsToBatchItems(operations, signer, network); dispatch(addToBatch({ pkh: sender.address.pkh, items })); } catch (error) { dispatch(batchSimulationEnd({ pkh: sender.address.pkh })); diff --git a/src/utils/tezos/estimate.ts b/src/utils/tezos/estimate.ts index 98e093003..9eef3e07a 100644 --- a/src/utils/tezos/estimate.ts +++ b/src/utils/tezos/estimate.ts @@ -1,5 +1,5 @@ import { Estimate } from "@taquito/taquito"; -import { Account, ImplicitAccount } from "../../types/Account"; +import { ImplicitAccount } from "../../types/Account"; import { Operation } from "../../types/Operation"; import { TezosNetwork } from "../../types/TezosNetwork"; import { @@ -36,11 +36,10 @@ export const estimateMultisigApproveOrExecute = async ( export const estimateBatch = async ( operations: Operation[], - sender: Account, signer: ImplicitAccount, network: TezosNetwork ): Promise => { - const batch = await operationsToBatchParams(operations, sender); + const batch = operationsToBatchParams(operations); const tezosToolkit = await makeToolkit({ type: "fake", signer, network }); diff --git a/src/utils/tezos/operations.ts b/src/utils/tezos/operations.ts index 3443f2a23..ea986b2b1 100644 --- a/src/utils/tezos/operations.ts +++ b/src/utils/tezos/operations.ts @@ -1,6 +1,5 @@ import { TezosToolkit, TransactionOperation } from "@taquito/taquito"; import { BatchWalletOperation } from "@taquito/taquito/dist/types/wallet/batch-operation"; -import { Account } from "../../types/Account"; import { Operation } from "../../types/Operation"; import { makeMultisigApproveOrExecuteMethod, makeMultisigProposeMethod } from "./helpers"; import { operationsToWalletParams } from "./params"; @@ -24,9 +23,8 @@ export const approveOrExecuteMultisigOperation = async ( export const submitBatch = async ( operation: Operation[], - sender: Account, tezosToolkit: TezosToolkit ): Promise => { - const params = await operationsToWalletParams(operation, sender); + const params = operationsToWalletParams(operation); return tezosToolkit.wallet.batch(params).send(); }; diff --git a/src/utils/tezos/params.ts b/src/utils/tezos/params.ts index 3e339a7f9..89fc88cea 100644 --- a/src/utils/tezos/params.ts +++ b/src/utils/tezos/params.ts @@ -1,57 +1,34 @@ import { OpKind, ParamsWithKind, WalletParamsWithKind } from "@taquito/taquito"; -import { Account } from "../../types/Account"; import { Operation } from "../../types/Operation"; import { makeTokenTransferParams } from "./helpers"; -export const operationsToWalletParams = async ( - operations: Operation[], - sender: Account -): Promise => - operationsToParams(operations, sender) as Promise; - -export const operationsToParams = async ( - operations: Operation[], - sender: Account -): Promise => { - const result: ParamsWithKind[] = []; - - for (const operation of operations) { +export const operationsToBatchParams = (operations: Operation[]): ParamsWithKind[] => + // eslint-disable-next-line array-callback-return + operations.map(operation => { switch (operation.type) { case "tez": - result.push({ + return { kind: OpKind.TRANSACTION, to: operation.recipient.pkh, amount: parseInt(operation.amount), parameter: operation.parameter, mutez: true, - }); - break; + }; case "delegation": - result.push({ + return { kind: OpKind.DELEGATION, - source: sender.address.pkh, + source: operation.sender.pkh, delegate: operation.recipient?.pkh, - }); - break; + }; case "fa1.2": case "fa2": - result.push({ + return { kind: OpKind.TRANSACTION, ...makeTokenTransferParams(operation), - }); - break; + }; } - } - - return result; -}; + }); -export const operationsToBatchParams = async ( - operations: Operation[], - sender: Account -): Promise => { - if (!operations.length) { - return []; - } - return operationsToParams(operations, sender); -}; +export const operationsToWalletParams = operationsToBatchParams as ( + operations: Operation[] +) => WalletParamsWithKind[]; diff --git a/src/views/batch/BatchView.test.tsx b/src/views/batch/BatchView.test.tsx index 0ad8e33fa..504ee5d93 100644 --- a/src/views/batch/BatchView.test.tsx +++ b/src/views/batch/BatchView.test.tsx @@ -264,7 +264,6 @@ describe("", () => { recipient: mockImplicitAddress(3), }, ], - mockImplicitAccount(1), MOCK_TEZOS_TOOLKIT ); diff --git a/src/views/batch/batchUtils.ts b/src/views/batch/batchUtils.ts index aef4928c7..7ee2f5415 100644 --- a/src/views/batch/batchUtils.ts +++ b/src/views/batch/batchUtils.ts @@ -5,7 +5,7 @@ import { zip } from "../../utils/helpers"; import { Operation } from "../../types/Operation"; import { TezosNetwork } from "../../types/TezosNetwork"; import { BatchItem } from "../../utils/redux/slices/assetsSlice"; -import { Account, ImplicitAccount } from "../../types/Account"; +import { ImplicitAccount } from "../../types/Account"; export const getTotalFee = (items: BatchItem[]): BigNumber => { const fee = items.reduce((acc, curr) => { @@ -37,12 +37,11 @@ export const sumEstimations = (es: Estimate[]) => { export const operationsToBatchItems = async ( operations: Operation[], - sender: Account, signer: ImplicitAccount, network: TezosNetwork ) => { // TODO: add support for Multisig - const estimations = await estimateBatch(operations, sender, signer, network); + const estimations = await estimateBatch(operations, signer, network); return zip(operations, estimations).map(([operation, estimate]) => { return { From e21a9cd9861718cebc8962eacaeb4b7c1dc431a5 Mon Sep 17 00:00:00 2001 From: Sergey Kintsel Date: Wed, 26 Jul 2023 13:20:36 +0100 Subject: [PATCH 4/4] Prohibit unnecessary await statements --- .eslintrc | 3 ++- src/multisig/multisigSandbox.integration.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index e6165d54c..fa4ed6276 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,8 @@ "curly": ["error", "all"], "jest/no-focused-tests": "warn", "jest/no-identical-title": "warn", - "jest/valid-expect": "warn" + "jest/valid-expect": "warn", + "@typescript-eslint/await-thenable": "error" }, "overrides": [ { diff --git a/src/multisig/multisigSandbox.integration.test.ts b/src/multisig/multisigSandbox.integration.test.ts index 82655483e..30cc05b60 100644 --- a/src/multisig/multisigSandbox.integration.test.ts +++ b/src/multisig/multisigSandbox.integration.test.ts @@ -96,7 +96,7 @@ describe("multisig Sandbox", () => { const tezos = await makeToolkitFromDefaultDevSeed(0); const keys1 = await makeDefaultDevSignerKeys(1); const keys2 = await makeDefaultDevSignerKeys(2); - const batch = await makeBatchLambda([ + const batch = makeBatchLambda([ { type: "tez", amount: "600000", recipient: parsePkh(keys1.pkh) }, { type: "fa1.2",