Skip to content

Commit

Permalink
Exporting kit components, hooks, contexts as separate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed May 13, 2024
1 parent aea324f commit 57f6693
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 89 deletions.
4 changes: 3 additions & 1 deletion examples/next/src/app/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { kitConfig, wagmiConfig } from '@/config'
const queryClient = new QueryClient()

export interface ProvidersProps {
initialState: State
initialState: State | undefined
children: React.ReactNode
// wagmiConfig: Config
// kitConfig: KitConfig
Expand All @@ -20,6 +20,8 @@ export interface ProvidersProps {
export const Providers = (props: ProvidersProps) => {
const { initialState, children /* , wagmiConfig, kitConfig */ } = props

console.log('initialState', initialState)

return (
<WagmiProvider config={wagmiConfig} initialState={initialState}>
<QueryClientProvider client={queryClient}>
Expand Down
3 changes: 2 additions & 1 deletion examples/next/src/app/components/Connected.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Text, Card, Button, Select, SignoutIcon } from '@0xsequence/design-system'
import { signEthAuthProof, useIndexerClient, useWaasFeeOptions, validateEthProof } from '@0xsequence/kit'
import { signEthAuthProof, validateEthProof } from '@0xsequence/kit'
import { useIndexerClient, useWaasFeeOptions } from '@0xsequence/kit/hooks'
import { CheckoutSettings } from '@0xsequence/kit-checkout'
import { useOpenWalletModal } from '@0xsequence/kit-wallet'
import { allNetworks } from '@0xsequence/network'
Expand Down
15 changes: 8 additions & 7 deletions examples/next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import './globals.css'
import '@0xsequence/design-system/styles.css'
import { ThemeProvider } from '@0xsequence/design-system'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { headers } from 'next/headers'
import { cookieToInitialState } from 'wagmi'

import './globals.css'
import '@0xsequence/design-system/styles.css'

import { wagmiConfig, kitConfig } from '../config'
import { wagmiConfig } from '../config'

import { Providers } from './Providers'

Expand All @@ -21,13 +22,13 @@ export default function RootLayout({
}: Readonly<{
children: React.ReactNode
}>) {
const initialState = cookieToInitialState(wagmiConfig, headers().get('cookie'))

return (
<html lang="en">
<body className={inter.className}>
<ThemeProvider theme="dark">
<Providers wagmiConfig={wagmiConfig} kitConfig={kitConfig}>
{children}
</Providers>
<Providers initialState={initialState}>{children}</Providers>
</ThemeProvider>
</body>
</html>
Expand Down
58 changes: 24 additions & 34 deletions examples/next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
'use client'

import { Box, Image, Button } from '@0xsequence/design-system'
import { useOpenConnectModal } from '@0xsequence/kit'
import { useOpenConnectModal } from '@0xsequence/kit/hooks'
import { useEffect, useState } from 'react'
import { useAccount } from 'wagmi'

import { Connected } from './components/Connected'
import { Footer } from './components/Footer'

export default function Home() {
const [isClient, setIsClient] = useState(false)
const { isConnected } = useAccount()
const { setOpenConnectModal } = useOpenConnectModal()

useEffect(() => {
setIsClient(true)
}, [])

return (
<main>
{isClient ? (
<>
{!isConnected ? (
<Box flexDirection="column" alignItems="center" justifyContent="center" gap="5" height="vh">
<Box background="white" padding="2" borderRadius="sm">
<Image alt="Next" src="next.svg" height="3" />
</Box>
<Box flexDirection="row" alignItems="center" justifyContent="center" gap="3">
<Image alt="Sequence Kit Logo" style={{ width: '48px' }} src="kit-logo.svg" />
<Image
alt="Sequence Kit Text Logo"
style={{
width: '32px'
// filter: theme === 'dark' ? 'invert(0)' : 'invert(1)'
}}
src="kit-logo-text.svg"
/>
</Box>
<Box gap="2" flexDirection="row" alignItems="center">
<Button onClick={() => setOpenConnectModal(true)} variant="feature" label="Connect" />
</Box>
</Box>
) : (
<Connected />
)}
</>
) : null}

{!isConnected ? (
<Box flexDirection="column" alignItems="center" justifyContent="center" gap="5" height="vh">
<Box background="white" padding="2" borderRadius="sm">
<Image alt="Next" src="next.svg" height="3" disableAnimation />
</Box>
<Box flexDirection="row" alignItems="center" justifyContent="center" gap="3">
<Image alt="Sequence Kit Logo" style={{ width: '48px' }} src="kit-logo.svg" disableAnimation />
<Image
alt="Sequence Kit Text Logo"
style={{
width: '32px'
}}
src="kit-logo-text.svg"
disableAnimation
/>
</Box>
<Box gap="2" flexDirection="row" alignItems="center">
<Button onClick={() => setOpenConnectModal(true)} variant="feature" label="Connect" />
</Box>
</Box>
) : (
<Connected />
)}
<Footer />
</main>
)
Expand Down
9 changes: 5 additions & 4 deletions examples/next/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { KitConfig, getKitConnectWallets } from '@0xsequence/kit'
import { getDefaultConnectors, getDefaultWaasConnectors, mock } from '@0xsequence/kit-connectors'
import { findNetworkConfig, allNetworks } from '@0xsequence/network'
import { Transport, zeroAddress } from 'viem'
import { createConfig, createStorage, http, noopStorage } from 'wagmi'
import { createConfig, createStorage, http, noopStorage, cookieStorage } from 'wagmi'
import { Chain, arbitrumNova, arbitrumSepolia, mainnet, polygon } from 'wagmi/chains'

export type ConnectionMode = 'waas' | 'universal'
Expand Down Expand Up @@ -83,9 +83,10 @@ export const wagmiConfig = createConfig({
transports,
chains,
connectors: connectionMode === 'waas' ? getWaasConnectors() : getUniversalConnectors(),
storage: createStorage({
storage: typeof window !== 'undefined' && window.localStorage ? window.localStorage : noopStorage
}),
// storage: createStorage({
// storage: typeof window !== 'undefined' && window.localStorage ? window.localStorage : noopStorage
// }),
storage: createStorage({ storage: cookieStorage }),
ssr: true
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Modal, ThemeProvider } from '@0xsequence/design-system'
import { getModalPositionCss, useTheme } from '@0xsequence/kit'
import { getModalPositionCss } from '@0xsequence/kit'
import { useTheme } from '@0xsequence/kit/hooks'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { AnimatePresence } from 'framer-motion'
import React, { useState, useEffect } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Card, Image, Text, Skeleton, TokenImage, NetworkImage } from '@0xsequence/design-system'
import { useContractInfo, useTokenMetadata } from '@0xsequence/kit'
import { useContractInfo, useTokenMetadata } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'

Expand Down
3 changes: 2 additions & 1 deletion packages/checkout/src/views/CheckoutSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
Skeleton,
TokenImage
} from '@0xsequence/design-system'
import { getNativeTokenInfoByChainId, useBalances, useContractInfo, useTokenMetadata, useProjectAccessKey } from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useBalances, useContractInfo, useTokenMetadata, useProjectAccessKey } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'
import { useAccount, useConfig } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/src/views/PendingTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box } from '@0xsequence/design-system'
import { useProjectAccessKey } from '@0xsequence/kit'
import { useProjectAccessKey } from '@0xsequence/kit/hooks'
import React, { useEffect } from 'react'

import { fetchSardineOrderStatus } from '../api'
Expand Down
4 changes: 4 additions & 0 deletions packages/kit/components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "dist/0xsequence-kit-components.cjs.js",
"module": "dist/0xsequence-kit-components.esm.js"
}
4 changes: 4 additions & 0 deletions packages/kit/contexts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "dist/0xsequence-kit-contexts.cjs.js",
"module": "dist/0xsequence-kit-contexts.esm.js"
}
4 changes: 4 additions & 0 deletions packages/kit/hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "dist/0xsequence-kit-hooks.cjs.js",
"module": "dist/0xsequence-kit-hooks.esm.js"
}
15 changes: 13 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
},
"files": [
"src",
"dist"
]
"dist",
"components",
"hooks",
"contexts"
],
"preconstruct": {
"entrypoints": [
"index.ts",
"components/index.ts",
"hooks/index.ts",
"contexts/index.ts"
]
}
}
2 changes: 2 additions & 0 deletions packages/kit/src/components/KitProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { sequence } from '0xsequence'
import { Box, Button, Card, Collapsible, Modal, Text, ThemeProvider } from '@0xsequence/design-system'
import { GoogleOAuthProvider } from '@react-oauth/google'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/components/TxnDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commons } from '@0xsequence/core'
import { Box, Card, GradientAvatar, Skeleton, Text, TokenImage } from '@0xsequence/design-system'
import { ContractType } from '@0xsequence/indexer'
import { useTokenMetadata, useBalances } from '@0xsequence/kit'
import { useTokenMetadata, useBalances } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React, { useEffect, useState } from 'react'
import { useConfig } from 'wagmi'
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
'use client'

