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

refactor: better TokenBalance #2068

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

Conversation

brendan-defi
Copy link
Contributor

@brendan-defi brendan-defi commented Mar 4, 2025

What changed? Why?

  • Refactored the "Action Button" (typically "use max")
  • Refactored types to be discriminated unions that disallow erroneous prop combinations

Notes to reviewers

How has it been tested?

  • locally, playground, test coverage

Copy link

vercel bot commented Mar 4, 2025

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

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 7:15pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 7:15pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 7:15pm

@@ -141,3 +139,31 @@ function TokenBalanceContent({
</div>
);
}

function TokenBalanceActionButton({
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this isn't used anywhere outside of TokenBalance I think it'd be better to call this ActionButton or even Action - TokenBalance isn't really adding much

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, i've renamed

import { formatUnits } from 'viem';
import type { TokenBalanceProps } from '../types';

export function TokenBalance({
token,
onClick,
onActionPress,
actionText = 'Use max',
Copy link
Contributor

Choose a reason for hiding this comment

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

swap is just "max", should this match?

@cpcramer
Copy link
Contributor

cpcramer commented Mar 6, 2025

nit: title category should fall under chore, fix, feat, or docs.

chore: Update TokenBalance

Comment on lines +153 to +154
/** Hide the token image */
showImage: false;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
/** Hide the token image */
showImage: false;
/** Hide the token image (default: false) */
showImage: false;

Comment on lines +161 to +162
/** Hide the action button (default)*/
onActionPress?: never;
Copy link
Contributor

@cpcramer cpcramer Mar 6, 2025

Choose a reason for hiding this comment

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

What's the default here? The code comment looks unfinished

@@ -141,3 +139,31 @@ function TokenBalanceContent({
</div>
);
}

function ActionButton({
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on putting ActionButton and or TokenBalanceContent in a separate file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like TokenBalanceContent should be extracted

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

Successfully merging this pull request may close these issues.

4 participants