import { CustomizeContext } from "../../providers/CustomizeProvider"; import { useState, useEffect, useContext } from "react"; import { ExternalLink } from "react-feather"; import { ethers } from "ethers"; import useMappedChainData from "../../hooks/useMappedChainData"; import { getExplorerLink, ExplorerDataType, timeInMinutes } from "../../utils/"; import { UserTxType } from "../../consts/"; import { TxDetails } from "../../types"; // components import { Spinner } from "../common/Spinner"; import { TokenDetailsRow } from "../common/TokenDetailsRow"; import { SocketScanLink } from "../common/SocketScanLink"; // This component is displayed when transaction of type 'fund-movr' (bridging tx) is in progress export const BridgingLoader = ({ currentRoute, explorerParams, txDetails, refuelEnabled, }) => { const mappedChainData = useMappedChainData(); const [srcTxHash, setSrcTxHash] = useState(""); const [destTxHash, setDestTxHash] = useState(""); const [destRefuelTxHash, setDestRefuelTxHash] = useState(""); const [bridgeDetails, setBridgeDetails] = useState(null); const [showSupportLink, setShowSupportLink] = useState(false); const [furtherStepsAvailable, setFurtherStepsAvailable] = useState(false); useEffect(() => { const srcUrl = getExplorerLink( mappedChainData?.[explorerParams.srcChainId]?.explorers[0], explorerParams.srcTxHash, ExplorerDataType.TRANSACTION ); const destUrl = getExplorerLink( mappedChainData?.[explorerParams.destChainId]?.explorers[0], explorerParams.destTxHash, ExplorerDataType.TRANSACTION ); const destRefuelUrl = getExplorerLink( mappedChainData?.[explorerParams.destRefuelTxHash]?.explorers[0], explorerParams.destRefuelTxHash, ExplorerDataType.TRANSACTION ); setSrcTxHash(srcUrl); setDestTxHash(destUrl); setDestRefuelTxHash(destRefuelUrl); }, [mappedChainData, explorerParams]); // To set the bridge name, service time and discord url useEffect(() => { // Filtering out bridge tx from userTxs. const bridgeTx = currentRoute?.route?.userTxs?.filter( (x) => x.userTxType === UserTxType.FUND_MOVR )?.[0]; // Filtering out the bridge step from the steps in bridgeTx const bridgeStep = bridgeTx?.steps?.filter((x) => x.type === "bridge")?.[0]; setBridgeDetails(bridgeStep); // Getting txDetails as an array const txDetailValues: TxDetails[] = txDetails && Object.values(txDetails); // Getting the timestamp of the bridging transaction const bridgingTimeStamp: number = txDetailValues?.filter( (x: TxDetails): boolean => x.userTxType === UserTxType.FUND_MOVR )?.[0]?.timeStamp; const currentTime = new Date().getTime(); if (bridgingTimeStamp && currentTime) { // Difference between current time and the time when the bridging transaction was triggered const timeDiff = ethers.BigNumber.from(currentTime).sub( ethers.BigNumber.from(bridgingTimeStamp) ); const timeDiffInSeconds = timeDiff.div(1000).toString(); // If time difference is twice the service time, show discord support link if (Number(timeDiffInSeconds) > bridgeStep?.serviceTime * 2) { setShowSupportLink(true); } } // Check if there are any further steps const _currentUserTx = currentRoute?.route?.currentUserTxIndex ? currentRoute?.route?.currentUserTxIndex + 1 : 1; setFurtherStepsAvailable( _currentUserTx < currentRoute?.route?.userTxs?.length ); }, [currentRoute, txDetails]); const refuelSourceToken = { amount: currentRoute?.refuel?.fromAmount, asset: currentRoute?.refuel?.fromAsset, }; const refuelDestToken = { amount: currentRoute?.refuel?.toAmount, asset: currentRoute?.refuel?.toAsset, }; return (

Bridging in progress

{showSupportLink ? ( Get in touch for support on{" "} Discord ) : ( Estimated wait time is{" "} {timeInMinutes(bridgeDetails?.serviceTime)} {furtherStepsAvailable && ", please come back later to sign the next transaction."} )}

{!!refuelEnabled && (
)}
{explorerParams?.srcTxHash && (
)}
); }; const TxUrlChip = ({ url, label }: { url?: string; label: string }) => { const customSettings = useContext(CustomizeContext); const { borderRadius } = customSettings.customization; return ( {url && !url.match("undefined") ? ( {label}{" "} ) : ( {label} )} ); }; const TxRow = ({ title, srcUrl, destUrl, }: { title: string; srcUrl?: string; destUrl?: string; }) => { return (
{title}
{!!srcUrl && ( )}
); };