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

Add isPeraDiscoverBrowser check to enable auto-connect #311

Open
yasincaliskan opened this issue Nov 1, 2024 · 1 comment
Open

Add isPeraDiscoverBrowser check to enable auto-connect #311

yasincaliskan opened this issue Nov 1, 2024 · 1 comment
Labels
feature request New feature or enhancement v4 Issue related to v4.x

Comments

@yasincaliskan
Copy link

Currently, we use an isPeraDiscoverBrowser property within Pera Connect to detect if the dApp is opened within the Pera Discover Browser. When this property returns true, we bypass the typical wallet selection screen and directly initiate the Pera Connect connection, providing a smoother user experience. Reference

In use-wallet, the default flow initiates the wallet selection screen immediately after the "Connect wallet" button is clicked. This works well in general scenarios, but in cases where isPeraDiscoverBrowser is true, it would be more efficient to skip this step and auto-connect with Pera Connect.

The only workaround I see is listing only the PeraWallet option, but this isn't ideal, especially since the "Connect wallet" button is controlled by the dApp and cannot be manipulated externally.

Is there a way to incorporate isPeraDiscoverBrowser into use-wallet to enable an auto-connect flow when detected?

@drichar
Copy link
Collaborator

drichar commented Nov 4, 2024

Currently the library waits until a wallet provider's connect method is invoked for the first time to lazily load its dependencies. This is a performance optimization for apps that are configured to support multiple wallets. If a wallet isn't used its dependencies are never loaded.

The auto-connect flow would require bypassing this behavior in the Pera provider. Pera Connect would need to be loaded every time the app mounts, whether the user is on a mobile device using the Discover browser or not. I'd like to give developers a way to opt-in to this behavior.

There are two approaches that would work:

  1. Expose a configuration property like autoConnect: true to signal that the provider should load the module right away
  2. The app imports the module and passes it directly to a property like staticModule: PeraWalletConnect

With the module available in the constructor, the client is initialized and conditionally triggers the automatic connection.

I'm leaning towards option 2, because it aligns with a change I'm considering for the next major release. Lazy loading by default prohibits the library from being used in projects that don't support dynamic imports. Actually I think it makes sense to save this feature for v4.0.0 so it can be incorporated with the broader change.

I'll tag you @yasincaliskan in the PR when the feature is ready to review.

@drichar drichar added feature request New feature or enhancement v4 Issue related to v4.x labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or enhancement v4 Issue related to v4.x
Projects
None yet
Development

No branches or pull requests

2 participants