mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
WalletConnect updates (#749)
* bump @walletconnect/web3-provider to v1.5.0-rc.7 * bump web3 to v1.4.0 * proper wallet logout * listen to chainChanged instead of networkChanged * restores network switching for WalletConnect * fix wallet switching * get and set initial chainId * walletconnect modal visual fixes
This commit is contained in:
parent
15b947bb3f
commit
4ec23c882f
633
package-lock.json
generated
633
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,7 @@
|
|||||||
"@portis/web3": "^4.0.4",
|
"@portis/web3": "^4.0.4",
|
||||||
"@sindresorhus/slugify": "^2.1.0",
|
"@sindresorhus/slugify": "^2.1.0",
|
||||||
"@tippyjs/react": "^4.2.5",
|
"@tippyjs/react": "^4.2.5",
|
||||||
"@walletconnect/web3-provider": "^1.4.1",
|
"@walletconnect/web3-provider": "^1.5.0-rc.7",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"chart.js": "^2.9.4",
|
"chart.js": "^2.9.4",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
@ -82,7 +82,7 @@
|
|||||||
"slugify": "^1.5.3",
|
"slugify": "^1.5.3",
|
||||||
"swr": "^0.5.6",
|
"swr": "^0.5.6",
|
||||||
"use-dark-mode": "^2.3.1",
|
"use-dark-mode": "^2.3.1",
|
||||||
"web3": "^1.3.6",
|
"web3": "^1.4.0",
|
||||||
"web3modal": "^1.9.3",
|
"web3modal": "^1.9.3",
|
||||||
"yup": "^0.32.9"
|
"yup": "^0.32.9"
|
||||||
},
|
},
|
||||||
|
@ -14,6 +14,7 @@ export default function Details(): ReactElement {
|
|||||||
const {
|
const {
|
||||||
web3Provider,
|
web3Provider,
|
||||||
web3ProviderInfo,
|
web3ProviderInfo,
|
||||||
|
web3Modal,
|
||||||
connect,
|
connect,
|
||||||
logout,
|
logout,
|
||||||
networkId,
|
networkId,
|
||||||
@ -95,8 +96,8 @@ export default function Details(): ReactElement {
|
|||||||
<Button
|
<Button
|
||||||
style="text"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
logout()
|
await web3Modal?.clearCachedProvider()
|
||||||
connect()
|
connect()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -81,6 +81,30 @@ div.walletconnect-modal__base {
|
|||||||
box-shadow: 0 6px 17px 0 var(--box-shadow-color);
|
box-shadow: 0 6px 17px 0 var(--box-shadow-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.walletconnect-modal__mobile__toggle {
|
||||||
|
width: 95%;
|
||||||
|
text-transform: uppercase;
|
||||||
|
cursor: pointer;
|
||||||
|
background: var(--background-body);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
div.walletconnect-modal__mobile__toggle a {
|
||||||
|
color: var(--color-secondary);
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
font-size: var(--font-size-small);
|
||||||
|
padding: calc(var(--spacer) / 12) var(--spacer);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.walletconnect-modal__mobile__toggle_selector {
|
||||||
|
background: var(--font-color-heading);
|
||||||
|
color: var(--background-body);
|
||||||
|
border-color: var(--font-color-heading);
|
||||||
|
height: calc(100% - calc(var(--spacer) / 12));
|
||||||
|
top: calc(var(--spacer) / 24);
|
||||||
|
}
|
||||||
|
|
||||||
div.walletconnect-modal__header p {
|
div.walletconnect-modal__header p {
|
||||||
color: var(--font-color-heading);
|
color: var(--font-color-heading);
|
||||||
}
|
}
|
||||||
@ -89,6 +113,11 @@ p.walletconnect-qrcode__text {
|
|||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3.walletconnect-modal__base__row__h3 {
|
||||||
|
font-size: var(--font-size-base);
|
||||||
|
color: var(--font-color-text);
|
||||||
|
}
|
||||||
|
|
||||||
svg.walletconnect-qrcode__image path:first-child {
|
svg.walletconnect-qrcode__image path:first-child {
|
||||||
fill: var(--background-body);
|
fill: var(--background-body);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ interface Web3ProviderValue {
|
|||||||
web3ProviderInfo: IProviderInfo
|
web3ProviderInfo: IProviderInfo
|
||||||
accountId: string
|
accountId: string
|
||||||
networkId: number
|
networkId: number
|
||||||
|
chainId: number
|
||||||
networkDisplayName: string
|
networkDisplayName: string
|
||||||
networkData: EthereumListsChain
|
networkData: EthereumListsChain
|
||||||
block: number
|
block: number
|
||||||
@ -109,6 +110,7 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
const [web3Modal, setWeb3Modal] = useState<Web3Modal>()
|
const [web3Modal, setWeb3Modal] = useState<Web3Modal>()
|
||||||
const [web3ProviderInfo, setWeb3ProviderInfo] = useState<IProviderInfo>()
|
const [web3ProviderInfo, setWeb3ProviderInfo] = useState<IProviderInfo>()
|
||||||
const [networkId, setNetworkId] = useState<number>()
|
const [networkId, setNetworkId] = useState<number>()
|
||||||
|
const [chainId, setChainId] = useState<number>()
|
||||||
const [networkDisplayName, setNetworkDisplayName] = useState<string>()
|
const [networkDisplayName, setNetworkDisplayName] = useState<string>()
|
||||||
const [networkData, setNetworkData] = useState<EthereumListsChain>()
|
const [networkData, setNetworkData] = useState<EthereumListsChain>()
|
||||||
const [block, setBlock] = useState<number>()
|
const [block, setBlock] = useState<number>()
|
||||||
@ -136,6 +138,10 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
setNetworkId(networkId)
|
setNetworkId(networkId)
|
||||||
Logger.log('[web3] network id ', networkId)
|
Logger.log('[web3] network id ', networkId)
|
||||||
|
|
||||||
|
const chainId = await web3.eth.getChainId()
|
||||||
|
setChainId(chainId)
|
||||||
|
Logger.log('[web3] chain id ', chainId)
|
||||||
|
|
||||||
const accountId = (await web3.eth.getAccounts())[0]
|
const accountId = (await web3.eth.getAccounts())[0]
|
||||||
setAccountId(accountId)
|
setAccountId(accountId)
|
||||||
Logger.log('[web3] account id', accountId)
|
Logger.log('[web3] account id', accountId)
|
||||||
@ -235,16 +241,27 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
// Logout helper
|
// Logout helper
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
async function logout() {
|
async function logout() {
|
||||||
web3Modal?.clearCachedProvider()
|
if (web3 && web3.currentProvider && (web3.currentProvider as any).close) {
|
||||||
|
await (web3.currentProvider as any).close()
|
||||||
|
}
|
||||||
|
await web3Modal.clearCachedProvider()
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
// Handle change events
|
// Handle change events
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
|
async function handleChainChanged(chainId: string) {
|
||||||
|
Logger.log('[web3] Chain changed', chainId)
|
||||||
|
const networkId = await web3.eth.net.getId()
|
||||||
|
setChainId(Number(chainId))
|
||||||
|
setNetworkId(Number(networkId))
|
||||||
|
}
|
||||||
|
|
||||||
async function handleNetworkChanged(networkId: string) {
|
async function handleNetworkChanged(networkId: string) {
|
||||||
Logger.log('[web3] Network changed', networkId)
|
Logger.log('[web3] Network changed', networkId)
|
||||||
// const networkId = Number(chainId.replace('0x', ''))
|
const chainId = await web3.eth.getChainId()
|
||||||
setNetworkId(Number(networkId))
|
setNetworkId(Number(networkId))
|
||||||
|
setChainId(Number(chainId))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAccountsChanged(accounts: string[]) {
|
async function handleAccountsChanged(accounts: string[]) {
|
||||||
@ -255,19 +272,14 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!web3Provider || !web3) return
|
if (!web3Provider || !web3) return
|
||||||
|
|
||||||
//
|
web3Provider.on('chainChanged', handleChainChanged)
|
||||||
// HEADS UP! We should rather listen to `chainChanged` exposing the `chainId`
|
|
||||||
// but for whatever reason the exposed `chainId` is wildly different from
|
|
||||||
// what is shown on https://chainid.network, in turn breaking our network/config
|
|
||||||
// mapping. The networkChanged is deprecated but works as expected for our case.
|
|
||||||
// See: https://eips.ethereum.org/EIPS/eip-1193#chainchanged
|
|
||||||
//
|
|
||||||
web3Provider.on('networkChanged', handleNetworkChanged)
|
web3Provider.on('networkChanged', handleNetworkChanged)
|
||||||
web3Provider.on('accountsChanged', handleAccountsChanged)
|
web3Provider.on('accountsChanged', handleAccountsChanged)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
web3Provider.removeListener('networkChanged')
|
web3Provider.removeListener('chainChanged', handleChainChanged)
|
||||||
web3Provider.removeListener('accountsChanged')
|
web3Provider.removeListener('networkChanged', handleNetworkChanged)
|
||||||
|
web3Provider.removeListener('accountsChanged', handleAccountsChanged)
|
||||||
}
|
}
|
||||||
}, [web3Provider, web3])
|
}, [web3Provider, web3])
|
||||||
|
|
||||||
@ -280,6 +292,7 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
web3ProviderInfo,
|
web3ProviderInfo,
|
||||||
accountId,
|
accountId,
|
||||||
networkId,
|
networkId,
|
||||||
|
chainId,
|
||||||
networkDisplayName,
|
networkDisplayName,
|
||||||
networkData,
|
networkData,
|
||||||
block,
|
block,
|
||||||
|
Loading…
Reference in New Issue
Block a user