Skip to content

Commit

Permalink
983: Submitted Deposit overlay (#1003)
Browse files Browse the repository at this point in the history
* 983: Added DepositSubmittedScreen

* Fixed OverlyLoader size

* Fixed useDepositPending
  • Loading branch information
makkelie-dev authored Dec 12, 2024
1 parent 3cd5294 commit b6e2de0
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 30 deletions.
2 changes: 2 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"continue": "Continue",
"copyLink": "Copy link",
"counterPartyAddress": "Counterparty address",
"depositComplete": "Deposit complete",
"depositProcessing": "Deposit processing...",
"dismiss": "Dismiss",
"editCustomTokens": "Edit",
"enterAmount": "Enter an amount",
Expand Down
16 changes: 14 additions & 2 deletions src/components/@widgets/MakeWidget/MakeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import ApproveReview from "../../@reviewScreens/ApproveReview/ApproveReview";
import MakeOrderReview from "../../@reviewScreens/MakeOrderReview/MakeOrderReview";
import WrapReview from "../../@reviewScreens/WrapReview/WrapReview";
import ApprovalSubmittedScreen from "../../ApprovalSubmittedScreen/ApprovalSubmittedScreen";
import DepositSubmittedScreen from "../../DepositSubmittedScreen/DepositSubmittedScreen";
import { SelectOption } from "../../Dropdown/Dropdown";
import OrderTypesModal from "../../InformationModals/subcomponents/OrderTypesModal/OrderTypesModal";
import ModalOverlay from "../../ModalOverlay/ModalOverlay";
Expand Down Expand Up @@ -156,13 +157,13 @@ const MakeWidget: FC = () => {
makerTokenInfo?.address === ADDRESS_ZERO &&
!!nativeCurrencySafeTransactionFee[makerTokenInfo.chainId];
const approvalTransaction = useApprovalPending(makerTokenInfo?.address, true);
const depositTransaction = useDepositPending(true);
const wrappedNativeToken = useNativeWrappedToken(chainId);
const shouldDepositNativeTokenAmount = useShouldDepositNativeToken(
makerTokenInfo?.address,
makerAmount
);
const shouldDepositNativeToken = !!shouldDepositNativeTokenAmount;
const hasDepositPending = useDepositPending();
const isValidAddress = useValidAddress(takerAddress);
const isAllowancesOrBalancesFailed = useAllowancesOrBalancesFailed();
const isNetworkSupported = useNetworkSupported();
Expand Down Expand Up @@ -384,7 +385,7 @@ const MakeWidget: FC = () => {
<>
<WrapReview
hasEditButton
isLoading={hasDepositPending}
isLoading={!!depositTransaction}
amount={makerAmount}
amountPlusFee={makerAmountPlusFee}
shouldDepositNativeTokenAmount={shouldDepositNativeTokenAmount}
Expand Down Expand Up @@ -545,6 +546,17 @@ const MakeWidget: FC = () => {
)}
</TransactionOverlay>

<TransactionOverlay
isHidden={ordersStatus === "signing" || !depositTransaction}
>
{depositTransaction && (
<DepositSubmittedScreen
chainId={chainId}
transaction={depositTransaction}
/>
)}
</TransactionOverlay>

<ModalOverlay
hasDynamicHeight
onClose={() => setShowTokenSelectModal(null)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
);
const isAllowancesOrBalancesFailed = useAllowancesOrBalancesFailed();
const shouldDepositNativeToken = !!shouldDepositNativeTokenAmount;
const hasDepositPending = useDepositPending();
const hasDepositPending = !!useDepositPending();
const orderTransactionLink = useOrderTransactionLink(order.nonce);
const orderChainId = useMemo(() => order.chainId, [order]);
const walletChainIdIsDifferentThanOrderChainId =
Expand Down
2 changes: 1 addition & 1 deletion src/components/@widgets/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const SwapWidget: FC = () => {
!hasSufficientAllowance &&
!hasApprovalSuccess &&
swapType !== SwapType.wrapOrUnwrap;
const hasDepositPending = useDepositPending();
const hasDepositPending = !!useDepositPending();
const hasWithdrawalPending = useWithdrawalPending();
const hasDepositOrWithdrawalPending =
hasDepositPending || hasWithdrawalPending;
Expand Down
13 changes: 3 additions & 10 deletions src/components/ApprovalSubmittedScreen/ApprovalSubmittedScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { SubmittedApprovalTransaction } from "../../entities/SubmittedTransactio
import useDebounce from "../../hooks/useDebounce";
import {
OverlayContainer,
OverlayLoader,
OverlaySubHeading,
OverlayTitle,
OverlayTransactionLink,
} from "../../styled-components/Overlay/Overlay";
import { TransactionStatusType } from "../../types/transactionTypes";
import { IconWrapper, StyledIcon } from "./ApprovalSubmittedScreen.styles";
import OverlayLoader from "../OverlayLoader/OverlayLoader";

interface ApprovalSubmittedScreenProps {
chainId?: number;
Expand Down Expand Up @@ -43,16 +42,10 @@ const ApprovalSubmittedScreen: FC<ApprovalSubmittedScreenProps> = ({
<OverlayContainer
className={className}
style={{
transform: isAnimatedToCenter ? "translateY(5rem)" : "translateY(0)",
transform: isAnimatedToCenter ? "translateY(2.5rem)" : "translateY(0)",
}}
>
{isSucceeded ? (
<IconWrapper>
<StyledIcon name="check-circle" />
</IconWrapper>
) : (
<OverlayLoader />
)}
<OverlayLoader isSucceeded={isSucceeded} />
<OverlayTitle type="h2">
{isSucceeded
? t("orders.approvalComplete")
Expand Down
67 changes: 67 additions & 0 deletions src/components/DepositSubmittedScreen/DepositSubmittedScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { FC, useState } from "react";
import { useTranslation } from "react-i18next";

import { SubmittedDepositTransaction } from "../../entities/SubmittedTransaction/SubmittedTransaction";
import useDebounce from "../../hooks/useDebounce";
import {
OverlayContainer,
OverlaySubHeading,
OverlayTitle,
OverlayTransactionLink,
} from "../../styled-components/Overlay/Overlay";
import { TransactionStatusType } from "../../types/transactionTypes";
import OverlayLoader from "../OverlayLoader/OverlayLoader";

interface DepositSubmittedScreenProps {
chainId?: number;
transaction?: SubmittedDepositTransaction;
className?: string;
}

const DepositSubmittedScreen: FC<DepositSubmittedScreenProps> = ({
chainId,
transaction,
className = "",
}) => {
const { t } = useTranslation();
const [isAnimatedToCenter, setIsAnimatedToCenter] = useState(false);

const isSucceeded = transaction?.status === TransactionStatusType.succeeded;

useDebounce(
() => {
if (isSucceeded) {
setIsAnimatedToCenter(true);
}
},
500,
[isSucceeded]
);

return (
<OverlayContainer
className={className}
style={{
transform: isAnimatedToCenter ? "translateY(2.5rem)" : "translateY(0)",
}}
>
<OverlayLoader isSucceeded={isSucceeded} />
<OverlayTitle type="h2">
{isSucceeded
? t("orders.depositComplete")
: t("orders.depositProcessing")}
</OverlayTitle>
<OverlaySubHeading isHidden={isSucceeded}>
{transaction?.hash && chainId && (
<OverlayTransactionLink
isHidden={isSucceeded}
chainId={chainId}
hash={transaction.hash}
/>
)}
</OverlaySubHeading>
</OverlayContainer>
);
};

export default DepositSubmittedScreen;
12 changes: 2 additions & 10 deletions src/components/OrderSubmittedScreen/OrderSubmittedScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { useTranslation } from "react-i18next";
import { SubmittedTransaction } from "../../entities/SubmittedTransaction/SubmittedTransaction";
import {
OverlayContainer,
OverlayLoader,
OverlaySubHeading,
OverlayTitle,
OverlayTransactionLink,
} from "../../styled-components/Overlay/Overlay";
import { TransactionStatusType } from "../../types/transactionTypes";
import OverlayLoader from "../OverlayLoader/OverlayLoader";
import {
ButtonsContainer,
IconWrapper,
MakeNewOrderButton,
StyledIcon,
TrackTransactionButton,
} from "./OrderSubmittedScreen.styles";

Expand Down Expand Up @@ -43,13 +41,7 @@ const OrderSubmittedScreen: FC<OrderSubmittedInfoProps> = ({

return (
<OverlayContainer className={className}>
{isSucceeded ? (
<IconWrapper>
<StyledIcon name="check-circle" />
</IconWrapper>
) : (
<OverlayLoader />
)}
<OverlayLoader isSucceeded={isSucceeded} />
{isSendingOrder && (
<>
<OverlayTitle type="h2">{t("orders.orderSent")}</OverlayTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from "styled-components/macro";

import Icon from "../Icon/Icon";

export const IconWrapper = styled.div`
export const Container = styled.div`
display: flex;
align-items: flex-end;
justify-content: center;
Expand Down
23 changes: 23 additions & 0 deletions src/components/OverlayLoader/OverlayLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FC } from "react";

import { OverlaySpinningLoader } from "../../styled-components/Overlay/Overlay";
import { Container, StyledIcon } from "./OverlayLoader.styles";

interface OverlayLoaderProps {
isSucceeded?: boolean;
className?: string;
}

const OverlayLoader: FC<OverlayLoaderProps> = ({ isSucceeded, className }) => {
return (
<Container className={className}>
{isSucceeded ? (
<StyledIcon name="check-circle" />
) : (
<OverlaySpinningLoader />
)}
</Container>
);
};

export default OverlayLoader;
3 changes: 2 additions & 1 deletion src/components/WalletSignScreen/WalletSignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import i18n from "i18next";

import {
OverlayContainer,
OverlayLoader,
OverlaySpinningLoader,
OverlaySubHeading,
OverlayTitle,
} from "../../styled-components/Overlay/Overlay";
import OverlayLoader from "../OverlayLoader/OverlayLoader";

type WalletSignScreenType =
| "approve"
Expand Down
5 changes: 5 additions & 0 deletions src/features/transactions/transactionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export const selectSuccessfulTransactions = (
(tx) => tx.status === TransactionStatusType.succeeded
) as SubmittedTransaction[];

export const selectAllDeposits = (state: RootState) =>
state.transactions.transactions.filter(
(tx) => tx.type === TransactionTypes.deposit
) as SubmittedDepositTransaction[];

export const selectPendingDeposits = (
state: RootState
): SubmittedDepositTransaction[] =>
Expand Down
48 changes: 45 additions & 3 deletions src/hooks/useDepositPending.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
import { useEffect, useMemo, useState } from "react";
import { useDebounce } from "react-use";

import { useAppSelector } from "../app/hooks";
import { selectPendingDeposits } from "../features/transactions/transactionsSlice";
import { SubmittedDepositTransaction } from "../entities/SubmittedTransaction/SubmittedTransaction";
import {
selectAllDeposits,
selectPendingDeposits,
} from "../features/transactions/transactionsSlice";

const useDepositPending = (): boolean => {
const useDepositPending = (
showResolvedDeposit: boolean = false
): SubmittedDepositTransaction | undefined => {
const pendingDeposits = useAppSelector(selectPendingDeposits);
const allDeposits = useAppSelector(selectAllDeposits);

const [debouncedDeposit, setDebouncedDeposit] = useState<
SubmittedDepositTransaction | undefined
>(undefined);

const pendingDeposit = pendingDeposits.length
? pendingDeposits[0]
: undefined;

const resolvedDeposit = useMemo(() => {
if (debouncedDeposit) {
return allDeposits.find((tx) => tx.hash === debouncedDeposit.hash);
}

return undefined;
}, [debouncedDeposit, allDeposits]);

useEffect(() => {
if (pendingDeposit) {
setDebouncedDeposit(pendingDeposit);
}
}, [pendingDeposit]);

useDebounce(
() => {
if (pendingDeposit === undefined) {
setDebouncedDeposit(undefined);
}
},
3000,
[pendingDeposit]
);

return !!pendingDeposits.length;
return pendingDeposit || (showResolvedDeposit ? resolvedDeposit : undefined);
};

export default useDepositPending;
2 changes: 1 addition & 1 deletion src/styled-components/Overlay/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const spin = keyframes`
}
`;

export const OverlayLoader = styled.div`
export const OverlaySpinningLoader = styled.div`
width: 3.6875rem;
height: 3.6875rem;
border-radius: 50%;
Expand Down

0 comments on commit b6e2de0

Please sign in to comment.