Skip to content

Commit

Permalink
feat: optimize dot provider OK-33654 OK-33512 (#6164)
Browse files Browse the repository at this point in the history
* feat: optimize dot provider

* chore: fix lint
  • Loading branch information
ByteZhang1024 authored Nov 11, 2024
1 parent 986bebb commit 6758694
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 253 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@
"@glif/filecoin-rpc-client": "3.0.2",
"@mysten/sui": "1.13.0",
"@ngraveio/bc-ur": "^1.1.13",
"@onekeyfe/cross-inpage-provider-core": "2.1.12",
"@onekeyfe/cross-inpage-provider-errors": "2.1.12",
"@onekeyfe/cross-inpage-provider-injected": "2.1.12",
"@onekeyfe/cross-inpage-provider-types": "2.1.12",
"@onekeyfe/extension-bridge-hosted": "2.1.12",
"@onekeyfe/cross-inpage-provider-core": "2.1.13",
"@onekeyfe/cross-inpage-provider-errors": "2.1.13",
"@onekeyfe/cross-inpage-provider-injected": "2.1.13",
"@onekeyfe/cross-inpage-provider-types": "2.1.13",
"@onekeyfe/extension-bridge-hosted": "2.1.13",
"@onekeyfe/hd-ble-sdk": "1.0.12",
"@onekeyfe/hd-core": "1.0.12",
"@onekeyfe/hd-shared": "1.0.12",
"@onekeyfe/hd-transport": "1.0.12",
"@onekeyfe/hd-web-sdk": "1.0.12",
"@onekeyfe/onekey-cross-webview": "2.1.12",
"@onekeyfe/onekey-cross-webview": "2.1.13",
"@polkadot/extension-inject": "0.46.6",
"@polkadot/types": "11.3.1",
"@polkadot/util-crypto": "12.6.2",
Expand Down
41 changes: 28 additions & 13 deletions packages/kit-bg/src/providers/ProviderApiPolkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ProviderApiPolkadot extends ProviderApiBase {
const params = await this.account({ origin, scope: 'polkadot' });
const result = {
method: 'wallet_events_accountChanged',
params,
params: this.accountsToInjectedAccount(params),
};
return result;
};
Expand Down Expand Up @@ -104,6 +104,27 @@ class ProviderApiPolkadot extends ProviderApiBase {
return !!res;
}

private accountsToInjectedAccount(
account:
| {
address: string;
name: string;
networkId?: string;
id?: string;
}
| undefined,
): InjectedAccount | undefined {
if (!account) {
return undefined;
}
return {
address: account.address,
genesisHash: null,
name: account.name,
type: 'ed25519',
};
}

@providerApiMethod()
public web3Enable(request: IJsBridgeMessagePayload): Promise<boolean> {
return this._queue.runExclusive(async () => {
Expand All @@ -125,21 +146,15 @@ class ProviderApiPolkadot extends ProviderApiBase {
params: boolean,
): Promise<InjectedAccount[]> {
let account = await this.account(request);

if (account) {
return [
{
address: account.address,
genesisHash: null,
name: account.name,
type: 'ed25519',
},
];
let injectedAccount = this.accountsToInjectedAccount(account);
if (injectedAccount) {
return [injectedAccount];
}

account = await this.account(request);
if (account) {
return [account];
injectedAccount = this.accountsToInjectedAccount(account);
if (injectedAccount) {
return [injectedAccount];
}
return [];
}
Expand Down
Loading

0 comments on commit 6758694

Please sign in to comment.