Skip to content

omaidf/DeadManSwitch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dead Man's Switch dApp - React Version

A pure React implementation of the Dead Man's Switch dApp, converted from the original Next.js version. This decentralized application allows users to create time-locked encrypted secrets that automatically reveal if they fail to reset the timer within a specified interval.

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • NPM or Yarn
  • A Solana wallet (Phantom or Solflare recommended)

Installation

  1. Clone and navigate to the React app:
cd react-app
npm install
  1. Set up environment variables:
cp .env.example .env.local

Edit .env.local with your configuration:

VITE_SOLANA_NETWORK=devnet
VITE_SOLANA_RPC_URL=https://api.devnet.solana.com
VITE_PROGRAM_ID=f9kTeCnUyNX3Pg43d7DtjNixVYHLBynCY5ukfXDXcrs
VITE_LIT_NETWORK=datil-dev
  1. Start the development server:
npm run dev
  1. Open your browser: Navigate to http://localhost:3000

πŸ“ Project Structure

react-app/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ WalletProvider.tsx
β”‚   β”‚   β”œβ”€β”€ ErrorBoundary.tsx
β”‚   β”‚   β”œβ”€β”€ Layout.tsx
β”‚   β”‚   β”œβ”€β”€ Sidebar.tsx
β”‚   β”‚   β”œβ”€β”€ WalletButton.tsx
β”‚   β”‚   └── NetworkStatus.tsx
β”‚   β”œβ”€β”€ pages/              # Page components
β”‚   β”‚   β”œβ”€β”€ HomePage.tsx
β”‚   β”‚   β”œβ”€β”€ CreatePage.tsx
β”‚   β”‚   β”œβ”€β”€ MyLocksPage.tsx
β”‚   β”‚   β”œβ”€β”€ PublicUnlocksPage.tsx
β”‚   β”‚   β”œβ”€β”€ HelpPage.tsx
β”‚   β”‚   └── AboutPage.tsx
β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useWalletAuth.ts
β”‚   β”‚   β”œβ”€β”€ useProgram.ts
β”‚   β”‚   β”œβ”€β”€ useLitProtocol.ts
β”‚   β”‚   β”œβ”€β”€ useIpfs.ts
β”‚   β”‚   β”œβ”€β”€ useNetworkStats.ts
β”‚   β”‚   └── useUserSwitches.ts
β”‚   β”œβ”€β”€ lib/                # Utility libraries
β”‚   β”‚   β”œβ”€β”€ env-validation.ts
β”‚   β”‚   β”œβ”€β”€ time-utils.ts
β”‚   β”‚   β”œβ”€β”€ rate-limit.ts
β”‚   β”‚   β”œβ”€β”€ retry-utils.ts
β”‚   β”‚   └── wallet-utils.ts
β”‚   β”œβ”€β”€ types/              # TypeScript type definitions
β”‚   β”œβ”€β”€ App.tsx             # Main app component
β”‚   β”œβ”€β”€ main.tsx            # React entry point
β”‚   β”œβ”€β”€ index.css           # Global styles
β”‚   └── idl.json            # Anchor program IDL
β”œβ”€β”€ public/                 # Static assets
β”œβ”€β”€ package.json            # Dependencies and scripts
β”œβ”€β”€ vite.config.ts          # Vite configuration
β”œβ”€β”€ tailwind.config.js      # Tailwind CSS configuration
└── tsconfig.json           # TypeScript configuration

πŸ”„ Key Differences from Next.js Version

Routing

  • Next.js: File-based routing with app/ directory
  • React: React Router DOM with route definitions in App.tsx

Environment Variables

  • Next.js: NEXT_PUBLIC_* prefix
  • React: VITE_* prefix for Vite

Build System

  • Next.js: Built-in webpack configuration
  • React: Vite with custom configuration for Solana/crypto polyfills

SSR/SSG

  • Next.js: Server-side rendering and static generation
  • React: Client-side rendering only

Dynamic Imports

  • Next.js: next/dynamic for code splitting
  • React: React lazy loading and standard dynamic imports

πŸ”§ Development Commands

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

# Run TypeScript checks
npm run lint

# Solana/Anchor commands (run from parent directory)
npm run anchor:build     # Build Anchor program
npm run anchor:deploy    # Deploy to devnet
npm run anchor:test      # Run tests
npm run check:deployment # Verify deployment

🌐 Environment Configuration

Required Variables

VITE_PROGRAM_ID=f9kTeCnUyNX3Pg43d7DtjNixVYHLBynCY5ukfXDXcrs

Optional Variables

VITE_SOLANA_NETWORK=devnet                    # mainnet-beta, testnet, devnet
VITE_SOLANA_RPC_URL=https://api.devnet.solana.com
VITE_LIT_NETWORK=datil-dev                    # datil-dev, datil-test

πŸ”Œ Browser Compatibility

The app includes polyfills for Node.js modules to work in browsers:

  • crypto β†’ crypto-browserify
  • stream β†’ stream-browserify
  • buffer β†’ buffer
  • process β†’ process/browser

🚧 Current Status

βœ… Completed

  • Basic React app structure
  • Vite configuration with Solana polyfills
  • Environment variable setup
  • Component architecture
  • Routing with React Router
  • Wallet integration (WalletProvider, WalletButton)
  • Layout and navigation (Sidebar, Layout)
  • Error boundaries
  • TypeScript configuration
  • Tailwind CSS styling
  • Hooks migration (core utilities)

🚧 In Progress

  • Core components migration
    • SwitchCreator component
    • SwitchDashboard component
    • PublicUnlocksClient component
    • RevealedSecrets component
    • InputValidation component
    • LoadingSpinner component

πŸ“‹ Todo

  • API routes migration (currently in Next.js /api directory)
  • IPFS integration testing
  • Lit Protocol integration testing
  • Complete component testing
  • Production deployment setup
  • Performance optimization

πŸ”„ Migration Guide

For Developers

  1. Component Migration:

    • Remove 'use client' directives
    • Replace next/link with react-router-dom
    • Update useRouter with useNavigate and useLocation
    • Replace process.env.NEXT_PUBLIC_* with import.meta.env.VITE_*
  2. API Routes:

    • Current API routes in /api directory need to be migrated to a separate backend
    • Or adapted to work with Vite's dev server proxy
  3. Dynamic Imports:

    • Replace next/dynamic with React's lazy() and Suspense

Example Migration

Next.js:

'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation';

const network = process.env.NEXT_PUBLIC_SOLANA_NETWORK;

React:

import { Link, useNavigate } from 'react-router-dom';

const network = import.meta.env.VITE_SOLANA_NETWORK;
const navigate = useNavigate();

πŸ“¦ Deployment

Development

npm run dev

Production Build

npm run build
npm run preview

Static Hosting

The built app is a static site that can be deployed to:

  • Vercel
  • Netlify
  • GitHub Pages
  • AWS S3 + CloudFront
  • Any static hosting service

πŸ”— Related

  • Original Next.js Version: ../ (parent directory)
  • Solana Program: ../solana/
  • Deployment Scripts: ../scripts/

⚠️ Important Notes

  1. Experimental: This is a migration in progress. Not all features are complete.

  2. Testnet Only: Currently configured for Solana devnet. Don't use real funds.

  3. API Dependencies: Some features depend on API routes that are still in the Next.js version.

  4. Security: Always verify transactions and never share private keys.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

MIT License - see the main project's LICENSE file for details.


Note: This React version is actively being developed. Check the Next.js version in the parent directory for the most complete implementation.

About

Deadman Switch on the Solana Blockchain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published