Skip to content

Commit b089e68

Browse files
committed
fix: type configs on hooks and build
1 parent a6ca72c commit b089e68

7 files changed

+70
-39
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"type-check": "tsc-files --pretty --project ./tsconfig.build.json --noEmit --module ESNext --declaration",
3737
"build": "bun clean && bun build:cjs && bun build:esm && bun build:types && bun build:css",
3838
"build:css": "postcss src/styles/global.css -o dist/cjs/styles/global.css && cp -r dist/cjs/styles dist/esm",
39-
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && tsc-alias --outDir ./dist/cjs && ts-add-js-extension --dir=dist/cjs --showchanges=false",
39+
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --moduleResolution node --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && tsc-alias --outDir ./dist/cjs && ts-add-js-extension --dir=dist/cjs --showchanges=false",
4040
"build:esm": "tsc --project ./tsconfig.build.json --module ESNext --outDir ./dist/esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/esm/package.json && tsc-alias --outDir ./dist/esm && ts-add-js-extension --dir=dist/esm --showchanges=false",
4141
"build:types": "tsc --project ./tsconfig.build.json --module ESNext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap && tsc-alias --outDir ./dist/types",
4242
"clean": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",

src/components/wallet-widget.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import { CircleAlert, Pointer, Wallet } from 'lucide-react'
1111
export interface WalletWidgetProps extends ButtonProps {
1212
text?: string
1313
applyClassToLoading?: boolean
14-
size?: ButtonProps['size']
15-
variant?: ButtonProps['variant']
16-
showWalletWidget: () => void
17-
closeWalletWidget: () => void
14+
setShowWalletWidget: () => void
1815
}
1916

2017
export function WalletWidget(props: WalletWidgetProps) {
21-
const { size, className, text, applyClassToLoading = true, ...rest } = props
18+
const {
19+
size,
20+
className,
21+
text,
22+
applyClassToLoading = true,
23+
setShowWalletWidget,
24+
...rest
25+
} = props
2226
const isHydrated = useIsHydrated()
2327
const { isConnected, address, iconSrc, isUnsupportedChain } = useChainSpecs()
2428

@@ -72,11 +76,7 @@ export function WalletWidget(props: WalletWidgetProps) {
7276
className={cn(className, 'in--leading-[unset]')}
7377
type="button"
7478
size={!size ? 'sm' : size}
75-
onClick={() => {
76-
if (!isConnected) props.showWalletWidget()
77-
else props.closeWalletWidget()
78-
return
79-
}}
79+
onClick={setShowWalletWidget}
8080
>
8181
{getChildren()}
8282
</Button>

src/hooks/use-graphql-query.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export type UseGraphQLQueryParams<T extends GraphQLQueryArgs> = {
1919
>
2020
}
2121

22-
export type UseGraphQLQueryReturnType = ReturnType<typeof useGraphQLQuery>
22+
export type UseGraphQLQueryReturnType<
23+
T extends GraphQLQueryArgs = GraphQLQueryArgs,
24+
> = ReturnType<typeof useGraphQLQuery<T>>
2325

2426
export const useGraphQLQuery = <T extends GraphQLQueryArgs>({
2527
fields,

src/hooks/use-graphql-subscription.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,45 @@
22

33
import * as React from 'react'
44
import { useInverter } from './use-inverter'
5-
import type { GraphQLSubscriptionArgs } from '@inverter-network/sdk'
5+
import type {
6+
GraphQLSubscriptionArgs,
7+
GraphQLSubscriptionResult,
8+
} from '@inverter-network/sdk'
69

7-
export type UseGraphQLSubscriptionParams = {
8-
fields: GraphQLSubscriptionArgs
10+
export type UseGraphQLSubscriptionParams<T extends GraphQLSubscriptionArgs> = {
11+
fields: T
912
}
1013

11-
export type UseBondingCurveSubscriptionReturnType = ReturnType<
12-
typeof useGraphQLSubscription
13-
>
14+
export type UseBondingCurveSubscriptionReturnType<
15+
T extends GraphQLSubscriptionArgs,
16+
> = ReturnType<typeof useGraphQLSubscription<T>>
1417

15-
export const useGraphQLSubscription = ({
18+
export const useGraphQLSubscription = <T extends GraphQLSubscriptionArgs>({
1619
fields,
17-
}: UseGraphQLSubscriptionParams) => {
20+
}: UseGraphQLSubscriptionParams<T>): GraphQLSubscriptionResult<T> | null => {
1821
const inverter = useInverter()
1922

2023
const memo = React.useMemo(() => {
2124
if (!inverter.data) return null
2225
return inverter.data!.graphql.subscription(fields)
2326
}, [inverter.data, fields])
2427

25-
return memo
28+
const [data, setData] = React.useState<Awaited<typeof memo> | null>(null)
29+
30+
React.useEffect(() => {
31+
if (!memo) return
32+
33+
const fetchData = async () => {
34+
try {
35+
const result = await memo
36+
setData(result)
37+
} catch (error) {
38+
console.error('Error in GraphQL subscription:', error)
39+
}
40+
}
41+
42+
fetchData()
43+
}, [memo])
44+
45+
return data
2646
}

src/hooks/use-workflow.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
'use-client'
22

33
import { useQuery } from '@tanstack/react-query'
4-
import type { UseQueryResult } from '@tanstack/react-query'
4+
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query'
55
import { useInverter } from '.'
66
import type {
77
FactoryType,
88
PopWalletClient,
99
RequestedModules,
1010
Workflow,
1111
} from '@inverter-network/sdk'
12+
import type { Except } from 'type-fest-4'
1213

13-
export type UseWorkFlowReturnType = ReturnType<typeof useWorkflow>
14+
export type UseWorkFlowParams<T extends RequestedModules<FactoryType>> = {
15+
orchestratorAddress?: `0x${string}`
16+
requestedModules?: T
17+
options?: Except<
18+
UseQueryOptions<Workflow<PopWalletClient, T> | undefined, Error>,
19+
'queryKey' | 'queryFn' | 'enabled'
20+
>
21+
}
22+
23+
export type UseWorkFlowReturnType<T extends RequestedModules<FactoryType>> =
24+
ReturnType<typeof useWorkflow<T>>
1425

1526
export function useWorkflow<T extends RequestedModules<FactoryType>>({
1627
orchestratorAddress,
1728
requestedModules,
18-
}: {
19-
orchestratorAddress?: `0x${string}`
20-
requestedModules?: T
21-
}): UseQueryResult<Workflow<PopWalletClient, T>> {
29+
options,
30+
}: UseWorkFlowParams<T>): UseQueryResult<Workflow<PopWalletClient, T>> {
2231
const inverter = useInverter()
2332

2433
const enabled = !!inverter.data && !!orchestratorAddress
@@ -29,9 +38,10 @@ export function useWorkflow<T extends RequestedModules<FactoryType>>({
2938
inverter.data!.getWorkflow({
3039
orchestratorAddress: orchestratorAddress!,
3140
requestedModules,
32-
}),
41+
}) as any,
3342
enabled,
3443
refetchOnWindowFocus: false,
44+
...options,
3545
})
3646

3747
return query as any

src/store/use-orchestrator-store.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ export const useOrchestratorStore = create<OrchestratorStore>()(
2323
)
2424

2525
set((state) => {
26-
if (existingIndex !== -1) {
27-
// Update the date if the address already exists
28-
state.orchestrators[existingIndex].date = new Date()
29-
} else {
30-
// Add new orchestrator
31-
state.orchestrators.unshift({
32-
address: orchestratorAddress,
33-
date: new Date(),
34-
})
35-
}
26+
// remove the existing index
27+
if (existingIndex !== -1) state.orchestrators.splice(existingIndex, 1)
28+
29+
// Add new orchestrator
30+
state.orchestrators.unshift({
31+
address: orchestratorAddress,
32+
date: new Date(),
33+
})
34+
3635
state.editingOrchestrators = false
3736
})
3837
},

tsconfig.build.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"include": ["src"],
55
"exclude": ["tests", "tools"],
66
"compilerOptions": {
7-
"moduleResolution": "node",
7+
"moduleResolution": "Bundler",
88
"sourceMap": true,
99
"rootDir": "./src"
1010
}

0 commit comments

Comments
 (0)