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

869: Speeding up the tx changes the tx id and is not tracked #894

Merged
7 commits merged into from
Apr 17, 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: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import PageLoader from "./components/PageLoader/PageLoader";
import Routes from "./components/Routes/Routes";
import InterfaceProvider from "./contexts/interface/Interface";
import LastLookProvider from "./contexts/lastLook/LastLook";
import useTransactionsFilterFromLocalStorage from "./features/transactions/hooks/useTransactionsFilterFromLocalStorage";
import { useTransactions } from "./features/transactions/transactionsHooks";
import { selectTheme } from "./features/userSettings/userSettingsSlice";
import useCustomServer from "./hooks/useCustomServer";
import useSystemTheme from "./hooks/useSystemTheme";
Expand Down
13 changes: 3 additions & 10 deletions src/components/@widgets/CancelWidget/CancelWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { useWeb3React } from "@web3-react/core";

import { useAppDispatch, useAppSelector } from "../../../app/hooks";
import { cancelOrder } from "../../../features/takeOtc/takeOtcActions";
import {
selectTakeOtcReducer,
selectTakeOtcStatus,
setIsCancelSuccessFull,
} from "../../../features/takeOtc/takeOtcSlice";
import { selectTakeOtcStatus } from "../../../features/takeOtc/takeOtcSlice";
import useCancellationPending from "../../../hooks/useCancellationPending";
import useCancellationSuccess from "../../../hooks/useCancellationSuccess";
import { AppRoutes } from "../../../routes";
Expand Down Expand Up @@ -43,7 +39,6 @@ export const CancelWidget: FC<CancelWidgetProps> = ({ order, library }) => {
const { chainId } = useWeb3React();
const dispatch = useAppDispatch();

const { isCancelSuccessFull } = useAppSelector(selectTakeOtcReducer);
const status = useAppSelector(selectTakeOtcStatus);

const params = useParams<{ compressedOrder: string }>();
Expand All @@ -61,14 +56,12 @@ export const CancelWidget: FC<CancelWidgetProps> = ({ order, library }) => {
};

useEffect(() => {
if (isCancelSuccessFull && isCancelSuccess) {
if (isCancelSuccess) {
history.push({
pathname: `/${AppRoutes.order}/${params.compressedOrder}`,
});

dispatch(setIsCancelSuccessFull(false));
}
}, [history, params, isCancelSuccessFull, isCancelSuccess, dispatch]);
}, [isCancelSuccess]);

const handleCancelClick = async () => {
await dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useMemo, useState } from "react";
import { useAppSelector } from "../../../../app/hooks";
import { SubmittedTransaction } from "../../../../entities/SubmittedTransaction/SubmittedTransaction";
import { selectOrderTransactions } from "../../../../features/transactions/transactionsSlice";
import { TransactionStatusType } from "../../../../types/transactionTypes";

// This hook is very similar to useOrderTransaction but it will only return transactions that have been added since the component was mounted.

