Skip to content

Commit

Permalink
fix _initProviderState conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
marxeille committed Feb 11, 2025
1 parent f3906fd commit 37ad504
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
1 change: 1 addition & 0 deletions apps/extension/src/stores/chain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export class ChainStore extends BaseChainStore<ChainInfoWithCoreTypes> {
if (!this.keyRingStore.selectedKeyInfo) {
return;
}
console.log("enableChainInfoInUI");

const msg = new EnableChainsMsg(
this.keyRingStore.selectedKeyInfo.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/background/src/keyring-ethereum/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const handleRequestJsonRpcToEvmMsg: (
permissionInteractionService
) => {
return async (env, msg) => {
if (msg.method !== "owallet_initProviderState") {
if (msg.method !== "keplr_initProviderState") {
await permissionInteractionService.ensureEnabledForEVM(env, msg.origin);
}

Expand Down
6 changes: 2 additions & 4 deletions packages/background/src/keyring-ethereum/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,8 @@ export class KeyRingEthereumService {
let currentChainId =
this.permissionService.getCurrentChainIdForEVM(origin) ?? chainId;

console.log("currentChainId request", method, currentChainId, params);

if (currentChainId == null) {
if (method === "owallet_initProviderState") {
if (method === "keplr_initProviderState") {
return {
currentEvmChainId: null,
currentChainId: null,
Expand Down Expand Up @@ -402,7 +400,7 @@ export class KeyRingEthereumService {

const result = (await (async () => {
switch (method) {
case "owallet_initProviderState":
case "keplr_initProviderState":
case "owallet_connect": {
return {
currentEvmChainId: currentChainEVMInfo.chainId,
Expand Down
46 changes: 23 additions & 23 deletions packages/background/src/permission/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,30 +230,30 @@ export class PermissionService {
options,
};

if (options?.isForEVM) {
const chainId = chainIds[0];
// if (options?.isForEVM) {
// const chainId = chainIds[0];

this.addPermission([chainId], type, origins);
this.setCurrentChainIdForEVM(origins, chainId);
} else {
this.addPermission(chainIds, type, origins);
}

// await this.interactionService.waitApproveV2(
// env,
// "/permission",
// INTERACTION_TYPE_PERMISSION,
// permissionData,
// (newChainId?: string) => {
// if (options?.isForEVM) {
// const chainId = newChainId ?? chainIds[0];
// this.addPermission([chainId], type, origins);
// this.setCurrentChainIdForEVM(origins, chainId);
// } else {
// this.addPermission(chainIds, type, origins);
// }
// }
// );
// this.addPermission([chainId], type, origins);
// this.setCurrentChainIdForEVM(origins, chainId);
// } else {
// this.addPermission(chainIds, type, origins);
// }

await this.interactionService.waitApproveV2(
env,
"/permission",
INTERACTION_TYPE_PERMISSION,
permissionData,
(newChainId?: string) => {
if (options?.isForEVM) {
const chainId = newChainId ?? chainIds[0];
this.addPermission([chainId], type, origins);
this.setCurrentChainIdForEVM(origins, chainId);
} else {
this.addPermission(chainIds, type, origins);
}
}
);
}

async grantBasicAccessPermission(
Expand Down
7 changes: 4 additions & 3 deletions packages/provider/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export class OWallet implements IOWallet, OWalletCoreTypes {
});
}

// TODO: 웹페이지에서도 필요할수도 있을 것 같으니 나중에 owallet의 API로 추가해준다.
async isEnabled(chainIds: string | string[]): Promise<boolean> {
if (typeof chainIds === "string") {
chainIds = [chainIds];
Expand Down Expand Up @@ -1299,7 +1298,9 @@ class EthereumProvider extends EventEmitter implements IEthereumProvider {
throw new Error("Invalid paramater: `method` must be a string");
}

if (method !== "owallet_initProviderState") {
console.log("method request", method);

if (method !== "keplr_initProviderState") {
await this.protectedEnableAccess();
}

Expand Down Expand Up @@ -2209,7 +2210,7 @@ class TronProvider extends EventEmitter implements ITronProvider {
throw new Error("Invalid paramater: `method` must be a string");
}

if (method !== "owallet_initProviderState") {
if (method !== "keplr_initProviderState") {
await this.protectedEnableAccess();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ class EthereumProvider extends EventEmitter implements IEthereumProvider {
}

const initialProviderState = await this._requestMethod("request", {
method: "owallet_initProviderState",
method: "keplr_initProviderState",
});

if (initialProviderState) {
Expand Down
1 change: 1 addition & 0 deletions packages/router-extension/src/requester/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class InExtensionMessageRequester implements MessageRequester {
msg: M
): Promise<M extends Message<infer R> ? R : never> {
msg.validateBasic();
console.log("msg InExtensionMessageRequester", msg);

// Set message's origin.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down

0 comments on commit 37ad504

Please sign in to comment.