TalentLayer Documentation
  • 👋Introduction
    • Value Proposition
    • Options for Integration
      • On-Demand Integration
      • Native Integration
    • TalentLayer's Functions
      • PlatformID
        • Fees & Economics
      • TalentLayerID
      • Reviews
      • Services
      • Escrow and Dispute
        • Dispute Workflow
        • Arbitration
          • Kleros Arbitration
          • Platform Managed Arbitration
    • Current Network Liquidity
    • Decentralization
  • ⚙️Technical Guides
    • Web 3 SDK & API
    • StarterKit Template
    • Technical Schemas
    • Network Support
    • Lower-Level Guides
      • Smart Contracts
        • Deployments
        • TalentLayerPlatformID.sol
        • TalentLayerID.sol
        • TalentLayerService.sol
        • TalentLayerReview.sol
        • Escrow & Dispute Contracts
      • The Graph
        • Introduction
        • Querying from an application
        • Queries examples
        • Implementing the pagination
      • Metadata
      • Third-Party Modules
        • Lens Protocol - Social
        • XMTP - Messaging
        • Sismo - Privacy
        • Iexec - Web3Mail
      • Messaging
        • Integrating XMTP
      • Standards
        • ERC-792: Arbitration standard
        • ERC-1497: Evidence Standard
      • How-To Guides
        • How to implement minting TalentLayer IDs?
        • How to implement the service creation?
        • How to implement the proposal creation?
        • How to implement the proposal validation?
    • Delegation
      • Meta Transaction
      • Delegate System
        • Setting
        • User workflow
        • Service creation example
        • How mintForAddress works
  • ⭐Get a Platform ID
  • 🧠Inspiration for Builders
  • 💬Contact The Team
  • 🦝Core Developer Guides
    • Subgraph Local Setup
    • Smart Contracts Local Setup
    • Advanced Documentation
    • Contract & Graph Deployment Guide
    • TalentLayer Improvement Proposals
    • Audit Report
Powered by GitBook
On this page
  • 1 - The component
  • See the Full Code Implemented on Our Demo DAPP

Was this helpful?

  1. Technical Guides
  2. Delegation
  3. Delegate System

User workflow

In this section, we will see how the user can activate or deactivate the delegation feature on their dashboard.

1 - The component

Feel free to add the activation wherever you want. Currently, it is added in a popup modal, but it will soon be moved to a dedicated setting section in the user dashboard.

import { Provider } from '@wagmi/core';
import { ethers } from 'ethers';
import { createMultiStepsTransactionToast, showErrorTransactionToast } from '../utils/toast';

export const toggleDelegation = async (
  user: string,
  DelegateAddress: string,
  provider: Provider,
  validateState: boolean,
  contract: ethers.Contract,
): Promise<void> => {
  try {
    let tx: ethers.providers.TransactionResponse;
    let toastMessages;
    if (validateState === true) {
      tx = await contract.addDelegate(user, DelegateAddress);
      toastMessages = {
        pending: 'Submitting the delegation...',
        success: 'Congrats! the delegation is active',
        error: 'An error occurred while delegation process',
      };
    } else {
      tx = await contract.removeDelegate(user, DelegateAddress);
      toastMessages = {
        pending: 'Canceling the delegation...',
        success: 'The delegation has been canceled',
        error: 'An error occurred while canceling the delegation',
      };
    }

    await createMultiStepsTransactionToast(toastMessages, provider, tx, 'Delegation');
  } catch (error) {
    showErrorTransactionToast(error);
  }
};

As you can see, we have added the addDelegate and removeDelegate functions from the TalentLayerID contract. By triggering these functions, it will call the respective function with two parameters.

  • user : is the TalentLayer user ID

  • DelegateAddress : is the delegate address add by the platform in the .env file

See the Full Code Implemented on Our Demo DAPP

PreviousSettingNextService creation example

Last updated 1 year ago

Was this helpful?

Delegate Modal :

Toggle Delegation :

⚙️
https://github.com/TalentLayer-Labs/indie-frontend/blob/main/src/components/Modal/DelegateModal.tsx
https://github.com/TalentLayer-Labs/indie-frontend/blob/main/src/contracts/toggleDelegation.tsx