-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Task: Implement User Management Contract Integration Hook
Description
Implement the integration of the user_management contract in the frontend to manage user creation, updates, and retrieval using Stellar smart contracts. The integration must be modular, reusable, and ready for use in the welcome page for user onboarding logic.
Prerequisites
-
Wallet Provider Context:
Ensure that the wallet provider is functional and accessible across the app to retrieve the user wallet address. -
Contract Deployment:
Verify that theuser_managementcontract is deployed on the Stellar testnet. Check deployment details or connections in the SkillCert Contracts Repository. -
Contract Binding:
Confirm that the contract binding (auto-generated classes/interfaces) exists.- Expected path:
src/contract_connections/user_management_binding - If missing, generate the binding using the Stellar CLI and place it in the specified folder.
- Expected path:
Requirements
-
Hook Creation:
Create a React hook file nameduseUserManagement.tsinsidesrc/hooks/.The hook must:
-
Import and use the
user_management_bindingcontract. -
Provide functions:
createUser(address: string, data: UserProfileInput): Promise<void>updateUser(address: string, data: UserProfileUpdate): Promise<void>getUser(address: string): Promise<UserProfile | null>
-
Use the wallet address, signer, and contract ID as external parameters — do not access wallet context directly inside the hook.
-
-
Error Handling:
- Implement structured error handling with clear console logs or thrown exceptions.
- Validate required parameters (e.g.,
address,contractId) before calling the contract.
-
Usage Example (Welcome Page):
Insrc/app/welcome/page.tsx:- Retrieve the connected wallet address from context.
- Call
getUser(address)on load. - If a profile exists, redirect to
/dashboard. - Otherwise, remain in
/welcome.
-
Testing:
-
Include temporary console logs to confirm:
- Contract call success.
- Returned user data.
- Route redirection behavior.
-
Deliverables
- New hook file:
src/hooks/useUserManagement.ts - Contract binding validated or generated under
src/contract_connections/user_management_binding - Logic integrated in
src/app/welcome/page.tsx - Tested and verified on Stellar testnet
Acceptance Criteria
- The hook successfully connects to the deployed contract.
getUser,createUser, andupdateUsermethods work without context dependencies.- Routing logic in
/welcomebehaves correctly based on user existence. - No wallet or contract hardcoding in the hook.
- Clean, documented code following TypeScript best practices.