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
- Clone the repository:
git clone https://github.com/yourusername/cookie-jar-v3.git
cd cookie-jar-v3
- Install dependencies:
npm install
# or
yarn install
- 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
- Run the development server:
npm run dev
# or
yarn dev
- Open http://localhost:3000 in your browser.
Usage
Creating a Cookie Jar
-
Connect your wallet
-
Navigate to the "Create Jar" page
-
Fill in the jar details:
-
Basic information (name, description, currency)
-
Access control settings (allowlist or NFT-gated)
-
Withdrawal options (fixed or variable, amount, cooldown period)
-
Additional features (strict purpose, emergency withdrawal)
-
Review and confirm
-
Sign the transaction
Managing a Cookie Jar
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)
Using a Cookie Jar
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Additional Resources
- Frontend Architecture - Detailed architecture
- NFT Integration Guide - NFT functionality
- Development Guide - Development workflow
- Testing Guide - Testing strategies
- Main Project README: ../README.md - Setup and overview
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- OpenZeppelin for secure smart contract libraries
- RainbowKit for wallet connection UI
- shadcn/ui for beautiful UI components
- Vercel for hosting and deployment