Skip to content

chore: add mint button#1145

Merged
ctrlc03 merged 3 commits into
mainfrom
chore/mint-button
Dec 24, 2025
Merged

chore: add mint button#1145
ctrlc03 merged 3 commits into
mainfrom
chore/mint-button

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Dec 23, 2025

Copy link
Copy Markdown
Collaborator

fix #1144

Adding the token in the .env as it should be the same for all rounds. People need it before a round start to be able to join in

Summary by CodeRabbit

  • New Features

    • Mint CRISP tokens from the app via a new "Mint tokens" button in the navigation bar.
    • Minting shows progress (button disabled while processing) and user-facing notifications for success, already-owned tokens, and errors.
  • Chores

    • Example environment configuration updated to include a CRISP token variable.

✏️ Tip: You can customize this high-level summary in your review settings.

@ctrlc03 ctrlc03 requested a review from cedoor December 23, 2025 19:53
@vercel

vercel Bot commented Dec 23, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
crisp Ready Ready Preview, Comment Dec 24, 2025 9:37am
1 Skipped Deployment
Project Deployment Review Updated (UTC)
enclave-docs Skipped Skipped Dec 24, 2025 9:37am

@coderabbitai

coderabbitai Bot commented Dec 23, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a client-side token-minting flow to the CRISP example: new ERC‑20 ABI and ROUND_TOKEN constant, a React hook that validates wallet/balance and mints tokens (with toasts), a Navbar "Mint tokens" button, an env var for the token address, and a minor server import cleanup.

Changes

Cohort / File(s) Summary
Token Minting Hook
examples/CRISP/client/src/hooks/generic/useMintToken.tsx
New default-exported React hook that validates wallet/public clients, reads ERC‑20 balanceOf, and calls mint via writeContract when balance is zero; exposes isMinting and mintTokens and shows toasts for status.
UI Integration
examples/CRISP/client/src/components/Navbar.tsx
Imports and uses the mint hook; adds a "Mint tokens" button (disabled while isMinting) which triggers mintTokens.
Configuration & Utilities
examples/CRISP/client/.env.example, examples/CRISP/client/src/utils/constants.ts, examples/CRISP/client/src/utils/abi.ts
.env.example: removed VITE_TWITTER_SERVERLESS_API, added VITE_CRISP_TOKEN (address present); constants.ts exports ROUND_TOKEN from import.meta.env.VITE_CRISP_TOKEN; abi.ts exports parsed iERC20Abi with balanceOf and mint signatures.
Server Cleanup
examples/CRISP/server/src/cli/approve.rs
Removed unused Provider import; retained ProviderBuilder import only.

Sequence Diagram

sequenceDiagram
    autonumber
    participant User as User
    participant Navbar as Navbar (UI)
    participant Hook as useMintToken Hook
    participant Clients as Wallet/Public Clients
    participant Contract as ROUND_TOKEN Contract
    participant Toast as Toasts

    User->>Navbar: Click "Mint tokens"
    Navbar->>Hook: call mintTokens()
    Hook->>Clients: validate walletClient & publicClient
    alt wallet not connected
        Hook->>Toast: danger "Wallet not connected"
        Hook-->>Navbar: return
    else wallet connected
        Hook->>Contract: call balanceOf(userAddress)
        Contract-->>Hook: return balance
        alt balance > 0
            Hook->>Toast: info "You already have tokens"
            Hook-->>Navbar: return
        else balance == 0
            Hook->>Navbar: set isMinting = true
            Hook->>Clients: writeContract(mint, to=user, amount=1e18)
            Clients->>Contract: execute mint(...)
            alt mint success
                Contract-->>Clients: tx confirmed
                Hook->>Toast: success "Tokens minted successfully"
            else mint failure
                Hook->>Toast: danger "Error minting tokens"
            end
            Hook->>Navbar: set isMinting = false
            Hook-->>Navbar: return
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • cedoor
  • 0xjei

Poem

I'm a rabbit in the code, hopping light and quick,
I added tokens to mint with a little magic trick.
Click the button in the bar, watch the chain attest,
Toasts cheer success — a tiny dev delight expressed.
🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'chore: add mint button' accurately and concisely describes the main feature addition—implementing a mint button component in the CRISP client application.
Linked Issues check ✅ Passed The PR successfully implements the token mint button functionality for testnet demos by adding useMintToken hook, Navbar button, contract ABI, and configuration, addressing issue #1144 requirements.
Out of Scope Changes check ✅ Passed Removal of unused Provider import in approve.rs is a minor cleanup unrelated to the mint button feature but does not materially impact the PR scope.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/mint-button

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
examples/CRISP/client/src/utils/constants.ts (1)

