-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
983: Submitted Deposit overlay (#1003)
* 983: Added DepositSubmittedScreen * Fixed OverlyLoader size * Fixed useDepositPending
- Loading branch information
1 parent
3cd5294
commit b6e2de0
Showing
13 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/components/DepositSubmittedScreen/DepositSubmittedScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters