Skip to content

Commit

Permalink
Adding hooks for getting memoized sequence clients with included proj…
Browse files Browse the repository at this point in the history
…ectAccessKey
  • Loading branch information
corbanbrook committed Apr 29, 2024
1 parent 3989510 commit 1b3b609
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/kit/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export * from './useOpenConnectModal'
export * from './useTheme'
export * from './useWalletSettings'
export * from './useWaasFeeOptions'
export * from './useProjectAccessKey'
export * from './useAPIClient'
export * from './useMetadataClient'
export * from './useIndexerClient'
13 changes: 13 additions & 0 deletions packages/kit/src/hooks/useAPIClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMemo } from 'react'
import { useProjectAccessKey } from './useProjectAccessKey'
import { SequenceAPIClient } from '@0xsequence/api'

export const useAPIClient = () => {
const projectAccessKey = useProjectAccessKey()

const apiClient = useMemo(() => {
return new SequenceAPIClient('https://api.sequence.app', projectAccessKey)
}, [projectAccessKey])

return apiClient
}
20 changes: 20 additions & 0 deletions packages/kit/src/hooks/useIndexerClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useMemo } from 'react'
import { useProjectAccessKey } from './useProjectAccessKey'
import { SequenceIndexer } from '@0xsequence/indexer'
import { ChainId, indexerURL, networks } from '@0xsequence/network'

export const useIndexerClient = (chainId: ChainId) => {
const projectAccessKey = useProjectAccessKey()

const indexerClients = useMemo(() => {
return new Map<ChainId, SequenceIndexer>()
}, [projectAccessKey])

const network = networks[chainId]

if (!indexerClients.has(chainId)) {
indexerClients.set(chainId, new SequenceIndexer(indexerURL(network.name), projectAccessKey))
}

return indexerClients.get(chainId)
}
13 changes: 13 additions & 0 deletions packages/kit/src/hooks/useMetadataClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SequenceMetadata } from '@0xsequence/metadata'
import { useProjectAccessKey } from './useProjectAccessKey'
import { useMemo } from 'react'

export const useMetadataClient = () => {
const projectAccessKey = useProjectAccessKey()

const metadataClient = useMemo(() => {
return new SequenceMetadata('https://metadata.sequence.app', projectAccessKey)
}, [projectAccessKey])

return metadataClient
}
1 change: 0 additions & 1 deletion packages/kit/src/hooks/useWaasConfirmationHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { commons } from '@0xsequence/core'
import { ethers } from 'ethers'
import { useState, useEffect } from 'react'
import { Deferred } from '../utils/deferred'

Expand Down

0 comments on commit 1b3b609

Please sign in to comment.