Cookie Jar Client ๐Ÿช

October 1, 2025 ยท View on GitHub

Next.js frontend for Cookie Jar protocol - decentralized funding pools with multi-protocol access control.

Overview

React frontend for creating and managing Cookie Jar funding pools with customizable access control, withdrawal rules, and transparent on-chain tracking.

Features

Access Control: Allowlist, NFT-gated, POAP, Unlock Protocol, Hypercerts, Hats Protocol
Withdrawals: Fixed/variable amounts, time restrictions, purpose tracking
Assets: ETH + any ERC20 token
Admin: Allowlist management, NFT gates, emergency controls
Security: On-chain transparency, custom error handling

Architecture

client/
โ”œโ”€โ”€ app/                      # Next.js App Router
โ”‚   โ”œโ”€โ”€ admin/                # Admin pages
โ”‚   โ”œโ”€โ”€ create/               # Jar creation page
โ”‚   โ”œโ”€โ”€ docs/                 # Documentation pages
โ”‚   โ”œโ”€โ”€ jar/[address]/        # Individual jar page
โ”‚   โ”œโ”€โ”€ jars/                 # Jar listing page
โ”‚   โ”œโ”€โ”€ profile/              # User profile page
โ”‚   โ”œโ”€โ”€ globals.css           # Global styles
โ”‚   โ””โ”€โ”€ layout.tsx            # Root layout
โ”œโ”€โ”€ components/               # React components
โ”‚   โ”œโ”€โ”€ admin/                # Admin-related components
โ”‚   โ”‚   โ””โ”€โ”€ AdminFunctions.tsx
โ”‚   โ”œโ”€โ”€ design/               # UI design components
โ”‚   โ”‚   โ”œโ”€โ”€ animated-button.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ back-button.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ collapsible-sidebar.tsx
|   |
โ”‚   โ”œโ”€โ”€ FeeCollector/         # Fee collector components
โ”‚   โ”‚   โ””โ”€โ”€ DefaultFeeCollector.tsx
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ page/                 # Page-specific components
โ”‚   โ”‚   โ”œโ”€โ”€ docs/             # Documentation components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ docs-content.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ docs-sidebar.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ home/             # Home page components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ features.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ footer.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ landing-hero.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ social-media-buttons.tsx
โ”‚   โ”‚       โ””โ”€โ”€ network-support.tsx
โ”‚   โ”œโ”€โ”€ ui/                   # UI components (shadcn/ui)
โ”‚   โ”‚   โ”œโ”€โ”€ button.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ card.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ checkbox.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ input.tsx
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ forms/                # Form-related components
โ”‚   โ”‚   โ”œโ”€โ”€ NFTGateInput.tsx  # NFT address input with validation
โ”‚   โ”‚   โ””โ”€โ”€ NFTSelector.tsx   # Visual NFT selection grid
โ”‚   โ”œโ”€โ”€ protocol/             # Protocol-specific components
โ”‚   โ”‚   โ”œโ”€โ”€ POAPGateConfig.tsx        # POAP event configuration
โ”‚   โ”‚   โ”œโ”€โ”€ UnlockGateConfig.tsx      # Unlock Protocol configuration
โ”‚   โ”‚   โ”œโ”€โ”€ HypercertGateConfig.tsx   # Hypercert configuration
โ”‚   โ”‚   โ”œโ”€โ”€ HatsGateConfig.tsx        # Hats Protocol configuration
โ”‚   โ”‚   โ”œโ”€โ”€ ProtocolGateSelector.tsx  # Unified access method selector
โ”‚   โ”œโ”€โ”€ users/                # Jar User-related components
โ”‚   โ”‚   โ”œโ”€โ”€ ConfigDetailsSection.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ConfigItem.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ConfigView.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ CountdownTimer.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ FundingSection.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ NFTGatedWithdrawalSection.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ AllowlistWithdrawalSection.tsx
โ”‚   โ”‚   โ””โ”€โ”€ WithdrawlHistorySection.tsx
โ”‚   โ””โ”€โ”€ wallet/               # Wallet-related components
โ”‚       โ”œโ”€โ”€ custom-connect-button.tsx
โ”‚       โ”œโ”€โ”€ rainbow-kit-provider.tsx
โ”‚       โ”œโ”€โ”€ terms-and-conditions-auth.tsx
โ”‚       โ””โ”€โ”€ wallet-auth-layer.tsx
|
โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ design/               # Design-related hooks
โ”‚   โ”‚   โ”œโ”€โ”€ use-mobile.tsx    # Mobile detection
โ”‚   โ”‚   โ””โ”€โ”€ use-toast.ts      # Toast notifications
โ”‚   โ”œโ”€โ”€ protocol/             # Protocol-specific hooks
โ”‚   โ”‚   โ”œโ”€โ”€ usePOAPs.ts  # POAP event search and validation
โ”‚   โ”‚   โ”œโ”€โ”€ useUnlock.ts # Unlock Protocol membership validation
โ”‚   โ”‚   โ”œโ”€โ”€ useHypercerts.ts  # Hypercert verification
โ”‚   โ”‚   โ””โ”€โ”€ useHats.ts        # Hats Protocol role validation
โ”‚   โ”œโ”€โ”€ useNftValidation.ts   # NFT contract validation via EIP-165
โ”‚   โ”œโ”€โ”€ useUserNFTs.ts        # User NFT collection fetching (Alchemy)
โ”‚   โ”œโ”€โ”€ use-cookie-jar.ts     # Jar interaction hook
โ”‚   โ”œโ”€โ”€ use-cookie-jar-factory.ts
โ”‚   โ”œโ”€โ”€ use-cookie-jar-registry.ts
โ”‚   โ””โ”€โ”€ use-allowlist-status.ts
โ”œโ”€โ”€ lib/                      # Utility libraries
โ”‚   โ””โ”€โ”€ utils/                # Utility functions
โ”‚       โ”œโ”€โ”€ format.ts         # Formatting utilities
โ”‚       โ”œโ”€โ”€ time-utils.ts     # Time-related utilities
โ”‚       โ””โ”€โ”€ utils.ts          # General utilities
โ””โ”€โ”€ public/                   # Static assets

