Closed IsaccoSordo closed 4 months ago
Hi, thanks for the issue. Please see the discussion here to achieve what you want: https://github.com/polkadot-js/extension/pull/1382#issuecomment-2199747134
Thank you @Tbaut for the reply.
While .enable()
on the target extension works, any subsequent web3 function calls fail. For instance, we need to display the list of available accounts, which we accomplished using web3Accounts
.
We noticed that the object returned from enable()
contains a property named accounts, but it is an empty object.
Could you point me towards a documentation page that could help with this issue?
I don't think that there are much documentation around this, that's why I recommend to use tools that leverage it so as not to re-invent the wheel. Here are some others:
Ultimately, we ended up using @talisman-connect as it integrates pretty nicely with our codebase. Thank you very much for all the support.
We noticed that the object returned from enable() contains a property named accounts, but it is an empty object.
For anyone reading this later, and willing to do the whole thing themselves. You can't use web3Accounts
, because it indeed goes through all the extension, you have to selectively call enable
on the ones you want, then you get objects with the accounts
field that you have to get()
it, like this.
window.injectedWeb3["polkadot-js"]
.enable("app-name").then(o =>
o.accounts.get()
.then(console.log)
)
// Array [ {…} ]
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.
Calling
web3Enable
asks for permissions from all available extensions in a user's browser. This can become undesirable when a user has multiple extensions, as all the wallets will prompt an alert to ask for user permissions.Additionally, our frontend differentiates between wallets. This means that if a user clicks a button to pair with a specific wallet, all the other Polkadot wallets will still ask for permissions.
Would it be possible to add
Web3AccountsOptions
toweb3Enable
so that a developer can programmatically choose which wallet to pair with?We have a custom alert that allows a user to choose one wallet instead of another. With the current behavior, it is impossible to pair only with the selected wallet.
Please tell us about your environment:
Version: "0.46.5",
Environment: "@polkadot/extension-dapp": "0.46.5", "@polkadot/api": "10.9.1", "@polkadot/keyring": "^12.6.2", "@angular/core": "^14.2.0", "@angular/cli": "~14.2.6",
[ ] Node.js
[x] Browser
[ ] Other (limited support for other environments)
Language:
[ ] JavaScript
[x] TypeScript "~4.7.2"
[ ] Other