Skip to content

Conversation

@envoy1084
Copy link
Contributor

@envoy1084 envoy1084 commented Nov 30, 2025

Fixes: #141

Added a Dialog for getting Faucet Tokens, initial support for FAU-sepolia, fUSDT-sepolia

faucet.mp4

Summary by CodeRabbit

  • New Features
    • Added a token faucet feature enabling users to mint ERC20 tokens through an intuitive dialog interface
    • Users can select from available tokens and specify mint amounts with automatic wallet connectivity and chain switching support

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Walkthrough

Adds a FaucetTokens React component that opens a dialog to select a faucet ERC20 and mint an amount via the connected wallet (including network switch, signer retrieval, tx construction and submission). The component is rendered in the authenticated topbar.

Changes

Cohort / File(s) Change Summary
Faucet token minting feature
src/components/faucet.tsx, src/components/navigation/topbar.tsx
Added FaucetTokens component with dialog UI for selecting a token and amount, wallet connection checks, optional chain switching, signer retrieval, tx construction using encodeFunctionData for mint(address,uint256), submission via provider signer, and toast-based loading/success/error feedback. Integrated the component into the authenticated Topbar before UserMenu and ModeToggle.

Sequence Diagram

sequenceDiagram
    participant User
    participant FaucetUI as Faucet UI
    participant Wallet as Wallet Provider
    participant TokenContract as Token Contract

    User->>FaucetUI: Open dialog, select token, enter amount, click Mint
    FaucetUI->>Wallet: Ensure connected
    alt Wallet disconnected
        Wallet-->>FaucetUI: Not connected
        FaucetUI-->>User: Show error toast / prompt connect
    else Wallet connected
        FaucetUI->>Wallet: Get current chain
        alt Chain mismatch
            FaucetUI->>Wallet: Request chain switch
            Wallet-->>FaucetUI: Chain switched
        end
        FaucetUI->>Wallet: Get signer
        FaucetUI->>TokenContract: Encode mint(to, amount)
        FaucetUI-->>User: Show loading toast
        Wallet->>TokenContract: Send transaction (mint)
        TokenContract-->>Wallet: Tx mined
        FaucetUI-->>User: Show success toast
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review wallet integration and edge cases (disconnected wallet, missing signer).
  • Verify chain switching logic and handling of unsupported chains.
  • Validate ABI/encodeFunctionData usage and decimals/amount parsing.
  • Confirm UI state management (disabling during mutation) and toast messages.

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 title accurately describes the main change: adding a feature to request faucet tokens from within the app, which aligns with the primary objective of the PR.
Linked Issues check ✅ Passed The PR fulfills issue #141's requirement by implementing an in-app mechanism (dialog with FaucetTokens component) for users to request and mint testnet/faucet tokens.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the faucet token feature: new FaucetTokens component, integration into the topbar, and supporting UI/logic for token minting.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (3)
src/components/faucet.tsx (3)

32-55: Consider removing redundant hash field.

The hash field duplicates the address field in both token configurations and doesn't appear to be used anywhere in the component. Removing it would simplify the data structure.

 const faucetTokens = [
   {
     id: "FAU-sepolia",
     name: "FAU",
     symbol: "FAU",
     decimals: 18,
     address: "0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623C",
     network: "sepolia",
     type: "ERC20",
-    hash: "0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623C",
     chainId: 11155111,
   },
   {
     id: "fUSDT-sepolia",
     name: "fUSDT",
     symbol: "fUSDT",
     decimals: 6,
     address: "0xF046b3CA5ae2879c6bAcC4D42fAF363eE8379F78",
     network: "sepolia",
     type: "ERC20",
-    hash: "0xF046b3CA5ae2879c6bAcC4D42fAF363eE8379F78",
     chainId: 11155111,
   },
 ] as const;

115-118: toast.dismiss() clears all toasts.

Calling toast.dismiss() without an ID dismisses all active toasts in the application, which could affect unrelated notifications. Consider tracking the toast ID in component state so it can be dismissed specifically in onError.

+  const [toastId, setToastId] = useState<string | number | undefined>();
+
   const mintHandler = useMutation({
     mutationFn: async () => {
       // ... existing code ...
       const id = toast.loading("Minting tokens...");
+      setToastId(id);
       // ... rest of mutation ...
     },
     onSuccess: (data) => {
       toast.success("Tokens minted successfully", { id: data.id });
+      setToastId(undefined);
     },
     onError: (error) => {
-      toast.dismiss();
+      if (toastId) toast.dismiss(toastId);
+      setToastId(undefined);
       toast.error(error.message);
     },
   });

182-189: Consider using mutate() instead of mutateAsync().

Since error handling is already done via onError, using mutate() avoids the unhandled promise rejection when the mutation fails. Alternatively, wrap mutateAsync() in a try-catch.

             <Button
               disabled={!amount || amount <= 0 || mintHandler.isPending}
