import React from 'react' import { Box, Text } from 'ink' import { Surface } from '../../../ui/Surface.js' import { Select } from '../../../ui/Select.js' import { theme } from '../../../ui/theme.js' import { WalletApprovalScreen } from '../shared/components/WalletApprovalScreen.js' import { shortAddress } from '../shared/model/format.js' import type { Step } from '../reducer.js' import type { CustodyFlowDeps } from './types.js' import { chainLabel, humanOwnerAddress } from './helpers.js' const Row: React.FC<{ label: string; value: string }> = ({ label, value }) => ( {label.padEnd(18)} {value} ) export function renderCustodyStep({ step, setStep, walletSession, }: CustodyFlowDeps): React.ReactElement | null { if (step.kind === 'custody-vault-deploy-tx') { return ( setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-vault-deposit-tx') { return ( setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-vault-withdraw-discovering') { const targetAgentId = step.identity.agentId ?? '' return ( esc cancel} > ) } if (step.kind === 'custody-vault-withdraw-tx') { const targetAgentId = step.agentId ?? step.identity.agentId ?? '' return ( setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-vault-withdraw-pick-token') { const activeId = step.identity.agentId const options = step.tokens.map(t => ({ value: t.agentId, label: `Token #${t.agentId}${activeId && t.agentId === activeId ? ' (active)' : ''}`, hint: 'Withdraw to owner wallet', })) return ( ↵ select · esc back} > options={[ ...options, { value: 'cancel', label: 'Back', role: 'utility' }, ]} hintLayout="inline" onSubmit={choice => { if (choice === 'cancel') { setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo }) return } setStep({ kind: 'custody-vault-withdraw-tx', identity: step.identity, registry: step.registry, vaultAddress: step.vaultAddress, agentId: choice, returnTo: step.returnTo, ...(step.returnContext ? { returnContext: step.returnContext } : {}), }) }} onCancel={() => setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-vault-withdraw-done') { const onReturnToVault = () => { setStep({ kind: 'custody-vault-deposit-tx', identity: step.identity, registry: step.registry, vaultAddress: step.vaultAddress, profileUpdates: { operatorVaultAddress: step.vaultAddress }, returnTo: step.returnTo, }) } const onKeepOut = () => { if (step.returnContext === 'ens' && step.returnTo) { setStep(step.returnTo) } else { setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo }) } } return ( ↵ select · esc back} > options={[ { value: 'return-to-vault', label: 'Return Token to Vault', hint: 'Redeposit' }, { value: 'keep-out', label: 'Keep Out For Now', role: 'utility' }, ]} hintLayout="inline" onSubmit={choice => { if (choice === 'return-to-vault') onReturnToVault() else onKeepOut() }} onCancel={onKeepOut} /> ) } if (step.kind === 'custody-vault-unwrap-tx') { return ( setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-advanced-done') { const state = (step.identity.state ?? {}) as Record const ownerWallet = humanOwnerAddress(step.identity) as string const operatorCount = Array.isArray(state.approvedOperatorWallets) ? state.approvedOperatorWallets.length : 0 return ( ↵ continue} > {step.vaultAddress ? : null} options={[{ value: 'continue', label: 'Done' }]} onSubmit={() => setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} onCancel={() => setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } if (step.kind === 'custody-simple-done') { const ownerWallet = humanOwnerAddress(step.identity) as string return ( ↵ continue} > options={[{ value: 'continue', label: 'Done' }]} onSubmit={() => setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} onCancel={() => setStep({ kind: 'custody-model', identity: step.identity, registry: step.registry, returnTo: step.returnTo })} /> ) } return null } export function renderRebackupSubtitle( defaultSubtitle: React.ReactNode, vaultRouted: boolean, ): React.ReactNode { if (!vaultRouted) return defaultSubtitle return {defaultSubtitle} Routed through this token's Vault. }