Tech Stack

Frontend: Next.js 15, React 18, TypeScript, Tailwind CSS, shadcn/ui
Web3: viem, wagmi, RainbowKit
Protocol APIs: POAP, Unlock Protocol, Hypercerts, Hats Protocol, Alchemy
Testing: Vitest, React Testing Library
Networks: Base, Optimism, Gnosis Chain, Base Sepolia

Testing Infrastructure

Frontend Tests

  • Jest: Unit testing framework
  • React Testing Library: Component testing utilities
  • User Event: User interaction simulation
  • Comprehensive Test Coverage: Hooks, components, and protocol integrations

Test Organization

client/__tests__/
โ”œโ”€โ”€ hooks/                    # Hook unit tests
โ”‚   โ”œโ”€โ”€ useNftValidation.test.ts     # NFT validation logic
โ”‚   โ”œโ”€โ”€ useUserNFTs.test.ts          # Alchemy NFT fetching
โ”‚   โ””โ”€โ”€ usePOAPs.test.ts        # POAP event handling
โ”œโ”€โ”€ components/               # Component tests
โ”‚   โ”œโ”€โ”€ NFTGateInput.test.tsx        # NFT input validation
โ”‚   โ”œโ”€โ”€ ProtocolGateSelector.test.tsx # Access method selection
โ””โ”€โ”€ utils/                    # Utility tests
    โ””โ”€โ”€ ProtocolValidation.test.ts   # Validation helpers

Contract Tests

  • Foundry: Solidity testing framework
  • Mock Contracts: For protocol integration testing
  • Comprehensive Coverage: All access types and withdrawal methods

Contract Test Organization

contracts/test/
โ”œโ”€โ”€ CookieJar.t.sol          # Core functionality tests
โ””โ”€โ”€ CookieJarProtocols.t.sol # Multi-protocol access tests

Smart Contracts

CookieJar.sol

The main contract implementing comprehensive jar functionality with multi-protocol access control:

  • Core Features: Deposits, withdrawals, access control, purpose tracking
  • Access Types: Allowlist, NFT-gated, POAP, Unlock Protocol, Hypercerts, Hats Protocol
  • Withdrawal Methods: withdrawAllowlist, withdrawNFTMode, withdrawPOAPMode, withdrawUnlockMode, withdrawHypercertMode, withdrawHatsMode
  • Protocol Integration: Built-in support for external protocol verification

CookieJarFactory.sol

Factory contract for creating new CookieJar instances with multi-protocol support:

  • Jar Creation: Handles complex access configuration for all supported protocols
  • Registry Integration: Maintains comprehensive jar registry
  • Access Configuration: Supports all 6 access control methods

CookieJarLib.sol

Library containing core data structures and constants:

  • Access Types: Allowlist, NFTGated, POAP, Unlock, Hypercert, Hats
  • Protocol Requirements: Dedicated structs for each protocol's specific needs
  • Error Handling: Custom errors for secure transaction processing

Getting Started

Prerequisites

  • Node.js 18.18.0 or higher
  • npm or yarn
  • A Web3 wallet (MetaMask, Rainbow, etc.)
  • ETH or tokens on a supported network

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/cookie-jar-v3.git
cd cookie-jar-v3

  1. Install dependencies:
npm install
# or
yarn install
  1. Set up environment variables (optional - basic development works without): Copy the example environment file and configure:
cp ../example.env .env.local
# Edit .env.local with your actual API keys (optional)

Required for basic functionality:

  • None! The app works in development mode without any environment variables.

Enhanced features (optional):

# NFT & Metadata Services
NEXT_PUBLIC_ALCHEMY_API_KEY=your_alchemy_api_key
NEXT_PUBLIC_OPENSEA_API_KEY=your_opensea_api_key
NEXT_PUBLIC_MORALIS_API_KEY=your_moralis_api_key

# IPFS Configuration  
NEXT_PUBLIC_PINATA_JWT=your_pinata_jwt

# Performance Optimization
NEXT_PUBLIC_NFT_CACHE_DURATION=60
NEXT_PUBLIC_MAX_NFTS_PER_COLLECTION=1000
NEXT_PUBLIC_API_RATE_LIMIT=60

For production deployment:

# Analytics & Monitoring
NEXT_PUBLIC_SENTRY_DSN=your_sentry_dsn
NEXT_PUBLIC_ENABLE_NFT_ANALYTICS=true
  1. Run the development server:
npm run dev
# or
yarn dev
  1. Open http://localhost:3000 in your browser.

Usage

  1. Connect your wallet

  2. Navigate to the "Create Jar" page

  3. Fill in the jar details:

  4. Basic information (name, description, currency)

  5. Access control settings (allowlist or NFT-gated)

  6. Withdrawal options (fixed or variable, amount, cooldown period)

  7. Additional features (strict purpose, emergency withdrawal)

  8. Review and confirm

  9. Sign the transaction

As a jar admin, you can:

  • Transfer jar ownership
  • Add/remove addresses from allowlist
  • Add/remove addresses from denylist
  • Add/remove NFT gates
  • Perform emergency withdrawals (if enabled)

As an allowlisted user or NFT holder, you can:

  • Deposit funds into the jar
  • Withdraw funds according to the jar's rules
  • View withdrawal history

Deployment

The smart contracts are deployed on the following networks:

  • Base Sepolia: 00xa004A762FC3dcDaBdB0392707bD25ff8d428403f (Factory)
  • Base: Coming soon
  • Optimism: Coming soon
  • Gnosis Chain: Coming soon

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Additional Resources

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements