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

No way to check for a dapp connection without auto-prompting the user to choose a wallet #110

Open
esot321c opened this issue Sep 8, 2023 · 3 comments
Labels
dapp connector enhancement New feature or request

Comments

@esot321c
Copy link

esot321c commented Sep 8, 2023

When a user navigates to a page, we need a way to check if they have an active nautilus connection.

This is problematic because it will automatically prompt the user to choose a wallet if they haven't already connected one:

// @ts-ignore
const injectApi = await ergoConnector.nautilus.connect();
  if (injectApi) {
    // @ts-ignore
    const changeAddress = await ergo.get_change_address();
    if (changeAddress) {
      setDappConnected(true);
      return changeAddress;
  }
}

If we auto-prompt a user, then it negates the "sign in" button. If we decide not to potentially auto-prompt non-logged in users, we have no way of knowing when a user navigates to the page and has already connected in the past.

We can store an active connection in localStorage or a database, but then if the user manually disconnects via Nautilus, the dapp will think they're logged in. It will then use the ergoConnector.nautilus.connect() to instantiate the API, causing an automatic wallet selection prompt. If the app is operating under the premise that the user chose a specific wallet before, and now the user chooses a different one, there are differences between the user's connected wallet and the app session.

The app can compare the two, but then a new session must be created. Sometimes, this forces a page refresh (like with next-auth), and the user-flow is interrupted and not automatically started again.

@capt-nemo429
Copy link
Member

Hey, you can use the method ergoConnector.nautilus.isConnected() to check if the dApp is authorized without popping up the connection window.

@esot321c
Copy link
Author

esot321c commented Sep 8, 2023

Brilliant! I'll try that today and close the issue.

@esot321c esot321c reopened this Sep 18, 2023
@esot321c
Copy link
Author

esot321c commented Sep 18, 2023

const checkDappConnection = async () => {
  const isNautilusConnected = await window.ergoConnector.nautilus.isConnected();
  if (!isNautilusConnected) {
    console.log('Nautilus not connected')
  }
  else console.log('Nautilus is connected')
}
checkDappConnection();

This code always returns "Nautilus not connected"

When changed to const isNautilusConnected = await window.ergoConnector.nautilus.connect(); it works as intended when they are connected, but it prompts a connection when they are not connected (which is not the desired functionality for this app)

@arobsn arobsn added enhancement New feature or request dapp connector labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dapp connector enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants