Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useNameRenew Hook #2088

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cryptobeijing
Copy link

@cryptobeijing cryptobeijing commented Mar 27, 2025

Add useNameRenew Hook

The useNameRenew hook provides functionality for renewing Basenames. It handles the entire renewal process including price calculation, network switching, and transaction execution.

Features

  • Name input validation
  • Duration selection (1-10 years)
  • Price calculation and display
  • Automatic network switching to Base
  • Transaction handling with proper error states
  • Analytics tracking
  • Error logging

Implementation Details

The hook:

  1. Uses useRentPrice to calculate renewal costs
  2. Handles network switching to Base if needed
  3. Tracks transaction status and provides loading states
  4. Integrates with analytics and error logging
  5. Provides proper error handling and user feedback
  6. Uses the Base name contract for renewal transactions

How has it been tested?

The changes have been tested through:

  1. Unit Tests:

    • Price calculation accuracy
    • Input validation
    • Network switching logic
  2. Integration Tests:

    • End-to-end renewal flow
    • Contract interaction
    • Error handling scenarios
  3. Manual Testing:

    • Tested on Base mainnet
    • Verified with different name lengths and durations
    • Confirmed proper error messages for various failure cases
    • Validated network switching behavior
    • Tested wallet connection/disconnection scenarios
  4. Contract Verification:

    • Confirmed correct contract method calls
    • Verified event emission
    • Validated transaction parameters

The functionality has been tested with both MetaMask and Coinbase Wallet to ensure broad compatibility.

Have you tested the following pages?

BaseWeb

  • [] base.org
  • [] base.org/names
  • [] base.org/builders
  • [] base.org/ecosystem
  • [] base.org/name/jesse
  • [] base.org/manage-names
  • [] base.org/resources
  • [] docs.base.org
  • [] docs sub-pages

Copy link

vercel bot commented Mar 27, 2025

@cryptobeijing is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Mar 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
base-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2025 9:58pm
web-base-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2025 9:58pm

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Mar 27, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/2
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@cryptobeijing
Copy link
Author

renew basename screenshot

@wbnns
Copy link
Contributor

wbnns commented Mar 28, 2025

@cryptobeijing Thanks so much! 🙌 We'll do our best to review this soon 🙏

@cryptobeijing
Copy link
Author

@cryptobeijing Thanks so much! 🙌 We'll do our best to review this soon 🙏
Hi Will:
No Hurry! Though I read through the project before I code, I am still expecting some back and forth in my first commit.Thank you very much!

@brendan-defi
Copy link
Collaborator

@cryptobeijing thanks very much for your submission. really cool to see such a significant PR 👏 .

With that said, while there's a lot here to like, this isn't the UX that we would implement for this experience.

What I'd recommend is to focus on a hook specifically for managing renewal transactions. This hook could then be repurposed throughout the codebase wherever we want to initiate renewals.

Let me know if you think you're up for that.

@@ -33,6 +33,11 @@ export type UseWriteContractWithReceiptProps = {
eventName: string;
};

// Extend ContractFunctionParameters to include value property
export type PayableContractFunctionParameters = ContractFunctionParameters & {
value?: bigint;
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems wrong to have this be optional. in the case where we want it, it's required. in the case where we don't want it, it's irrelevant.

let's try to figure out a way to create a discriminated union, based on whether the specified ABI method is payable

Copy link
Author

Choose a reason for hiding this comment

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

Hi @brendan-defi Thanks for your comments! I will follow your suggestions and focus on a hook. And I will test it with UI locally and only commit the hook.

Comment on lines 101 to 107
await initiateTransaction({
abi: REGISTER_CONTRACT_ABI,
address: REGISTER_CONTRACT_ADDRESSES[connectedChain.id],
functionName: 'renew',
args: [selectedName, secondsInYears(years)],
value: lastQueryPrice,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is great, let's extract into a reusable hook

Copy link
Author

Choose a reason for hiding this comment

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

Got it! Thanks for your detailed comments!

@cryptobeijing cryptobeijing changed the title Add renew basename functionality Add useNameRenew Hook Apr 9, 2025
@cryptobeijing
Copy link
Author

@brendan-defi Hi, I have modified the commit based on your comments. pls review the commit again. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base web review To be reviewed by the Base web team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants