Skip to content

Commit

Permalink
clearLocalStorageFailedTx function
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestarrdev committed Jun 28, 2023
1 parent 5d019bd commit c6aa717
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/components/TransactionsTab/TransactionsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";

import { chainCurrencies, chainNames } from "@airswap/constants";
import { TokenInfo } from "@airswap/types";
Expand All @@ -12,7 +13,10 @@ import { AnimatePresence, useReducedMotion } from "framer-motion";

import { nativeCurrencyAddress } from "../../constants/nativeCurrency";
import { BalancesState } from "../../features/balances/balancesSlice";
import { setTransactions, SubmittedTransaction } from "../../features/transactions/transactionsSlice";
import {
setTransactions,
SubmittedTransaction,
} from "../../features/transactions/transactionsSlice";
import useAddressOrEnsName from "../../hooks/useAddressOrEnsName";
import { useKeyPress } from "../../hooks/useKeyPress";
import useMediaQuery from "../../hooks/useMediaQuery";
Expand Down Expand Up @@ -40,11 +44,10 @@ import {
MobileWalletInfoButton,
StyledWalletMobileMenu,
BackdropFilter,
ClearFailedTxButton
ClearFailedTxButton,
} from "./TransactionsTab.styles";
import { clearLocalStorage } from "./helpers/clearLocalStorage";
import { clearLocalStorageFailedTx } from "./helpers/clearLocalStorageFailedTx";
import AnimatedWalletTransaction from "./subcomponents/AnimatedWalletTransaction/AnimatedWalletTransaction";
import { useDispatch } from "react-redux";

type TransactionsTabType = {
address: string;
Expand Down Expand Up @@ -157,7 +160,7 @@ const TransactionsTab = ({

const handleClearTransactions = () => {
// dispatch(setTransactions(null));
clearLocalStorage();
clearLocalStorageFailedTx(address);
};

return (
Expand Down
11 changes: 0 additions & 11 deletions src/components/TransactionsTab/helpers/clearLocalStorage.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const clearLocalStorageFailedTx = (address: string) => {
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
const localStorageKey = `airswap/transactions/${address}`
if (key?.includes(localStorageKey)) {
const keysWithTransactions = localStorage.getItem(key)
if (keysWithTransactions) {
const objectKeys = JSON.parse(keysWithTransactions);
const orders = objectKeys.all;
const filteredOrders = orders.filter((order: any) => {
return order.status !== 'failed'
});
const updatedKeys = JSON.stringify({ all: filteredOrders })

localStorage.setItem(key, updatedKeys);
}
}
}
};

0 comments on commit c6aa717

Please sign in to comment.