OpeningAutoChannel.tsx raw

   1  import React from "react";
   2  import { useLocation, useNavigate } from "react-router";
   3  import { ChannelWaitingForConfirmations } from "src/components/channels/ChannelWaitingForConfirmations";
   4  import { useChannels } from "src/hooks/useChannels";
   5  import { useSyncWallet } from "src/hooks/useSyncWallet";
   6  
   7  export function OpeningAutoChannel() {
   8    useSyncWallet();
   9    const { data: channels } = useChannels(true);
  10    const navigate = useNavigate();
  11  
  12    const { state } = useLocation();
  13    const newChannelId = state?.newChannelId as string | undefined;
  14  
  15    const channel = channels?.find(
  16      (channel) => channel.id && channel.id === newChannelId
  17    );
  18  
  19    React.useEffect(() => {
  20      if (channel?.active) {
  21        navigate("/channels/auto/opened");
  22      }
  23    }, [channel, navigate]);
  24  
  25    return <ChannelWaitingForConfirmations channel={channel} />;
  26  }
  27