|
1 | 1 | import React, { useState, useEffect } from "react"; |
2 | | -import { View, Text, Button } from "react-native"; |
| 2 | +import { View, Text, Button, StyleSheet, ActivityIndicator, Alert } from "react-native"; |
3 | 3 | import { MarketData } from "../market_data"; |
4 | 4 | import { RiskManager } from "../risk_management"; |
| 5 | +import PushNotification from "react-native-push-notification"; |
5 | 6 |
|
6 | 7 | const App = () => { |
7 | | - const [tradingPerformance, setTradingPerformance] = useState({}); |
8 | | - const [customizableDashboard, setCustomizableDashboard] = useState({}); |
| 8 | + const [tradingPerformance, setTradingPerformance] = useState(null); |
| 9 | + const [customizableDashboard, setCustomizableDashboard] = useState(null); |
| 10 | + const [loading, setLoading] = useState(true); |
| 11 | + const [error, setError] = useState(null); |
9 | 12 |
|
10 | 13 | useEffect(() => { |
11 | 14 | const marketData = new MarketData(); |
12 | | - const riskManager = new RiskManager(marketData, positionSize=1000, riskRewardRatio=2); |
| 15 | + const riskManager = new RiskManager(marketData, 1000, 2); |
13 | 16 |
|
14 | | - marketData.getTradingPerformance().then(data => setTradingPerformance(data)); |
15 | | - marketData.getCustomizableDashboard().then(data => setCustomizableDashboard(data)); |
| 17 | + const fetchData = async () => { |
| 18 | + try { |
| 19 | + const performanceData = await marketData.getTradingPerformance(); |
| 20 | + setTradingPerformance(performanceData); |
| 21 | + |
| 22 | + const dashboardData = await marketData.getCustomizableDashboard(); |
| 23 | + setCustomizableDashboard(dashboardData); |
| 24 | + } catch (err) { |
| 25 | + setError("Failed to fetch data. Please try again later."); |
| 26 | + console.error(err); |
| 27 | + } finally { |
| 28 | + setLoading(false); |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + fetchData(); |
16 | 33 | }, []); |
17 | 34 |
|
18 | 35 | const handlePushNotification = () => { |
19 | | - // Implement push notification logic here |
| 36 | + PushNotification.localNotification({ |
| 37 | + title: "Trading Alert", |
| 38 | + message: "Check your trading performance!", |
| 39 | + playSound: true, |
| 40 | + soundName: "default", |
| 41 | + }); |
| 42 | + Alert.alert("Notification Sent", "Your push notification has been sent!"); |
20 | 43 | }; |
21 | 44 |
|
| 45 | + if (loading) { |
| 46 | + return ( |
| 47 | + <View style={styles.loadingContainer}> |
| 48 | + <ActivityIndicator size="large" color="#0000ff" /> |
| 49 | + <Text>Loading...</Text> |
| 50 | + </View> |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + if (error) { |
| 55 | + return ( |
| 56 | + <View style={styles.errorContainer}> |
| 57 | + <Text style={styles.errorText}>{error}</Text> |
| 58 | + </View> |
| 59 | + ); |
| 60 | + } |
| 61 | + |
22 | 62 | return ( |
23 | | - <View> |
24 | | - <Text>Trading Performance:</Text> |
| 63 | + <View style={styles.container}> |
| 64 | + <Text style={styles.title}>Trading Performance:</Text> |
25 | 65 | <Text>{tradingPerformance.metrics}</Text> |
26 | | - <Text>Customizable Dashboard:</Text> |
| 66 | + <Text style={styles.title}>Customizable Dashboard:</Text> |
27 | 67 | <Text>{customizableDashboard.data}</Text> |
28 | 68 | <Button title="Send Push Notification" onPress={handlePushNotification} /> |
29 | 69 | </View> |
30 | 70 | ); |
31 | 71 | }; |
32 | 72 |
|
| 73 | +const styles = StyleSheet.create({ |
| 74 | + container: { |
| 75 | + flex: 1, |
| 76 | + padding: 20, |
| 77 | + justifyContent: "center", |
| 78 | + alignItems: "center", |
| 79 | + }, |
| 80 | + title: { |
| 81 | + fontSize: 20, |
| 82 | + fontWeight: "bold", |
| 83 | + marginVertical: 10, |
| 84 | + }, |
| 85 | + loadingContainer: { |
| 86 | + flex: 1, |
| 87 | + justifyContent: "center", |
| 88 | + alignItems: "center", |
| 89 | + }, |
| 90 | + errorContainer: { |
| 91 | + flex: 1, |
| 92 | + justifyContent: "center", |
| 93 | + alignItems: "center", |
| 94 | + }, |
| 95 | + errorText: { |
| 96 | + color: "red", |
| 97 | + fontSize: 16, |
| 98 | + }, |
| 99 | +}); |
| 100 | + |
33 | 101 | export default App; |
0 commit comments