feat: complete URL-based referral system integration

Frontend changes:
- Add ReferralHandler to App.tsx to capture ?ref= URL parameter
- Store referrer address in localStorage for KYC registration
- Improve DashboardContext error handling for Supabase

All referral functionality now complete:
- URL parameter capture and storage
- On-chain referral initiation via InviteUserModal
- Auto-confirmation via OnKycApproved hook
- DefaultReferrer fallback to QaziMuhammedAccount
- Real-time stats and event subscription
- Referral score calculation (0-500 points)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-20 02:28:22 +03:00
parent d4ce6bf8de
commit c57ce99c10
2 changed files with 29 additions and 6 deletions
+23 -3
View File
@@ -1,4 +1,5 @@
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { useEffect } from 'react';
import { BrowserRouter as Router, Routes, Route, useLocation } from 'react-router-dom';
import { ThemeProvider } from '@/components/theme-provider'; import { ThemeProvider } from '@/components/theme-provider';
import Index from '@/pages/Index'; import Index from '@/pages/Index';
import Login from '@/pages/Login'; import Login from '@/pages/Login';
@@ -32,6 +33,24 @@ import { ErrorBoundary } from '@/components/ErrorBoundary';
import './App.css'; import './App.css';
import './i18n/config'; import './i18n/config';
function ReferralHandler() {
const location = useLocation();
useEffect(() => {
// Check for ?ref= parameter in URL
const params = new URLSearchParams(location.search);
const refParam = params.get('ref');
if (refParam) {
// Store referrer address in localStorage
localStorage.setItem('referrerAddress', refParam);
console.log('Referrer address saved:', refParam);
}
}, [location]);
return null;
}
function App() { function App() {
return ( return (
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme"> <ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
@@ -45,8 +64,9 @@ function App() {
<DashboardProvider> <DashboardProvider>
<ReferralProvider> <ReferralProvider>
<Router> <Router>
<Routes> <ReferralHandler />
<Route path="/login" element={<Login />} /> <Routes>
<Route path="/login" element={<Login />} />
<Route path="/email-verification" element={<EmailVerification />} /> <Route path="/email-verification" element={<EmailVerification />} />
<Route path="/reset-password" element={<PasswordReset />} /> <Route path="/reset-password" element={<PasswordReset />} />
+6 -3
View File
@@ -35,7 +35,10 @@ export function DashboardProvider({ children }: { children: ReactNode }) {
}, [user, selectedAccount, api, isApiReady]); }, [user, selectedAccount, api, isApiReady]);
const fetchProfile = async () => { const fetchProfile = async () => {
if (!user) return; if (!user) {
setLoading(false);
return;
}
try { try {
const { data, error } = await supabase const { data, error } = await supabase
@@ -45,13 +48,13 @@ export function DashboardProvider({ children }: { children: ReactNode }) {
.maybeSingle(); .maybeSingle();
if (error) { if (error) {
console.error('Profile fetch error:', error); console.warn('Profile fetch error (this is normal if Supabase is not configured):', error.message);
return; return;
} }
setProfile(data); setProfile(data);
} catch (error) { } catch (error) {
console.error('Error fetching profile:', error); console.warn('Error fetching profile (this is normal if Supabase is not configured):', error);
} finally { } finally {
setLoading(false); setLoading(false);
} }