Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:airswap/airswap-web into ipfs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmosites committed Dec 21, 2023
2 parents bfe36c7 + ac18b82 commit 70e9c39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/features/metadata/metadataSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ export const subscribeToSavedTokenChangesForLocalStoragePersisting = () => {
) {
transactionCache[wallet.address!][wallet.chainId!] =
mostRecentTransactions;

// Filter out processing transactions to prevent them being stuck perpetually, we should enable this again once we have a better solution
// TODO: https://github.com/airswap/airswap-web/issues/876
const updatedLocalStorageTransactions = mostRecentTransactions.filter(
(tx) => tx.status !== "processing"
);

localStorage.setItem(
getTransactionsLocalStorageKey(wallet.address!, wallet.chainId!),
JSON.stringify({
all: mostRecentTransactions,
all: updatedLocalStorageTransactions,
})
);
}
Expand Down
22 changes: 18 additions & 4 deletions src/features/transactions/useHistoricalTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";

import { useCustomCompareEffect } from "@react-hookz/web/esm";
import { useWeb3React } from "@web3-react/core";
Expand All @@ -10,6 +10,7 @@ import Weth9 from "../../constants/Weth9";
import {
checkPendingTransactionState,
getSwapArgsFromWrappedSwapForLog,
getTransactionsLocalStorageKey,
SwapEventArgs,
} from "./transactionUtils";
import {
Expand All @@ -23,13 +24,14 @@ import useTransactionsFromLocalStorage from "./useTransactionsFromLocalStorage";
const useHistoricalTransactions = () => {
const { chainId, library, account } = useWeb3React();
const { result: swapLogs, status: swapLogStatus } = useSwapLogs();
const transactions = useAppSelector(selectTransactions);
const {
transactions: localStorageTransactions,
setTransactions: setLocalStorageTransactions,
} = useTransactionsFromLocalStorage();
const dispatch = useAppDispatch();

const [activeLocalStorageKey, setActiveLocalStorageKey] = useState<string>();

useCustomCompareEffect(
() => {
if (swapLogStatus === "loading" || swapLogStatus === "not-executed")
Expand Down Expand Up @@ -170,8 +172,20 @@ const useHistoricalTransactions = () => {
);

useEffect(() => {
setLocalStorageTransactions({ all: transactions });
}, [transactions]);
if (!chainId || !account) {
return;
}

const localStorageKey = getTransactionsLocalStorageKey(account, chainId);

if (localStorageKey === activeLocalStorageKey) {
return;
}

setActiveLocalStorageKey(localStorageKey);

dispatch(setTransactions(localStorageTransactions?.all || []));
}, [localStorageTransactions]);
};

export default useHistoricalTransactions;

0 comments on commit 70e9c39

Please sign in to comment.