chore: add mint button#1145
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
📝 WalkthroughWalkthroughAdds 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
undefinedif 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
📒 Files selected for processing (6)
examples/CRISP/client/.env.exampleexamples/CRISP/client/src/components/Navbar.tsxexamples/CRISP/client/src/hooks/generic/useMintToken.tsxexamples/CRISP/client/src/utils/abi.tsexamples/CRISP/client/src/utils/constants.tsexamples/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
Providerfrom the import list is correct, as the type is not explicitly referenced in the code. Theprovidervariable's type is properly inferred fromProviderBuilder.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:
balanceOffor checking token balancemintfor the custom minting functionality (non-standard ERC20, but intentional for this test token)The use of
parseAbifrom 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
readContractwith the correct ABI and parameters
48-70: Minting flow structure is well implemented.The minting logic has good structure:
- Proper state management with
isMintingto 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.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
examples/CRISP/client/.env.exampleexamples/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.
15d0849 to
cc5d9e3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
examples/CRISP/client/.env.example (1)
1-5: Reorder environment variables alphabetically.The
VITE_CRISP_TOKENkey should be placed beforeVITE_ENCLAVE_APIto 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
📒 Files selected for processing (6)
examples/CRISP/client/.env.exampleexamples/CRISP/client/src/components/Navbar.tsxexamples/CRISP/client/src/hooks/generic/useMintToken.tsxexamples/CRISP/client/src/utils/abi.tsexamples/CRISP/client/src/utils/constants.tsexamples/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
Providerimport was unused in the code, which only requiresProviderBuilder. 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
useCallbackincludes all necessary dependencies, and the return value provides the appropriate interface for consuming components.
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
Chores
✏️ Tip: You can customize this high-level summary in your review settings.