-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding hooks for getting memoized sequence clients with included proj…
…ectAccessKey
- Loading branch information
1 parent
3989510
commit 1b3b609
Showing
5 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters