From 6688b0cc06e7b7df85a58dede7966e2ab0df550f Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Thu, 22 Aug 2024 21:17:08 +0800 Subject: [PATCH] feat: support alwaysInject (#226) --- packages/core/src/walletProperty.ts | 7 +++++-- .../inpage-providers-hub/src/injectWeb3Provider.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/src/walletProperty.ts b/packages/core/src/walletProperty.ts index 78d6bfa4..8122b57c 100644 --- a/packages/core/src/walletProperty.ts +++ b/packages/core/src/walletProperty.ts @@ -93,10 +93,13 @@ export function defineWindowProperty( options?: { enumerable?: boolean; disablePlatform?: IPlatformType[]; + alwaysInject?: boolean; }, ) { - if (!checkPlatformEnable(options?.disablePlatform)) return; - if (!checkWalletSwitchEnable()) return; + if (!options?.alwaysInject) { + if (!checkPlatformEnable(options?.disablePlatform)) return; + if (!checkWalletSwitchEnable()) return; + } const enable = checkEnableDefineProperty(property); const proxyProvider = new Proxy(provider as object, { defineProperty(target, property, attributes) { diff --git a/packages/providers/inpage-providers-hub/src/injectWeb3Provider.ts b/packages/providers/inpage-providers-hub/src/injectWeb3Provider.ts index 6004eb70..d01ac8b9 100644 --- a/packages/providers/inpage-providers-hub/src/injectWeb3Provider.ts +++ b/packages/providers/inpage-providers-hub/src/injectWeb3Provider.ts @@ -152,7 +152,7 @@ function injectWeb3Provider(): unknown { algorand, }; - defineWindowProperty('$onekey', $onekey, { enumerable: true }); + defineWindowProperty('$onekey', $onekey, { enumerable: true, alwaysInject: true }); const martianProxy = new Proxy(martian, { get: (target, property, ...args) => {