Skip to content
Merged
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
1 change: 1 addition & 0 deletions examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@0xsequence/network": "^2.3.10",
"@0xsequence/waas": "^2.3.10",
"@0xsequence/wallet-widget": "workspace:*",
"@radix-ui/react-select": "^2.2.5",
"@tailwindcss/postcss": "^4.1.4",
"@tanstack/react-query": "^5.74.11",
"example-shared-components": "workspace:*",
Expand Down
25 changes: 13 additions & 12 deletions examples/next/src/app/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import {
useWallets,
validateEthProof
} from '@0xsequence/connect'
import { Button, Card, cn, Select, Text } from '@0xsequence/design-system'
import { Button, Card, cn, Text } from '@0xsequence/design-system'
import { useIndexerClient } from '@0xsequence/hooks'
import { allNetworks, ChainId } from '@0xsequence/network'
import { useOpenWalletModal } from '@0xsequence/wallet-widget'
import { CardButton, Header, WalletListItem } from 'example-shared-components'
import { useEffect, useState, type ComponentProps } from 'react'
import { useCallback, useEffect, useState, type ComponentProps } from 'react'
import { encodeFunctionData, formatUnits, parseAbi, parseUnits } from 'viem'
import { createSiweMessage, generateSiweNonce } from 'viem/siwe'
import { useAccount, useChainId, usePublicClient, useSendTransaction, useWalletClient, useWriteContract } from 'wagmi'

import { isDebugMode, sponsoredContractAddresses } from '../../config'

import { Select } from './Select'

import { messageToSign } from '@/constants'
import { abi } from '@/constants/nft-abi'

