Skip to content

Commit

Permalink
Fixes and improvements (#878)
Browse files Browse the repository at this point in the history
* RPC URLs and packages update (#865)

* generalize rpc urls, update packages

* upgrade metadata package; remove unused code

* url and ogp fixes

* limit ens to mainnet; rpc urls

* restore error overlay to review screen

* upgrade libraries with improved event parser

* upgrade packages; restore all networks
  • Loading branch information
dmosites authored Jan 8, 2024
1 parent ac18b82 commit d677d37
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 133 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
REACT_APP_RPC_URL_1: ${{ vars.REACT_APP_RPC_URL_1 }}
REACT_APP_RPC_URL_5: ${{ vars.REACT_APP_RPC_URL_5 }}
REACT_APP_RPC_URL_59140: ${{ vars.REACT_APP_RPC_URL_59140 }}
REACT_APP_RPC_URL_59144: ${{ vars.REACT_APP_RPC_URL_59144 }}
run: |
yarn
yarn build
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "airswap-web",
"version": "0.1.0",
"private": true,
"homepage": "https://www.airswap.io/",
"homepage": "https://swap.eth.limo/",
"scripts": {
"start": "craco start",
"build": "craco build",
Expand All @@ -13,8 +13,8 @@
"prepare": "husky install"
},
"dependencies": {
"@airswap/libraries": "4.1.13",
"@airswap/metadata": "4.1.12",
"@airswap/libraries": "4.1.16",
"@airswap/metadata": "4.1.15",
"@craco/craco": "^6.2.0",
"@fontsource/dm-mono": "^4.5.0",
"@greypixel_/nicenumbers": "^0.0.18",
Expand Down
Binary file modified public/airswap-ogp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<meta name="theme-color" content="#2b71ff" />

<!-- Open Graph Metadata -->
<meta property="og:image" content="https://www.airswap.io/airswap-ogp.png" />
<meta property="og:image" content="https://uploads-ssl.webflow.com/645a5e62baf4b2054b2bf9d8/65250baa69591c108c27f9ae_airswap-og.webp" />
<meta property="og:type" content="website" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:url" content="https://www.airswap.io/" />
<meta property="og:url" content="https://swap.eth.limo/" />

<!-- Twitter Metadata -->
<meta name="twitter:image" content="https://www.airswap.io/airswap-ogp.png" />
<meta name="twitter:image" content="https://uploads-ssl.webflow.com/645a5e62baf4b2054b2bf9d8/65250baa69591c108c27f9ae_airswap-og.webp" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@AirSwap" />

Expand Down
8 changes: 4 additions & 4 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@
"invalidSignature": "Invalid signature",
"invalidValue": "{{address}} is an invalid value",
"nonceAlreadyUsed": "Nonce has been already used or cancelled",
"senderAllowanceLow": "Sender has not approved the sender amount",
"senderBalanceLow": "Sender does not have enough balance",
"signerAllowanceLow": "Signer has not approved the signer amount",
"signerBalanceLow": "Signer does not have enough balance",
"senderAllowanceLow": "Sender (taker) has not approved the required amount",
"senderBalanceLow": "Sender (taker) does not have the required balance",
"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.",
"unableSwap": "Unable to swap",
"unauthorized": "Signature is incorrect or signer is not authorized",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Sentry.init({
dsn: process.env.REACT_APP_SENTRY_DSN,
integrations: [
new Sentry.BrowserTracing({
tracePropagationTargets: ["localhost", "airswap.io", "airswap.eth.limo"],
tracePropagationTargets: ["localhost", "eth.limo"],
}),
new Sentry.Replay(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MakeOrderReview: FC<TakeOrderReviewProps> = ({
<ReviewListItem>
<ReviewListItemLabel>{t("orders.total")}</ReviewListItemLabel>
<ReviewListItemValue>
{senderAmount} {justifiedSignerToken?.symbol}
{senderAmount} {justifiedSenderToken?.symbol}
</ReviewListItemValue>
</ReviewListItem>
</ReviewList>
Expand Down
19 changes: 17 additions & 2 deletions src/components/@widgets/OrderDetailWidget/OrderDetailWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
dispatch(
getFilteredOrders({
filter: {
senderTokens: [senderToken.address],
signerTokens: [signerToken.address],
senderToken: senderToken.address,
signerToken: signerToken.address,
},
})
);
Expand Down Expand Up @@ -334,6 +334,21 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
onEditButtonClick={handleEditButtonClick}
onSignButtonClick={takeOrder}
/>
<Overlay
title={t("validatorErrors.unableSwap")}
subTitle={t("validatorErrors.swapFail")}
onCloseButtonClick={() =>
handleActionButtonClick(ButtonActions.restart)
}
isHidden={!errors.length}
>
<ErrorList
errors={errors}
onBackButtonClick={() =>
handleActionButtonClick(ButtonActions.restart)
}
/>
</Overlay>
</Container>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/@widgets/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ const SwapWidget: FC = () => {
dispatch(
getFilteredOrders({
filter: {
senderTokens: [baseTokenInfo.address],
signerTokens: [quoteTokenInfo.address],
senderToken: baseTokenInfo.address,
signerToken: quoteTokenInfo.address,
},
})
);
Expand Down
6 changes: 3 additions & 3 deletions src/constants/rpcUrls.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { apiUrls, ChainIds } from "@airswap/constants";
import { apiUrls, mainnets, testnets } from "@airswap/constants";

const rpcUrls: Record<number, string> = {};
for (let chainId in ChainIds) {
mainnets.concat(testnets).map((chainId) => {
rpcUrls[chainId] =
process.env[`REACT_APP_RPC_URL_${chainId}`] || apiUrls[chainId];
}
});
export default rpcUrls;
2 changes: 1 addition & 1 deletion src/features/indexer/indexerRegistryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const getIndexerUrls = async (
return await Registry.getServerURLs(
provider,
chainId,
Protocols.StorageERC20
Protocols.IndexingERC20
);
};
14 changes: 8 additions & 6 deletions src/features/indexer/indexerSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const fetchIndexerUrls = createAsyncThunk<

export const getFilteredOrders = createAsyncThunk<
FullOrderERC20[],
{ filter: Pick<OrderFilter, "senderTokens" | "signerTokens"> },
{ filter: Pick<OrderFilter, "senderToken" | "signerToken"> },
{
dispatch: AppDispatch;
state: RootState;
Expand All @@ -65,11 +65,13 @@ export const getFilteredOrders = createAsyncThunk<

const orderPromises = servers.map(async (indexer, i) => {
try {
const orderResponse = await indexer.getOrdersERC20({
...filter,
offset: 0,
limit: 100,
});
const orderResponse = await indexer.getOrdersERC20(
{
...filter,
},
0,
100
);
const ordersToAdd = orderResponse.orders;
orders = { ...orders, ...ordersToAdd };
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/orders/orderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export async function check(
: errors;

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

return filteredErrors.map((error) => transformSwapErrorToAppError(error));
Expand Down
121 changes: 61 additions & 60 deletions src/features/transactions/swapEventSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,70 @@ export default function subscribeToSwapEvents(params: {

const _account = account.toLowerCase();
const wrapperAddress = Wrapper.getAddress(chainId) || "";
swapContract.protocolFeeWallet().then((feeReceiver: string) => {
swapContract.on(
"SwapERC20",
async (
nonce: BigNumber,
signerWallet: string,
swapEvent: EthersEvent
) => {
const receipt = await swapEvent.getTransactionReceipt();
const fullArgs = await getFullSwapERC20(
nonce.toString(),
signerWallet,
feeReceiver,
receipt.logs
);
if (
fullArgs.senderWallet.toLowerCase() !== _account &&
fullArgs.signerWallet.toLowerCase() !== _account &&
(fullArgs.senderWallet.toLowerCase() !==
wrapperAddress.toLowerCase() ||
(await getSenderWalletForWrapperSwapLog(swapEvent)) !== _account)
) {
// Ignore events that don't involve us.
return;
}

const onSwap = async (
nonce: BigNumber,
signerWallet: string,
swapEvent: EthersEvent
) => {
const fullArgs = await getFullSwapERC20(
swapInterface,
tokenInterface,
await swapEvent.getTransaction(),
{
nonce: nonce.toString(),
signerWallet,
}
);
dispatch(
mineTransaction({
signerWallet,
nonce: nonce.toString(),
hash: swapEvent.transactionHash,
protocol:
signerWallet.toLowerCase() === _account
? "last-look-erc20"
: "request-for-quote-erc20",
})
);

if (
fullArgs.senderWallet.toLowerCase() !== _account &&
fullArgs.signerWallet.toLowerCase() !== _account &&
(fullArgs.senderWallet.toLowerCase() !== wrapperAddress.toLowerCase() ||
(await getSenderWalletForWrapperSwapLog(swapEvent)) !== _account)
) {
// Ignore events that don't involve us.
return;
}
const transactions = store.getState().transactions;

dispatch(
mineTransaction({
signerWallet,
nonce: nonce.toString(),
hash: swapEvent.transactionHash,
protocol:
signerWallet.toLowerCase() === _account
? "last-look-erc20"
: "request-for-quote-erc20",
})
);
const matchingTransaction = transactions.all.find((tx) => {
if (tx.protocol === "last-look-erc20") {
// Last look transactions don't have a nonce, but the
const llTransaction = tx as LastLookTransaction;
return (
llTransaction.order.nonce === nonce.toString() &&
llTransaction.order.signerWallet.toLowerCase() === _account
);
} else {
// rfq transactions will have a hash
return tx.hash === swapEvent.transactionHash;
}
});

const transactions = store.getState().transactions;

const matchingTransaction = transactions.all.find((tx) => {
if (tx.protocol === "last-look-erc20") {
// Last look transactions don't have a nonce, but the
const llTransaction = tx as LastLookTransaction;
return (
llTransaction.order.nonce === nonce.toString() &&
llTransaction.order.signerWallet.toLowerCase() === _account
);
} else {
// rfq transactions will have a hash
return tx.hash === swapEvent.transactionHash;
if (matchingTransaction) {
notifyTransaction(
"Order",
matchingTransaction,
Object.values(store.getState().metadata.tokens.all),
false,
chainId
);
}
}
});

if (matchingTransaction) {
notifyTransaction(
"Order",
matchingTransaction,
Object.values(store.getState().metadata.tokens.all),
false,
chainId
);
}
};
swapContract.on("SwapERC20", onSwap);
);
});
}
8 changes: 6 additions & 2 deletions src/helpers/addChain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { apiUrls, explorerUrls } from "@airswap/constants";
import { apiUrls, chainNames, explorerUrls } from "@airswap/constants";

import nativeCurrency from "../constants/nativeCurrency";

// https://eips.ethereum.org/EIPS/eip-3085

Expand All @@ -9,7 +11,9 @@ const addChain = (chainId: number): Promise<null> => {
{
chainId: `0x${chainId.toString(16)}`,
rpcUrls: [apiUrls[chainId]],
chainName: [explorerUrls[chainId]],
blockExplorerUrls: [explorerUrls[chainId]],
chainName: chainNames[chainId],
nativeCurrency: nativeCurrency[chainId],
},
],
});
Expand Down
29 changes: 17 additions & 12 deletions src/hooks/useAddressOrEnsName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useLayoutEffect } from "react";

import { ChainIds } from "@airswap/constants";
import { Web3Provider } from "@ethersproject/providers";
import { useWeb3React } from "@web3-react/core";

Expand Down Expand Up @@ -33,18 +34,22 @@ const useAddressOrEnsName = (
if (cached !== undefined) {
setResult(cached || fallback);
} else {
library
.lookupAddress(address)
.then((name) => {
ensCachedResponses[chainId] = {
...ensCachedResponses[chainId],
[address]: name,
};
setResult(name || fallback);
})
.catch(() => {
setResult(fallback);
});
if (library.network?.chainId === ChainIds.MAINNET) {
library
.lookupAddress(address)
.then((name) => {
ensCachedResponses[chainId] = {
...ensCachedResponses[chainId],
[address]: name,
};
setResult(name || fallback);
})
.catch(() => {
setResult(fallback);
});
} else {
setResult(fallback);
}
}
}, [library, address, chainId, fallback]);

Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useEnsAddress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";

import { ChainIds } from "@airswap/constants";
import { Web3Provider } from "@ethersproject/providers";
import { useWeb3React } from "@web3-react/core";

Expand All @@ -9,8 +10,11 @@ const useEnsAddress = (address?: string): string | undefined => {

const lookupAddress = async (library: Web3Provider, value: string) => {
// Note: lookupAddress only seems to work on mainnet.
const newLookedUpAddress = await library.lookupAddress(value);
setLookedUpAddress(newLookedUpAddress);
if (library.network?.chainId === ChainIds.MAINNET) {
setLookedUpAddress(await library.lookupAddress(value));
} else {
setLookedUpAddress(value);
}
};

useEffect(() => {
Expand Down
Loading

0 comments on commit d677d37

Please sign in to comment.