Skip to content

Commit

Permalink
refactor: separate react export for siwe hooks, update lab examples a…
Browse files Browse the repository at this point in the history
…nd configs
  • Loading branch information
enesozturk committed Oct 14, 2024
1 parent ff46923 commit f37e111
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@examples/*"]
"ignore": ["@examples/*", "@services/*"]
}
2 changes: 1 addition & 1 deletion apps/laboratory/src/components/AppKitAuthInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from 'react'

import { AppKitInfo } from './AppKitInfo'
import { useSiweSession } from '@reown/appkit-siwe'
import { useSiweSession } from '@reown/appkit-siwe/react'

export function AppKitAuthInfo() {
const { session, status } = useSiweSession()
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/src/components/Siwe/SiweData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Text
} from '@chakra-ui/react'
import { useSession } from 'next-auth/react'
import type { SIWESession } from '@reown/appkit-siwe'
import type { SIWESession } from '@reown/appkit-siwe/react'

export function SiweData() {
const { data, status } = useSession()
Expand Down
6 changes: 5 additions & 1 deletion apps/laboratory/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import nextAuth from 'next-auth'
import credentialsProvider from 'next-auth/providers/credentials'
import { type SIWESession, getChainIdFromMessage, getAddressFromMessage } from '@reown/appkit-siwe'
import {
type SIWESession,
getChainIdFromMessage,
getAddressFromMessage
} from '@reown/appkit-siwe/react'
import { verifySignature } from '../../../utils/SignatureUtil'

declare module 'next-auth' {
Expand Down
8 changes: 6 additions & 2 deletions apps/laboratory/src/utils/SiweUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { SIWECreateMessageArgs, SIWESession, SIWEVerifyMessageArgs } from '@reown/appkit-siwe'
import { createSIWEConfig, formatMessage } from '@reown/appkit-siwe'
import type {
SIWECreateMessageArgs,
SIWESession,
SIWEVerifyMessageArgs
} from '@reown/appkit-siwe/react'
import { createSIWEConfig, formatMessage } from '@reown/appkit-siwe/react'
import { getCsrfToken, getSession, signIn, signOut } from 'next-auth/react'

export const siweConfig = createSIWEConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/siwe/core/utils/TypeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface SIWECreateMessageArgs {
export type SIWEMessageArgs = {
/**
* @deprecated - Chains are set based on the `networks` you provided to the `createAppKit` function.
* @see https://docs.reown.com/appkit/react/core/installation#implementation
* @see https://docs.reown.com/appkit/react/core/options#networks
*/
chains?: number[]
methods?: string[]
Expand Down
1 change: 0 additions & 1 deletion packages/siwe/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export {
getChainIdFromMessage,
verifySignature
} from '../core/helpers/index.js'
export { useSiweSession } from '../core/hooks/react.js'
export * from '../core/utils/AppKitAuthUtil.js'

export { formatMessage, getDidAddress, getDidChainId } from '@walletconnect/utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
import { OptionsController } from '@reown/appkit-core'
import { useEffect, useState } from 'react'
import { SIWEController } from '../controller/SIWEController.js'

import type {
SIWEClientMethods,
SIWEConfig,
SIWECreateMessageArgs,
SIWESession,
SIWEVerifyMessageArgs
} from '../core/utils/TypeUtils.js'
import { AppKitSIWEClient } from '../src/client.js'
import { SIWEController } from '../core/controller/SIWEController.js'
export {
getAddressFromMessage,
getChainIdFromMessage,
verifySignature
} from '../core/helpers/index.js'
export * from '../core/utils/AppKitAuthUtil.js'

export { formatMessage, getDidAddress, getDidChainId } from '@walletconnect/utils'
export { SIWEController, type SIWEControllerClient } from '../core/controller/SIWEController.js'
export * from '../core/utils/TypeUtils.js'
export type {
AppKitSIWEClient,
SIWEClientMethods,
SIWEConfig,
SIWECreateMessageArgs,
SIWESession,
SIWEVerifyMessageArgs
}

export * from '../scaffold/partials/w3m-connecting-siwe/index.js'
export * from '../scaffold/views/w3m-connecting-siwe-view/index.js'

export function createSIWEConfig(siweConfig: SIWEConfig) {
return new AppKitSIWEClient(siweConfig)
}

// -- Hooks ------------------------------------------------------------

export function useSiweSession() {
if (
Expand Down
21 changes: 20 additions & 1 deletion packages/siwe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,32 @@
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"exports": {
".": {
"types": "./dist/types/exports/index.d.ts",
"import": "./dist/esm/exports/index.js",
"default": "./dist/esm/exports/index.js"
},
"./react": {
"types": "./dist/types/exports/react.d.ts",
"import": "./dist/esm/exports/react.js",
"default": "./dist/esm/exports/react.js"
}
},
"typesVersions": {
"*": {
"react": [
"./dist/types/exports/react.d.ts"
]
}
},
"dependencies": {
"@walletconnect/utils": "2.17.0",
"@reown/appkit-core": "workspace:*",
"@reown/appkit-ui": "workspace:*",
"@reown/appkit-common": "workspace:*",
"@reown/appkit-wallet": "workspace:*",
"@reown/appkit-utils": "workspace:*",
"@walletconnect/utils": "2.17.0",
"valtio": "1.11.2",
"lit": "3.1.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/siwe/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"compilerOptions": {
"composite": true,
"outDir": "./dist/esm",
"declarationDir": "./dist/types"
"declarationDir": "./dist/types",
"removeComments": false
},
"extends": "../../tsconfig.json",
"include": ["exports", "src", "core", "scaffold", "tests"]
Expand Down
Loading

0 comments on commit f37e111

Please sign in to comment.