export * from './KitProvider'
2 changes: 2 additions & 0 deletions packages/kit/src/contexts/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { sequence } from '0xsequence'
import React from 'react'

Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './components'
// export * from './components'
// export * from './hooks'
// export * from './contexts'
export * from './constants'
export * from './hooks'
export * from './contexts'
export * from './utils'
export * from './types'
4 changes: 2 additions & 2 deletions packages/wallet/src/hooks/data.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { SequenceAPIClient, TokenPrice } from '@0xsequence/api'
import { Transaction, TokenBalance, SequenceIndexer } from '@0xsequence/indexer'
import { DisplayedAsset } from '@0xsequence/kit'
import {
getTransactionHistory,
useAPIClient,
useIndexerClients,
DisplayedAsset,
getNativeTokenBalance,
getTokenBalances,
getCoinPrices,
getCollectionBalance,
useMetadataClient
} from '@0xsequence/kit'
} from '@0xsequence/kit/hooks'
import { GetContractInfoBatchReturn, SequenceMetadata } from '@0xsequence/metadata'
import { useQuery } from '@tanstack/react-query'
import { ethers } from 'ethers'
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/src/shared/KitWalletProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Modal, ThemeProvider, Scroll } from '@0xsequence/design-system'
import { getModalPositionCss, useTheme } from '@0xsequence/kit'
import { getModalPositionCss } from '@0xsequence/kit'
import { useTheme } from '@0xsequence/kit/hooks'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { AnimatePresence } from 'framer-motion'
import React, { useState, useEffect } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TokenPrice } from '@0xsequence/api'
import { ArrowRightIcon, Box, Text, Image, TransactionIcon, vars, Skeleton, NetworkImage } from '@0xsequence/design-system'
import { Transaction, TxnTransfer, TxnTransferType } from '@0xsequence/indexer'
import { getNativeTokenInfoByChainId, useCoinPrices, useExchangeRate } from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useCoinPrices, useExchangeRate } from '@0xsequence/kit/hooks'
import dayjs from 'dayjs'
import { ethers } from 'ethers'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TransactionIcon,
vars
} from '@0xsequence/design-system'
import { useTheme } from '@0xsequence/kit'
import { useTheme } from '@0xsequence/kit/hooks'
import React, { forwardRef } from 'react'
import { useDisconnect, useAccount } from 'wagmi'

