Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Relay QR generation flow improvements #2652

Closed
wants to merge 1 commit into from

Conversation

tomiir
Copy link
Collaborator

@tomiir tomiir commented Aug 5, 2024

Description

  • WC Relay QR code generation has flaky behaviors.
  • There is a lot of overhead in the connection setup: repeated event handlers, multiple connection requests that are stacked on top of each other, complex retry logic with two different timing conditions and poor error handling.
  • This PR refactors the QR flow to bring some improvements:
    => Only subscribe to display_uri event once per client
    => Only re-initialize the connection flow after 15 minutes, given the sdk internally handles retries for that time
    => Always regenerate the URI on an error.

WIP:

  • Handling internal errors / network errors => Somehow we get no messages nor session updates from event handlers

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

For Linear issues: Closes APKT-144

Checklist

  • [] Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections

…e after 15m. Remove duplicated display_uri handlers and subscribe in client constructors
Copy link

linear bot commented Aug 5, 2024

Copy link

vercel bot commented Aug 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
web3modal-gallery ✅ Ready (Inspect) Visit Preview Aug 5, 2024 5:16pm
web3modal-laboratory ✅ Ready (Inspect) Visit Preview Aug 5, 2024 5:16pm

@tomiir tomiir marked this pull request as draft August 5, 2024 17:17
@@ -699,6 +695,10 @@ export class Web3Modal extends Web3ModalScaffold {

this.walletConnectProvider = await EthereumProvider.init(walletConnectProviderOptions)

this.walletConnectProvider.on('display_uri', (uri: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor but you could also

this.walletConnectProvider.on('display_uri', this.setQRCodeURI)

@@ -327,6 +327,10 @@ export class Web3ModalScaffold {
BlockchainApiController.setClientId(clientId)
}

protected setQRCodeURI: (typeof ConnectionController)['setQRCodeURI'] = uri => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the uri is not only for the QR code but for all connections using WalletConnect protocol. maybe setURI or setWalletConnectURI works better?

@@ -7,7 +7,7 @@ import { UniversalProviderFactory } from './universalProvider.js'
import { BaseConnector } from './baseConnector.js'

import type { Signer } from '@solana/web3.js'
import type UniversalProvider from '@walletconnect/universal-provider'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually breaks in some bundlers (default import of UP), it should be a name import.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glitch-txs can we make a lint or tsconfig role to disallow this?

* For 15minutes, the relay handles retries and reconnections internally.
* We re-initialize the connection after that
*/
this.interval = setInterval(this.initializeConnection.bind(this), 15 * 60 * 1000)
Copy link
Member

@chris13524 chris13524 Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Sign SDK that handles this, not the relay. And I would be concerned that depending on this behavior is dangerous. E.g. if the SDK is updated to a version w/o this

@tomiir tomiir closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants