Real-world Integration

Complete integration examples for common use cases.

DeFi Dashboard

A complete DeFi application with wallet connection and reputation display:

// components/DeFiDashboard.tsx
import { useState, useEffect, useRef } from 'react';
import { createWidget, DotPassportClient } from '@dotpassport/sdk';

interface WalletState {
  address: string | null;
  isConnected: boolean;
}

export function DeFiDashboard() {
  const [wallet, setWallet] = useState<WalletState>({ address: null, isConnected: false });
  const [theme, setTheme] = useState<'light' | 'dark'>('light');
  const [scores, setScores] = useState<any>(null);

  const reputationRef = useRef<HTMLDivElement>(null);
  const badgeRef = useRef<HTMLDivElement>(null);
  const widgetsRef = useRef<ReturnType<typeof createWidget>[]>([]);

  const client = useRef(new DotPassportClient({
    apiKey: import.meta.env.VITE_DOTPASSPORT_API_KEY
  }));

  // Connect wallet
  async function connectWallet() {
    try {
      // Using Polkadot.js extension
      const { web3Enable, web3Accounts } = await import('@polkadot/extension-dapp');
      const extensions = await web3Enable('My DeFi App');

      if (extensions.length === 0) {
        alert('Please install Polkadot.js extension');
        return;
      }

      const accounts = await web3Accounts();
      if (accounts.length > 0) {
        setWallet({ address: accounts[0].address, isConnected: true });
      }
    } catch (error) {
      console.error('Failed to connect wallet:', error);
    }
  }

  // Fetch scores for eligibility check
  useEffect(() => {
    if (!wallet.address) return;

    async function fetchScores() {
      try {
        const data = await client.current.getScores(wallet.address!);
        setScores(data);
      } catch (error) {
        console.error('Failed to fetch scores:', error);
      }
    }

    fetchScores();
  }, [wallet.address]);

  // Create widgets
  useEffect(() => {
    if (!wallet.address) return;

    const apiKey = import.meta.env.VITE_DOTPASSPORT_API_KEY;

    if (reputationRef.current) {
      const w = createWidget({
        apiKey,
        address: wallet.address,
        type: 'reputation',
        theme,
        showCategories: true
      });
      w.mount(reputationRef.current);
      widgetsRef.current.push(w);
    }

    if (badgeRef.current) {
      const w = createWidget({
        apiKey,
        address: wallet.address,
        type: 'badge',
        theme,
        maxBadges: 6
      });
      w.mount(badgeRef.current);
      widgetsRef.current.push(w);
    }

    return () => {
      widgetsRef.current.forEach(w => w.destroy());
      widgetsRef.current = [];
    };
  }, [wallet.address]);

  // Update theme
  useEffect(() => {
    widgetsRef.current.forEach(w => w.update({ theme }));
  }, [theme]);

  // Eligibility check based on reputation
  const isEligibleForPremium = scores?.totalScore >= 500;
  const isEligibleForGovernance = scores?.categories?.governance?.score >= 50;

  if (!wallet.isConnected) {
    return (
      <div className="connect-prompt">
        <h1>Welcome to DeFi Dashboard</h1>
        <p>Connect your wallet to view your reputation and access features.</p>
        <button onClick={connectWallet}>Connect Wallet</button>
      </div>
    );
  }

  return (
    <div className={`dashboard ${theme}`}>
      <header>
        <h1>DeFi Dashboard</h1>
        <div className="header-controls">
          <span>{wallet.address?.slice(0, 8)}...{wallet.address?.slice(-6)}</span>
          <button onClick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}>
            {theme === 'light' ? '🌙' : '☀️'}
          </button>
        </div>
      </header>

      <div className="grid">
        <section className="reputation-section">
          <h2>Your Reputation</h2>
          <div ref={reputationRef} />
        </section>

        <section className="badges-section">
          <h2>Achievements</h2>
          <div ref={badgeRef} />
        </section>

        <section className="features-section">
          <h2>Available Features</h2>

          <div className={`feature-card ${isEligibleForPremium ? 'enabled' : 'disabled'}`}>
            <h3>Premium Pools</h3>
            <p>Access high-yield liquidity pools</p>
            {isEligibleForPremium ? (
              <button>Enter Pool</button>
            ) : (
              <span>Requires 500+ reputation score</span>
            )}
          </div>

          <div className={`feature-card ${isEligibleForGovernance ? 'enabled' : 'disabled'}`}>
            <h3>Governance Voting</h3>
            <p>Participate in protocol decisions</p>
            {isEligibleForGovernance ? (
              <button>View Proposals</button>
            ) : (
              <span>Requires 50+ governance score</span>
            )}
          </div>
        </section>
      </div>
    </div>
  );
}

NFT Marketplace

Reputation-gated NFT marketplace:


DAO Voting System

Reputation-weighted voting:


Social Profile Page

User profile with reputation display:


Leaderboard

Display top reputation holders:


Last updated