From 6c8188a0195ba8df5bd649d692d8825c3bddb2c4 Mon Sep 17 00:00:00 2001 From: Ludovic Levalleux Date: Thu, 22 Feb 2024 14:32:23 +0000 Subject: [PATCH] feat: deactivate use of meta-transaction when the connected wallet is a contract --- package-lock.json | 102 +++++++++--------- package.json | 2 +- .../components/Chat/ResolveDisputeModal.tsx | 7 +- .../EscalateModal/steps/EscalateStepTwo.tsx | 18 ++-- .../modal/components/RetractDisputeModal.tsx | 7 +- .../modal/components/VoidProduct.tsx | 5 +- src/lib/utils/hooks/offer/useCreateOffers.tsx | 7 +- src/lib/utils/hooks/seller/useCreateSeller.ts | 7 +- src/lib/utils/hooks/seller/useUpdateSeller.ts | 6 +- src/pages/dispute-centre/RaiseDisputePage.tsx | 9 +- 10 files changed, 84 insertions(+), 86 deletions(-) diff --git a/package-lock.json b/package-lock.json index a9cf65e31..556b87b52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@apollo/client": "^3.8.1", "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/react-kit": "^0.26.2-alpha.4", + "@bosonprotocol/react-kit": "^0.27.0-alpha.0", "@davatar/react": "^1.10.4", "@ethersproject/address": "^5.6.1", "@ethersproject/units": "^5.7.0", @@ -2306,11 +2306,11 @@ } }, "node_modules/@bosonprotocol/common": { - "version": "1.25.3-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.25.3-alpha.4.tgz", - "integrity": "sha512-eAsDNkLbbe8mEnNAsY3n3MbFV+aAwuNNxy1nD+FROxsiUfVWrLFwzvKKrZMu5wPZ+CaRGp+3U4cnSJG7vN4wcw==", + "version": "1.26.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.26.0-alpha.0.tgz", + "integrity": "sha512-8a46jiK9FvY2gNOXp5CxyRIeHIxyRj+EengJ9KlGbF1m9BBW+HIKJ6w9pLFfs7W5EZ+2Zh5KqQGys+EsBrR8mA==", "dependencies": { - "@bosonprotocol/metadata": "^1.15.0-alpha.4", + "@bosonprotocol/metadata": "^1.15.0-alpha.7", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -2320,11 +2320,11 @@ } }, "node_modules/@bosonprotocol/core-sdk": { - "version": "1.37.0-alpha.3", - "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.37.0-alpha.3.tgz", - "integrity": "sha512-bRQsh+GZtGiff+6N/Yc/SwwxjcCZGVuAsZGy4T8XcZYshluZF++g9WH6PBgvFN6jjML7n/Cq8bSWHsYS+d+kIA==", + "version": "1.37.0-alpha.6", + "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.37.0-alpha.6.tgz", + "integrity": "sha512-s36FTmUE3BxV4SIP8MVVq96/TWhOA9w2BsVELWO8M+9rYQY9bbMQ1Bwhj6iiq/GKT852REX5wNSy8kJKXhuw/w==", "dependencies": { - "@bosonprotocol/common": "^1.25.3-alpha.4", + "@bosonprotocol/common": "^1.26.0-alpha.0", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -2340,44 +2340,44 @@ } }, "node_modules/@bosonprotocol/ethers-sdk": { - "version": "1.12.14-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.14-alpha.4.tgz", - "integrity": "sha512-7NF0m/SsGJRaufIsp73ytXO1y8KMHmUOExBoQSSs6A9wJDzfd2Bmd8YdHJPIpWtNll6emMTQk7HZq02z7hqHig==", + "version": "1.13.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.13.0-alpha.0.tgz", + "integrity": "sha512-RcKCtpIhLJzhukeA/QVgc71uxMtYp+IIJRGlq4JkEHV5OP79kq05eFGjKAMMg/BUiP0eW5CuW0pCh7+PulAIRA==", "dependencies": { - "@bosonprotocol/common": "^1.25.3-alpha.4" + "@bosonprotocol/common": "^1.26.0-alpha.0" }, "peerDependencies": { "ethers": "^5.5.0" } }, "node_modules/@bosonprotocol/ipfs-storage": { - "version": "1.11.1-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ipfs-storage/-/ipfs-storage-1.11.1-alpha.4.tgz", - "integrity": "sha512-5tkIDsOqg+/q0RQRzOXlH7IMO8crFrvZf4t4AAJJ3XsVmoyjBRe7k2Itv1xEjwBHeFl/KRIfF4VlvoUqbmC6pg==", + "version": "1.11.1-alpha.7", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ipfs-storage/-/ipfs-storage-1.11.1-alpha.7.tgz", + "integrity": "sha512-gZ6uJkR9KvXIenlhW3/dwCu4am9kPV+8hyh78OlviRGYKUKH5ZrnlisMw2yTYUrIB9mIgTWOIx8SVQEu1KR4Nw==", "dependencies": { - "@bosonprotocol/metadata": "^1.15.0-alpha.4", + "@bosonprotocol/metadata": "^1.15.0-alpha.7", "ipfs-http-client": "^56.0.1", "multiformats": "^9.6.4", "uint8arrays": "^3.0.0" } }, "node_modules/@bosonprotocol/metadata": { - "version": "1.15.0-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/metadata/-/metadata-1.15.0-alpha.4.tgz", - "integrity": "sha512-H7uPPdwjStoZE2Qi6PmaatWsNBcLSarewkSYpfaIacNlCoZNtGpoEzDvN+W0LJdWH7ibfDTZXIvy+H2N1iAH0Q==", + "version": "1.15.0-alpha.7", + "resolved": "https://registry.npmjs.org/@bosonprotocol/metadata/-/metadata-1.15.0-alpha.7.tgz", + "integrity": "sha512-AlZZTp5TnRXJ9nDoDZcehkTW1XiSIc2dBsNxzCRfvrii9pfZ982FPOv4hWSwN/mpApIieuh3tEom1vYeJT6g5Q==", "dependencies": { "schema-to-yup": "^1.11.11" } }, "node_modules/@bosonprotocol/react-kit": { - "version": "0.26.2-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.26.2-alpha.4.tgz", - "integrity": "sha512-LjjbWBoCvWbuRaFxf41ZCEYOF7CPBKNwnOo0KU5lEEc9wcpoxBYALT5ZmK0L9FptFErHD3Li4KwuKGj2E+FJFA==", + "version": "0.27.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.27.0-alpha.0.tgz", + "integrity": "sha512-Ky5eByJE3brqaqBCJihhNGzBIJYMcQDBjul4hbHzunwtOHIm31qf+L+Xh524mJagLcJzOU/9S6t0VxTOmpOZpw==", "dependencies": { "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/core-sdk": "^1.37.0-alpha.3", - "@bosonprotocol/ethers-sdk": "^1.12.14-alpha.4", - "@bosonprotocol/ipfs-storage": "^1.11.1-alpha.4", + "@bosonprotocol/core-sdk": "^1.37.0-alpha.6", + "@bosonprotocol/ethers-sdk": "^1.13.0-alpha.0", + "@bosonprotocol/ipfs-storage": "^1.11.1-alpha.7", "@davatar/react": "1.11.1", "@ethersproject/units": "5.6.0", "@glidejs/glide": "3.6.0", @@ -49113,11 +49113,11 @@ } }, "@bosonprotocol/common": { - "version": "1.25.3-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.25.3-alpha.4.tgz", - "integrity": "sha512-eAsDNkLbbe8mEnNAsY3n3MbFV+aAwuNNxy1nD+FROxsiUfVWrLFwzvKKrZMu5wPZ+CaRGp+3U4cnSJG7vN4wcw==", + "version": "1.26.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.26.0-alpha.0.tgz", + "integrity": "sha512-8a46jiK9FvY2gNOXp5CxyRIeHIxyRj+EengJ9KlGbF1m9BBW+HIKJ6w9pLFfs7W5EZ+2Zh5KqQGys+EsBrR8mA==", "requires": { - "@bosonprotocol/metadata": "^1.15.0-alpha.4", + "@bosonprotocol/metadata": "^1.15.0-alpha.7", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -49127,11 +49127,11 @@ } }, "@bosonprotocol/core-sdk": { - "version": "1.37.0-alpha.3", - "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.37.0-alpha.3.tgz", - "integrity": "sha512-bRQsh+GZtGiff+6N/Yc/SwwxjcCZGVuAsZGy4T8XcZYshluZF++g9WH6PBgvFN6jjML7n/Cq8bSWHsYS+d+kIA==", + "version": "1.37.0-alpha.6", + "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.37.0-alpha.6.tgz", + "integrity": "sha512-s36FTmUE3BxV4SIP8MVVq96/TWhOA9w2BsVELWO8M+9rYQY9bbMQ1Bwhj6iiq/GKT852REX5wNSy8kJKXhuw/w==", "requires": { - "@bosonprotocol/common": "^1.25.3-alpha.4", + "@bosonprotocol/common": "^1.26.0-alpha.0", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -49147,41 +49147,41 @@ } }, "@bosonprotocol/ethers-sdk": { - "version": "1.12.14-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.14-alpha.4.tgz", - "integrity": "sha512-7NF0m/SsGJRaufIsp73ytXO1y8KMHmUOExBoQSSs6A9wJDzfd2Bmd8YdHJPIpWtNll6emMTQk7HZq02z7hqHig==", + "version": "1.13.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.13.0-alpha.0.tgz", + "integrity": "sha512-RcKCtpIhLJzhukeA/QVgc71uxMtYp+IIJRGlq4JkEHV5OP79kq05eFGjKAMMg/BUiP0eW5CuW0pCh7+PulAIRA==", "requires": { - "@bosonprotocol/common": "^1.25.3-alpha.4" + "@bosonprotocol/common": "^1.26.0-alpha.0" } }, "@bosonprotocol/ipfs-storage": { - "version": "1.11.1-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ipfs-storage/-/ipfs-storage-1.11.1-alpha.4.tgz", - "integrity": "sha512-5tkIDsOqg+/q0RQRzOXlH7IMO8crFrvZf4t4AAJJ3XsVmoyjBRe7k2Itv1xEjwBHeFl/KRIfF4VlvoUqbmC6pg==", + "version": "1.11.1-alpha.7", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ipfs-storage/-/ipfs-storage-1.11.1-alpha.7.tgz", + "integrity": "sha512-gZ6uJkR9KvXIenlhW3/dwCu4am9kPV+8hyh78OlviRGYKUKH5ZrnlisMw2yTYUrIB9mIgTWOIx8SVQEu1KR4Nw==", "requires": { - "@bosonprotocol/metadata": "^1.15.0-alpha.4", + "@bosonprotocol/metadata": "^1.15.0-alpha.7", "ipfs-http-client": "^56.0.1", "multiformats": "^9.6.4", "uint8arrays": "^3.0.0" } }, "@bosonprotocol/metadata": { - "version": "1.15.0-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/metadata/-/metadata-1.15.0-alpha.4.tgz", - "integrity": "sha512-H7uPPdwjStoZE2Qi6PmaatWsNBcLSarewkSYpfaIacNlCoZNtGpoEzDvN+W0LJdWH7ibfDTZXIvy+H2N1iAH0Q==", + "version": "1.15.0-alpha.7", + "resolved": "https://registry.npmjs.org/@bosonprotocol/metadata/-/metadata-1.15.0-alpha.7.tgz", + "integrity": "sha512-AlZZTp5TnRXJ9nDoDZcehkTW1XiSIc2dBsNxzCRfvrii9pfZ982FPOv4hWSwN/mpApIieuh3tEom1vYeJT6g5Q==", "requires": { "schema-to-yup": "^1.11.11" } }, "@bosonprotocol/react-kit": { - "version": "0.26.2-alpha.4", - "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.26.2-alpha.4.tgz", - "integrity": "sha512-LjjbWBoCvWbuRaFxf41ZCEYOF7CPBKNwnOo0KU5lEEc9wcpoxBYALT5ZmK0L9FptFErHD3Li4KwuKGj2E+FJFA==", + "version": "0.27.0-alpha.0", + "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.27.0-alpha.0.tgz", + "integrity": "sha512-Ky5eByJE3brqaqBCJihhNGzBIJYMcQDBjul4hbHzunwtOHIm31qf+L+Xh524mJagLcJzOU/9S6t0VxTOmpOZpw==", "requires": { "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/core-sdk": "^1.37.0-alpha.3", - "@bosonprotocol/ethers-sdk": "^1.12.14-alpha.4", - "@bosonprotocol/ipfs-storage": "^1.11.1-alpha.4", + "@bosonprotocol/core-sdk": "^1.37.0-alpha.6", + "@bosonprotocol/ethers-sdk": "^1.13.0-alpha.0", + "@bosonprotocol/ipfs-storage": "^1.11.1-alpha.7", "@davatar/react": "1.11.1", "@ethersproject/units": "5.6.0", "@glidejs/glide": "3.6.0", diff --git a/package.json b/package.json index 3b6d6922d..12cd492e1 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "dependencies": { "@apollo/client": "^3.8.1", "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/react-kit": "^0.26.2-alpha.4", + "@bosonprotocol/react-kit": "^0.27.0-alpha.0", "@davatar/react": "^1.10.4", "@ethersproject/address": "^5.6.1", "@ethersproject/units": "^5.7.0", diff --git a/src/components/modal/components/Chat/ResolveDisputeModal.tsx b/src/components/modal/components/Chat/ResolveDisputeModal.tsx index ae0a5f260..dbb04f11e 100644 --- a/src/components/modal/components/Chat/ResolveDisputeModal.tsx +++ b/src/components/modal/components/Chat/ResolveDisputeModal.tsx @@ -6,7 +6,7 @@ import { version } from "@bosonprotocol/chat-sdk/dist/esm/util/v0.0.1/definitions"; import { TransactionResponse } from "@bosonprotocol/common"; -import { CoreSDK, Provider, subgraph } from "@bosonprotocol/react-kit"; +import { CoreSDK, hooks, Provider, subgraph } from "@bosonprotocol/react-kit"; import { extractUserFriendlyError, getHasUserRejectedTx @@ -14,7 +14,7 @@ import { import * as Sentry from "@sentry/browser"; import { useConfigContext } from "components/config/ConfigContext"; import { BigNumber, BigNumberish, providers, utils } from "ethers"; -import { useAccount, useSigner } from "lib/utils/hooks/connection/connection"; +import { useSigner } from "lib/utils/hooks/connection/connection"; import { poll } from "lib/utils/promises"; import { sendAndAddMessageToUI, @@ -125,7 +125,7 @@ export default function ResolveDisputeModal({ const { bosonXmtp } = useChatContext(); const coreSDK = useCoreSDK(); const addPendingTransaction = useAddPendingTransaction(); - const { account: address } = useAccount(); + const { isMetaTx, signerAddress: address } = hooks.useMetaTx(coreSDK); const threadId = useMemo(() => { if (!exchange) { return null; @@ -249,7 +249,6 @@ export default function ResolveDisputeModal({ } ); await handleSendingAcceptProposalMessage(); - const isMetaTx = Boolean(coreSDK?.isMetaTxConfigSet && address); await sendErrorMessageIfTxFails({ sendsTxFn: async () => { diff --git a/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx b/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx index c73b8419b..e86c17491 100644 --- a/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx +++ b/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx @@ -5,7 +5,7 @@ import { version } from "@bosonprotocol/chat-sdk/dist/esm/util/v0.0.1/definitions"; import { TransactionResponse } from "@bosonprotocol/common"; -import { CoreSDK, Provider, subgraph } from "@bosonprotocol/react-kit"; +import { CoreSDK, hooks, Provider, subgraph } from "@bosonprotocol/react-kit"; import { extractUserFriendlyError, getHasUserRejectedTx @@ -15,7 +15,6 @@ import { useConfigContext } from "components/config/ConfigContext"; import { BigNumber, BigNumberish, ethers, providers, utils } from "ethers"; import { Form, Formik, FormikProps, FormikState } from "formik"; import { - useAccount, useSigner, useSignMessage } from "lib/utils/hooks/connection/connection"; @@ -203,7 +202,8 @@ function EscalateStepTwo({ const [activeStep, setActiveStep] = useState(0); const [loading, setLoading] = useState(false); const [signature, setSignature] = useState(null); - const { account: address } = useAccount(); + const { isMetaTx: _useMetaTx, signerAddress: address } = + hooks.useMetaTx(coreSDK); const { isLoading, mutateAsync: signMessage } = useSignMessage(); const threadId = useMemo(() => { @@ -498,13 +498,11 @@ function EscalateStepTwo({ .buyerEscalationDeposit; const exchangeTokenAddress = exchange.offer.exchangeToken.address; - const isMetaTx = Boolean( - coreSDK?.isMetaTxConfigSet && - address && - (exchangeTokenAddress !== - ethers.constants.AddressZero || - BigNumber.from(buyerEscalationDeposit).eq(0)) - ); + const isMetaTx = + _useMetaTx && + (exchangeTokenAddress !== + ethers.constants.AddressZero || + BigNumber.from(buyerEscalationDeposit).eq(0)); await handleSendingEscalateMessage(); await sendErrorMessageIfTxFails({ diff --git a/src/components/modal/components/RetractDisputeModal.tsx b/src/components/modal/components/RetractDisputeModal.tsx index 742af54c6..1e9ae9c6a 100644 --- a/src/components/modal/components/RetractDisputeModal.tsx +++ b/src/components/modal/components/RetractDisputeModal.tsx @@ -5,7 +5,7 @@ import { version } from "@bosonprotocol/chat-sdk/dist/esm/util/v0.0.1/definitions"; import { TransactionResponse } from "@bosonprotocol/common"; -import { CoreSDK, Provider, subgraph } from "@bosonprotocol/react-kit"; +import { CoreSDK, hooks, Provider, subgraph } from "@bosonprotocol/react-kit"; import { extractUserFriendlyError, getHasUserRejectedTx @@ -13,7 +13,7 @@ import { import * as Sentry from "@sentry/browser"; import { useConfigContext } from "components/config/ConfigContext"; import { BigNumberish, providers } from "ethers"; -import { useAccount, useSigner } from "lib/utils/hooks/connection/connection"; +import { useSigner } from "lib/utils/hooks/connection/connection"; import { poll } from "lib/utils/promises"; import { sendAndAddMessageToUI, @@ -101,7 +101,7 @@ export default function RetractDisputeModal({ const coreSDK = useCoreSDK(); const addPendingTransaction = useAddPendingTransaction(); const { showModal } = useModal(); - const { account: address } = useAccount(); + const { isMetaTx, signerAddress: address } = hooks.useMetaTx(coreSDK); const [retractDisputeError, setRetractDisputeError] = useState( null ); @@ -198,7 +198,6 @@ export default function RetractDisputeModal({ xs: "400px" } ); - const isMetaTx = Boolean(coreSDK?.isMetaTxConfigSet && address); await sendErrorMessageIfTxFails({ sendsTxFn: async () => { diff --git a/src/components/modal/components/VoidProduct.tsx b/src/components/modal/components/VoidProduct.tsx index 08741e384..e49503219 100644 --- a/src/components/modal/components/VoidProduct.tsx +++ b/src/components/modal/components/VoidProduct.tsx @@ -1,6 +1,7 @@ import { TransactionResponse } from "@bosonprotocol/common"; import { CoreSDK, + hooks, Provider, subgraph, VoidButton @@ -204,6 +205,7 @@ export default function VoidProduct({ const [isLoading, setIsLoading] = useState(false); const signer = useSigner(); const { hideModal } = useModal(); + const { isMetaTx } = hooks.useMetaTx(coreSdk); const handleFinish = useCallback(() => { hideModal(); @@ -286,7 +288,6 @@ export default function VoidProduct({ try { setIsLoading(true); let txResponse: TransactionResponse; - const isMetaTx = Boolean(coreSdk?.isMetaTxConfigSet && signer); if (isMetaTx) { txResponse = await voidOfferBatchWithMetaTx(coreSdk, offerIds); } else { @@ -306,7 +307,7 @@ export default function VoidProduct({ console.error("onError", error); Sentry.captureException(error); } - }, [offers, coreSdk, signer, handleSuccess]); + }, [offers, isMetaTx, handleSuccess, coreSdk]); return ( diff --git a/src/lib/utils/hooks/offer/useCreateOffers.tsx b/src/lib/utils/hooks/offer/useCreateOffers.tsx index b37d85f46..53f39afc1 100644 --- a/src/lib/utils/hooks/offer/useCreateOffers.tsx +++ b/src/lib/utils/hooks/offer/useCreateOffers.tsx @@ -1,5 +1,5 @@ import { TransactionResponse } from "@bosonprotocol/common"; -import { accounts, offers, subgraph } from "@bosonprotocol/react-kit"; +import { accounts, hooks, offers, subgraph } from "@bosonprotocol/react-kit"; import { poll } from "lib/utils/promises"; import toast from "react-hot-toast"; import { useMutation } from "react-query"; @@ -12,7 +12,6 @@ import { PartialTokenGating } from "../../../../pages/create-product/utils/buildCondition"; import { useCoreSDK } from "../../useCoreSdk"; -import { useAccount } from "../connection/connection"; import { useAddPendingTransaction } from "../transactions/usePendingTransactions"; const getOfferCreationToast = () => { @@ -40,10 +39,10 @@ type UseCreateOffersProps = { export function useCreateOffers() { const coreSDK = useCoreSDK(); - const { account: address } = useAccount(); + const { isMetaTx } = hooks.useMetaTx(coreSDK); const { showModal, hideModal } = useModal(); const addPendingTransaction = useAddPendingTransaction(); - const isMetaTx = Boolean(coreSDK.isMetaTxConfigSet && address); + return useMutation( async ({ sellerToCreate, diff --git a/src/lib/utils/hooks/seller/useCreateSeller.ts b/src/lib/utils/hooks/seller/useCreateSeller.ts index b63f82d55..36f3f5e33 100644 --- a/src/lib/utils/hooks/seller/useCreateSeller.ts +++ b/src/lib/utils/hooks/seller/useCreateSeller.ts @@ -2,6 +2,7 @@ import { TransactionResponse } from "@bosonprotocol/common"; import { accounts, CoreSDK, + hooks, IpfsMetadataStorage } from "@bosonprotocol/react-kit"; import { ethers } from "ethers"; @@ -17,14 +18,16 @@ type Props = Parameters[1]; export default function useCreateSeller() { const coreSDK = useCoreSDK(); const storage = useIpfsStorage(); + const { isMetaTx } = hooks.useMetaTx(coreSDK); return useMutation((props: Props) => { - return createSellerAccount(coreSDK, props, storage); + return createSellerAccount(coreSDK, isMetaTx, props, storage); }); } async function createSellerAccount( coreSDK: CoreSDK, + isMetaTx: boolean, { address, addressForRoyaltyPayment, @@ -86,7 +89,7 @@ async function createSellerAccount( metadataUri }; let tx: TransactionResponse; - if (coreSDK.isMetaTxConfigSet) { + if (isMetaTx) { // createSeller with meta-transaction const nonce = Date.now(); const { r, s, v, functionName, functionSignature } = diff --git a/src/lib/utils/hooks/seller/useUpdateSeller.ts b/src/lib/utils/hooks/seller/useUpdateSeller.ts index b790523b9..8528c9320 100644 --- a/src/lib/utils/hooks/seller/useUpdateSeller.ts +++ b/src/lib/utils/hooks/seller/useUpdateSeller.ts @@ -10,14 +10,16 @@ type Props = Parameters[1]; export default function useUpdateSeller() { const coreSDK = useCoreSDK(); + const { isMetaTx } = hooks.useMetaTx(coreSDK); return useMutation(async (props: Props) => { - return await updateSellerAccount(coreSDK, props); + return await updateSellerAccount(coreSDK, isMetaTx, props); }); } async function updateSellerAccount( coreSDK: CoreSDK, + isMetaTx: boolean, { sellerId, admin, @@ -60,7 +62,7 @@ async function updateSellerAccount( return value !== oldSellerValue; }); if (thereAreChanges) { - if (coreSDK.isMetaTxConfigSet) { + if (isMetaTx) { await coreSDK.signMetaTxUpdateSellerAndOptIn(newSeller); } else { await coreSDK.updateSellerAndOptIn(newSeller); diff --git a/src/pages/dispute-centre/RaiseDisputePage.tsx b/src/pages/dispute-centre/RaiseDisputePage.tsx index 8cfc881f7..1b736f489 100644 --- a/src/pages/dispute-centre/RaiseDisputePage.tsx +++ b/src/pages/dispute-centre/RaiseDisputePage.tsx @@ -1,6 +1,6 @@ import { MessageType } from "@bosonprotocol/chat-sdk/dist/esm/util/v0.0.1/definitions"; import { TransactionResponse } from "@bosonprotocol/common"; -import { CoreSDK, Provider, subgraph } from "@bosonprotocol/react-kit"; +import { CoreSDK, hooks, Provider, subgraph } from "@bosonprotocol/react-kit"; import { extractUserFriendlyError, getHasUserRejectedTx @@ -12,7 +12,7 @@ import { EmptyErrorMessage } from "components/error/EmptyErrorMessage"; import { LoadingMessage } from "components/loading/LoadingMessage"; import { BigNumberish, providers } from "ethers"; import { Formik } from "formik"; -import { useAccount, useSigner } from "lib/utils/hooks/connection/connection"; +import { useSigner } from "lib/utils/hooks/connection/connection"; import { poll } from "lib/utils/promises"; import { ArrowLeft } from "phosphor-react"; import { useState } from "react"; @@ -132,8 +132,8 @@ function RaiseDisputePage() { const { config } = useConfigContext(); const { bosonXmtp } = useChatContext(); const { showModal, hideModal } = useModal(); - const { account: address } = useAccount(); const coreSDK = useCoreSDK(); + const { isMetaTx, signerAddress: address } = hooks.useMetaTx(coreSDK); const [currentStep, setCurrentStep] = useState(0); const [submitError, setSubmitError] = useState(null); const [isRightArrowEnabled, setIsRightArrowEnabled] = @@ -309,9 +309,6 @@ function RaiseDisputePage() { xs: "400px" } ); - const isMetaTx = Boolean( - coreSDK?.isMetaTxConfigSet && address - ); await sendErrorMessageIfTxFails({ sendsTxFn: async () => { if (isMetaTx) {