'use client' import Link from 'next/link' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog' import { IconExternalLink } from '@/components/ui/icons' import { useGlobalStore } from '@/app/state/global-store' import toast from 'react-hot-toast' export function DeployFrontendButton({ sourceCode, address, abi }: { sourceCode: string address?: string abi?: any }) { const { lastDeploymentData } = useGlobalStore() const [isOpen, setIsOpen] = useState(false) const [deployResults, setDeployResults] = useState<{ junoUrl?: string icpUrl?: string isError?: boolean }>({}) const { junoUrl, icpUrl, isError } = deployResults const _address = address || lastDeploymentData?.address || '' const _abi = abi || lastDeploymentData?.abi const disabled = !sourceCode || !_address || !_abi async function handleDeployFrontend() { const deployment = await deployFrontend({ sourceCode, contractAddress: _address, abi: _abi }) setDeployResults(deployment) } return ( Deploy Frontend Deploy your frontend on chain. One deployment will be on the Juno blockchain the other will be on ICP as a frontend canister.
{isError && (

Error deploying frontend.

)} {junoUrl && ( View on Juno )} {icpUrl && ( View on ICP )}
) } async function deployFrontend({ sourceCode, contractAddress, abi }: { sourceCode: string contractAddress: string abi: any }) { // replace CONTRACT_ABI and CONTRACT_ADDRESS with the actual contract abi and address in the source code const abiString = JSON.stringify(abi) sourceCode = sourceCode.replace('CONTRACT_ABI', abiString) sourceCode = sourceCode.replace('CONTRACT_ADDRESS', contractAddress) const res = await toast.promise( fetch('http://localhost:4040/deploy-html', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sourceCode }) }), { loading: 'Deploying frontend...', success: 'Frontend deployed!', error: 'Failed to deploy frontend' } ) const deployResult = await res.json() return deployResult }