PR #4: Wallet Connect V2 tracking branch. #28
@ -181,6 +181,19 @@ export default {
|
|||||||
config.module.rules.push({
|
config.module.rules.push({
|
||||||
test: /\.bin$/,
|
test: /\.bin$/,
|
||||||
use: 'arraybuffer-loader'
|
use: 'arraybuffer-loader'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /node_modules[\\/]@walletconnect/,
|
||||||
|
use: {
|
||||||
|
loader: 'babel-loader',
|
||||||
|
options: {
|
||||||
|
presets: ['@babel/preset-env'],
|
||||||
|
plugins: [
|
||||||
|
'@babel/plugin-proposal-optional-chaining',
|
||||||
|
'@babel/plugin-proposal-nullish-coalescing-operator'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
11
package.json
11
package.json
@ -23,13 +23,17 @@
|
|||||||
"@apollo/client": "^3.3.20",
|
"@apollo/client": "^3.3.20",
|
||||||
"@metamask/onboarding": "^1.0.0",
|
"@metamask/onboarding": "^1.0.0",
|
||||||
"@nuxtjs/moment": "^1.6.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",
|
"ajv": "^6.10.2",
|
||||||
"arraybuffer-loader": "^1.0.8",
|
"arraybuffer-loader": "^1.0.8",
|
||||||
"base-path-converter": "^1.0.2",
|
"base-path-converter": "^1.0.2",
|
||||||
"bignumber.js": "^9.0.0",
|
"bignumber.js": "^9.0.0",
|
||||||
"bloomfilter.js": "^1.0.2",
|
"bloomfilter.js": "^1.0.2",
|
||||||
"circomlibjs": "0.1.2",
|
"circomlibjs": "0.1.2",
|
||||||
|
"cross-env": "7.0.3",
|
||||||
"crypto": "^1.0.1",
|
"crypto": "^1.0.1",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"eth-ens-namehash": "^2.0.8",
|
"eth-ens-namehash": "^2.0.8",
|
||||||
@ -53,10 +57,7 @@
|
|||||||
"vue-clipboard2": "^0.3.1",
|
"vue-clipboard2": "^0.3.1",
|
||||||
"vue-i18n": "^8.15.4",
|
"vue-i18n": "^8.15.4",
|
||||||
"vuex-persistedstate": "^2.7.0",
|
"vuex-persistedstate": "^2.7.0",
|
||||||
"web3": "1.5.2",
|
"web3": "1.5.2"
|
||||||
"cross-env": "7.0.3",
|
|
||||||
"@tornado/snarkjs": "0.1.20-p2",
|
|
||||||
"@tornado/websnark": "0.0.4-p1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxtjs/eslint-config": "^1.1.2",
|
"@nuxtjs/eslint-config": "^1.1.2",
|
||||||
|
@ -1,50 +1,69 @@
|
|||||||
|
// Imports
|
||||||
|
|
||||||
import BN from 'bignumber.js'
|
import BN from 'bignumber.js'
|
||||||
import WalletConnectProvider from '@walletconnect/web3-provider'
|
import { EthereumProvider } from '@walletconnect/ethereum-provider'
|
||||||
|
import networkConfig, { enabledChains } from '@/networkConfig'
|
||||||
|
|
||||||
import { NETWORKS } from '@/constants'
|
// Build an array of the first RPC URL for each network in a reduce
|
||||||
import networkConfig from '@/networkConfig'
|
const createRpcMapIterator = (accumulator, chainId) => {
|
||||||
|
// Get RPCs urls
|
||||||
|
const { rpcUrls } = networkConfig[`netId${chainId}`]
|
||||||
|
|
||||||
const { WC_BRIDGE } = process.env
|
// Choose for each network the first rpc's url
|
||||||
|
|
||||||
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}`]
|
|
||||||
const [{ url }] = Object.values(rpcUrls)
|
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 = enabledChains.reduce(createRpcMapIterator, {})
|
||||||
|
|
||||||
const walletConnectConnector = (chainId) => {
|
const walletConnectConnector = async (chainId) => {
|
||||||
try {
|
try {
|
||||||
const prevConnection = localStorage.getItem('walletconnectTimeStamp')
|
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')
|
localStorage.removeItem('walletconnect')
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = new WalletConnectProvider({
|
const optionalChains = enabledChains.filter((chain) => chain !== chainId)
|
||||||
chainId,
|
|
||||||
rpc: RPC,
|
const provider = await EthereumProvider.init({
|
||||||
pollingInterval: WALLET_CONNECT_INTERVAL,
|
projectId: process.env.WC_PROJECT_ID,
|
||||||
qrcodeModalOptions: {
|
relayUrl: process.env.WC_BRIDGE,
|
||||||
mobileLinks: SUPPORTED_WALLETS
|
chains: [chainId],
|
||||||
},
|
optionalChains,
|
||||||
bridge: WC_BRIDGE
|
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
|
provider.injectedRequest = provider.enable
|
||||||
|
|
||||||
localStorage.setItem('walletconnectTimeStamp', Date.now())
|
localStorage.setItem('walletconnectTimeStamp', Date.now())
|
||||||
|
|
||||||
return provider
|
return provider
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.error(err)
|
||||||
throw new Error('WalletConnect error: ', err)
|
throw new Error('WalletConnectConnector error: ', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,6 +402,7 @@ const actions = {
|
|||||||
if (providerName === 'walletConnect') {
|
if (providerName === 'walletConnect') {
|
||||||
await dispatch(listener, { provider })
|
await dispatch(listener, { provider })
|
||||||
}
|
}
|
||||||
|
|
||||||
const address = await this.$provider.initProvider(provider, {})
|
const address = await this.$provider.initProvider(provider, {})
|
||||||
|
|
||||||
if (!address) {
|
if (!address) {
|
||||||
@ -421,8 +422,8 @@ const actions = {
|
|||||||
await dispatch('updateAccountBalance', address)
|
await dispatch('updateAccountBalance', address)
|
||||||
|
|
||||||
if (getters.isWalletConnect) {
|
if (getters.isWalletConnect) {
|
||||||
if (provider.wc.peerMeta) {
|
if (provider.signer.client.name) {
|
||||||
commit('SET_WALLET_NAME', provider.wc.peerMeta.name)
|
commit('SET_WALLET_NAME', provider.signer.client.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,33 +458,33 @@ const actions = {
|
|||||||
const { enabled } = rootState.loading
|
const { enabled } = rootState.loading
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider.wc.on('disconnect', (error, payload) => {
|
provider.on('disconnect', (error, payload) => {
|
||||||
if (state.isReconnecting) {
|
if (state.isReconnecting) {
|
||||||
console.warn('Provider reconnect payload', { payload, error, isReconnecting: state.isReconnecting })
|
console.warn('Provider reconnect payload', { payload, error, isReconnecting: state.isReconnecting })
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
dispatch('loading/disable', {}, { root: true })
|
dispatch('loading/disable', {}, { root: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
commit('SET_RECONNECTING', false)
|
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) {
|
dispatch('onLogOut')
|
||||||
console.warn('Provider disconnect payload', {
|
}
|
||||||
payload,
|
|
||||||
error,
|
|
||||||
isReconnecting: state.isReconnecting
|
|
||||||
})
|
|
||||||
|
|
||||||
dispatch('onLogOut')
|
if (enabled) {
|
||||||
}
|
dispatch('loading/disable', {}, { root: true })
|
||||||
|
}
|
||||||
if (enabled) {
|
|
||||||
dispatch('loading/disable', {}, { root: true })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -55,6 +55,7 @@ async function fetchFile({ url, name, getProgress, id, retryAttempt = 0 }) {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
},
|
},
|
||||||
|
timeout: 10_000,
|
||||||
onDownloadProgress: (progressEvent) => {
|
onDownloadProgress: (progressEvent) => {
|
||||||
if (typeof getProgress === 'function') {
|
if (typeof getProgress === 'function') {
|
||||||
const progress = Math.round((progressEvent.loaded * 100) / 9626311)
|
const progress = Math.round((progressEvent.loaded * 100) / 9626311)
|
||||||
|
Loading…
Reference in New Issue
Block a user