Expand Down Expand Up @@ -100,13 +102,7 @@ export const Connected = () => {

const [feeOptionAlert, setFeeOptionAlert] = useState<AlertProps | undefined>(undefined)

useEffect(() => {
if (pendingFeeOptionConfirmation) {
checkTokenBalancesForFeeOptions()
}
}, [pendingFeeOptionConfirmation])

const checkTokenBalancesForFeeOptions = async () => {
const checkTokenBalancesForFeeOptions = useCallback(async () => {
if (pendingFeeOptionConfirmation) {
const [account] = await walletClient!.getAddresses()
const nativeTokenBalance = await indexerClient.getNativeTokenBalance({ accountAddress: account })
Expand Down Expand Up @@ -138,7 +134,13 @@ export const Connected = () => {

setFeeOptionBalances(balances)
}
}
}, [pendingFeeOptionConfirmation, indexerClient, walletClient])

useEffect(() => {
if (pendingFeeOptionConfirmation) {
checkTokenBalancesForFeeOptions()
}
}, [pendingFeeOptionConfirmation, checkTokenBalancesForFeeOptions])

const networkForCurrentChainId = allNetworks.find(n => n.chainId === chainId)!

Expand Down Expand Up @@ -495,7 +497,6 @@ export const Connected = () => {
<div className="my-3">
<Select
name="feeOption"
labelLocation="top"
label="Pick a fee option"
onValueChange={val => {
const selected = pendingFeeOptionConfirmation?.options?.find(option => option.token.name === val)
Expand All @@ -504,7 +505,7 @@ export const Connected = () => {
setFeeOptionAlert(undefined)
}
}}
value={selectedFeeOptionTokenName}
value={selectedFeeOptionTokenName || ''}
options={
pendingFeeOptionConfirmation?.options?.map(option => ({
label: (
Expand Down
85 changes: 85 additions & 0 deletions examples/next/src/app/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { ChevronDownIcon, cn, Field, textVariants } from '@0xsequence/design-system'
import * as SelectPrimitive from '@radix-ui/react-select'
import { forwardRef, type ReactNode, type Ref } from 'react'

type SelectOption = {
label: string | ReactNode
value: string
}

export type SelectProps = SelectPrimitive.SelectProps & {
name: string
label: string
value: string
onValueChange: (value: string) => void
options: SelectOption[]
}

const SelectItem = forwardRef(({ children, className, ...props }: SelectPrimitive.SelectItemProps, ref: Ref<HTMLDivElement>) => {
return (
<SelectPrimitive.Item
className={cn(
textVariants({ variant: 'normal' }),
'flex justify-between items-center px-4 py-3 h-[52px] cursor-pointer rounded-sm',
'text-base text-primary opacity-100 data-disabled:cursor-default data-disabled:opacity-50',
'data-highlighted:bg-background-secondary data-[state=checked]:bg-background-control outline-hidden',
className
)}
{...props}
ref={ref}
>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
)
})

SelectItem.displayName = 'SelectItem'

export const Select = forwardRef((props: SelectProps, ref: Ref<HTMLButtonElement>) => {
const { name, label, options } = props

return (
<Field id={name} label={label} labelLocation={'top'} className="grid whitespace-nowrap">
<SelectPrimitive.Root name={name}>
<SelectPrimitive.Trigger
id={name}
className={cn(
textVariants({ variant: 'normal' }),
'inline-flex items-center justify-between gap-1 p-4 h-[52px] bg-background-primary rounded-xl',
'text-base font-medium text-primary select-none cursor-pointer border-none',
'outline-hidden ring-inset ring-1 ring-border-normal focus-within:ring-2 focus-within:ring-border-focus focus-within:opacity-100',
'[&:has(:disabled)]:cursor-default [&:has(:disabled)]:opacity-50',
'[&:has(:disabled):hover]:cursor-default [&:has(:disabled):hover]:opacity-50'
)}
ref={ref}
>
<SelectPrimitive.Value />
<SelectPrimitive.Icon className="inline-flex">
<ChevronDownIcon />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>

<SelectPrimitive.Portal>
<SelectPrimitive.Content
position="popper"
side="bottom"
align="start"
className="mt-2 p-1 bg-background-backdrop backdrop-blur-md min-w-[var(--radix-select-trigger-width)] rounded-lg overflow-hidden z-30 outline-hidden ring-inset focus-within:ring-2 focus-within:ring-border-focus max-h-[360px] overflow-y-auto"
>
<SelectPrimitive.Viewport>
<SelectPrimitive.Group className="flex flex-col gap-0.5">
{options.map(({ value, label, ...rest }) => (
<SelectItem key={value} value={value} {...rest}>
{label}
</SelectItem>
))}
</SelectPrimitive.Group>
</SelectPrimitive.Viewport>
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
</SelectPrimitive.Root>
</Field>
)
})

Select.displayName = 'Select'
1 change: 1 addition & 0 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@0xsequence/wallet-widget": "workspace:*",
"@imtbl/config": "^2.2.0",
"@imtbl/sdk": "^2.2.0",
"@radix-ui/react-select": "^2.2.5",
"@tanstack/react-query": "^5.74.11",
"clsx": "^2.1.1",
"example-shared-components": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions examples/react/src/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
useWallets,
validateEthProof
} from '@0xsequence/connect'
import { Button, Card, cn, Modal, Scroll, Select, Switch, Text, TextInput } from '@0xsequence/design-system'
import { Button, Card, cn, Modal, Scroll, Switch, Text, TextInput } from '@0xsequence/design-system'
import { allNetworks, ChainId } from '@0xsequence/network'
import { useOpenWalletModal } from '@0xsequence/wallet-widget'
import { CardButton, Header, WalletListItem } from 'example-shared-components'
Expand All @@ -34,6 +34,7 @@ import { abi } from '../constants/nft-abi'
import { delay, getCheckoutSettings, getOrderbookCalldata } from '../utils'

import { CustomCheckout } from './CustomCheckout'
import { Select } from './Select'

// append ?debug to url to enable debug mode
const searchParams = new URLSearchParams(location.search)
Expand Down Expand Up @@ -656,7 +657,6 @@ export const Connected = () => {
<div className="my-3">
<Select
name="feeOption"
labelLocation="top"
label="Pick a fee option"
onValueChange={val => {
const selected = pendingFeeOptionConfirmation?.options?.find(option => option.token.name === val)
Expand All @@ -665,7 +665,7 @@ export const Connected = () => {
setFeeOptionAlert(undefined)
}
}}
value={selectedFeeOptionTokenName}
value={selectedFeeOptionTokenName || ''}
options={[
...pendingFeeOptionConfirmation.options.map(option => ({
label: (
Expand Down
81 changes: 81 additions & 0 deletions examples/react/src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ChevronDownIcon, cn, Field, textVariants } from '@0xsequence/design-system'
import * as SelectPrimitive from '@radix-ui/react-select'
import { forwardRef, type ReactNode, type Ref } from 'react'

type SelectOption = {
label: string | ReactNode
value: string
}

export type SelectProps = SelectPrimitive.SelectProps & {
name: string
label: string
value: string
onValueChange: (value: string) => void
options: SelectOption[]
}

const SelectItem = forwardRef(({ children, className, ...props }: SelectPrimitive.SelectItemProps, ref: Ref<HTMLDivElement>) => {
return (
<SelectPrimitive.Item
className={cn(
textVariants({ variant: 'normal' }),
'flex justify-between items-center px-4 py-3 h-[52px] cursor-pointer rounded-sm',
'text-base text-primary opacity-100 data-disabled:cursor-default data-disabled:opacity-50',
'data-highlighted:bg-background-secondary data-[state=checked]:bg-background-control outline-hidden',
className
)}
{...props}
ref={ref}
>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
)
})

export const Select = forwardRef((props: SelectProps, ref: Ref<HTMLButtonElement>) => {
const { name, label, options } = props

return (
<Field id={name} label={label} labelLocation={'top'} className="grid whitespace-nowrap">
<SelectPrimitive.Root name={name}>
<SelectPrimitive.Trigger
id={name}
className={cn(
textVariants({ variant: 'normal' }),
'inline-flex items-center justify-between gap-1 p-4 h-[52px] bg-background-primary rounded-xl',
'text-base font-medium text-primary select-none cursor-pointer border-none',
'outline-hidden ring-inset ring-1 ring-border-normal focus-within:ring-2 focus-within:ring-border-focus focus-within:opacity-100',
'[&:has(:disabled)]:cursor-default [&:has(:disabled)]:opacity-50',
'[&:has(:disabled):hover]:cursor-default [&:has(:disabled):hover]:opacity-50'
)}
ref={ref}
>
<SelectPrimitive.Value />
<SelectPrimitive.Icon className="inline-flex">
<ChevronDownIcon />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>

<SelectPrimitive.Portal>
<SelectPrimitive.Content
position="popper"
side="bottom"
align="start"
className="mt-2 p-1 bg-background-backdrop backdrop-blur-md min-w-[var(--radix-select-trigger-width)] rounded-lg overflow-hidden z-30 outline-hidden ring-inset focus-within:ring-2 focus-within:ring-border-focus max-h-[360px] overflow-y-auto"
>
<SelectPrimitive.Viewport>
<SelectPrimitive.Group className="flex flex-col gap-0.5">
{options.map(({ value, label, ...rest }) => (
<SelectItem key={value} value={value} {...rest}>
{label}
</SelectItem>
))}
</SelectPrimitive.Group>
</SelectPrimitive.Viewport>
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
</SelectPrimitive.Root>
</Field>
)
})
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.