'use client'; import { Spinner } from '@/internal/components/Spinner'; import { cn, pressable, text } from '@/styles/theme'; import { ConnectWallet } from '@/wallet/components/ConnectWallet'; import type { SwapButtonProps } from '../types'; import { useSwapContext } from './SwapProvider'; export function SwapButton({ className, label = 'Swap', disabled = false, render, }: SwapButtonProps) { const { address, to, from, lifecycleStatus, handleSubmit } = useSwapContext(); const statusName = lifecycleStatus.statusName; const isLoading = to.loading || from.loading || statusName === 'transactionPending' || statusName === 'transactionApproved'; const isDisabled = !from.amount || !from.token || !to.amount || !to.token || disabled || isLoading; // disable swap if to and from token are the same const isSwapInvalid = to.token?.address === from.token?.address; if (render) { return render({ onSubmit: handleSubmit, isLoading, lifecycleStatus, isDisabled, isSwapInvalid, }); } // prompt user to connect wallet if (!isDisabled && !address) { return ; } return ( ); }