7-7: Consider adding type assertion for the environment variable.

The exported constant could be undefined if the environment variable is not set. Consider adding a type assertion or runtime check to ensure type safety.

🔎 Proposed fix
-export const ROUND_TOKEN = import.meta.env.VITE_CRISP_TOKEN
+export const ROUND_TOKEN = import.meta.env.VITE_CRISP_TOKEN as `0x${string}`

Alternatively, add a runtime check:

-export const ROUND_TOKEN = import.meta.env.VITE_CRISP_TOKEN
+const token = import.meta.env.VITE_CRISP_TOKEN
+if (!token) throw new Error('VITE_CRISP_TOKEN environment variable is required')
+export const ROUND_TOKEN = token as `0x${string}`
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad8c74b and ad3e61d.

📒 Files selected for processing (6)
  • examples/CRISP/client/.env.example
  • examples/CRISP/client/src/components/Navbar.tsx
  • examples/CRISP/client/src/hooks/generic/useMintToken.tsx
  • examples/CRISP/client/src/utils/abi.ts
  • examples/CRISP/client/src/utils/constants.ts
  • examples/CRISP/server/src/cli/approve.rs
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-28T08:58:17.434Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 665
File: packages/enclave-sdk/src/contract-client.ts:110-118
Timestamp: 2025-08-28T08:58:17.434Z
Learning: viem's TypeScript ABI inference maps uint32[2] to [number, number], not [bigint, bigint]. The library uses number type for uint32 values to align with traditional database patterns and avoid unnecessary BigInt conversion.

Applied to files:

  • examples/CRISP/client/src/utils/abi.ts
📚 Learning: 2025-10-10T12:56:40.538Z
Learnt from: 0xjei
Repo: gnosisguild/enclave PR: 830
File: templates/default/README.md:123-128
Timestamp: 2025-10-10T12:56:40.538Z
Learning: In the Enclave repository, the hard-coded Hardhat development private key `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` is acceptable in template README files and documentation for local testing/interaction purposes.

Applied to files:

  • examples/CRISP/client/.env.example
📚 Learning: 2024-09-26T03:11:29.311Z
Learnt from: ryardley
Repo: gnosisguild/enclave PR: 107
File: packages/ciphernode/sortition/src/distance.rs:1-1
Timestamp: 2024-09-26T03:11:29.311Z
Learning: In `packages/ciphernode/core/src/events.rs`, the import statements use the correct and updated `alloy::primitives` module.

Applied to files:

  • examples/CRISP/server/src/cli/approve.rs
🧬 Code graph analysis (1)
examples/CRISP/client/src/hooks/generic/useMintToken.tsx (4)
examples/CRISP/client/src/context/NotificationAlert/NotificationAlert.context.tsx (1)
  • useNotificationAlertContext (88-88)
examples/CRISP/client/src/utils/abi.ts (1)
  • iERC20Abi (9-12)
examples/CRISP/client/src/utils/constants.ts (1)
  • ROUND_TOKEN (7-7)
examples/CRISP/client/src/utils/methods.ts (1)
  • getChain (26-28)
🪛 dotenv-linter (4.0.0)
examples/CRISP/client/.env.example

