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

Support announcing the Alephium provider #253

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ProviderSolana, registerSolanaWallet, WalletIcon } from '@onekeyfe/onek
// import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
import { ProviderAptos, ProviderAptosMartian } from '@onekeyfe/onekey-aptos-provider';
import { ProviderConflux } from '@onekeyfe/onekey-conflux-provider';
import { ProviderAlph } from '@onekeyfe/onekey-alph-provider';
import { ProviderAlph, registerAlephiumProvider } from '@onekeyfe/onekey-alph-provider';
originalix marked this conversation as resolved.
Show resolved Hide resolved
import { ProviderTron } from '@onekeyfe/onekey-tron-provider';
import { ProviderCardano, defineWindowCardanoProperty } from '@onekeyfe/onekey-cardano-provider';
// import { ProviderPrivateExternalAccount } from '@onekeyfe/onekey-private-external-account-provider';
Expand Down Expand Up @@ -205,6 +205,7 @@ function injectWeb3Provider(): unknown {
defineWindowProperty('alephiumProviders', {
alephium,
});
registerAlephiumProvider(alephium);
defineWindowProperty('tronLink', tron);
defineWindowProperty('suiWallet', sui);
defineWindowProperty('onekeyTonWallet', {
Expand Down
13 changes: 10 additions & 3 deletions packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function isWalletEventMethodMatch({ method, name }: { method: string; name: stri
}

export class ProviderAlph extends InteractiveSignerProvider implements AlephiumWindowObject {
id = 'alephium';
name = 'Alephium';
id = 'onekey';
name = 'OneKey';
icon = 'https://uni.onekey-asset.com/static/logo/onekey.png';
version = '0.9.4';
_accountInfo: Account | undefined;
Expand Down Expand Up @@ -148,9 +148,16 @@ export class ProviderAlph extends InteractiveSignerProvider implements AlephiumW
if (options.onDisconnected) {
this.onDisconnected = options.onDisconnected
}
const params: Record<string, unknown> = {};
Object.keys(options).forEach((key) => {
if (options[key as keyof EnableOptions] instanceof Function) {
return;
}
params[key] = options[key as keyof EnableOptions];
})
originalix marked this conversation as resolved.
Show resolved Hide resolved
return this.bridgeRequest({
method: 'enableIfConnected',
params: options,
params,
}) as Promise<Account | undefined>;
}

Expand Down
1 change: 1 addition & 0 deletions packages/providers/onekey-alph-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './OnekeyAlphProvider';
export * from './ProviderAlphBase';
export * from './registerAlephiumProvider'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ProviderAlph } from './OnekeyAlphProvider';

export function registerAlephiumProvider(provider: ProviderAlph) {
function announceProvider() {
window.dispatchEvent(
new CustomEvent('announceAlephiumProvider', {
detail: Object.freeze({ provider }),
}),
originalix marked this conversation as resolved.
Show resolved Hide resolved
);
}
window.addEventListener('requestAlephiumProvider', announceProvider);
announceProvider();
}
originalix marked this conversation as resolved.
Show resolved Hide resolved
Loading