import * as React from 'react'; import { useState } from 'react' import { useTranslate } from '@portal/hooks'; import { clsx } from 'clsx' import { type Transaction, type Wallet } from 'xrpl' import { SubmitConstData, submitAndUpdateUI, canSendTransaction } from '../utils'; export interface TransactionButtonProps { submitConstData: SubmitConstData, connectionReady: boolean, transaction: Transaction, sendingWallet: Wallet | undefined id: string, // Used to set all ids within component content: { buttonText: string, units: string, // Displays after the input number longerDescription: React.JSX.Element // JSX allows for embedding links within the longer description buttonTitle?: string // Only used while loading bar is activated }, inputSettings?: { defaultValue: number, // Should NOT be a dynamic number setInputValue: React.Dispatch>, min: number, max: number, }, loadingBar?: { id: string, widthPercent: number, description: string, defaultOn: boolean, }, checkBox?: { setCheckValue: React.Dispatch>, defaultValue: boolean, description: string, } customOnClick?: Function } function shouldDisableButton( connectionReady: boolean, sendingWallet: Wallet | undefined, waitingForTransaction: boolean, loadingBar?: { widthPercent: number } ): boolean { return !canSendTransaction(connectionReady, sendingWallet?.address) || waitingForTransaction || (!!(loadingBar?.widthPercent) && loadingBar.widthPercent < 100) } export function TransactionButton({ id, submitConstData, connectionReady, transaction, sendingWallet, content, inputSettings, loadingBar, checkBox, customOnClick }: TransactionButtonProps ) { const { translate } = useTranslate() const [waitingForTransaction, setWaitingForTransaction] = useState(false) return (
{/* Optional loading bar - Used for Partial Payments setup and EscrowFinish wait time */} {loadingBar?.id &&
0) && "progress-bar-animated")} style={{width: (Math.min(loadingBar?.widthPercent + (loadingBar?.defaultOn ? 1 : 0), 100)).toString() + "%", display: (loadingBar?.widthPercent >= 100) ? 'none' : ''}}>  
{(loadingBar?.widthPercent < 100 && loadingBar?.widthPercent > 0 || (loadingBar.defaultOn && loadingBar?.widthPercent === 0)) && {translate(loadingBar?.description)} }
}
{/* Loading icon for when transaction is being submitted */}
{translate("(loading)")}
{inputSettings && ) => { // Enforce min / max values let { value, min, max } = event.target; const newValue = Math.max(Number(min), Math.min(Number(max), Number(value))); // Share the value so other logic can update based on it inputSettings?.setInputValue(newValue) } } />} {inputSettings &&
{translate(content.units)}
} {/* Used for Escrow */} {checkBox && ( ) => checkBox.setCheckValue(event.target.checked)} /> ) }
{content.longerDescription}

) }