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

wallet provider, few ideas for improvement #280

Open
pkieltyka opened this issue Jun 10, 2022 · 1 comment
Open

wallet provider, few ideas for improvement #280

pkieltyka opened this issue Jun 10, 2022 · 1 comment

Comments

@pkieltyka
Copy link
Member

Wallet connect + passing your own provider

It's helpful for the dapp to provide one of more provider urls. We already support this on wallet constructor, but have some more ideas too. ie.

// setup wallet on polygon with infura host
const wallet = new sequence.Wallet('https://polygon-mainnet.infura.io/etc')

// setup wallet with multiple networks

const wallet = new sequence.Wallet({
  polygon: 'https://polygon-mainnet.infura.io/etc',
  bsc: 'https://bsc.infura.io/etc'
})

note, currently in master we have.. const wallet = new sequence.Wallet('polygon', { networkRpcUrl: 'https://polygon-mainnet.infura.io/etc' }) .. this is clean enough, but, for simplicity for new developers, its nice to provide the url up front.

other syntax ideas..

const wallet = new sequence.Wallet(['polygon', 'mainnet'], { networkUrls: { polygon: 'https://...', mainnet: 'https://...' })

alternatively, can keep new sequence.Wallet() simple, or just as a place where we pass the provider urls + networks, like in first example, then on wallet.connect({ }) we pass wallet.connect({ network: 'polygon', ... })

we should also think to support wallet.switchNetwork('polygon') as well. and wallet.listNetworks()

On-demand wallet usage with window.ethereum

Many developers integrate with window.ethereum / window.ethereum.providers (which is great). With the sequence package, we don't use this since we have the instance directly on-demand. However, for simplicity of integrations, we could do the following..

sequence.enable()

which will then add the sequence wallet provider into existing window.ethereum.providers array, or instantiate a new one.

we can also pass params like, sequence.enable({ configStuffLikeProviderUrlsetc: '' }

of course, enable() will have to check if window is even defined, otherwise it should throw.

as well, we can put the enable method as a static method on Wallet in @0xsequence/provider .. so that alternative syntax works as..

import { sequence } from '0xsequence'
sequence.Wallet.enable()

Chrome extension -- append to window.ethereum.providers

As well, in the wallet app, we need to append the sequence provider to window.ethereum.providers instead of overwriting it. I believe we have work on this + PR already.

Utils for developers to more easily connect multiple wallets in a dapp

Many dapps like to connect many wallets (makes sense). Let's consider a few simple utility functions which are generic from Sequence to allow these developers some helper utilities to find out which wallets are registered, so they can present their own simple interface, and we can also return a simple provider equivalent of window.ethereum.provider .. which we already have btw from wallet.getProvider(), but its not clear to other developers, and its nice to consider other wallets.. ie.

like... @0xsequence/utils and call it "ethereum-sign-in.ts" or.. "sign-in-with-ethereum.ts" or "ethereum-enable.ts" or "ethereum-connect.ts" .. and we have..

  • EthereumConnect.listWallets()
  • EthereumConnect.connect('metamask') or EthereumConnect.connect('sequence'), and will return a provider
  • EthereumConnect.getProvider('metamask') or EthereumConnect.connect('sequence') and will provider a provider liek above
  • etc..
@pkieltyka
Copy link
Member Author

  • update demo-dapp to show how to connect multiple wallets easily

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

No branches or pull requests

1 participant