Skip to content

[INTEGRATION] Hook for user profile operations #263

@BravarDev

Description

@BravarDev

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

  1. Wallet Provider Context:
    Ensure that the wallet provider is functional and accessible across the app to retrieve the user wallet address.

  2. Contract Deployment:
    Verify that the user_management contract is deployed on the Stellar testnet. Check deployment details or connections in the SkillCert Contracts Repository.

  3. 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.

Requirements

  1. Hook Creation:
    Create a React hook file named useUserManagement.ts inside src/hooks/.

    The hook must:

    • Import and use the user_management_binding contract.

    • 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.

  2. Error Handling:

    • Implement structured error handling with clear console logs or thrown exceptions.
    • Validate required parameters (e.g., address, contractId) before calling the contract.
  3. Usage Example (Welcome Page):
    In src/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.
  4. 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, and updateUser methods work without context dependencies.
  • Routing logic in /welcome behaves correctly based on user existence.
  • No wallet or contract hardcoding in the hook.
  • Clean, documented code following TypeScript best practices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions