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

feat: Token Picker component #1683

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions playground/nextjs-app-router/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TransactionDemo from './demo/Transaction';
import TransactionDefaultDemo from './demo/TransactionDefault';
import WalletDemo from './demo/Wallet';
import WalletDefaultDemo from './demo/WalletDefault';
import TokenPickerDemo from './demo/TokenPicker';

const activeComponentMapping: Record<OnchainKitComponent, React.FC> = {
[OnchainKitComponent.Fund]: FundDemo,
Expand All @@ -35,6 +36,7 @@ const activeComponentMapping: Record<OnchainKitComponent, React.FC> = {
[OnchainKitComponent.NFTMintCardDefault]: NFTMintCardDefaultDemo,
[OnchainKitComponent.NFTCardDefault]: NFTCardDefaultDemo,
[OnchainKitComponent.IdentityCard]: IdentityCardDemo,
[OnchainKitComponent.TokenPicker]: TokenPickerDemo,
};

function Demo() {
Expand Down
54 changes: 54 additions & 0 deletions playground/nextjs-app-router/components/demo/TokenPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client';

import { Token } from '../../../../src/token';
import { TokenPicker } from '../../../../src/token/components/TokenPicker';
import { useState } from 'react';

export default function TokenPickerDemo() {
const [pickedToken, setPickedToken] = useState<Token>({
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
chainId: 1,
image: 'https://assets.coingecko.com/coins/images/279/small/ethereum.png',
});

const defaultTokens: Token[] = [
{
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
chainId: 1,
image: 'https://assets.coingecko.com/coins/images/279/small/ethereum.png',
},
{
name: 'USDC',
symbol: 'USDC',
decimals: 6,
address: '0x833589fCD6eDb6E08B1Daf2d5eB29B519B68F139',
chainId: 8453,
image: 'https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png',
},
{
name: 'DEGEN',
symbol: 'DEGEN',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
chainId: 8453,
image: 'https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png',
},
];

return (
<div className="flex flex-col items-center justify-center gap-4">
<TokenPicker
pickedToken={pickedToken}
defaultTokens={defaultTokens}
onTokenPicked={setPickedToken}
onError={(error) => console.error(error)}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export function ActiveComponent() {
<SelectItem value={OnchainKitComponent.NFTMintCardDefault}>
NFT Mint Card Default
</SelectItem>
<SelectItem value={OnchainKitComponent.TokenPicker}>
Token Picker
</SelectItem>
</SelectContent>
</Select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion playground/nextjs-app-router/onchainkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/onchainkit",
"version": "0.35.7",
"version": "0.35.8",
"type": "module",
"repository": "https://github.com/coinbase/onchainkit.git",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions playground/nextjs-app-router/types/onchainkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum OnchainKitComponent {
NFTCardDefault = 'nft-card-default',
NFTMintCard = 'nft-mint-card',
NFTMintCardDefault = 'nft-mint-card-default',
TokenPicker = 'token-picker',
}

export enum TransactionTypes {
Expand Down
61 changes: 61 additions & 0 deletions src/token/components/TokenPicker.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import { TokenPicker } from './TokenPicker';
import type { Token } from '../types';

const defaultTokens: Token[] = [
{
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
chainId: 1,
image: 'https://assets.coingecko.com/coins/images/279/small/ethereum.png',
},
{
name: 'USDC',
symbol: 'USDC',
decimals: 6,
address: '0x833589fCD6eDb6E08B1Daf2d5eB29B519B68F139',
chainId: 8453,
image: 'https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png',
},
{
name: 'DEGEN',
symbol: 'DEGEN',
decimals: 18,
address: '0x4ed4e862860bed51a9570b96d89af5e1b0efefed',
chainId: 8453,
image: 'https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png',
},
];

const meta = {
title: 'Token/TokenPicker',
component: TokenPicker,
tags: ['autodocs'],
args: {
pickedToken: defaultTokens[0],
defaultTokens,
onTokenPicked: fn(),
onError: fn(),
},
} satisfies Meta<typeof TokenPicker>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};

export const NoDefaultTokens: Story = {
args: {
defaultTokens: [],
},
};

export const WithError: Story = {
args: {
onError: fn((error: Error) => console.error(error)),
},
};
Loading
Loading