-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add clientId to web3modal info (#2365)
- Loading branch information
Showing
7 changed files
with
64 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import * as React from 'react' | ||
import { useWeb3ModalAccount } from '@web3modal/ethers/react' | ||
import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/ethers/react' | ||
import EthereumProvider from '@walletconnect/ethereum-provider' | ||
|
||
import { Web3ModalInfo } from '../Web3ModalInfo' | ||
|
||
export function EthersModalInfo() { | ||
const { isConnected, address, chainId } = useWeb3ModalAccount() | ||
const [ready, setReady] = React.useState(false) | ||
const [clientId, setClientId] = React.useState<string | null>(null) | ||
const { walletProvider, walletProviderType } = useWeb3ModalProvider() | ||
async function getClientId() { | ||
if (walletProviderType === 'walletConnect') { | ||
const ethereumProvider = walletProvider as unknown as EthereumProvider | ||
|
||
return ethereumProvider?.signer?.client?.core?.crypto?.getClientId() | ||
} | ||
|
||
return null | ||
} | ||
|
||
React.useEffect(() => { | ||
getClientId().then(setClientId) | ||
}, [walletProvider]) | ||
|
||
React.useEffect(() => { | ||
setReady(true) | ||
}, []) | ||
|
||
return ready && isConnected ? <Web3ModalInfo address={address} chainId={chainId} /> : null | ||
return ready && isConnected ? ( | ||
<Web3ModalInfo address={address} chainId={chainId} clientId={clientId} /> | ||
) : null | ||
} |
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,10 +1,29 @@ | ||
import * as React from 'react' | ||
import EthereumProvider from '@walletconnect/ethereum-provider' | ||
|
||
import { useAccount } from 'wagmi' | ||
import { Web3ModalInfo } from '../Web3ModalInfo' | ||
|
||
export function WagmiModalInfo() { | ||
const { isConnected, address, chainId } = useAccount() | ||
const { isConnected, address, chainId, connector } = useAccount() | ||
const [clientId, setClientId] = React.useState<string | null>(null) | ||
|
||
return isConnected ? <Web3ModalInfo address={address} chainId={chainId} /> : null | ||
async function getClientId() { | ||
const provider = await connector?.getProvider() | ||
if (connector?.type === 'walletConnect') { | ||
const ethereumProvider = provider as EthereumProvider | ||
|
||
return ethereumProvider?.signer?.client?.core?.crypto?.getClientId() | ||
} | ||
|
||
return null | ||
} | ||
|
||
React.useEffect(() => { | ||
getClientId().then(setClientId) | ||
}, [connector]) | ||
|
||
return isConnected ? ( | ||
<Web3ModalInfo address={address} chainId={chainId} clientId={clientId} /> | ||
) : null | ||
} |
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