generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.tsx
More file actions
353 lines (322 loc) · 14.7 KB
/
context.tsx
File metadata and controls
353 lines (322 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { User, BetSelection, BetTicket, Match, Transaction, SocialPost, P2PChallenge, ChatMessage, Notification } from './types';
import { MOCK_MATCHES } from './constants';
interface AppContextType {
user: User | null;
login: (email: string, pass: string) => Promise<boolean>;
register: (name: string, email: string, pass: string) => Promise<boolean>;
logout: () => void;
matches: Match[];
betSlip: BetSelection[];
addToSlip: (selection: BetSelection) => void;
removeFromSlip: (selectionId: string) => void;
clearSlip: () => void;
placeBet: (stake: number) => Promise<boolean>;
myBets: BetTicket[];
cashOut: (ticketId: string) => void;
walletTransactions: Transaction[];
deposit: (amount: number) => void;
withdraw: (amount: number) => void;
claimDailyBonus: () => boolean;
isSlipOpen: boolean;
setSlipOpen: (v: boolean) => void;
socialPosts: SocialPost[];
postMessage: (content: string) => void;
toggleFollow: (userId: string) => void;
p2pChallenges: P2PChallenge[];
createP2PChallenge: (matchId: string, selectionName: string, stake: number) => boolean;
acceptP2PChallenge: (challengeId: string) => boolean;
globalChat: ChatMessage[];
sendGlobalMessage: (text: string) => void;
notifications: Notification[];
markNotificationsRead: () => void;
addNotification: (type: Notification['type'], title: string, message: string) => void;
}
const AppContext = createContext<AppContextType | undefined>(undefined);
const MOCK_INFLUENCERS = [
{ id: 'inf1', name: 'VegasDave', isVip: true, isInfluencer: true },
{ id: 'inf2', name: 'SoccerGirl', isVip: false, isInfluencer: true },
{ id: 'inf3', name: 'CryptoKing', isVip: true, isInfluencer: false },
{ id: 'inf4', name: 'BetSniper', isVip: true, isInfluencer: true },
{ id: 'inf5', name: 'LuckyLuke', isVip: false, isInfluencer: false },
];
export const AppProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [user, setUser] = useState<User | null>(null);
const [matches, setMatches] = useState<Match[]>(MOCK_MATCHES);
const [betSlip, setBetSlip] = useState<BetSelection[]>([]);
const [myBets, setMyBets] = useState<BetTicket[]>([]);
const [transactions, setTransactions] = useState<Transaction[]>([]);
const [isSlipOpen, setSlipOpen] = useState(false);
const [socialPosts, setSocialPosts] = useState<SocialPost[]>([
{ id: 's1', userId: 'inf3', username: 'CryptoKing', content: 'Just hit 50x on Crash! 🚀 The multiplier is insane right now.', timestamp: Date.now() - 120000, likes: 45, isVip: true },
{ id: 's2', userId: 'inf1', username: 'VegasDave', content: 'My algorithm predicts Arsenal win. Loading up heavily.', timestamp: Date.now() - 300000, likes: 128, isVip: true, isInfluencer: true },
]);
const [p2pChallenges, setP2PChallenges] = useState<P2PChallenge[]>([
{ id: 'p1', creatorId: 'u5', creatorName: 'HighRoller', matchId: 'm1', matchName: 'Arsenal vs Liverpool', selectionName: 'Arsenal', stake: 100, status: 'open' },
{ id: 'p2', creatorId: 'u6', creatorName: 'SafePlayer', matchId: 'm2', matchName: 'Real Madrid vs Barcelona', selectionName: 'Real Madrid', stake: 20, status: 'open' },
]);
const [globalChat, setGlobalChat] = useState<ChatMessage[]>([
{ id: 'c1', userId: 'inf1', username: 'VegasDave', text: 'Anyone watching the Arsenal game?', timestamp: Date.now() - 60000, vipLevel: 'Gold' },
{ id: 'c2', userId: 'u8', username: 'Newbie123', text: 'This crash game is addictive!', timestamp: Date.now() - 30000, vipLevel: 'Bronze' },
]);
const [notifications, setNotifications] = useState<Notification[]>([
{ id: 'n1', type: 'system', title: 'Welcome Bonus', message: 'Sign up now to get $50 bonus!', timestamp: Date.now() - 1000000, read: true },
]);
const addNotification = (type: Notification['type'], title: string, message: string) => {
const newNotif: Notification = {
id: Date.now().toString(),
type,
title,
message,
timestamp: Date.now(),
read: false
};
setNotifications(prev => [newNotif, ...prev]);
};
const markNotificationsRead = () => {
setNotifications(prev => prev.map(n => ({ ...n, read: true })));
};
useEffect(() => {
const interval = setInterval(() => {
setMatches(prevMatches => {
return prevMatches.map(match => {
const shouldUpdate = Math.random() > 0.7;
if (!shouldUpdate) return match;
const newMarkets = match.markets.map(market => ({
...market,
selections: market.selections.map(sel => {
const change = (Math.random() - 0.5) * 0.2;
const newVal = Math.max(1.01, parseFloat((sel.value + change).toFixed(2)));
return { ...sel, prevValue: sel.value, value: newVal };
})
}));
return { ...match, markets: newMarkets };
});
});
}, 3000);
return () => clearInterval(interval);
}, []);
useEffect(() => {
const interval = setInterval(() => {
const randomAction = Math.random();
if (randomAction < 0.25) {
const bot = MOCK_INFLUENCERS[Math.floor(Math.random() * MOCK_INFLUENCERS.length)];
const botMsgs = [
'Who is riding with me on the Lakers game? 🏀',
'Just cashed out $500 profit! Easy money.',
'Crash game is hot right now, careful though.',
'Live odds on Madrid are shifting fast.',
'Anyone want a P2P challenge? $50 stake.'
];
const newPost: SocialPost = {
id: Date.now().toString(),
userId: bot.id,
username: bot.name,
content: botMsgs[Math.floor(Math.random() * botMsgs.length)],
timestamp: Date.now(),
likes: Math.floor(Math.random() * 20),
isVip: bot.isVip,
isInfluencer: bot.isInfluencer
};
setSocialPosts(prev => [newPost, ...prev].slice(0, 50));
}
if (randomAction > 0.85) {
const match = MOCK_MATCHES[Math.floor(Math.random() * MOCK_MATCHES.length)];
const newChallenge: P2PChallenge = {
id: 'p' + Date.now(),
creatorId: 'bot' + Date.now(),
creatorName: 'Bot' + Math.floor(Math.random() * 1000),
matchId: match.id,
matchName: `${match.homeTeam} vs ${match.awayTeam}`,
selectionName: Math.random() > 0.5 ? match.homeTeam : match.awayTeam,
stake: [10, 20, 50, 100][Math.floor(Math.random() * 4)],
status: 'open'
};
setP2PChallenges(prev => [newChallenge, ...prev]);
}
if (randomAction > 0.6 && randomAction < 0.8) {
const bot = MOCK_INFLUENCERS[Math.floor(Math.random() * MOCK_INFLUENCERS.length)];
const msgs = ["LFG!", "Who is betting on Real?", "Cashed out just in time", "This app is slick", "Need a lock for tonight", "Anyone want to P2P?", "Crash went to 50x!"];
const newMsg: ChatMessage = {
id: Date.now().toString() + 'c',
userId: bot.id,
username: bot.name,
text: msgs[Math.floor(Math.random() * msgs.length)],
timestamp: Date.now(),
vipLevel: bot.isVip ? 'Gold' : 'Bronze'
};
setGlobalChat(prev => [...prev, newMsg].slice(-50));
}
if (randomAction > 0.95 && user) {
const types: Notification['type'][] = ['social', 'win', 'p2p'];
const type = types[Math.floor(Math.random() * types.length)];
let title = '';
let message = '';
if (type === 'social') {
title = 'New Follower';
message = `${MOCK_INFLUENCERS[0].name} started following you!`;
} else if (type === 'p2p') {
title = 'P2P Update';
message = 'A player accepted your challenge on Arsenal vs Liverpool.';
} else {
title = 'Big Win Alert';
message = 'Someone just won $10,000 on the Jackpot Slots!';
}
addNotification(type, title, message);
}
}, 6000);
return () => clearInterval(interval);
}, [user]);
const login = async (email: string, pass: string) => {
await new Promise(resolve => setTimeout(resolve, 800));
if (email.includes('@') && pass.length >= 3) {
setUser({
id: 'u1', name: email.split('@')[0], email: email, balance: 1000,
bonusBalance: 0, verified: false, vipLevel: 'Bronze', following: [],
followersCount: 0, lastDailyBonus: 0
});
return true;
}
return false;
};
const register = async (name: string, email: string, pass: string) => {
await new Promise(resolve => setTimeout(resolve, 1000));
setUser({
id: 'u' + Date.now(), name: name, email: email, balance: 100,
bonusBalance: 50.00, verified: false, vipLevel: 'Bronze', following: [],
followersCount: 0, lastDailyBonus: 0
});
addNotification('system', 'Welcome!', 'Account created with $100 bonus.');
return true;
};
const logout = () => setUser(null);
const addToSlip = (selection: BetSelection) => {
setBetSlip(prev => {
const filtered = prev.filter(s => s.matchId !== selection.matchId);
return [...filtered, selection];
});
setSlipOpen(true);
};
const removeFromSlip = (selectionId: string) => {
setBetSlip(prev => prev.filter(s => s.selectionId !== selectionId));
};
const clearSlip = () => setBetSlip([]);
const placeBet = async (stake: number) => {
if (!user || user.balance < stake) return false;
const totalOdds = betSlip.reduce((acc, curr) => acc * curr.odd, 1);
const potentialReturn = stake * totalOdds;
const newTicket: BetTicket = {
id: Date.now().toString(), selections: [...betSlip], stake,
totalOdds, potentialReturn, status: 'open', timestamp: Date.now(),
cashOutOffer: stake * 0.9
};
setMyBets(prev => [newTicket, ...prev]);
setUser(prev => prev ? { ...prev, balance: prev.balance - stake } : null);
return true;
};
const cashOut = (ticketId: string) => {
const ticket = myBets.find(b => b.id === ticketId);
if (!ticket || ticket.status !== 'open' || !ticket.cashOutOffer) return;
setUser(prev => prev ? { ...prev, balance: prev.balance + ticket.cashOutOffer! } : null);
setMyBets(prev => prev.map(b => b.id === ticketId ? { ...b, status: 'cashed_out' } : b));
addNotification('win', 'Cash Out', `Successfully cashed out $${ticket.cashOutOffer!.toFixed(2)}`);
};
const deposit = (amount: number) => {
setUser(prev => prev ? { ...prev, balance: prev.balance + amount } : null);
setTransactions(prev => [{
id: Date.now().toString(),
type: amount > 0 ? 'deposit' : 'bet',
amount: Math.abs(amount),
status: 'completed',
date: new Date().toISOString()
}, ...prev]);
};
const withdraw = (amount: number) => {
setUser(prev => {
if (!prev || prev.balance < amount) return prev;
return { ...prev, balance: prev.balance - amount };
});
setTransactions(prev => [{
id: Date.now().toString(), type: 'withdrawal', amount,
status: 'pending', date: new Date().toISOString()
}, ...prev]);
};
const claimDailyBonus = () => {
if(!user) return false;
const now = Date.now();
const oneDay = 24 * 60 * 60 * 1000;
if (now - user.lastDailyBonus < oneDay) return false;
const bonusAmount = 100;
setUser(prev => prev ? { ...prev, balance: prev.balance + bonusAmount, lastDailyBonus: now } : null);
setTransactions(prev => [{
id: Date.now().toString(), type: 'bonus', amount: bonusAmount,
status: 'completed', date: new Date().toISOString()
}, ...prev]);
return true;
};
const postMessage = (content: string) => {
if (!user) return;
const newPost: SocialPost = {
id: Date.now().toString(), userId: user.id, username: user.name,
content, timestamp: Date.now(), likes: 0, isVip: user.vipLevel !== 'Bronze',
isInfluencer: false
};
setSocialPosts(prev => [newPost, ...prev]);
};
const toggleFollow = (targetUserId: string) => {
setUser(prev => {
if (!prev) return null;
const isFollowing = prev.following.includes(targetUserId);
const newFollowing = isFollowing ? prev.following.filter(id => id !== targetUserId) : [...prev.following, targetUserId];
if (!isFollowing) addNotification('social', 'Following', `You followed User ${targetUserId}`);
return { ...prev, following: newFollowing };
});
};
const createP2PChallenge = (matchId: string, selectionName: string, stake: number) => {
if (!user || user.balance < stake) return false;
const match = matches.find(m => m.id === matchId);
if (!match) return false;
const newChallenge: P2PChallenge = {
id: Date.now().toString(), creatorId: user.id, creatorName: user.name,
matchId, matchName: `${match.homeTeam} vs ${match.awayTeam}`,
selectionName, stake, status: 'open'
};
setUser(prev => prev ? { ...prev, balance: prev.balance - stake } : null);
setP2PChallenges(prev => [newChallenge, ...prev]);
addNotification('p2p', 'Challenge Created', 'Waiting for opponent...');
return true;
};
const acceptP2PChallenge = (challengeId: string) => {
if (!user) return false;
const challenge = p2pChallenges.find(c => c.id === challengeId);
if (!challenge || challenge.status !== 'open' || user.balance < challenge.stake || challenge.creatorId === user.id) return false;
setUser(prev => prev ? { ...prev, balance: prev.balance - challenge.stake } : null);
setP2PChallenges(prev => prev.map(c => c.id === challengeId ? { ...c, status: 'matched', opponentId: user.id, opponentName: user.name } : c));
addNotification('p2p', 'Match On!', `You accepted the challenge for $${challenge.stake}`);
return true;
};
const sendGlobalMessage = (text: string) => {
if (!user) return;
const newMsg: ChatMessage = {
id: Date.now().toString(), userId: user.id, username: user.name,
text, timestamp: Date.now(), vipLevel: user.vipLevel
};
setGlobalChat(prev => [...prev, newMsg].slice(-50));
};
return (
<AppContext.Provider value={{
user, login, register, logout, matches, betSlip, addToSlip, removeFromSlip, clearSlip,
placeBet, myBets, cashOut, walletTransactions: transactions,
deposit, withdraw, claimDailyBonus, isSlipOpen, setSlipOpen,
socialPosts, postMessage, toggleFollow, p2pChallenges, createP2PChallenge, acceptP2PChallenge,
globalChat, sendGlobalMessage, notifications, markNotificationsRead, addNotification
}}>
{children}
</AppContext.Provider>
);
};
export const useApp = () => {
const context = useContext(AppContext);
if (!context) throw new Error("useApp must be used within AppProvider");
return context;
};