I’m trying to integrate Torus and Portis wallets, but with both I get:
Uncaught (in promise) TypeError: MWeb3 is not a constructor
at MoralisTorusProvider._callee$ (Login.vue?013f:112)
at tryCatch (runtime.js?89b8:63)
at Generator.invoke [as _invoke] (runtime.js?89b8:293)
at Generator.eval [as next] (runtime.js?89b8:118)
at asyncGeneratorStep (asyncToGenerator.js?c973:3)
at _next (asyncToGenerator.js?c973:25)
What am I missing? Should I import web3 myself when using a different wallet?
I’m running localhost, could that be an issue?
<script>
import { Moralis } from 'src/boot/moralis'
import Torus from '@toruslabs/torus-embed'
export default {
setup() {
const connectTorus = async () => {
class MoralisTorusProvider {
torus = new Torus({buttonPosition: 'bottom-left'})
async activate() {
this.provider = await this.torus.init(
{
enableLogging: true,
network: {
host: process.env.VUE_ETH_NETWORK_RPC,
networkName: "Ethereum - Rinkeby",
chainId: 4,
blockExplorer: process.env.VUE_ETH_NETWORK_EXPLORER,
ticker: 'ETH',
tickerName: 'ETH',
},
})
await this.torus.login()
const MWeb3 = typeof Web3 === 'function' ? Web3 : window.Web3
this.web3 = new MWeb3(this.torus.provider)
this.isActivated = true
return this.web3
}
}
Moralis.Web3.enable = async () => {
const web3Provider = new MoralisTorusProvider()
const web3 = await web3Provider.activate()
return web3
}
window.web3 = await Moralis.Web3.enable()
}
}