ArweaveWalletConnector
ArweaveWalletConnector copied to clipboard
Auto Reconnect on Browser Refresh
What is the best way to reconnect the wallet on browser refresh, I am making several attempts but not getting any feedback.
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
Going to give this a try now.
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()
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!
Cool
Thank you
I will follow the progress
Hi guys! Is this working now? I can't reconnect when I refresh the page yet, even configuring the listeners.
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 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 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 :)