@onekeyfe/inpage-providers-hub 1.1.16 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,23 @@ require("./connectButtonHack");
16
16
  const consts_1 = require("./connectButtonHack/consts");
17
17
  // import Web3 from 'web3'; // cause build error
18
18
  const { WALLET_INFO_LOACAL_KEY } = cross_inpage_provider_core_1.consts;
19
+ function checkWalletSwitchEnable(property) {
20
+ try {
21
+ const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
22
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
23
+ if (walletInfoLocal && walletInfoLocal.walletSwitchConfig) {
24
+ const { enable, disable } = walletInfoLocal.walletSwitchConfig;
25
+ const enableList = enable || [];
26
+ const disableList = disable || [];
27
+ return ((enableList.includes(property) && !disableList.includes(property)) ||
28
+ (!enableList.includes(property) && !disableList.includes(property)));
29
+ }
30
+ }
31
+ catch (e) {
32
+ console.error(e);
33
+ }
34
+ return true;
35
+ }
19
36
  function checkEnableDefineProperty(property) {
20
37
  if (property === '$onekey')
21
38
  return false;
@@ -30,6 +47,8 @@ function checkEnableDefineProperty(property) {
30
47
  return false;
31
48
  }
32
49
  function defineWindowProperty(property, provider) {
50
+ if (!checkWalletSwitchEnable(property))
51
+ return;
33
52
  const enable = checkEnableDefineProperty(property);
34
53
  const proxyProvider = new Proxy(provider, {
35
54
  defineProperty(target, property, attributes) {
@@ -107,17 +126,6 @@ function injectWeb3Provider() {
107
126
  cardano,
108
127
  cosmos });
109
128
  defineWindowProperty('$onekey', $onekey);
110
- try {
111
- const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
112
- const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
113
- if (walletInfoLocal && walletInfoLocal.platformEnv.isExtension && walletInfoLocal.disableExt) {
114
- // disable onekey ext stop inject
115
- return;
116
- }
117
- }
118
- catch (e) {
119
- console.error(e);
120
- }
121
129
  const martianProxy = new Proxy(martian, {
122
130
  get: (target, property, ...args) => {
123
131
  if (property === 'aptosProviderType') {
@@ -28,6 +28,10 @@ export declare type IWindowOneKeyHub = {
28
28
  disableExt?: boolean;
29
29
  platform: string;
30
30
  version: string;
31
+ walletSwitchConfig: {
32
+ enable: string[];
33
+ disable: [];
34
+ };
31
35
  platformEnv: {
32
36
  isExtension: boolean;
33
37
  isDesktop: boolean;
@@ -13,6 +13,23 @@ import './connectButtonHack';
13
13
  import { WALLET_CONNECT_INFO } from './connectButtonHack/consts';
14
14
  // import Web3 from 'web3'; // cause build error
15
15
  const { WALLET_INFO_LOACAL_KEY } = consts;
16
+ function checkWalletSwitchEnable(property) {
17
+ try {
18
+ const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
19
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
20
+ if (walletInfoLocal && walletInfoLocal.walletSwitchConfig) {
21
+ const { enable, disable } = walletInfoLocal.walletSwitchConfig;
22
+ const enableList = enable || [];
23
+ const disableList = disable || [];
24
+ return ((enableList.includes(property) && !disableList.includes(property)) ||
25
+ (!enableList.includes(property) && !disableList.includes(property)));
26
+ }
27
+ }
28
+ catch (e) {
29
+ console.error(e);
30
+ }
31
+ return true;
32
+ }
16
33
  function checkEnableDefineProperty(property) {
17
34
  if (property === '$onekey')
18
35
  return false;
@@ -27,6 +44,8 @@ function checkEnableDefineProperty(property) {
27
44
  return false;
28
45
  }
29
46
  function defineWindowProperty(property, provider) {
47
+ if (!checkWalletSwitchEnable(property))
48
+ return;
30
49
  const enable = checkEnableDefineProperty(property);
31
50
  const proxyProvider = new Proxy(provider, {
32
51
  defineProperty(target, property, attributes) {
@@ -104,17 +123,6 @@ function injectWeb3Provider() {
104
123
  cardano,
105
124
  cosmos });
106
125
  defineWindowProperty('$onekey', $onekey);
107
- try {
108
- const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
109
- const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
110
- if (walletInfoLocal && walletInfoLocal.platformEnv.isExtension && walletInfoLocal.disableExt) {
111
- // disable onekey ext stop inject
112
- return;
113
- }
114
- }
115
- catch (e) {
116
- console.error(e);
117
- }
118
126
  const martianProxy = new Proxy(martian, {
119
127
  get: (target, property, ...args) => {
120
128
  if (property === 'aptosProviderType') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/inpage-providers-hub",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -28,19 +28,19 @@
28
28
  "start": "tsc --watch"
29
29
  },
30
30
  "dependencies": {
31
- "@onekeyfe/cross-inpage-provider-core": "1.1.16",
32
- "@onekeyfe/cross-inpage-provider-types": "1.1.16",
33
- "@onekeyfe/onekey-aptos-provider": "1.1.16",
34
- "@onekeyfe/onekey-cardano-provider": "1.1.16",
35
- "@onekeyfe/onekey-conflux-provider": "1.1.16",
36
- "@onekeyfe/onekey-cosmos-provider": "1.1.16",
37
- "@onekeyfe/onekey-eth-provider": "1.1.16",
38
- "@onekeyfe/onekey-private-provider": "1.1.16",
39
- "@onekeyfe/onekey-solana-provider": "1.1.16",
40
- "@onekeyfe/onekey-starcoin-provider": "1.1.16",
41
- "@onekeyfe/onekey-sui-provider": "1.1.16",
42
- "@onekeyfe/onekey-tron-provider": "1.1.16",
31
+ "@onekeyfe/cross-inpage-provider-core": "1.1.18",
32
+ "@onekeyfe/cross-inpage-provider-types": "1.1.18",
33
+ "@onekeyfe/onekey-aptos-provider": "1.1.18",
34
+ "@onekeyfe/onekey-cardano-provider": "1.1.18",
35
+ "@onekeyfe/onekey-conflux-provider": "1.1.18",
36
+ "@onekeyfe/onekey-cosmos-provider": "1.1.18",
37
+ "@onekeyfe/onekey-eth-provider": "1.1.18",
38
+ "@onekeyfe/onekey-private-provider": "1.1.18",
39
+ "@onekeyfe/onekey-solana-provider": "1.1.18",
40
+ "@onekeyfe/onekey-starcoin-provider": "1.1.18",
41
+ "@onekeyfe/onekey-sui-provider": "1.1.18",
42
+ "@onekeyfe/onekey-tron-provider": "1.1.18",
43
43
  "web3": "^1.7.3"
44
44
  },
45
- "gitHead": "a2aa4f3e6d8ad7ac8ad73b31e7f8d80f5abd3d46"
45
+ "gitHead": "178945409c2c48d7a8c3b43fcd7ef610009c1ee0"
46
46
  }