Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5 upgrade #949

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepare": "husky install"
},
"dependencies": {
"@airswap/libraries": "4.3.6",
"@airswap/libraries": "5.0.1",
"@akkafinance/web3-react-bitkeep": "^1.0.0",
"@coinbase/wallet-sdk": "^3.7.2",
"@craco/craco": "^6.2.0",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"takeOtc": "Take",
"takeQuote": "Complete Swap",
"thisOrderIsForADifferentTaker": "This order is for a different taker",
"thisOrderIsForAnotherChain": "This order is for the {{chainName}} chain",
"thisOrderIsForAnotherChain": "This order is for {{chainName}}",
"thisOrderWasForADifferentTaker": "This order was for a different taker",
"to": "To",
"tokenInfoNotFound": "Token info not found",
Expand Down Expand Up @@ -215,6 +215,7 @@
"nonceAlreadyUsed": "Nonce has been already used or cancelled",
"senderAllowanceLow": "Sender (taker) has not approved the required amount",
"senderBalanceLow": "Sender (taker) does not have the required balance",
"signatureInvalid": "Invalid signature",
"signerAllowanceLow": "Signer (maker) has not approved the required amount",
"signerBalanceLow": "Signer (maker) does not have the required balance",
"swapFail": "The swap would fail for the following reasons.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useEffect, useState } from "react";

import { TokenInfo } from "@airswap/utils";
import { Web3Provider } from "@ethersproject/providers";
import { Web3Provider, JsonRpcProvider } from "@ethersproject/providers";
import { useWeb3React } from "@web3-react/core";

import { getDefaultProvider } from "ethers";

import { useAppDispatch, useAppSelector } from "../../../../app/hooks";
import { getAllTokensFromLocalStorage } from "../../../../features/metadata/metadataApi";
import {
Expand Down Expand Up @@ -65,7 +63,8 @@ const useTakerTokenInfo = (
const callScrapeToken = async () => {
setIsCallScrapeTokenLoading(true);

const lib = library || getDefaultProvider(getRpcUrl(activeOrder.chainId));
const lib =
library || new JsonRpcProvider(getRpcUrl(activeOrder.chainId));

if (lib) {
const result = await scrapeToken(address, lib);
Expand Down
7 changes: 7 additions & 0 deletions src/components/ErrorList/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { AppError, AppErrorType } from "../../../errors/appError";
import { ErrorListItemProps } from "../subcomponents/ErrorListItem/ErrorListItem";

export const getAppErrorTranslation = (error: AppError): ErrorListItemProps => {
if (error.type === AppErrorType.signatureInvalid) {
return {
title: AppErrorType.signatureInvalid,
text: i18n.t("validatorErrors.signatureInvalid"),
};
}

if (error.type === AppErrorType.expiryPassed) {
return {
title: AppErrorType.expiryPassed,
Expand Down
30 changes: 2 additions & 28 deletions src/entities/Server/ServerService.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import { Server, RegistryV3, Registry } from "@airswap/libraries";
import { Server, Registry } from "@airswap/libraries";
import { ProtocolIds } from "@airswap/utils";
import { BaseProvider } from "@ethersproject/providers";

import { REGISTRY_SERVER_RESPONSE_TIME_MS } from "../../constants/configParams";
import { isServer } from "./ServerHelpers";

export const getVersionedRegistryServers = (
provider: BaseProvider,
chainId: number,
protocol: ProtocolIds,
quoteToken: string,
baseToken: string
): Promise<Server[]> => {
if (RegistryV3.addresses[chainId]) {
return RegistryV3.getServers(provider, chainId, quoteToken, baseToken);
}

return Registry.getServers(
provider,
chainId,
protocol,
quoteToken,
baseToken
);
};

export const getRegistryServers = async (
provider: BaseProvider,
chainId: number,
Expand All @@ -34,13 +14,7 @@ export const getRegistryServers = async (
): Promise<Server[]> => {
try {
const response = await Promise.race([
getVersionedRegistryServers(
provider,
chainId,
protocol,
quoteToken,
baseToken
),
Registry.getServers(provider, chainId, protocol, quoteToken, baseToken),
new Promise((_, reject) =>
setTimeout(
() => reject(new Error("Timeout")),
Expand Down
2 changes: 1 addition & 1 deletion src/features/orders/ordersHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function check(
: errors;

if (filteredErrors.length) {
console.error("check returned errors", errors);
console.error("check returned errors", filteredErrors);
}

return filteredErrors.map((error) => transformSwapErrorToAppError(error));
Expand Down
4 changes: 3 additions & 1 deletion src/features/transactions/helpers/getOrdersFromLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const getOrdersFromLogs = async (
hash: swapLog.transactionHash,
order,
swap,
timestamp: blocks[index].timestamp * 1000,
timestamp: blocks[index]?.timestamp
? blocks[index].timestamp * 1000
: 0,
};
})
);
Expand Down
6 changes: 0 additions & 6 deletions src/features/transactions/hooks/useLatestSwapFromEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ 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();
Expand Down
5 changes: 1 addition & 4 deletions src/helpers/createSwapSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ 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,
Expand All @@ -23,8 +21,7 @@ export const createOrderERC20Signature = (
// @ts-ignore
signer,
swapContract,
chainId,
SWAP_ERC20_VERSION
chainId
);
resolve(signature);
} catch (error: unknown) {
Expand Down
14 changes: 0 additions & 14 deletions src/helpers/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ export const clearedCachedLibrary = (): void => {
cachedLibrary = {};
};

export const getRpcUrl = (chainId: number): string | undefined => {
const rpcUrl = rpcUrls[chainId];

if (!rpcUrl) {
console.error(
`No rpc url found for chainId ${chainId}, did you setup your .env correctly?`
);

return undefined;
}

return rpcUrl;
};

export const getTransactionReceiptMined = (
transactionHash: string,
provider: Web3Provider
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getContractEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const getContractEvents = (

if (!blockLimit) {
console.error(
"[getContractQueryFilter]: Error when getting logs, but no block limit could be found",
`[getContractQueryFilter]: Error when getting logs (${startBlock} to ${endBlock}) but no block limit could be found`,
error
);

Expand Down
Loading
Loading