Expand Down
9 changes: 2 additions & 7 deletions packages/wallet/src/views/CoinDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Box, Button, Image, SendIcon, Text } from '@0xsequence/design-system'
import {
getNativeTokenInfoByChainId,
useExchangeRate,
useCoinPrices,
useTransactionHistory,
useCoinBalance
} from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useExchangeRate, useCoinPrices, useTransactionHistory, useCoinBalance } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'
import { useAccount, useConfig } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/src/views/CollectibleDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, Image, NetworkImage, SendIcon, Text } from '@0xsequence/design-system'
import { useExchangeRate, useTransactionHistory, useCollectiblePrices, useCollectibleBalance } from '@0xsequence/kit'
import { useExchangeRate, useTransactionHistory, useCollectiblePrices, useCollectibleBalance } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'
import { useAccount } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/src/views/CollectionDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Image, Text, TokenImage, vars } from '@0xsequence/design-system'
import { TokenBalance } from '@0xsequence/indexer'
import { useCollectionBalance } from '@0xsequence/kit'
import { useCollectionBalance } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'
import { useAccount } from 'wagmi'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Box } from '@0xsequence/design-system'
import { TokenBalance } from '@0xsequence/indexer'
import { getNativeTokenInfoByChainId, useContractInfo, useExchangeRate, useCoinPrices } from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useContractInfo, useExchangeRate, useCoinPrices } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import React from 'react'
import { useConfig } from 'wagmi'


import { useSettings } from '../../../../../hooks'
import { computeBalanceFiat, formatDisplay, getPercentagePriceChange, compareAddress } from '../../../../../utils'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TokenBalance } from '@0xsequence/indexer'
import { useTokenMetadata } from '@0xsequence/kit'
import { useTokenMetadata } from '@0xsequence/kit/hooks'
import React from 'react'

import { CollectibleTileImage } from '../../../../../shared/CollectibleTileImage'


interface CollectibleTileProps {
balance: TokenBalance
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, vars } from '@0xsequence/design-system'
import { TokenBalance } from '@0xsequence/indexer'
import { useWalletSettings } from '@0xsequence/kit'
import { useWalletSettings } from '@0xsequence/kit/hooks'
import React from 'react'
import { useAccount } from 'wagmi'

Expand All @@ -11,7 +11,6 @@ import { CoinTile } from './CoinTile'
import { CollectibleTile } from './CollectibleTile'
import { SkeletonTiles } from './SkeletonTiles'


export const AssetSummary = () => {
const { address } = useAccount()
const { setNavigation } = useNavigation()
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/src/views/Search/SearchWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, SearchIcon, Skeleton, Text, TextInput } from '@0xsequence/design-system'
import { getNativeTokenInfoByChainId, useExchangeRate, useCoinPrices, useBalances } from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useExchangeRate, useCoinPrices, useBalances } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import Fuse from 'fuse.js'
import React, { useState } from 'react'
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/src/views/Search/SearchWalletViewAll.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, SearchIcon, Skeleton, TabsContent, TabsHeader, TabsRoot, Text, TextInput } from '@0xsequence/design-system'
import { getNativeTokenInfoByChainId, useExchangeRate, useCoinPrices, useBalances } from '@0xsequence/kit'
import { getNativeTokenInfoByChainId } from '@0xsequence/kit'
import { useExchangeRate, useCoinPrices, useBalances } from '@0xsequence/kit/hooks'
import { ethers } from 'ethers'
import Fuse from 'fuse.js'
import React, { useState, useEffect } from 'react'
Expand Down
Loading

0 comments on commit 57f6693

Please sign in to comment.