question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QR modal doesn't open after being closed

See original GitHub issue

How to reproduce:

Lib: @walletconnect/web3-provider Version: 1.4.1

  1. call await wcProvider.enable()
  2. modal opens
  3. click the x button on top right corner
  4. modal closes
  5. call await wcProvider.enable() again
  6. nothing happens

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
0x62commented, Mar 16, 2022

I’m working around this in the @walletconnect/client and @walletconnect/qrcode-modal libraries. This is a pretty horrible hack, but works for now.

It promisifies the connect call, and after the first call it invokes the open method on the underlying modal forcing it to be opened every time. To track closing it uses a MutationObserver and resolves with the users address.

import WalletConnect from '@walletconnect/client'
import QRCodeModal from '@walletconnect/qrcode-modal'

export default class WalletConnectProvider {
  constructor() {
    this.name = 'WalletConnect'
    this.provider = new WalletConnect({
      bridge: 'https://bridge.walletconnect.org',
      qrcodeModal: QRCodeModal,
    })

    this._forceOpen = false
  }

  getAddress() {
    const [account] = this.provider.accounts
    return account
  }

  async connect() {
    return new Promise(async (r, j) => {
      let setForceOpen = false
      if (!this.provider.connected) {
        await this.provider.createSession()
        setForceOpen = true
      }

      // https://github.com/NoahZinsmeister/web3-react/issues/376
      if (this._forceOpen) {
        // Modal has already been opened once, force it to open
        this.provider._qrcodeModal.open(this.provider.uri, this.provider._qrcodeModalOptions)
      } else if (setForceOpen) {
        // Modal opened for the first time, force on future attempts
        this._forceOpen = true
      }

      const ob = new MutationObserver(([event]) => {
        // Check if the wallet connect wrapper was removed
        const removed = [...event.removedNodes].find(el => el.id === 'walletconnect-wrapper')
        if (!removed) return
        ob.disconnect() // kill observer
        return this.provider.connected ? r(this.getAddress()) : j()
      })
      ob.observe(document.querySelector('body'), { childList: true })
    })
  }

  async sign(message) {
    const encodedMessage = new TextEncoder().encode(message)
    return this.provider.signPersonalMessage([encodedMessage, this.getAddress()])
  }
}
0reactions
finessevanescommented, Dec 13, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

QR code modal doesnt open after closing once #747 - GitHub
I posted a workaround for the @walletconnect/core and @walletconnect/qrcode-modal packages but could likely be applied to the provider if you ...
Read more >
Cannot open WalletConnect modal after closing it for the first ...
Having a strange issue where as the WalletConnect modal will not open if click on the “X” icon to close the modal when...
Read more >
@walletconnect/qrcode-modal - npm
QR Code Modal for WalletConnect. ... Start using @walletconnect/qrcode-modal in your project by running `npm i @walletconnect/qrcode-modal`.
Read more >
OPEN BOOTSTRAP MODAL AFTER SCANNING THE VALUE ...
I have a form that when the user scans their QR code into the scanner a modal will pop-out with their details. But...
Read more >
After opening and closing modal, it won't open again
I wanted to work first on the modal, making sure It is displayed once you click on a div and then close after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found