Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"lint"
],
"dependencies": {
"@portis/web3": "3.0.10",
"@walletconnect/web3-provider": "^1.4.1",
"animate.css": "^3.7.0",
"axios": "^0.21.1",
"basscss": "^8.1.0",
Expand All @@ -29,7 +27,6 @@
"decimal.js": "^10.2.0",
"ethereum-ens": "^0.8.0",
"ethjs": "^0.2.9",
"fortmatic": "^0.8.2",
"fs": "0.0.1-security",
"lazysizes": "^5.2.1",
"moment": "^2.24.0",
Expand Down
85 changes: 38 additions & 47 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,62 @@ import Clv from '@/components/Clv'
// import CloverGridItem from '@/components/CloverGridItem'

import Web3Connect from 'web3modal'
import WalletConnectProvider from '@walletconnect/web3-provider'
import Portis from '@portis/web3'
import Fortmatic from 'fortmatic'

// Keyless public RPC, replacing Infura. Nothing here needs an account: these
// are the same endpoints the API's chain listener already runs on, and the
// backend has had no Infura dependency for a while.
//
// The key it replaced was not a secret that leaked -- any VUE_APP_* value is
// compiled into the browser bundle by design, so it was public the moment it
// shipped, and it was additionally being printed to the console on the line
// this comment replaces. It was also unrestricted, so anyone reading the public
// repo could spend the quota. Removing it is simpler than scoping it.
const PUBLIC_RPC = {
1: 'https://ethereum-rpc.publicnode.com',
4: 'https://ethereum-rpc.publicnode.com'
}

const networks = {
4: 'rinkeby',
5777: 'ganache',
1: 'mainnet'
}

// A visitor with no wallet extension previously fell through to Portis, whose
// widget host is NXDOMAIN -- so global.web3, and the ENS instance built from it
// on the next line, were backed by a provider that could never connect. Clover
// data comes from the API and kept working, which is why this was not obvious,
// but every chain read for a visitor without a wallet failed silently.
//
// A plain public RPC is the right fallback: reads work for everyone, and
// connecting a wallet still replaces the provider as before.
if (global.ethereum) {
global.web3 = new Web3(global.ethereum)
} else if (global.web3) {
global.web3 = new Web3(global.web3.currentProvider)
} else {
const portis = new Portis(process.env.VUE_APP_PORTIS_DAPP, networks[store.state.correctNetwork])
global.web3 = new Web3(portis.provider)
global.web3 = new Web3(new Web3.providers.HttpProvider(
PUBLIC_RPC[store.state.correctNetwork] || PUBLIC_RPC[1]
))
}
global.ens = new ENS(global.web3.currentProvider)

// Keyless public RPC, replacing Infura. Nothing here needs an account: these
// are the same endpoints the API's chain listener already runs on, and the
// backend has had no Infura dependency for a while.
//
// The key it replaced was not a secret that leaked -- any VUE_APP_* value is
// compiled into the browser bundle by design, so it was public the moment it
// shipped, and it was additionally being printed to the console on the line
// this comment replaces. It was also unrestricted, so anyone reading the public
// repo could spend the quota. Removing it is simpler than scoping it.
const PUBLIC_RPC = {
1: 'https://ethereum-rpc.publicnode.com',
4: 'https://ethereum-rpc.publicnode.com'
}

global.web3Connect = new Web3Connect({
network: networks[store.state.correctNetwork],
providerOptions: {
walletconnect: {
package: WalletConnectProvider, // required
options: {
// `rpc` instead of `infuraId`. WalletConnect v1 accepts either.
//
// This path cannot currently succeed regardless: v1's bridge is gone --
// bridge.walletconnect.org is NXDOMAIN -- as are Portis
// (widget.portis.io, NXDOMAIN) and Fortmatic below. Injected wallets
// are the only working option on this build. Kept configured rather
// than removed because deleting the entries changes what the modal
// offers, which is a UI decision and not this one; see
// feature/vue-upgrade-appkit for the actual replacement.
rpc: PUBLIC_RPC
}
},
portis: !global.web3.currentProvider.isPortis && {
package: Portis,
options: {
id: process.env.VUE_APP_PORTIS_DAPP // required
}
},
fortmatic: {
package: Fortmatic,
options: {
key: store.state.correctNetwork === 1 ? process.env.VUE_APP_FORTMATIC_MAIN : process.env.VUE_APP_FORTMATIC_TEST // required
}
}
}
// No providerOptions: web3modal falls back to injected wallets, which is the
// only thing here that still works.
//
// The three that were configured are dead ends rather than merely deprecated
// -- WalletConnect v1's bridge (bridge.walletconnect.org) and Portis
// (widget.portis.io) are both NXDOMAIN, and Fortmatic's API answers 404. The
// modal offered four choices of which three could only hang, which is worse
// than offering one that works: a user who picks a dead one cannot tell
// whether the fault is theirs.
//
// Removing them needs no account and no key. Restoring WalletConnect properly
// means v2, which requires a Reown projectId -- that work is on
// feature/vue-upgrade-appkit.
})

// subscibe to connect
Expand Down
Loading
Loading