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

limit kit export & fix git status is dirty #2047

Merged
merged 2 commits into from
Jul 2, 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
2 changes: 0 additions & 2 deletions .github/workflows/check_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jobs:
## Build and test app start
- name: Install pnpm dependencies
run: npm install [email protected] -g && pnpm install
- name: Gen SDK dependencie Code
run: pnpm rooch-sdk gen
- name: Lint
run: pnpm lint
continue-on-error: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import { useContext } from 'react'

import { RoochClientContext, RoochClientProviderContext } from '../../provider/index.js'
import { ClientContext, ClientProviderContext } from '../../provider/clientProvider.js'

export function useRoochContext(): RoochClientProviderContext {
const context = useContext(RoochClientContext)
export function useRoochContext(): ClientProviderContext {
const context = useContext(ClientContext)
if (!context) {
throw new Error(
'Could not find RoochClientContext. Ensure that you have set up the RoochClientProvider.',
Expand Down
1 change: 0 additions & 1 deletion sdk/typescript/rooch-sdk-kit/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from './client/index.js'
export * from './wallet/index.js'
export * from './useCurrentSession.js'
export * from './useSessions.js'
export * from './useSessionsStore.js'
export * from './useRemoveSession.js'
4 changes: 2 additions & 2 deletions sdk/typescript/rooch-sdk-kit/src/hooks/useCurrentSession.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { useRoochSessionStore } from './index.js'
import { useSessionStore } from './useSessionsStore.js'

/**
* Retrieves the session account that is currently selected, if one exists.
*/
export function useCurrentSession() {
return useRoochSessionStore((state) => state.currentSession)
return useSessionStore((state) => state.currentSession)
}
7 changes: 4 additions & 3 deletions sdk/typescript/rooch-sdk-kit/src/hooks/useRemoveSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useMutation } from '@tanstack/react-query'

import { Session } from '@roochnetwork/rooch-sdk'
import { roochMutationKeys } from '../constants/index.js'
import { useCurrentSession, useRoochClient, useRoochSessionStore, useSession } from './index.js'
import { useCurrentSession, useRoochClient, useSession } from './index.js'
import { useSessionStore } from './useSessionsStore.js'

type UseRemoveSessionArgs = {
authKey: string
Expand All @@ -29,8 +30,8 @@ export function useRemoveSession({
unknown
> {
const sessionsKeys = useSession()
const removeSession = useRoochSessionStore((state) => state.removeSession)
const setCurrentSession = useRoochSessionStore((state) => state.setCurrentSession)
const removeSession = useSessionStore((state) => state.removeSession)
const setCurrentSession = useSessionStore((state) => state.setCurrentSession)
const currentSession = useCurrentSession()
const client = useRoochClient()
const curSessionKey = useCurrentSession()
Expand Down
4 changes: 2 additions & 2 deletions sdk/typescript/rooch-sdk-kit/src/hooks/useSessions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { useRoochSessionStore } from './index.js'
import { useSessionStore } from './useSessionsStore.js'

/**
* Retrieves the all session account
*/
export function useSession() {
return useRoochSessionStore((state) =>
return useSessionStore((state) =>
state.sessions.sort((a, b) => b.getCreateTime() - a.getCreateTime()),
)
}
4 changes: 2 additions & 2 deletions sdk/typescript/rooch-sdk-kit/src/hooks/useSessionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import { useContext } from 'react'
import { useStore } from 'zustand'

import { SessionStoreState } from '../provider/roochStore.js'
import { SessionStoreState } from '../provider/sessionStore.js'
import { RoochContext } from '../provider/index.js'

export function useRoochSessionStore<T>(selector: (state: SessionStoreState) => T): T {
export function useSessionStore<T>(selector: (state: SessionStoreState) => T): T {
const store = useContext(RoochContext)
if (!store) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ThirdPartyAddress, Session } from '@roochnetwork/rooch-sdk'
import { useWalletStore } from './useWalletStore.js'
import { walletMutationKeys } from '../../constants/index.js'
import { Wallet } from '../../wellet/index.js'
import { useRoochSessionStore } from '../useSessionsStore.js'
import { useSessionStore } from '../useSessionsStore.js'
import { useSession } from '../useSessions.js'

type ConnectWalletArgs = {
Expand All @@ -35,7 +35,7 @@ export function useConnectWallet({
unknown
> {
const sessions = useSession()
const setCurrentSession = useRoochSessionStore((state) => state.setCurrentSession)
const setCurrentSession = useSessionStore((state) => state.setCurrentSession)
const setWalletConnected = useWalletStore((state) => state.setWalletConnected)
const setConnectionStatus = useWalletStore((state) => state.setConnectionStatus)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useRoochClient } from '../client/index.js'
import { useCurrentWallet } from './useCurrentWallet.js'
import { walletMutationKeys } from '../../constants/index.js'
import { WalletNotConnectedError } from '../../error/walletErrors.js'
import { useRoochSessionStore } from '../useSessionsStore.js'
import { useSessionStore } from '../useSessionsStore.js'

type UseCreateSessionKeyArgs = CreateSessionArgs

Expand Down Expand Up @@ -39,7 +39,7 @@ export function useCreateSessionKey({
> {
const client = useRoochClient()
const currentWallet = useCurrentWallet()
const setCurrentSession = useRoochSessionStore((state) => state.setCurrentSession)
const setCurrentSession = useSessionStore((state) => state.setCurrentSession)

return useMutation({
mutationKey: walletMutationKeys.createSessionKey(mutationKey),
Expand Down
13 changes: 7 additions & 6 deletions sdk/typescript/rooch-sdk-kit/src/provider/clientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ import {
RoochClientOptions,
} from '@roochnetwork/rooch-sdk'

import { NetworkConfig, useRoochSessionStore } from '../hooks/index.js'
import { NetworkConfig } from '../hooks/index.js'
import { useSessionStore } from '../hooks/useSessionsStore.js'
import { HTTPTransport } from '../http/httpTransport.js'

export type NetworkConfigs<T extends NetworkConfig | RoochClient = NetworkConfig | RoochClient> =
Record<string, T>

export interface RoochClientProviderContext {
export interface ClientProviderContext {
client: RoochClient
networks: NetworkConfigs
network: string
config: NetworkConfig | null
selectNetwork: (network: string) => void
}

export const RoochClientContext = createContext<RoochClientProviderContext | null>(null)
export const ClientContext = createContext<ClientProviderContext | null>(null)

export type RoochClientProviderProps<T extends NetworkConfigs> = {
networks?: NetworkConfigs
Expand Down Expand Up @@ -68,7 +69,7 @@ const DEFAULT_CREATE_CLIENT = function createClient(

export function RoochClientProvider<T extends NetworkConfigs>(props: RoochClientProviderProps<T>) {
const { onNetworkChange, network, children } = props
const setCurrentSession = useRoochSessionStore((state) => state.setCurrentSession)
const setCurrentSession = useSessionStore((state) => state.setCurrentSession)
const networks = (props.networks ?? DEFAULT_NETWORKS) as T
const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(
props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),
Expand All @@ -89,7 +90,7 @@ export function RoochClientProvider<T extends NetworkConfigs>(props: RoochClient
})
}, [currentNetwork, networks, clearSession])

const ctx = useMemo((): RoochClientProviderContext => {
const ctx = useMemo((): ClientProviderContext => {
return {
client,
network: currentNetwork,
Expand All @@ -112,5 +113,5 @@ export function RoochClientProvider<T extends NetworkConfigs>(props: RoochClient
}
}, [client, currentNetwork, networks, network, selectedNetwork, onNetworkChange])

return <RoochClientContext.Provider value={ctx}>{children}</RoochClientContext.Provider>
return <ClientContext.Provider value={ctx}>{children}</ClientContext.Provider>
}
1 change: 0 additions & 1 deletion sdk/typescript/rooch-sdk-kit/src/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

export * from './clientProvider.js'
export * from './roochProvider.js'
export * from './walletProvider.js'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ReactNode } from 'react'
import { createContext, useRef } from 'react'

import { NetworkConfigs, RoochClientProvider } from './clientProvider.js'
import { createSessionStore, SessionStore } from './roochStore.js'
import { createSessionStore, SessionStore } from './sessionStore.js'
import { getDefaultStorage, StorageType } from '../utils/index.js'

const DEFAULT_SESSION_STORAGE_KEY = function (_?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { createWalletStore, WalletStore } from './walletStore.js'
import {
useAutoConnectWallet,
useCurrentSession,
useRoochSessionStore,
useSession,
useWalletStore,
useCurrentNetwork,
} from '../hooks/index.js'
import { useSessionStore } from '../hooks/useSessionsStore.js'
import { getDefaultStorage, StorageType } from '../utils/index.js'
import { SupportChain } from '../feature/index.js'
import { getWallets } from '../wellet/util.js'
Expand Down Expand Up @@ -76,7 +76,7 @@ function WalletConnectionManager({ children }: WalletConnectionManagerProps) {
const currentAddress = useWalletStore((state) => state.currentAddress)
const sessions = useSession()
const curSession = useCurrentSession()
const setCurrentSession = useRoochSessionStore((state) => state.setCurrentSession)
const setCurrentSession = useSessionStore((state) => state.setCurrentSession)

const accountsChangedHandler = useCallback(
async (address: string[]) => {
Expand Down
4 changes: 2 additions & 2 deletions sdk/typescript/rooch-sdk/genversion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const WARNING = '// This file is generated by genversion.mjs. Do not edit it dir

async function main() {
const pkg = JSON.parse(await readFile('./package.json', 'utf8'))
const cargo = TOML.parse(await readFile('../../../crates/rooch-rpc-server/Cargo.toml', 'utf8'))
const cargo = TOML.parse(await readFile('../../../Cargo.toml', 'utf8'))
await writeFile(
'src/version.ts',
LICENSE +
WARNING +
`export const PACKAGE_VERSION = '${pkg.version}';\nexport const TARGETED_RPC_VERSION = '${cargo.package.version}';\n`,
`export const PACKAGE_VERSION = '${pkg.version}'\nexport const TARGETED_RPC_VERSION = '${cargo.workspace.package.version}'\n`,
)
}

Expand Down
Loading
Loading