ArweaveWalletConnector icon indicating copy to clipboard operation
ArweaveWalletConnector copied to clipboard

Auto Reconnect on Browser Refresh

Open twilson63 opened this issue 2 years ago • 6 comments

What is the best way to reconnect the wallet on browser refresh, I am making several attempts but not getting any feedback.

twilson63 avatar Jul 04 '22 13:07 twilson63

The feature will be enabled entirely from the wallet side (arweave.app). If I didn't forget anything, the connector wont have to be updated at all.

Just make sure that you have your listeners setup using either .on('connect', callback) or on('change', callback), and called .setUrl('lastUrlThatWasUsed') on your wallet instance as early as possible after the page is loaded when there is the possibility of a reconnection. This will be all that's needed to keep a user session going

jfbeats avatar Jul 04 '22 20:07 jfbeats

Going to give this a try now.

twilson63 avatar Jul 05 '22 13:07 twilson63

It does not seem to be working on either Brave or Firefox, I have a reconnect flag set and it does the following:

export const reconnectApp = () => {
  wallet = new ArweaveWebWallet({
    name: 'permapages',
    logo: `${window.location.origin}/permapages_logo.svg`
  })
  //console.log('wallet', wallet)

  wallet.setUrl('https://arweave.app')
  wallet.on('connect', (x) => {
    console.log('reconnected: ', x)
    return x
  })
}

During a refresh the connect event never fires, should I be calling wallet.connect()

twilson63 avatar Jul 05 '22 14:07 twilson63

Sorry twilson! My reply wasn't clear. I meant that the feature will be implemented soon but is not yet available. Just have it configured like I said and, in theory, you won't have to do anything once it's rolled out. I'll keep you posted!

jfbeats avatar Jul 05 '22 20:07 jfbeats

Cool

Thank you

I will follow the progress

twilson63 avatar Jul 05 '22 20:07 twilson63

Hi guys! Is this working now? I can't reconnect when I refresh the page yet, even configuring the listeners.

rafaelmmathias avatar Sep 16 '22 03:09 rafaelmmathias

Hey guys! Sorry it took so long. The connector has been updated to 1.0.0, adding auto-reconnect management and universal reactivity for all frameworks. You can check the readme for examples.

All you have to do is call the constructor as soon as possible (now returns a singleton), without necessarily calling setUrl unless requested by the user input. It will automatically try what it has saved in memory a single time if the user was previously connected to anything.

Don't hesitate to reach out if you have any feedback! 😁

jfbeats avatar Feb 08 '23 12:02 jfbeats

@jfbeats The wallet does not reconnect on browser refresh. I am still facing this issue in Svelte.

const state = { url: 'arweave.app' }
const APP_NAME = "random"
const wallet = new ArweaveWebWallet(
        { name: APP_NAME, logo: 'logo.png' },
        { state }
 )

I am using like this but it does not reconnect on browser refresh.

pawanpaudel93 avatar Apr 15 '23 13:04 pawanpaudel93

@pawanpaudel93 make sure that the account you want to enable auto-connect for has that setting turned on in the connection page of arweave.app. It is still a user configured behavior but there will be additional shortcuts in the UI to make it easier eventually. If this doesn't work, send a link to a reproduction of the problem and I'll check it out :)

jfbeats avatar Apr 15 '23 14:04 jfbeats

@jfbeats Thank you for your response. Here I created a vite svelte app: Code Demo. Auto reconnect works on Chrome only but not on Firefox, brave, and Safari. Can you please check what I am doing wrong or is it a bug ??

pawanpaudel93 avatar Apr 16 '23 07:04 pawanpaudel93