working on wc v2 upgrade

Signed-off-by: AlienTornadosaurusHex <>
This commit is contained in:
AlienTornadosaurusHex 2023-07-02 22:38:30 +00:00
parent 6130c46d90
commit 2054cc53c3
4 changed files with 856 additions and 1111 deletions

@ -23,13 +23,17 @@
"@apollo/client": "^3.3.20",
"@metamask/onboarding": "^1.0.0",
"@nuxtjs/moment": "^1.6.0",
"@walletconnect/web3-provider": "1.7.8",
"@tornado/snarkjs": "0.1.20-p2",
"@tornado/websnark": "0.0.4-p1",
"@walletconnect/ethereum-provider": "^2.8.6",
"@walletconnect/modal": "^2.5.9",
"ajv": "^6.10.2",
"arraybuffer-loader": "^1.0.8",
"base-path-converter": "^1.0.2",
"bignumber.js": "^9.0.0",
"bloomfilter.js": "^1.0.2",
"circomlibjs": "0.1.2",
"cross-env": "7.0.3",
"crypto": "^1.0.1",
"dotenv": "^8.2.0",
"eth-ens-namehash": "^2.0.8",
@ -53,10 +57,7 @@
"vue-clipboard2": "^0.3.1",
"vue-i18n": "^8.15.4",
"vuex-persistedstate": "^2.7.0",
"web3": "1.5.2",
"cross-env": "7.0.3",
"@tornado/snarkjs": "0.1.20-p2",
"@tornado/websnark": "0.0.4-p1"
"web3": "1.5.2"
},
"devDependencies": {
"@nuxtjs/eslint-config": "^1.1.2",

@ -1,50 +1,69 @@
import BN from 'bignumber.js'
import WalletConnectProvider from '@walletconnect/web3-provider'
// Imports
import { NETWORKS } from '@/constants'
import BN from 'bignumber.js'
import { EthereumProvider } from '@walletconnect/ethereum-provider'
import networkConfig from '@/networkConfig'
const { WC_BRIDGE } = process.env
// Build an array of the first RPC URL for each network in a reduce
const createRpcMapIterator = (accumulator, chainId) => {
// Get RPCs urls
const { rpcUrls } = networkConfig[`netId${chainId}`]
const WALLET_CONNECT_INTERVAL = 1000
const SUPPORTED_WALLETS = ['metamask', 'trust', 'imtoken', 'genericWeb3']
const RECONNECT_TIME = 3600000 // 1 hour
const getFirstRpcUrls = (acc, netId) => {
const { rpcUrls } = networkConfig[`netId${netId}`]
// Choose for each network the first rpc's url
const [{ url }] = Object.values(rpcUrls)
return { ...acc, [netId]: url }
// Append and continue
return { ...accumulator, [chainId]: url }
}
const RPC = NETWORKS.reduce(getFirstRpcUrls, {})
// const walletConnectInterval = 1000 // TODO: Check if we still need
const reconnectInterval = 3600000 // 1 hour
const supportedWallets = ['metamask', 'trust', 'imtoken', 'genericWeb3']
const rpcMap = networkConfig.enabledChains.reduce(createRpcMapIterator, {})
const walletConnectConnector = (chainId) => {
const walletConnectConnector = async (chainId) => {
try {
const prevConnection = localStorage.getItem('walletconnectTimeStamp')
if (new BN(Date.now()).minus(prevConnection).isGreaterThanOrEqualTo(RECONNECT_TIME)) {
if (new BN(Date.now()).minus(prevConnection).isGreaterThanOrEqualTo(reconnectInterval)) {
localStorage.removeItem('walletconnect')
}
const provider = new WalletConnectProvider({
chainId,
rpc: RPC,
pollingInterval: WALLET_CONNECT_INTERVAL,
qrcodeModalOptions: {
mobileLinks: SUPPORTED_WALLETS
},
bridge: WC_BRIDGE
const optionalChains = networkConfig.enabledChains.filter((chain) => chain !== chainId)
const provider = await EthereumProvider.init({
projectId: process.env.WC_PROJECT_ID,
relayUrl: process.env.WC_BRIDGE,
chains: [chainId],
optionalChains,
rpcMap,
methods: [
'eth_sendTransaction',
'personal_sign',
'eth_signTypedData_v4',
'eth_getEncryptionPublicKey',
'eth_decrypt',
'eth_getBalance',
'eth_getTransactionReceipt',
'eth_accounts',
'eth_chainId',
'wallet_addEthereumChain',
'wallet_switchEthereumChain'
],
showQrModal: true,
qrModalOptions: {
mobileWallets: supportedWallets
}
})
provider.injectedRequest = provider.enable
localStorage.setItem('walletconnectTimeStamp', Date.now())
return provider
} catch (err) {
console.log(err)
throw new Error('WalletConnect error: ', err)
console.error(err)
throw new Error('WalletConnectConnector error: ', err)
}
}

@ -402,6 +402,7 @@ const actions = {
if (providerName === 'walletConnect') {
await dispatch(listener, { provider })
}
const address = await this.$provider.initProvider(provider, {})
if (!address) {
@ -421,8 +422,8 @@ const actions = {
await dispatch('updateAccountBalance', address)
if (getters.isWalletConnect) {
if (provider.wc.peerMeta) {
commit('SET_WALLET_NAME', provider.wc.peerMeta.name)
if (provider.signer.client.name) {
commit('SET_WALLET_NAME', provider.signer.client.name)
}
}
@ -457,33 +458,33 @@ const actions = {
const { enabled } = rootState.loading
try {
provider.wc.on('disconnect', (error, payload) => {
provider.on('disconnect', (error, payload) => {
if (state.isReconnecting) {
console.warn('Provider reconnect payload', { payload, error, isReconnecting: state.isReconnecting })
if (enabled) {
dispatch('loading/disable', {}, { root: true })
}
commit('SET_RECONNECTING', false)
return
}
} else {
const prevConnection = localStorage.getItem('walletconnectTimeStamp')
const prevConnection = localStorage.getItem('walletconnectTimeStamp')
const isPrevConnection = new BN(Date.now()).minus(prevConnection).isGreaterThanOrEqualTo(5000)
const isPrevConnection = new BN(Date.now()).minus(prevConnection).isGreaterThanOrEqualTo(5000)
if (isPrevConnection) {
console.warn('Provider disconnect payload', {
payload,
error,
isReconnecting: state.isReconnecting
})
if (isPrevConnection) {
console.warn('Provider disconnect payload', {
payload,
error,
isReconnecting: state.isReconnecting
})
dispatch('onLogOut')
}
dispatch('onLogOut')
}
if (enabled) {
dispatch('loading/disable', {}, { root: true })
if (enabled) {
dispatch('loading/disable', {}, { root: true })
}
}
})
} catch (err) {

1850
yarn.lock

File diff suppressed because it is too large Load Diff