-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0df8aa3
commit d503c2f
Showing
21 changed files
with
140 additions
and
68 deletions.
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
12 changes: 6 additions & 6 deletions
12
...lugins/Collectible/hooks/useOpenSeaSDK.ts → ...c/plugins/Collectible/hooks/useOpenSea.ts
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { useMemo } from 'react' | ||
import { OpenSeaPort } from 'opensea-js' | ||
import { useWeb3 } from '@masknet/plugin-infra/web3' | ||
import { useWeb3Provider } from '@masknet/plugin-infra/web3' | ||
import type { ChainId } from '@masknet/web3-shared-evm' | ||
import { NetworkPluginID } from '@masknet/web3-shared-base' | ||
import { OpenSeaAPI_Key } from '../constants' | ||
import { resolveOpenSeaNetwork } from '../pipes' | ||
|
||
export function useOpenSeaSDK(chainId?: ChainId.Mainnet | ChainId.Rinkeby) { | ||
const web3 = useWeb3(NetworkPluginID.PLUGIN_EVM) | ||
export function useOpenSea(chainId?: ChainId.Mainnet | ChainId.Rinkeby) { | ||
const web3Provider = useWeb3Provider(NetworkPluginID.PLUGIN_EVM) | ||
|
||
return useMemo(() => { | ||
if (!chainId || !web3) return | ||
if (!chainId || !web3Provider) return | ||
return new OpenSeaPort( | ||
web3, | ||
web3Provider, | ||
{ | ||
apiKey: OpenSeaAPI_Key, | ||
networkName: resolveOpenSeaNetwork(chainId), | ||
}, | ||
console.log, | ||
) | ||
}, [web3]) | ||
}, [web3Provider]) | ||
} |
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
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
Empty file.
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
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,28 @@ | ||
import { useAsyncRetry } from 'react-use' | ||
import type { NetworkPluginID } from '@masknet/web3-shared-base' | ||
import type { Web3Helper } from '../web3-helpers' | ||
import { useAccount } from './useAccount' | ||
import { useChainId } from './useChainId' | ||
import { useProviderType } from './useProviderType' | ||
import { useWeb3State } from './useWeb3State' | ||
|
||
export function useWeb3Provider<T extends NetworkPluginID>(pluginID?: T, options?: Web3Helper.Web3ConnectionOptions<T>) { | ||
type GetWeb3Provider = (options?: Web3Helper.Web3ConnectionOptions<T>) => Promise<Web3Helper.Web3Provider<T>> | ||
|
||
const { Connection } = useWeb3State(pluginID) | ||
const chainId = useChainId(pluginID) | ||
const account = useAccount(pluginID) | ||
const providerType = useProviderType(pluginID) | ||
|
||
const { value: web3Provider = null } = useAsyncRetry(async () => { | ||
if (!Connection?.getWeb3Provider) return null | ||
return (Connection.getWeb3Provider as GetWeb3Provider)({ | ||
account, | ||
chainId, | ||
providerType, | ||
...options, | ||
} as Web3Helper.Web3ConnectionOptions<T>) | ||
}, [account, chainId, providerType, Connection, JSON.stringify(options)]) | ||
|
||
return web3Provider | ||
} |
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
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
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
Oops, something went wrong.