Skip to content

Commit 37952da

Browse files
committed
generate buy transaction hook in kit
1 parent 5c35b94 commit 37952da

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

packages/checkout/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"typecheck": "tsc --noEmit"
3232
},
3333
"dependencies": {
34+
"@0xsequence/marketplace": "^2.1.3",
3435
"qrcode.react": "^4.0.1",
3536
"react-copy-to-clipboard": "^5.1.0",
3637
"timeago-react": "^3.0.6"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
import { GenerateBuyTransactionArgs } from '@0xsequence/marketplace'
3+
import { useMarketplaceClient } from './useMarketplaceClient'
4+
5+
export interface UseGenerateBuyTransactionOptions {
6+
disabled?: boolean
7+
}
8+
9+
export const useGenerateBuyTransaction = (args: GenerateBuyTransactionArgs, options?: UseGenerateBuyTransactionOptions) => {
10+
const marketplaceClient = useMarketplaceClient()
11+
12+
return useQuery({
13+
queryKey: ['useGenerateBuyTransaction', args],
14+
queryFn: async () => {
15+
const res = await marketplaceClient.generateBuyTransaction(args)
16+
17+
return res
18+
},
19+
retry: false,
20+
staleTime: 360 * 1000,
21+
enabled: !options?.disabled,
22+
})
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useProjectAccessKey } from '@0xsequence/kit'
2+
import { MarketplaceIndexer } from '@0xsequence/marketplace'
3+
import { useMemo } from 'react'
4+
5+
6+
export const useMarketplaceClient = () => {
7+
const projectAccessKey = useProjectAccessKey()
8+
9+
// TODO: move to env variable
10+
const isDev = false
11+
12+
const marketplaceClient = useMemo(() => {
13+
const clientUrl = isDev ? 'https://dev-marketplace-api.sequence-dev.app' : 'https://marketplace-api.sequence.app'
14+
15+
return new MarketplaceIndexer(clientUrl, projectAccessKey)
16+
}, [projectAccessKey])
17+
18+
return marketplaceClient
19+
}

pnpm-lock.yaml

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)