import { useState } from 'react';
function UnshieldForm() {
const [amount, setAmount] = useState('');
const [recipient, setRecipient] = useState('');
const [step, setStep] = useState('');
const [loading, setLoading] = useState(false);
const handleUnshield = async () => {
setLoading(true);
try {
const parsedAmount = parseAmount(amount, decimals);
await sdk.vault.unshield({
tokenAddress,
amount: parsedAmount,
recipientAddress: recipient as Hex,
onProgress: ({ step, message }) => {
setStep(message);
},
});
alert('Withdrawal successful!');
} catch (error) {
alert(`Withdrawal failed: ${error.message}`);
} finally {
setLoading(false);
setStep('');
}
};
return (
<div>
<input
type="text"
value={amount}
onChange={(e) => setAmount(e.target.value)}
placeholder="Amount"
disabled={loading}
/>
<input
type="text"
value={recipient}
onChange={(e) => setRecipient(e.target.value)}
placeholder="Recipient address"
disabled={loading}
/>
<button onClick={handleUnshield} disabled={loading}>
{loading ? step || 'Processing...' : 'Withdraw'}
</button>
</div>
);
}