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

Refine Package Exports #51

Merged
merged 7 commits into from
May 15, 2024
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
3 changes: 2 additions & 1 deletion examples/react-waas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "vite --port 4444",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"0xsequence": "^1.9.26",
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/src/api/data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TokenMetadata } from '@0xsequence/metadata'
import { ChainId, networks } from '@0xsequence/network'

import { SardineCheckout } from '..'
import { SardineCheckout } from '../contexts/CheckoutModal'

export interface FetchSardineClientTokenReturn {
token: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createGenericContext, Theme } from '@0xsequence/kit'
import { Theme } from '@0xsequence/kit'

import { createGenericContext } from './genericContext'

interface CoinQuantity {
contractAddress: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createGenericContext } from '@0xsequence/kit'
import { createGenericContext } from './genericContext'

export interface SelectCheckoutNavigation {
location: 'select-method-checkout'
Expand Down
7 changes: 7 additions & 0 deletions packages/checkout/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Provider
export { KitCheckoutProvider } from './shared/components/KitCheckoutProvider'

// Hooks
export { useCheckoutModal } from './hooks/useCheckoutModal'

export { type CheckoutSettings } from './contexts/CheckoutModal'
3 changes: 0 additions & 3 deletions packages/checkout/src/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/connectors/src/connectors/apple/AppleLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

interface GetAppleLogo {
isDarkMode: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const CoinbaseWalletLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

interface GetDiscordLogo {
isDarkMode: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/connectors/src/connectors/email/EmailLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

interface GetEmailLogo {
isDarkMode: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const FacebookLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/connectors/src/connectors/google/GoogleLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const GoogleLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
14 changes: 0 additions & 14 deletions packages/connectors/src/connectors/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const InjectedLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const MetamaskLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const SequenceLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/connectors/src/connectors/twitch/TwitchLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

interface GetTwitchLogo {
isDarkMode?: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { LogoProps } from '../types'
import { LogoProps } from '../../types'

export const WalletConnectLogo: React.FunctionComponent = (props: LogoProps) => {
return (
Expand Down
10 changes: 9 additions & 1 deletion packages/connectors/src/defaultConnectors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { getKitConnectWallets } from '@0xsequence/kit'
import { CreateConnectorFn } from 'wagmi'

import { apple, coinbaseWallet, email, facebook, google, metamask, sequence, twitch, walletConnect } from './connectors'
import { apple } from './connectors/apple'
import { appleWaas } from './connectors/apple/appleWaas'
// import { emailWaas } from './connectors/email/emailWaas'
import { coinbaseWallet } from './connectors/coinbaseWallet'
import { email } from './connectors/email'
import { facebook } from './connectors/facebook'
import { google } from './connectors/google'
import { googleWaas } from './connectors/google/googleWaas'
import { metamask } from './connectors/metamask'
import { sequence } from './connectors/sequence'
import { twitch } from './connectors/twitch'
import { walletConnect } from './connectors/walletConnect'

interface GetDefaultConnectors {
walletConnectProjectId: string
Expand Down
26 changes: 24 additions & 2 deletions packages/connectors/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
export * from './connectors'
export * from './defaultConnectors'
// Connectors
export { apple, type AppleOptions } from './connectors/apple'
export { coinbaseWallet } from './connectors/coinbaseWallet'
export { discord, type DiscordOptions } from './connectors/discord'
export { email, type EmailOptions } from './connectors/email'
export { facebook, type FacebookOptions } from './connectors/facebook'
export { google, type GoogleOptions } from './connectors/google'
export { injected } from './connectors/injected'
export { metamask } from './connectors/metamask'
export { mock } from './connectors/mock'
export { sequence, type SequenceOptions } from './connectors/sequence'
export { twitch, type TwitchOptions } from './connectors/twitch'
export { walletConnect } from './connectors/walletConnect'
export {
sequenceWallet,
sequenceWaasWallet,
type BaseSequenceConnectorOptions,
type BaseSequenceWaasConnectorOptions
} from './connectors/wagmiConnectors'

// Default Connectors
export { getDefaultConnectors, getDefaultWaasConnectors } from './defaultConnectors'

export type { LogoProps } from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { appleAuthHelpers, useScript } from 'react-apple-signin-auth'
import { useConnect, useAccount } from 'wagmi'

import { LocalStorageKey, defaultSignInOptions } from '../../../constants'
import { useStorage, useStorageItem } from '../../../hooks'
import { useStorage, useStorageItem } from '../../../hooks/useStorage'
import { useEmailAuth } from '../../../hooks/useWaasEmailAuth'
import { ExtendedConnector, KitConfig } from '../../../types'
import { isEmailValid } from '../../../utils'
import { isEmailValid } from '../../../utils/helpers'
import { KitConnectProviderProps } from '../index'

import { Banner } from './Banner'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/components/KitProvider/NetworkBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, NetworkImage, Text } from '@0xsequence/design-system'
import { getNetwork, getNetworkColor, getNetworkBackgroundColor } from '@0xsequence/kit'
import React from 'react'

import { capitalize } from '../../utils/string'
import { capitalize } from '../../utils/helpers'

interface NetworkBadgeProps {
chainId: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { ethers } from 'ethers'
import React, { useEffect, useState } from 'react'
import { useConfig } from 'wagmi'

import { useAPIClient } from '../../hooks'
import { capitalize, compareAddress, getNativeTokenInfoByChainId } from '../../utils'
import { DecodingType, TransferProps, AwardItemProps, decodeTransactions } from '../../utils/txnDecoding'
import { CollectibleTileImage } from '../KitProvider/CollectibleTileImage'
import { useAPIClient } from '../../../hooks/useAPIClient'
import { compareAddress, capitalize } from '../../../utils/helpers'
import { getNativeTokenInfoByChainId } from '../../../utils/tokens'
import { DecodingType, TransferProps, AwardItemProps, decodeTransactions } from '../../../utils/txnDecoding'
import { CollectibleTileImage } from '../CollectibleTileImage'

interface TxnDetailsProps {
address: string
Expand Down
18 changes: 8 additions & 10 deletions packages/kit/src/components/KitProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ import { Connector, useAccount, useConfig, useConnections } from 'wagmi'
import '@0xsequence/design-system/styles.css'

import { DEFAULT_SESSION_EXPIRATION, LocalStorageKey } from '../../constants'
import {
KitConfigContextProvider,
ConnectModalContextProvider,
ThemeContextProvider,
WalletConfigContextProvider,
AnalyticsContextProvider
} from '../../contexts'
import { useStorage } from '../../hooks'
import { AnalyticsContextProvider } from '../../contexts/Analytics'
import { ConnectModalContextProvider } from '../../contexts/ConnectModal'
import { KitConfigContextProvider } from '../../contexts/KitConfig'
import { ThemeContextProvider } from '../../contexts/Theme'
import { WalletConfigContextProvider } from '../../contexts/WalletSettings'
import { useStorage } from '../../hooks/useStorage'
import { useWaasConfirmationHandler } from '../../hooks/useWaasConfirmationHandler'
import { ExtendedConnector, DisplayedAsset, EthAuthSettings, KitConfig, Theme, ModalPosition } from '../../types'
import { getModalPositionCss } from '../../utils'
import { TxnDetails } from '../TxnDetails'
import { getModalPositionCss } from '../../utils/styling'

import { ConnectWalletContent } from './ConnectWalletContent'
import { NetworkBadge } from './NetworkBadge'
import { SequenceLogo } from './SequenceLogo'
import { TxnDetails } from './TxnDetails'

export type KitConnectProviderProps = {
children: React.ReactNode
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/components/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kit/src/contexts/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sequence } from '0xsequence'
import React from 'react'

import { createGenericContext } from '../utils'
import { createGenericContext } from './genericContext'

type AnalyticsContext = {
setAnalytics: React.Dispatch<React.SetStateAction<sequence.SequenceClient['analytics']>>
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/contexts/ConnectModal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { createGenericContext } from '../utils'
import { createGenericContext } from './genericContext'

type ConnectModalContext = {
setOpenConnectModal: React.Dispatch<React.SetStateAction<boolean>>
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/contexts/KitConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { KitConfig } from '../types'
import { createGenericContext } from '../utils'

import { createGenericContext } from './genericContext'

export const [useKitConfig, KitConfigContextProvider] = createGenericContext<KitConfig>()
3 changes: 2 additions & 1 deletion packages/kit/src/contexts/Theme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'

import { ModalPosition, Theme } from '../index'
import { createGenericContext } from '../utils'

import { createGenericContext } from './genericContext'

type ThemeContext = {
setTheme: React.Dispatch<React.SetStateAction<Theme>>
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/contexts/WalletSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'

import { DisplayedAsset } from '../types'
import { createGenericContext } from '../utils'

import { createGenericContext } from './genericContext'

type WalletConfigContext = {
setDisplayedAssets: React.Dispatch<React.SetStateAction<DisplayedAsset[]>>
Expand Down
19 changes: 19 additions & 0 deletions packages/kit/src/contexts/genericContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useContext, createContext } from 'react'

// https://medium.com/@rivoltafilippo/typing-react-context-to-avoid-an-undefined-default-value-2c7c5a7d5947

export const createGenericContext = <T>() => {
// Create a context with a generic parameter or undefined
const genericContext = createContext<T | undefined>(undefined)

// Check if the value provided to the context is defined or throw an error
const useGenericContext = () => {
const contextIsDefined = useContext(genericContext)
if (!contextIsDefined) {
throw new Error('useGenericContext must be used within a Provider')
}
return contextIsDefined
}

return [useGenericContext, genericContext.Provider] as const
}
6 changes: 0 additions & 6 deletions packages/kit/src/contexts/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/kit/src/hooks/index.ts

This file was deleted.

Loading