-
Notifications
You must be signed in to change notification settings - Fork 15
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
Detect injected providers #449
base: master
Are you sure you want to change the base?
Conversation
|
||
const detectProviders = () => { | ||
if (typeof window !== 'undefined') { | ||
const oneKeyProvider = window['alephium'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the onekey wallet does not announce the alephium provider, and since onekey sets window.alephium
, we will try to load the onekey provider from window.alephium
.
addNewProvider(oneKeyProvider) | ||
} | ||
|
||
const defaultProvider = getWalletObject(alephiumProvider.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to ensure compatibility with older versions of the alephium extension wallet. If only the alephium wallet is enabled and no provider is announced, we will directly try to load the provider from window.alephiumProviders.alephium
.
let allProviders: AlephiumWindowObject[] = [] | ||
|
||
const addNewProvider = (provider: AlephiumWindowObject) => { | ||
if (allProviders.find((p) => p.icon === provider.icon) === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the onekey wallet and the alephium wallet use the same id and name, so we can only differentiate between them using the icon.
await options.onConnected({ account: enabledAccount, signerProvider: provider }) | ||
setLastConnectedAccount('injected', enabledAccount, options.network) | ||
// eslint-disable-next-line | ||
;(provider as any)['onDisconnected'] = options.onDisconnected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to work around the enableIfConnected
serialization issue in onekey wallet: https://github.com/OneKeyHQ/cross-inpage-provider/blob/23a0e8e3ef2ace42e8a0359be49ddfd2a653d281/packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts#L147, it should handle the callback in the same way as unsafeEnable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
When both the onekey wallet and the alephium wallet are enabled(I can't connect to the onekey extension wallet because I don't have the onekey hardware wallet.):
alephium-and-onekey.mov
When only the alephium wallet is enabled
Screen.Recording.2024-11-18.at.11.39.09.mov
When only the onekey wallet is enabled
onekey.mov