Expand All @@ -21,7 +22,7 @@ const useSessionOrderTransaction = (

if (
transactions[0].nonce === nonce &&
transactions[0].status === "processing"
transactions[0].status === TransactionStatusType.processing
) {
setProcessingTransactionHash(transactions[0].hash);
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/@widgets/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import useTokenInfo from "../../../hooks/useTokenInfo";
import useWithdrawalPending from "../../../hooks/useWithdrawalPending";
import { AppRoutes } from "../../../routes";
import { TokenSelectModalTypes } from "../../../types/tokenSelectModalTypes";
import { TransactionStatusType } from "../../../types/transactionTypes";
import ApproveReview from "../../@reviewScreens/ApproveReview/ApproveReview";
import AvailableOrdersWidget from "../../AvailableOrdersWidget/AvailableOrdersWidget";
import { ErrorList } from "../../ErrorList/ErrorList";
Expand Down Expand Up @@ -338,7 +339,7 @@ const SwapWidget: FC = () => {
}, [hasDepositOrWithdrawalPending]);

useEffect(() => {
if (activeTransaction?.status === "processing") {
if (activeTransaction?.status === TransactionStatusType.processing) {
setShowOrderSubmitted(true);
setIsSwapping(false);
}
Expand Down Expand Up @@ -854,7 +855,8 @@ const SwapWidget: FC = () => {
isWrapping={isWrapping}
orderSubmitted={showOrderSubmitted}
orderCompleted={
showOrderSubmitted && activeTransaction?.status === "succeeded"
showOrderSubmitted &&
activeTransaction?.status === TransactionStatusType.succeeded
}
requiresApproval={bestRfqOrder && shouldApprove}
showViewAllQuotes={indexerOrders.length > 0}
Expand Down
5 changes: 3 additions & 2 deletions src/components/OrderSubmittedScreen/OrderSubmittedScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC } from "react";
import { useTranslation } from "react-i18next";

import { SubmittedTransaction } from "../../entities/SubmittedTransaction/SubmittedTransaction";
import { TransactionStatusType } from "../../types/transactionTypes";
import { InfoSubHeading } from "../Typography/Typography";
import {
Container,
Expand Down Expand Up @@ -31,13 +32,13 @@ const OrderSubmittedScreen: FC<OrderSubmittedInfoProps> = ({
<Container className={className}>
<InfoContainer>
<DoneAllIcon />
{transaction.status === "processing" && (
{transaction.status === TransactionStatusType.processing && (
<>
<StyledInfoHeading>{t("orders.submitted")}</StyledInfoHeading>
<InfoSubHeading>{t("orders.trackTransaction")}</InfoSubHeading>
</>
)}
{transaction.status === "succeeded" && (
{transaction.status === TransactionStatusType.succeeded && (
<>
<StyledInfoHeading>
{t("orders.transactionCompleted")}
Expand Down
6 changes: 0 additions & 6 deletions src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { useAppDispatch } from "../../app/hooks";
import { WalletProvider } from "../../constants/supportedWalletProviders";
import { InterfaceContext } from "../../contexts/interface/Interface";
import { clear, setResetStatus } from "../../features/orders/ordersSlice";
import useHistoricalTransactions from "../../features/transactions/hooks/useHistoricalTransactions";
import useTransactionsFilterFromLocalStorage from "../../features/transactions/hooks/useTransactionsFilterFromLocalStorage";
import { useTransactions } from "../../features/transactions/transactionsHooks";
import { Wallet } from "../../features/wallet/Wallet";
import { setActiveProvider } from "../../features/wallet/walletSlice";
import useAppRouteParams from "../../hooks/useAppRouteParams";
Expand Down Expand Up @@ -45,9 +42,6 @@ const Page: FC<PageProps> = ({ children, className }): ReactElement => {
setShowWalletList,
} = useContext(InterfaceContext);

useTransactions();
useTransactionsFilterFromLocalStorage();

useKeyPress(() => setShowMobileToolbar(false), ["Escape"]);

const reset = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Routes/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC } from "react";
import { Route, Switch } from "react-router-dom";

import { useTransactions } from "../../features/transactions/transactionsHooks";
import Cancel from "../../pages/Cancel/Cancel";
import MakePage from "../../pages/Make/Make";
import MySwapsPage from "../../pages/MyOrders/MyOrders";
Expand All @@ -9,6 +10,8 @@ import SwapPage from "../../pages/Swap/Swap";
import { AppRoutes } from "../../routes";

const Routes: FC = () => {
useTransactions();

return (
<Switch>
<Route path={`/${AppRoutes.make}`} component={MakePage} key="make" />
Expand Down
17 changes: 9 additions & 8 deletions src/components/Toasts/ToastController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import { findTokenByAddress, FullOrderERC20, TokenInfo } from "@airswap/utils";

import i18n from "i18next";

import nativeCurrency from "../../constants/nativeCurrency";
import {
SubmittedApprovalTransaction,
SubmittedDepositTransaction,
SubmittedTransaction,
SubmittedTransactionWithOrder,
SubmittedWithdrawTransaction,
TransactionType,
} from "../../entities/SubmittedTransaction/SubmittedTransaction";
import findEthOrTokenByAddress from "../../helpers/findEthOrTokenByAddress";
import { TransactionTypes } from "../../types/transactionTypes";
import ConfirmationToast from "./ConfirmationToast";
import CopyToast from "./CopyToast";
import ErrorToast from "./ErrorToast";
import OrderToast from "./OrderToast";
import TransactionToast from "./TransactionToast";

export const notifyTransaction = (
type: TransactionType,
type: TransactionTypes,
transaction: SubmittedTransaction,
tokens: TokenInfo[],
error: boolean,
Expand All @@ -30,7 +29,9 @@ export const notifyTransaction = (
let token: TokenInfo | null;
// TODO: make a switch case to render a different toast for each case
if (
(type === "Order" || type === "Deposit" || type === "Withdraw") &&
(type === TransactionTypes.order ||
type === TransactionTypes.deposit ||
type === TransactionTypes.withdraw) &&
chainId
) {
const tx: SubmittedTransactionWithOrder =
Expand Down Expand Up @@ -94,7 +95,7 @@ export const notifyApproval = (transaction: SubmittedApprovalTransaction) => {
(t) => (
<TransactionToast
onClose={() => toast.dismiss(t.id)}
type="Approval"
type={TransactionTypes.approval}
transaction={transaction}
approvalToken={transaction.token}
/>
Expand All @@ -110,7 +111,7 @@ export const notifyDeposit = (transaction: SubmittedDepositTransaction) => {
(t) => (
<TransactionToast
onClose={() => toast.dismiss(t.id)}
type="Deposit"
type={TransactionTypes.deposit}
transaction={transaction}
senderToken={transaction.senderToken}
signerToken={transaction.signerToken}
Expand All @@ -127,7 +128,7 @@ export const notifyWithdrawal = (transaction: SubmittedWithdrawTransaction) => {
(t) => (
<TransactionToast
onClose={() => toast.dismiss(t.id)}
type="Deposit"
type={TransactionTypes.withdraw}
transaction={transaction}
senderToken={transaction.senderToken}
signerToken={transaction.signerToken}
Expand All @@ -144,7 +145,7 @@ export const notifyOrder = (transaction: SubmittedTransactionWithOrder) => {
(t) => (
<TransactionToast
onClose={() => toast.dismiss(t.id)}
type="Order"
type={TransactionTypes.order}
transaction={transaction}
senderToken={transaction.senderToken}
signerToken={transaction.signerToken}
Expand Down
14 changes: 10 additions & 4 deletions src/components/Toasts/TransactionToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
SubmittedLastLookOrder,
SubmittedRFQOrder,
SubmittedTransaction,
TransactionType,
} from "../../entities/SubmittedTransaction/SubmittedTransaction";
import { TransactionTypes } from "../../types/transactionTypes";
import { InfoHeading } from "../Typography/Typography";
import {
Container,
Expand All @@ -37,7 +37,7 @@ export type TransactionToastProps = {
/**
* Type of transaction the toast will display;
*/
type: TransactionType;
type: TransactionTypes;
/**
* Token Info of sender token
*/
Expand Down Expand Up @@ -74,7 +74,9 @@ const TransactionToast = ({
</IconContainer>
<TextContainer>
<InfoHeading>
{type === "Order" || type === "Deposit" || type === "Withdraw"
{type === TransactionTypes.order ||
type === TransactionTypes.deposit ||
type === TransactionTypes.withdraw
? error
? t("toast.swapFail")
: t("toast.swapComplete")
Expand All @@ -84,7 +86,11 @@ const TransactionToast = ({
</InfoHeading>
<SwapAmounts>
{(() => {
if (type === "Order" || type === "Deposit" || type === "Withdraw") {
if (
type === TransactionTypes.order ||
type === TransactionTypes.deposit ||
type === TransactionTypes.withdraw
) {
if (transaction && senderToken && signerToken) {
const tx =
transaction.protocol === "last-look-erc20"
Expand Down
7 changes: 5 additions & 2 deletions src/components/TransactionsTab/TransactionsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useMediaQuery from "../../hooks/useMediaQuery";
import useWindowSize from "../../hooks/useWindowSize";
import breakPoints from "../../style/breakpoints";
import { ClearOrderType } from "../../types/clearOrderType";
import { TransactionStatusType } from "../../types/transactionTypes";
import Icon from "../Icon/Icon";
import {
Container,
Expand Down Expand Up @@ -145,13 +146,15 @@ const TransactionsTab = ({

const pendingTransactions = useMemo(() => {
return transactions.filter(
(transaction) => transaction.status === "processing"
(transaction) => transaction.status === TransactionStatusType.processing
);
}, [transactions]);

const completedTransactions = useMemo(() => {
return transactions
.filter((transaction) => transaction.status !== "processing")
.filter(
(transaction) => transaction.status !== TransactionStatusType.processing
)
.sort((a, b) => b.timestamp - a.timestamp);
}, [transactions]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { TFunction } from "react-i18next";

import { StatusType } from "../../../entities/SubmittedTransaction/SubmittedTransaction";
import { TransactionStatusType } from "../../../types/transactionTypes";

export default function getWalletTransactionStatusText(
status: StatusType,
status: TransactionStatusType,
t: TFunction
): string {
switch (status) {
case "succeeded":
case TransactionStatusType.succeeded:
return t("common.success");
case "processing":
case TransactionStatusType.processing:
return t("common.processing");
case "expired":
case TransactionStatusType.expired:
return t("common.expired");
case "reverted":
case TransactionStatusType.reverted:
return t("common.failed");
case "declined":
case TransactionStatusType.declined:
return t("orders.swapRejected");
default:
return t("common.unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isOrderTransaction,
isWithdrawTransaction,
} from "../../../../entities/SubmittedTransaction/SubmittedTransactionHelpers";
import { TransactionStatusType } from "../../../../types/transactionTypes";
import ProgressBar from "../../../ProgressBar/ProgressBar";
import getTimeAgoTranslation from "../../helpers/getTimeAgoTranslation";
import getWalletTransactionStatusText from "../../helpers/getWalletTransactionStatusText";
Expand Down Expand Up @@ -90,7 +91,11 @@ const WalletTransaction = ({
</SpanSubtitle>
</TextContainer>

<StyledTransactionLink chainId={chainId} hash={transaction.hash} />
<StyledTransactionLink
hideLabel
chainId={chainId}
hash={transaction.hash}
/>
</Container>
);
}
Expand Down Expand Up @@ -120,14 +125,17 @@ const WalletTransaction = ({

return (
<Container transition={transition} animate={animate} initial={initial}>
{transaction.status === "processing" && (
{transaction.status === TransactionStatusType.processing && (
<RotatedIcon name="swap" iconSize={1.25} />
)}
<TextContainer>
{transaction && senderToken && signerToken && (
<>
<SpanTitle
hasProgress={hasExpiry && transaction.status === "processing"}
hasProgress={
hasExpiry &&
transaction.status === TransactionStatusType.processing
}
>
{t(
transaction.protocol === "last-look-erc20"
Expand Down Expand Up @@ -155,7 +163,8 @@ const WalletTransaction = ({
}
)}
</SpanTitle>
{hasExpiry && transaction.status === "processing" ? (
{hasExpiry &&
transaction.status === TransactionStatusType.processing ? (
<ProgressBar
startTime={transaction.timestamp}
endTime={parseInt(transaction.expiry!) * 1000}
Expand Down
Loading
Loading