Skip to content

Commit

Permalink
Fix/wallet switch enable (#93)
Browse files Browse the repository at this point in the history
* fix: wallet switch enable from app walletinfo

Signed-off-by: 王山栋 <[email protected]>

* fix: update version

Signed-off-by: 王山栋 <[email protected]>

* fix: update version to 1.1.18

Signed-off-by: 王山栋 <[email protected]>

Signed-off-by: 王山栋 <[email protected]>
  • Loading branch information
ezailWang authored Jan 18, 2023
1 parent 968dcff commit 1789454
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 121 deletions.
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-core",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -29,9 +29,9 @@
"build-version-info": "node ./scripts/buildVersionInfo.js"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-events": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-events": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"events": "^3.3.0",
"lodash": "^4.17.21",
"ms": "^2.1.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/desktop/desktop-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/desktop-bridge-injected",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -34,7 +34,7 @@
"electron": "^17.2.0"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
}
}
2 changes: 1 addition & 1 deletion packages/empty/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-empty",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-errors",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/events/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-events",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down
22 changes: 11 additions & 11 deletions packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-example",
"version": "1.1.17",
"version": "1.1.18",
"private": true,
"scripts": {
"postinstall": "patch-package",
Expand All @@ -17,16 +17,16 @@
"@metamask/onboarding": "^1.0.1",
"@mysten/wallet-adapter-all-wallets": "^0.3.3",
"@mysten/wallet-adapter-react": "^8.0.1",
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/onekey-aptos-provider": "1.1.17",
"@onekeyfe/onekey-cardano-provider": "1.1.17",
"@onekeyfe/onekey-conflux-provider": "1.1.17",
"@onekeyfe/onekey-cosmos-provider": "1.1.17",
"@onekeyfe/onekey-near-provider": "1.1.17",
"@onekeyfe/onekey-solana-provider": "1.1.17",
"@onekeyfe/onekey-sui-provider": "1.1.17",
"@onekeyfe/onekey-tron-provider": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/onekey-aptos-provider": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18",
"@onekeyfe/onekey-conflux-provider": "1.1.18",
"@onekeyfe/onekey-cosmos-provider": "1.1.18",
"@onekeyfe/onekey-near-provider": "1.1.18",
"@onekeyfe/onekey-solana-provider": "1.1.18",
"@onekeyfe/onekey-sui-provider": "1.1.18",
"@onekeyfe/onekey-tron-provider": "1.1.18",
"@solana/web3.js": "^1.41.3",
"@starcoin/starcoin": "^2.1.6",
"@starcoin/starmask-onboarding": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/extension/extension-bridge-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/extension-bridge-hosted",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
}
}
6 changes: 3 additions & 3 deletions packages/extension/extension-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/extension-bridge-injected",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
}
}
14 changes: 7 additions & 7 deletions packages/injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-injected",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -42,12 +42,12 @@
"electron": "*"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/desktop-bridge-injected": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17",
"@onekeyfe/inpage-providers-hub": "1.1.17",
"@onekeyfe/native-bridge-injected": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/desktop-bridge-injected": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"@onekeyfe/inpage-providers-hub": "1.1.18",
"@onekeyfe/native-bridge-injected": "1.1.18",
"buffer": "^6.0.3"
}
}
6 changes: 3 additions & 3 deletions packages/native/native-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/native-bridge-injected",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
}
}
26 changes: 13 additions & 13 deletions packages/providers/inpage-providers-hub/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/inpage-providers-hub",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,18 +28,18 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/onekey-aptos-provider": "1.1.17",
"@onekeyfe/onekey-cardano-provider": "1.1.17",
"@onekeyfe/onekey-conflux-provider": "1.1.17",
"@onekeyfe/onekey-cosmos-provider": "1.1.17",
"@onekeyfe/onekey-eth-provider": "1.1.17",
"@onekeyfe/onekey-private-provider": "1.1.17",
"@onekeyfe/onekey-solana-provider": "1.1.17",
"@onekeyfe/onekey-starcoin-provider": "1.1.17",
"@onekeyfe/onekey-sui-provider": "1.1.17",
"@onekeyfe/onekey-tron-provider": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/onekey-aptos-provider": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18",
"@onekeyfe/onekey-conflux-provider": "1.1.18",
"@onekeyfe/onekey-cosmos-provider": "1.1.18",
"@onekeyfe/onekey-eth-provider": "1.1.18",
"@onekeyfe/onekey-private-provider": "1.1.18",
"@onekeyfe/onekey-solana-provider": "1.1.18",
"@onekeyfe/onekey-starcoin-provider": "1.1.18",
"@onekeyfe/onekey-sui-provider": "1.1.18",
"@onekeyfe/onekey-tron-provider": "1.1.18",
"web3": "^1.7.3"
}
}
32 changes: 21 additions & 11 deletions packages/providers/inpage-providers-hub/src/injectWeb3Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type IWindowOneKeyHub = {
disableExt?: boolean;
platform: string;
version: string;
walletSwitchConfig: { enable: string[]; disable: [] };
platformEnv: {
isExtension: boolean;
isDesktop: boolean;
Expand All @@ -46,6 +47,25 @@ export type IWindowOneKeyHub = {
};
};

function checkWalletSwitchEnable(property: string) {
try {
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
if (walletInfoLocal && walletInfoLocal.walletSwitchConfig) {
const { enable, disable } = walletInfoLocal.walletSwitchConfig;
const enableList: string[] = enable || [];
const disableList: string[] = disable || [];
return (
(enableList.includes(property) && !disableList.includes(property)) ||
(!enableList.includes(property) && !disableList.includes(property))
);
}
} catch (e) {
console.error(e);
}
return true;
}

function checkEnableDefineProperty(property: string) {
if (property === '$onekey') return false;
try {
Expand All @@ -59,6 +79,7 @@ function checkEnableDefineProperty(property: string) {
}

function defineWindowProperty(property: string, provider: unknown) {
if (!checkWalletSwitchEnable(property)) return;
const enable = checkEnableDefineProperty(property);
const proxyProvider = new Proxy(provider as object, {
defineProperty(target, property, attributes) {
Expand Down Expand Up @@ -153,17 +174,6 @@ function injectWeb3Provider(): unknown {

defineWindowProperty('$onekey', $onekey);

try {
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
if (walletInfoLocal && walletInfoLocal.platformEnv.isExtension && walletInfoLocal.disableExt) {
// disable onekey ext stop inject
return;
}
} catch (e) {
console.error(e);
}

const martianProxy = new Proxy(martian, {
get: (target, property, ...args) => {
if (property === 'aptosProviderType') {
Expand Down
10 changes: 5 additions & 5 deletions packages/providers/onekey-aptos-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-aptos-provider",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,10 +28,10 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"aptos": "^1.3.17",
"eth-rpc-errors": "^4.0.3"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/providers/onekey-cardano-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-cardano-provider",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider",
"cardano"
Expand Down Expand Up @@ -29,10 +29,10 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17",
"@onekeyfe/onekey-cardano-provider": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18"
}
}
10 changes: 5 additions & 5 deletions packages/providers/onekey-conflux-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-conflux-provider",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,9 +28,9 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17"
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18"
}
}
10 changes: 5 additions & 5 deletions packages/providers/onekey-cosmos-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-cosmos-provider",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -29,10 +29,10 @@
},
"dependencies": {
"@noble/hashes": "^1.1.4",
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"eth-rpc-errors": "^4.0.3",
"long": "^5.2.1",
"mitt": "^3.0.0"
Expand Down
10 changes: 5 additions & 5 deletions packages/providers/onekey-eth-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-eth-provider",
"version": "1.1.17",
"version": "1.1.18",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,10 +28,10 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.17",
"@onekeyfe/cross-inpage-provider-errors": "1.1.17",
"@onekeyfe/cross-inpage-provider-types": "1.1.17",
"@onekeyfe/extension-bridge-injected": "1.1.17",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"eth-rpc-errors": "^4.0.3"
}
}
Loading

0 comments on commit 1789454

Please sign in to comment.