mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 11:18:01 +00:00
Reorganize repository into monorepo structure
Restructured the project to support multiple frontend applications: - Move web app to web/ directory - Create pezkuwi-sdk-ui/ for Polkadot SDK clone (planned) - Create mobile/ directory for mobile app development - Add shared/ directory with common utilities, types, and blockchain code - Update README.md with comprehensive documentation - Remove obsolete DKSweb/ directory This monorepo structure enables better code sharing and organized development across web, mobile, and SDK UI projects.
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
import { useWallet } from './WalletContext';
|
||||
import {
|
||||
IdentityProfile,
|
||||
KYCData,
|
||||
Badge,
|
||||
Role,
|
||||
calculateReputationScore,
|
||||
generateZKProof,
|
||||
DEFAULT_BADGES,
|
||||
ROLES
|
||||
} from '@/lib/identity';
|
||||
|
||||
interface IdentityContextType {
|
||||
profile: IdentityProfile | null;
|
||||
isVerifying: boolean;
|
||||
startKYC: (data: KYCData) => Promise<void>;
|
||||
updatePrivacySettings: (settings: any) => void;
|
||||
addBadge: (badge: Badge) => void;
|
||||
assignRole: (role: Role) => void;
|
||||
refreshReputation: () => void;
|
||||
}
|
||||
|
||||
const IdentityContext = createContext<IdentityContextType | undefined>(undefined);
|
||||
|
||||
export function IdentityProvider({ children }: { children: React.ReactNode }) {
|
||||
const { account } = useWallet();
|
||||
const [profile, setProfile] = useState<IdentityProfile | null>(null);
|
||||
const [isVerifying, setIsVerifying] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (account) {
|
||||
// Load or create profile for connected wallet
|
||||
const storedProfile = localStorage.getItem(`identity_${account}`);
|
||||
if (storedProfile) {
|
||||
setProfile(JSON.parse(storedProfile));
|
||||
} else {
|
||||
// Create new profile
|
||||
const newProfile: IdentityProfile = {
|
||||
address: account,
|
||||
verificationLevel: 'none',
|
||||
kycStatus: 'none',
|
||||
reputationScore: 0,
|
||||
badges: [],
|
||||
roles: [],
|
||||
privacySettings: {
|
||||
showRealName: false,
|
||||
showEmail: false,
|
||||
showCountry: true,
|
||||
useZKProof: true
|
||||
}
|
||||
};
|
||||
setProfile(newProfile);
|
||||
localStorage.setItem(`identity_${account}`, JSON.stringify(newProfile));
|
||||
}
|
||||
} else {
|
||||
setProfile(null);
|
||||
}
|
||||
}, [account]);
|
||||
|
||||
const startKYC = async (data: KYCData) => {
|
||||
if (!profile) return;
|
||||
|
||||
setIsVerifying(true);
|
||||
try {
|
||||
// Simulate KYC verification process
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
|
||||
const zkProof = generateZKProof(data);
|
||||
|
||||
const updatedProfile: IdentityProfile = {
|
||||
...profile,
|
||||
kycStatus: 'approved',
|
||||
verificationLevel: data.documentType ? 'verified' : 'basic',
|
||||
verificationDate: new Date(),
|
||||
badges: [...profile.badges, ...DEFAULT_BADGES],
|
||||
roles: [ROLES.verified_user as Role],
|
||||
reputationScore: calculateReputationScore(
|
||||
[],
|
||||
data.documentType ? 'verified' : 'basic',
|
||||
[...profile.badges, ...DEFAULT_BADGES]
|
||||
)
|
||||
};
|
||||
|
||||
setProfile(updatedProfile);
|
||||
localStorage.setItem(`identity_${profile.address}`, JSON.stringify(updatedProfile));
|
||||
} catch (error) {
|
||||
console.error('KYC verification failed:', error);
|
||||
} finally {
|
||||
setIsVerifying(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updatePrivacySettings = (settings: any) => {
|
||||
if (!profile) return;
|
||||
|
||||
const updatedProfile = {
|
||||
...profile,
|
||||
privacySettings: { ...profile.privacySettings, ...settings }
|
||||
};
|
||||
|
||||
setProfile(updatedProfile);
|
||||
localStorage.setItem(`identity_${profile.address}`, JSON.stringify(updatedProfile));
|
||||
};
|
||||
|
||||
const addBadge = (badge: Badge) => {
|
||||
if (!profile) return;
|
||||
|
||||
const updatedProfile = {
|
||||
...profile,
|
||||
badges: [...profile.badges, badge]
|
||||
};
|
||||
|
||||
setProfile(updatedProfile);
|
||||
localStorage.setItem(`identity_${profile.address}`, JSON.stringify(updatedProfile));
|
||||
};
|
||||
|
||||
const assignRole = (role: Role) => {
|
||||
if (!profile) return;
|
||||
|
||||
const updatedProfile = {
|
||||
...profile,
|
||||
roles: [...profile.roles, role]
|
||||
};
|
||||
|
||||
setProfile(updatedProfile);
|
||||
localStorage.setItem(`identity_${profile.address}`, JSON.stringify(updatedProfile));
|
||||
};
|
||||
|
||||
const refreshReputation = () => {
|
||||
if (!profile) return;
|
||||
|
||||
const newScore = calculateReputationScore([], profile.verificationLevel, profile.badges);
|
||||
const updatedProfile = { ...profile, reputationScore: newScore };
|
||||
|
||||
setProfile(updatedProfile);
|
||||
localStorage.setItem(`identity_${profile.address}`, JSON.stringify(updatedProfile));
|
||||
};
|
||||
|
||||
return (
|
||||
<IdentityContext.Provider value={{
|
||||
profile,
|
||||
isVerifying,
|
||||
startKYC,
|
||||
updatePrivacySettings,
|
||||
addBadge,
|
||||
assignRole,
|
||||
refreshReputation
|
||||
}}>
|
||||
{children}
|
||||
</IdentityContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export const useIdentity = () => {
|
||||
const context = useContext(IdentityContext);
|
||||
if (!context) {
|
||||
throw new Error('useIdentity must be used within IdentityProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user