Skip to content

Commit

Permalink
feat: deactivate use of meta-transaction when the connected wallet is… (
Browse files Browse the repository at this point in the history
  • Loading branch information
levalleux-ludo committed Feb 23, 2024
1 parent 1008302 commit ca72f8a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 86 deletions.
102 changes: 51 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions src/components/modal/components/Chat/ResolveDisputeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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
} from "@bosonprotocol/react-kit";
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,
Expand Down Expand Up @@ -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<ThreadId | null>(() => {
if (!exchange) {
return null;
Expand Down Expand Up @@ -249,7 +249,6 @@ export default function ResolveDisputeModal({
}
);
await handleSendingAcceptProposalMessage();
const isMetaTx = Boolean(coreSDK?.isMetaTxConfigSet && address);

await sendErrorMessageIfTxFails({
sendsTxFn: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -203,7 +202,8 @@ function EscalateStepTwo({
const [activeStep, setActiveStep] = useState<number>(0);
const [loading, setLoading] = useState<boolean>(false);
const [signature, setSignature] = useState<string | null>(null);
const { account: address } = useAccount();
const { isMetaTx: _useMetaTx, signerAddress: address } =
hooks.useMetaTx(coreSDK);
const { isLoading, mutateAsync: signMessage } = useSignMessage();

const threadId = useMemo<ThreadId | null>(() => {
Expand Down Expand Up @@ -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({
Expand Down
7 changes: 3 additions & 4 deletions src/components/modal/components/RetractDisputeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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
} from "@bosonprotocol/react-kit";
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,
Expand Down Expand Up @@ -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<Error | null>(
null
);
Expand Down Expand Up @@ -198,7 +198,6 @@ export default function RetractDisputeModal({
xs: "400px"
}
);
const isMetaTx = Boolean(coreSDK?.isMetaTxConfigSet && address);

await sendErrorMessageIfTxFails({
sendsTxFn: async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/modal/components/VoidProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TransactionResponse } from "@bosonprotocol/common";
import {
CoreSDK,
hooks,
Provider,
subgraph,
VoidButton
Expand Down Expand Up @@ -204,6 +205,7 @@ export default function VoidProduct({
const [isLoading, setIsLoading] = useState<boolean>(false);
const signer = useSigner();
const { hideModal } = useModal();
const { isMetaTx } = hooks.useMetaTx(coreSdk);

const handleFinish = useCallback(() => {
hideModal();
Expand Down Expand Up @@ -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 {
Expand All @@ -306,7 +307,7 @@ export default function VoidProduct({
console.error("onError", error);
Sentry.captureException(error);
}
}, [offers, coreSdk, signer, handleSuccess]);
}, [offers, isMetaTx, handleSuccess, coreSdk]);

return (
<Grid flexDirection="column" alignItems="flex-start" gap="2rem">
Expand Down
7 changes: 3 additions & 4 deletions src/lib/utils/hooks/offer/useCreateOffers.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit ca72f8a

Please sign in to comment.