diff --git a/src/components/CopyTxHash/CopyTxHash.tsx b/src/components/CopyTxHash/CopyTxHash.tsx index 964afb2f..b6b5e509 100644 --- a/src/components/CopyTxHash/CopyTxHash.tsx +++ b/src/components/CopyTxHash/CopyTxHash.tsx @@ -20,32 +20,62 @@ const getExplorerUrl = ({ chain, txHash }: { chain: WalletChain; txHash: string } }; +enum ExplorerType { + STELLAR_EXPERT = 'STELLAR_EXPERT', + STELLAR_CHAIN = 'STELLAR_CHAIN', +} + +interface ExplorerLinks { + stellarExpert: string; + stellarChain: string; +} + const CopyTxHash = ({ txHash }: { txHash: string }) => { const { notify } = useNotification(); const sorobanContext = useSorobanReact(); - const [explorerLink, setExplorerLink] = useState(undefined); + const activeChain = sorobanContext?.activeChain; - useEffect(() => { - if (!sorobanContext) return; + const [explorersLinks, setExplorersLinks] = useState(undefined); - const activeChain = sorobanContext.activeChain; - if (!activeChain) return; + useEffect(() => { + if (!sorobanContext || !activeChain) return; - if (activeChain.name === testnet.name || activeChain.name === mainnet.name) { - setExplorerLink(getExplorerUrl({ chain: activeChain, txHash })); + if (activeChain.name === testnet.name) { + setExplorersLinks({ + stellarExpert: `https://stellar.expert/explorer/testnet/tx/${txHash}`, + stellarChain: `https://testnet.stellarchain.io/transactions/${txHash}`, + }); } - }, [sorobanContext, txHash]); - const handleClickViewOnExplorer = () => { - if (!explorerLink) return; + if (activeChain.name === mainnet.name) { + setExplorersLinks({ + stellarExpert: `https://stellar.expert/explorer/public/tx/${txHash}`, + stellarChain: `https://stellarchain.io/transactions/${txHash}`, + }); + } + }, [sorobanContext, txHash]); - window.open(explorerLink, '_blank'); - }; return ( - + + {(explorersLinks?.stellarChain && explorersLinks.stellarExpert) && ( + <> + + + View on Stellar.Expert + + + + + View on StellarChain.io + + + + )} @@ -61,11 +91,6 @@ const CopyTxHash = ({ txHash }: { txHash: string }) => { - {explorerLink && ( - - View on explorer - - )} ); };