diff --git a/src/features/orders/ordersActions.ts b/src/features/orders/ordersActions.ts index 9e06f6a7..ead3129d 100644 --- a/src/features/orders/ordersActions.ts +++ b/src/features/orders/ordersActions.ts @@ -277,6 +277,12 @@ export const approve = approveAmount ); + if (isAppError(tx)) { + dispatch(setStatus("failed")); + handleOrderError(dispatch, tx); + return; + } + if (!tx.hash) { console.error("Approval transaction hash is missing."); diff --git a/src/features/orders/ordersHelpers.ts b/src/features/orders/ordersHelpers.ts index 54fa63b3..20cea07c 100644 --- a/src/features/orders/ordersHelpers.ts +++ b/src/features/orders/ordersHelpers.ts @@ -98,19 +98,25 @@ export async function approveToken( provider: ethers.providers.Web3Provider, contractType: "Swap" | "Wrapper", amount: string | number -) { - const spender = - contractType === "Swap" - ? getSwapErc20Address(provider.network.chainId) - : Wrapper.getAddress(provider.network.chainId); - const erc20Contract = new ethers.Contract( - baseToken, - erc20Interface, - // @ts-ignore - provider.getSigner() - ); - const approvalTxHash = await erc20Contract.approve(spender, amount); - return approvalTxHash as any as Transaction; +): Promise { + return new Promise(async (resolve) => { + try { + const spender = + contractType === "Swap" + ? getSwapErc20Address(provider.network.chainId) + : Wrapper.getAddress(provider.network.chainId); + const erc20Contract = new ethers.Contract( + baseToken, + erc20Interface, + // @ts-ignore + provider.getSigner() + ); + const approvalTxHash = erc20Contract.approve(spender, amount); + resolve(approvalTxHash); + } catch (error: any) { + resolve(transformUnknownErrorToAppError(error)); + } + }); } export async function takeOrder( @@ -203,7 +209,7 @@ export async function check( provider: ethers.providers.Web3Provider, isSwapWithWrap?: boolean ): Promise { - const strings = await ( + const [count, strings] = await ( await getSwapErc20Contract(provider, chainId) ).check(senderWallet, ...orderERC20ToParams(order)); diff --git a/src/features/transactions/hooks/useLatestSwapFromEvents.ts b/src/features/transactions/hooks/useLatestSwapFromEvents.ts index fbd3c3d4..fc7f27ad 100644 --- a/src/features/transactions/hooks/useLatestSwapFromEvents.ts +++ b/src/features/transactions/hooks/useLatestSwapFromEvents.ts @@ -34,6 +34,12 @@ const useLatestSwapFromEvents = ( const handleSwapEvent = async ( nonce: BigNumber, signerAddress: string, + a: string, + b: number, + c: number, + d: string, + e: string, + f: number, swapEvent: Event ) => { const receipt = await swapEvent.getTransactionReceipt(); diff --git a/src/helpers/createSwapSignature.ts b/src/helpers/createSwapSignature.ts index c533385b..3823195b 100644 --- a/src/helpers/createSwapSignature.ts +++ b/src/helpers/createSwapSignature.ts @@ -8,6 +8,8 @@ import { JsonRpcSigner } from "@ethersproject/providers/src.ts/json-rpc-provider import { AppError } from "../errors/appError"; import transformUnknownErrorToAppError from "../errors/transformUnknownErrorToAppError"; +const SWAP_ERC20_VERSION = "4"; + export const createOrderERC20Signature = ( unsignedOrder: UnsignedOrderERC20, signer: JsonRpcSigner, @@ -21,7 +23,8 @@ export const createOrderERC20Signature = ( // @ts-ignore signer, swapContract, - chainId + chainId, + SWAP_ERC20_VERSION ); resolve(signature); } catch (error: unknown) {