Skip to content

Commit

Permalink
942: Added getFullSwapERC20 helper (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
piersss committed Jul 31, 2024
1 parent fdb8ece commit bce673f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/features/transactions/helpers/getOrdersFromLogs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Pool } from "@airswap/libraries";
import {
FullSwapERC20,
getFullSwapERC20,
OrderERC20,
protocolFeeReceiverAddresses,
} from "@airswap/utils";

import { BigNumber, Event } from "ethers";

import { transformFullSwapERC20ToOrderERC20 } from "../../../entities/OrderERC20/OrderERC20Transformers";
import { getFullSwapERC20 } from "../../../helpers/getFullSwapERC20";

export interface FullSwapErc20Log {
hash: string;
Expand Down Expand Up @@ -54,6 +54,8 @@ export const getOrdersFromLogs = async (
receipt.logs
);

if (!swap) return;

const order = transformFullSwapERC20ToOrderERC20(swap, nonce.toString());

return {
Expand Down
5 changes: 3 additions & 2 deletions src/features/transactions/hooks/useLatestSwapFromEvents.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useEffect, useState } from "react";

import { SwapERC20 } from "@airswap/libraries";
import { getFullSwapERC20 } from "@airswap/utils";
import { useWeb3React } from "@web3-react/core";

import { BigNumber, Event } from "ethers";

import { FullSwapERC20Event } from "../../../entities/FullSwapERC20Event/FullSwapERC20Event";
import { transformToFullSwapERC20Event } from "../../../entities/FullSwapERC20Event/FullSwapERC20EventTransformers";
import { getFullSwapERC20 } from "../../../helpers/getFullSwapERC20";
import { compareAddresses } from "../../../helpers/string";
import { getSwapErc20Contract } from "../../../helpers/swapErc20";
import useNetworkSupported from "../../../hooks/useNetworkSupported";
Expand Down Expand Up @@ -45,6 +44,8 @@ const useLatestSwapFromEvents = (
receipt.logs
);

if (!swap) return;

if (
!compareAddresses(swap.signerWallet, account) &&
!compareAddresses(swap.senderWallet, account) &&
Expand Down
29 changes: 29 additions & 0 deletions src/helpers/getFullSwapERC20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { getFullSwapERC20 as airswapGetFullSwapERC20 } from "@airswap/utils";
import { FullSwapERC20 } from "@airswap/utils/build/src/swap-erc20";

import { ethers } from "ethers";

// TODO: Remove this function when this issue is resolved:
// https://github.com/airswap/airswap-protocols/issues/1319

export const getFullSwapERC20 = async (
nonce: string,
signerWallet: string,
feeReceiver: string,
logs: ethers.providers.Log[]
): Promise<FullSwapERC20 | undefined> => {
try {
return await airswapGetFullSwapERC20(
nonce,
signerWallet,
feeReceiver,
logs
);
} catch (error) {
console.error(
`[getFullSwapERC20]: Error for transaction with nonce ${nonce}: ${error}`
);

return undefined;
}
};

0 comments on commit bce673f

Please sign in to comment.