Skip to content

Commit

Permalink
starting to write logic for clearing failed transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestarrdev committed Jun 28, 2023
1 parent cf4919a commit 5d019bd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
"activeTransactions": "Active transactions",
"approve": "Approve {{symbol}}",
"completedTransactions": "Completed transactions",
"clearFailedTransactions": "Clear failed transactions",
"connectWallet": "Connect Wallet",
"copyAddress": "Copy address",
"dayAgo_one": "{{count}} day ago",
Expand Down
8 changes: 8 additions & 0 deletions src/components/TransactionsTab/TransactionsTab.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,11 @@ export const BackdropFilter = styled.button`
display: block;
}
`;

export const ClearFailedTxButton = styled(Button)`
margin-top: 1rem;
${InputOrButtonBorderStyleType2};
@media ${breakPoints.phoneOnly} {
display: none;
}
`;
24 changes: 21 additions & 3 deletions src/components/TransactionsTab/TransactionsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AnimatePresence, useReducedMotion } from "framer-motion";

import { nativeCurrencyAddress } from "../../constants/nativeCurrency";
import { BalancesState } from "../../features/balances/balancesSlice";
import { 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,8 +40,11 @@ import {
MobileWalletInfoButton,
StyledWalletMobileMenu,
BackdropFilter,
ClearFailedTxButton
} from "./TransactionsTab.styles";
import { clearLocalStorage } from "./helpers/clearLocalStorage";
import AnimatedWalletTransaction from "./subcomponents/AnimatedWalletTransaction/AnimatedWalletTransaction";
import { useDispatch } from "react-redux";

type TransactionsTabType = {
address: string;
Expand Down Expand Up @@ -83,13 +86,15 @@ const TransactionsTab = ({
const transactionsScrollRef = useRef<HTMLDivElement>(null);
const buttonRef = useRef<HTMLDivElement>(null);

const dispatch = useDispatch();

const addressOrName = useAddressOrEnsName(address);
const walletInfoText = useMemo(() => {
return isUnsupportedNetwork
? t("wallet.unsupported")
: addressOrName
? addressOrName
: t("wallet.notConnected");
? addressOrName
: t("wallet.notConnected");
}, [addressOrName, isUnsupportedNetwork, t]);
const walletUrl = useMemo(
() => getAccountUrl(chainId, address),
Expand Down Expand Up @@ -150,6 +155,11 @@ const TransactionsTab = ({

const balance = balances.values[nativeCurrencyAddress] || "0";

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

return (
<AnimatePresence initial={false}>
{open && (
Expand Down Expand Up @@ -249,6 +259,14 @@ const TransactionsTab = ({
{t("wallet.noCompletedTransactions")}
</NoTransactions>
)}
{transactions.length > 0 && (
<ClearFailedTxButton
aria-label={t("wallet.clearFailedTransactions")}
onClick={handleClearTransactions}
>
{t("wallet.clearFailedTransactions")}
</ClearFailedTxButton>
)}
</TransactionContainer>
</TransactionsContainer>
<BottomButtonContainer ref={buttonRef}>
Expand Down
11 changes: 11 additions & 0 deletions src/components/TransactionsTab/helpers/clearLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// TODO: filter for transactions
export const clearLocalStorage = () => {
const filteredTransactions = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key?.startsWith("airswap/transactions")) {
console.log(key)
// localStorage.removeItem(key);
}
}
};

0 comments on commit 5d019bd

Please sign in to comment.