[warning] 5-5: [QuoteCharacter] The value has quote characters (', ")

(QuoteCharacter)


[warning] 5-5: [UnorderedKey] The VITE_CRISP_TOKEN key should go before the VITE_ENCLAVE_API key

(UnorderedKey)

🪛 Gitleaks (8.30.0)
examples/CRISP/client/.env.example

[high] 5-5: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: build_crisp_sdk
  • GitHub Check: build_sdk
  • GitHub Check: integration_prebuild
  • GitHub Check: build_enclave_cli
  • GitHub Check: rust_unit
  • GitHub Check: build_ciphernode_image
  • GitHub Check: rust_integration
  • GitHub Check: test_net
  • GitHub Check: Build & Push Image
🔇 Additional comments (6)
examples/CRISP/server/src/cli/approve.rs (1)

28-28: LGTM: Unused import removed.

The removal of Provider from the import list is correct, as the type is not explicitly referenced in the code. The provider variable's type is properly inferred from ProviderBuilder.

examples/CRISP/client/src/components/Navbar.tsx (1)

12-12: LGTM! Mint button integration looks good.

The hook integration and button implementation are correct:

  • Properly imports and uses the minting hook
  • Button is disabled during minting operations to prevent duplicate transactions
  • Click handler correctly triggers the mint function
  • Styling is consistent with other navbar elements

Also applies to: 26-26, 40-46

examples/CRISP/client/src/utils/abi.ts (1)

9-12: LGTM! ABI definition is correct.

The parsed ABI correctly defines the required functions:

  • balanceOf for checking token balance
  • mint for the custom minting functionality (non-standard ERC20, but intentional for this test token)

The use of parseAbi from viem ensures type safety for contract interactions.

examples/CRISP/client/src/hooks/generic/useMintToken.tsx (3)

24-31: LGTM! Wallet validation is properly implemented.

The early validation of wallet and public client connections prevents runtime errors and provides clear user feedback when prerequisites are not met.


33-46: LGTM! Balance check provides good UX.

The balance validation before minting is a good user experience improvement:

  • Prevents unnecessary minting when user already has tokens
  • Provides informative feedback to the user
  • Properly uses readContract with the correct ABI and parameters

48-70: Minting flow structure is well implemented.

The minting logic has good structure:

  • Proper state management with isMinting to prevent concurrent operations
  • Appropriate error handling with try/catch/finally
  • Clear user feedback via toast notifications
  • State cleanup in finally block ensures UI consistency

Note: Ensure the calculation issue on line 55 is addressed.

Comment thread examples/CRISP/client/.env.example Outdated
Comment thread examples/CRISP/client/src/hooks/generic/useMintToken.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad3e61d and 15d0849.

📒 Files selected for processing (2)
  • examples/CRISP/client/.env.example
  • examples/CRISP/client/src/hooks/generic/useMintToken.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/CRISP/client/src/hooks/generic/useMintToken.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-10T12:56:40.538Z
Learnt from: 0xjei
Repo: gnosisguild/enclave PR: 830
File: templates/default/README.md:123-128
Timestamp: 2025-10-10T12:56:40.538Z
Learning: In the Enclave repository, the hard-coded Hardhat development private key `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` is acceptable in template README files and documentation for local testing/interaction purposes.

Applied to files:

  • examples/CRISP/client/.env.example
🪛 dotenv-linter (4.0.0)
examples/CRISP/client/.env.example

[warning] 5-5: [UnorderedKey] The VITE_CRISP_TOKEN key should go before the VITE_ENCLAVE_API key

(UnorderedKey)

🪛 Gitleaks (8.30.0)
examples/CRISP/client/.env.example

[high] 5-5: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: integration_prebuild
  • GitHub Check: build_enclave_cli
  • GitHub Check: test_net
  • GitHub Check: rust_integration
  • GitHub Check: build_e3_support_dev
  • GitHub Check: build_sdk
  • GitHub Check: rust_unit
  • GitHub Check: build_ciphernode_image
  • GitHub Check: build_crisp_sdk
  • GitHub Check: Build & Push Image
🔇 Additional comments (1)
examples/CRISP/client/.env.example (1)

5-5: Good catch on removing the quotes.

The environment variable value is now correctly unquoted. This resolves the previous review comment.

Comment thread examples/CRISP/client/.env.example

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
examples/CRISP/client/.env.example (1)

1-5: Reorder environment variables alphabetically.

The VITE_CRISP_TOKEN key should be placed before VITE_ENCLAVE_API to maintain alphabetical ordering, as indicated by the static analysis tool.

🔎 Proposed fix
+# A token with a public mint function. Also used as the fee token for Enclave. 
+# This is its default address in Hardhat node
+VITE_CRISP_TOKEN=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
 VITE_ENCLAVE_API=http://127.0.0.1:4000
 VITE_WALLETCONNECT_PROJECT_ID=
-# A token with a public mint function. Also used as the fee token for Enclave. 
-# This is its default address in Hardhat node
-VITE_CRISP_TOKEN=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
🧹 Nitpick comments (1)
examples/CRISP/client/src/hooks/generic/useMintToken.tsx (1)

50-70: Consider waiting for transaction confirmation.

The success toast appears immediately after transaction submission without waiting for mining confirmation. Users might see "success" before the tokens are actually minted on-chain.

🔎 Optional improvement for transaction confirmation
     try {
-      await walletClient.writeContract({
+      const hash = await walletClient.writeContract({
         abi: iERC20Abi,
         address: ROUND_TOKEN,
         functionName: 'mint',
         args: [walletClient.account.address, BigInt(1 * 1e18)],
         chain: getChain(),
       })
+      await publicClient.waitForTransactionReceipt({ hash })
       showToast({
         type: 'success',
         message: 'Tokens minted successfully',
       })
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15d0849 and cc5d9e3.

📒 Files selected for processing (6)
  • examples/CRISP/client/.env.example
  • examples/CRISP/client/src/components/Navbar.tsx
  • examples/CRISP/client/src/hooks/generic/useMintToken.tsx
  • examples/CRISP/client/src/utils/abi.ts
  • examples/CRISP/client/src/utils/constants.ts
  • examples/CRISP/server/src/cli/approve.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/CRISP/client/src/utils/abi.ts
  • examples/CRISP/client/src/utils/constants.ts
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-28T08:58:17.434Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 665
File: packages/enclave-sdk/src/contract-client.ts:110-118
Timestamp: 2025-08-28T08:58:17.434Z
Learning: viem's TypeScript ABI inference maps uint32[2] to [number, number], not [bigint, bigint]. The library uses number type for uint32 values to align with traditional database patterns and avoid unnecessary BigInt conversion.

Applied to files:

  • examples/CRISP/client/src/hooks/generic/useMintToken.tsx
📚 Learning: 2024-09-26T03:11:29.311Z
Learnt from: ryardley
Repo: gnosisguild/enclave PR: 107
File: packages/ciphernode/sortition/src/distance.rs:1-1
Timestamp: 2024-09-26T03:11:29.311Z
Learning: In `packages/ciphernode/core/src/events.rs`, the import statements use the correct and updated `alloy::primitives` module.

Applied to files:

  • examples/CRISP/server/src/cli/approve.rs
📚 Learning: 2025-10-10T12:56:40.538Z
Learnt from: 0xjei
Repo: gnosisguild/enclave PR: 830
File: templates/default/README.md:123-128
Timestamp: 2025-10-10T12:56:40.538Z
Learning: In the Enclave repository, the hard-coded Hardhat development private key `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` is acceptable in template README files and documentation for local testing/interaction purposes.

Applied to files:

  • examples/CRISP/client/.env.example
🧬 Code graph analysis (1)
examples/CRISP/client/src/hooks/generic/useMintToken.tsx (5)
examples/CRISP/client/src/context/NotificationAlert/NotificationAlert.context.tsx (1)
  • useNotificationAlertContext (88-88)
examples/CRISP/client/src/utils/abi.ts (1)
  • iERC20Abi (9-12)
examples/CRISP/client/src/utils/constants.ts (1)
  • ROUND_TOKEN (7-7)
examples/CRISP/client/src/utils/methods.ts (1)
  • getChain (26-28)
crates/events/src/eventbus.rs (1)
  • error (73-77)
🪛 dotenv-linter (4.0.0)
examples/CRISP/client/.env.example

[warning] 5-5: [UnorderedKey] The VITE_CRISP_TOKEN key should go before the VITE_ENCLAVE_API key

(UnorderedKey)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: build_sdk
  • GitHub Check: integration_prebuild
  • GitHub Check: build_crisp_sdk
  • GitHub Check: rust_unit
  • GitHub Check: test_net
  • GitHub Check: build_enclave_cli
  • GitHub Check: build_ciphernode_image
  • GitHub Check: rust_integration
  • GitHub Check: Build & Push Image
🔇 Additional comments (9)
examples/CRISP/server/src/cli/approve.rs (1)

28-28: LGTM! Clean removal of unused import.

The Provider import was unused in the code, which only requires ProviderBuilder. This cleanup improves code clarity.

examples/CRISP/client/src/components/Navbar.tsx (3)

12-12: LGTM!

The import correctly references the default export from the new minting hook.


26-27: LGTM!

Clean hook integration following React best practices.


40-46: LGTM! Well-implemented button with proper state management.

The button correctly:

  • Disables during minting to prevent double-submission
  • Uses consistent styling with other navigation items
  • Implements responsive behavior matching the rest of the navbar
examples/CRISP/client/src/hooks/generic/useMintToken.tsx (5)

7-12: LGTM! Clean imports.

All imports are properly organized and used within the hook.


14-23: LGTM! Proper hook structure and initialization.

The hook is well-documented and follows React best practices with appropriate state management and wagmi client integration.


24-31: LGTM! Proper validation with user feedback.

The wallet and client validation ensures the hook fails gracefully with clear user feedback when prerequisites are missing.


55-55: LGTM! Correct token amount calculation.

The calculation BigInt(1 * 1e18) correctly evaluates to 1 token with 18 decimals (1×10^18 wei). This appears to be fixed from the previous review concern.


71-77: LGTM! Proper hook dependencies and return value.

The useCallback includes all necessary dependencies, and the return value provides the appropriate interface for consuming components.

Comment thread examples/CRISP/client/src/hooks/generic/useMintToken.tsx

@cedoor cedoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@ctrlc03 ctrlc03 merged commit 032c12e into main Dec 24, 2025
28 checks passed
@ctrlc03 ctrlc03 deleted the chore/mint-button branch December 24, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRISP add token mint button for testnet demos

2 participants