-              onClick={async () => {
-                await mintHandler.mutateAsync();
-              }}
+              onClick={() => mintHandler.mutate()}
             >
               Mint Tokens
             </Button>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2efaae6 and 7eebb7f.

📒 Files selected for processing (2)
  • src/components/faucet.tsx (1 hunks)
  • src/components/navigation/topbar.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/faucet.tsx (5)
src/lib/hooks/use-switch-network.ts (1)
  • useSwitchNetwork (7-40)
src/components/ui/dialog.tsx (5)
  • Dialog (112-112)
  • DialogTrigger (116-116)
  • DialogContent (117-117)
  • DialogHeader (118-118)
  • DialogTitle (120-120)
src/components/ui/button.tsx (1)
  • Button (56-56)
src/components/ui/select.tsx (5)
  • Select (150-150)
  • SelectTrigger (153-153)
  • SelectValue (152-152)
  • SelectContent (154-154)
  • SelectItem (156-156)
src/components/ui/input.tsx (1)
  • Input (22-22)
src/components/navigation/topbar.tsx (1)
src/components/faucet.tsx (1)
  • FaucetTokens (57-195)
⏰ 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). (2)
  • GitHub Check: Build
  • GitHub Check: Lint
🔇 Additional comments (1)
src/components/navigation/topbar.tsx (1)

7-8: LGTM!

Clean integration of the FaucetTokens component into the authenticated topbar. The placement before UserMenu and ModeToggle is appropriate for a utility action, and the component is correctly rendered only when the user is authenticated.

Also applies to: 23-23

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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)
src/components/faucet.tsx (1)

103-105: Toast message sequencing is still incorrect.

The "Waiting for confirmation..." toast appears after tx.wait() has already completed, which defeats its purpose. Move it before awaiting the transaction confirmation.

       const tx = await signer.sendTransaction({
         to: selectedToken.address,
         data: encodeFunctionData({
           abi: parseAbi(["function mint(address to, uint256 amount) public"]),
           functionName: "mint",
           args: [address as Hex, parsedAmount],
         }),
       });

+      toast.loading("Waiting for confirmation...", { id });
+
       await tx.wait();

-      toast.loading("Waiting for confirmation...", { id });
-
       return {
🧹 Nitpick comments (1)
src/components/faucet.tsx (1)

32-55: Consider removing redundant hash field.

The hash property duplicates address exactly for both tokens. If this field isn't used elsewhere, consider removing it to avoid confusion and maintenance burden.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7eebb7f and 6b1af58.

📒 Files selected for processing (1)
  • src/components/faucet.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-04T10:08:40.123Z
Learnt from: aimensahnoun
Repo: RequestNetwork/easy-invoice PR: 64
File: src/components/batch-payout.tsx:100-106
Timestamp: 2025-06-04T10:08:40.123Z
Learning: In src/components/batch-payout.tsx, the user prefers to keep the simple 2-second timeout for AppKit initialization over more complex polling mechanisms when the current approach is working adequately. They favor simplicity over potentially more robust but complex solutions.

Applied to files:

  • src/components/faucet.tsx
🧬 Code graph analysis (1)
src/components/faucet.tsx (4)
src/components/ui/dialog.tsx (5)
  • Dialog (112-112)
  • DialogTrigger (116-116)
  • DialogContent (117-117)
  • DialogHeader (118-118)
  • DialogTitle (120-120)
src/components/ui/button.tsx (1)
  • Button (56-56)
src/components/ui/select.tsx (5)
  • Select (150-150)
  • SelectTrigger (153-153)
  • SelectValue (152-152)
  • SelectContent (154-154)
  • SelectItem (156-156)
src/components/ui/input.tsx (1)
  • Input (22-22)
🔇 Additional comments (2)
src/components/faucet.tsx (2)

171-179: Input validation logic looks correct.

The number parsing now properly converts the string value before checking Number.isNaN(), addressing the previous review feedback.


182-189: Button guard and mutation usage look good.

The disabled condition properly prevents invalid submissions, and mutateAsync errors are handled by the mutation's onError callback.

Copy link
Contributor

@bassgeta bassgeta left a comment

Choose a reason for hiding this comment

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

Nice and simple 👍
The code is clean and straightforward and it works!
image

Got them in my wallet too 👌

@MantisClone
Copy link
Member

2nd Review needed.

@aimensahnoun aimensahnoun merged commit e5c1733 into RequestNetwork:main Dec 25, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from 🔖 Sprint Backlog to ✅ Done in Request Network Tech Backlog Dec 25, 2025
@MantisClone
Copy link
Member

Congratulations, your pull request has been merged! Thank you for your valuable contribution to Request Network. As a reminder, every merged PR is automatically entered into our Best PR Initiative, offering a quarterly prize of $500. Your work significantly supports our project's growth, and we encourage you to continue engaging with our community. Additionally, if you want to build or add crypto payments and invoicing features, explore how our API can reduce deployment time from months to hours while offering advanced features. Book a call with our expert to learn more and fast-track your development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

EasyInvoice - Add button to get faucet tokens

4 participants