import React from 'react'; import { Box, Text } from 'ink'; import { colors, formatSatoshis } from '../../../theme.js'; import { useSatoshisConversion } from '../../../hooks/useSatoshisConversion.js'; import type { VariableInput, SelectableUTXO } from '../types.js'; import type { XOTemplate } from '@xo-cash/types'; interface ReviewStepProps { template: XOTemplate; actionName: string; roleIdentifier: string; variables: VariableInput[]; availableUtxos: SelectableUTXO[]; changeAmount: bigint; } export function ReviewStep({ template, actionName, roleIdentifier, variables, availableUtxos, changeAmount, }: ReviewStepProps): React.ReactElement { const selectedUtxos = availableUtxos.filter((u) => u.selected); const { formatSatoshisToFiat } = useSatoshisConversion('USD'); const getFiatSuffix = (satoshis: bigint): string => { const fiatValue = formatSatoshisToFiat(satoshis); return fiatValue ? ` (~${fiatValue})` : ''; }; const getVariableFiatSuffix = (variable: VariableInput): string => { if (variable.type !== 'integer') { return ''; } if (variable.hint?.toLowerCase().includes('satoshi') !== true) { return ''; } if (!/^[-]?\d+$/.test(variable.value.trim())) { return ''; } try { return getFiatSuffix(BigInt(variable.value)); } catch { return ''; } }; return ( Review your invitation: {/* Summary */} Template: {template?.name} Action: {actionName} Role: {roleIdentifier} {/* Variables */} {variables.length > 0 && ( Variables: {variables.map((v) => ( {' '} {v.name}: {v.value || '(empty)'} {v.value ? getVariableFiatSuffix(v) : ''} ))} )} {/* Inputs */} {selectedUtxos.length > 0 && ( Inputs ({selectedUtxos.length}): {selectedUtxos.slice(0, 3).map((u) => ( {' '} {formatSatoshis(u.valueSatoshis)} {getFiatSuffix(u.valueSatoshis)} ))} {selectedUtxos.length > 3 && ( {' '}...and {selectedUtxos.length - 3} more )} )} {/* Outputs */} {changeAmount > 0n && ( Outputs: {' '}Change: {formatSatoshis(changeAmount)} {getFiatSuffix(changeAmount)} )} {/* Confirmation prompt */} Press Next to create and publish the invitation. ); }