Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/screens/CryptoPaymentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import { colors, spacing, typography, borderRadius } from '../utils/constants';
import { Button } from '../components/common/Button';
import { Card } from '../components/common/Card';
import walletServiceManager, { TokenBalance, GasEstimate } from '../services/walletService';
import { ethers } from 'ethers';
import walletServiceManager, {
TokenBalance,
GasEstimate,
WalletConnection
} from '../services/walletService';

interface RouteParams {
subscriptionId?: string;
Expand All @@ -42,7 +45,7 @@
const [isLoading, setIsLoading] = useState(false);

const [availableTokens, setAvailableTokens] = useState<TokenBalance[]>([]);
const [connection, setConnection] = useState<any>(null);
const [connection, setConnection] = useState<WalletConnection | null>(null);

useEffect(() => {
loadWalletData();
Expand All @@ -54,10 +57,15 @@
}
}, [amount, recipientAddress, connection, selectedProtocol, selectedToken]);

// Internal validation for type narrowing
const isWalletConnected = (conn: WalletConnection | null): conn is WalletConnection => {
return conn !== null && conn.isConnected;
};

const loadWalletData = async () => {
try {
const conn = walletServiceManager.getConnection();
if (!conn) {
if (!conn || !conn.isConnected) {
Alert.alert('Error', 'Please connect a wallet first');
navigation.goBack();
return;
Expand All @@ -76,7 +84,7 @@
};

const estimateGas = async () => {
if (!connection || !amount || !recipientAddress) return;
if (!isWalletConnected(connection) || !amount || !recipientAddress) return;

try {
if (selectedProtocol === 'superfluid') {
Expand Down Expand Up @@ -116,7 +124,7 @@
return false;
}

if (!recipientAddress || !ethers.utils.isAddress(recipientAddress)) {

Check failure on line 127 in src/screens/CryptoPaymentScreen.tsx

View workflow job for this annotation

GitHub Actions / TypeScript Type Check

Cannot find name 'ethers'.
Alert.alert('Error', 'Please enter a valid Ethereum address');
return false;
}
Expand All @@ -131,6 +139,11 @@

const handleCreateStream = async () => {
if (!validateForm()) return;

if (!isWalletConnected(connection)) {
Alert.alert('Error', 'Wallet not connected');
return;
}

try {
setIsLoading(true);
Expand Down Expand Up @@ -308,7 +321,7 @@
)}

{/* Create Stream Button */}
<View style={styles.footer}>
<div style={styles.footer}>
<Button
title={isLoading ? 'Creating Stream...' : 'Create Payment Stream'}
onPress={handleCreateStream}
Expand All @@ -317,7 +330,7 @@
fullWidth
size="large"
/>
</View>
</div>
</ScrollView>
</KeyboardAvoidingView>
</SafeAreaView>
Expand Down
Loading