mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-29 21:37:56 +00:00
fix: use People Chain API for referral data
This commit is contained in:
@@ -21,7 +21,7 @@ interface ReferralContextValue {
|
|||||||
const ReferralContext = createContext<ReferralContextValue | undefined>(undefined);
|
const ReferralContext = createContext<ReferralContextValue | undefined>(undefined);
|
||||||
|
|
||||||
export function ReferralProvider({ children }: { children: ReactNode }) {
|
export function ReferralProvider({ children }: { children: ReactNode }) {
|
||||||
const { api, isApiReady } = usePezkuwi();
|
const { peopleApi, isPeopleReady } = usePezkuwi();
|
||||||
const { account } = useWallet();
|
const { account } = useWallet();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ export function ReferralProvider({ children }: { children: ReactNode }) {
|
|||||||
const [myReferrals, setMyReferrals] = useState<string[]>([]);
|
const [myReferrals, setMyReferrals] = useState<string[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
// Fetch referral statistics
|
// Fetch referral statistics from People Chain
|
||||||
const fetchStats = useCallback(async () => {
|
const fetchStats = useCallback(async () => {
|
||||||
if (!api || !isApiReady || !account) {
|
if (!peopleApi || !isPeopleReady || !account) {
|
||||||
setStats(null);
|
setStats(null);
|
||||||
setMyReferrals([]);
|
setMyReferrals([]);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -42,8 +42,8 @@ export function ReferralProvider({ children }: { children: ReactNode }) {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const [fetchedStats, fetchedReferrals] = await Promise.all([
|
const [fetchedStats, fetchedReferrals] = await Promise.all([
|
||||||
getReferralStats(api, account),
|
getReferralStats(peopleApi, account),
|
||||||
getMyReferrals(api, account),
|
getMyReferrals(peopleApi, account),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setStats(fetchedStats);
|
setStats(fetchedStats);
|
||||||
@@ -58,20 +58,20 @@ export function ReferralProvider({ children }: { children: ReactNode }) {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [api, isApiReady, account, toast]);
|
}, [peopleApi, isPeopleReady, account, toast]);
|
||||||
|
|
||||||
// Initial fetch
|
// Initial fetch
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchStats();
|
fetchStats();
|
||||||
}, [fetchStats]);
|
}, [fetchStats]);
|
||||||
|
|
||||||
// Subscribe to referral events for real-time updates
|
// Subscribe to referral events for real-time updates (People Chain)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!api || !isApiReady || !account) return;
|
if (!peopleApi || !isPeopleReady || !account) return;
|
||||||
|
|
||||||
let unsub: (() => void) | undefined;
|
let unsub: (() => void) | undefined;
|
||||||
|
|
||||||
subscribeToReferralEvents(api, (event) => {
|
subscribeToReferralEvents(peopleApi, (event) => {
|
||||||
// If this user is involved in the event, refresh stats
|
// If this user is involved in the event, refresh stats
|
||||||
if (event.referrer === account || event.referred === account) {
|
if (event.referrer === account || event.referred === account) {
|
||||||
if (event.type === 'initiated') {
|
if (event.type === 'initiated') {
|
||||||
@@ -95,11 +95,11 @@ export function ReferralProvider({ children }: { children: ReactNode }) {
|
|||||||
return () => {
|
return () => {
|
||||||
if (unsub) unsub();
|
if (unsub) unsub();
|
||||||
};
|
};
|
||||||
}, [api, isApiReady, account, toast, fetchStats]);
|
}, [peopleApi, isPeopleReady, account, toast, fetchStats]);
|
||||||
|
|
||||||
// Invite a new user
|
// Invite a new user (via People Chain)
|
||||||
const inviteUser = async (referredAddress: string): Promise<boolean> => {
|
const inviteUser = async (referredAddress: string): Promise<boolean> => {
|
||||||
if (!api || !account) {
|
if (!peopleApi || !account) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: 'Wallet not connected',
|
description: 'Wallet not connected',
|
||||||
@@ -124,7 +124,7 @@ export function ReferralProvider({ children }: { children: ReactNode }) {
|
|||||||
description: 'Please sign the transaction...',
|
description: 'Please sign the transaction...',
|
||||||
});
|
});
|
||||||
|
|
||||||
await initiateReferral(api, { address: account, meta: { source: 'pezkuwi' } } as Record<string, unknown>, referredAddress);
|
await initiateReferral(peopleApi, { address: account, meta: { source: 'pezkuwi' } } as Record<string, unknown>, referredAddress);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Success!',
|
title: 'Success!',
|
||||||
|
|||||||
Reference in New Issue
Block a user