import React, { useState } from 'react';
import { View, Text, TextInput, Button, ActivityIndicator } from 'react-native';
import { SdkError } from '@sunnyside-io/privacy-boost-react-native';
function TransferScreen({ sdk, tokenAddress }: { sdk: PrivacyBoost; tokenAddress: string }) {
const [recipient, setRecipient] = useState('');
const [amount, setAmount] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleTransfer = async () => {
if (!sdk.isValidPrivacyAddress(recipient)) {
setError('Invalid privacy address');
return;
}
setLoading(true);
setError(null);
try {
const weiAmount = sdk.parseAmount(amount, 18);
await sdk.send(tokenAddress, weiAmount, recipient);
setRecipient('');
setAmount('');
} catch (err: any) {
if (SdkError.SignatureRejected.instanceOf(err)) return;
setError(err?.inner?.message ?? err?.message ?? 'Transfer failed');
} finally {
setLoading(false);
}
};
return (
<View style={{ padding: 16 }}>
<TextInput
value={recipient}
onChangeText={setRecipient}
placeholder="Recipient privacy address"
editable={!loading}
/>
<TextInput
value={amount}
onChangeText={setAmount}
placeholder="Amount (e.g. 1.0)"
keyboardType="decimal-pad"
editable={!loading}
/>
{error && <Text style={{ color: 'red' }}>{error}</Text>}
{loading ? (
<ActivityIndicator />
) : (
<Button
title="Send"
onPress={handleTransfer}
disabled={!recipient || !amount}
/>
)}
</View>
);
}