@onekeyfe/onekey-private-provider 2.0.0-alpha.9 → 2.0.1
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.
- package/dist/ProviderPrivate.d.ts +3 -0
- package/dist/ProviderPrivate.js +18 -9
- package/dist/cjs/ProviderPrivate.js +17 -8
- package/dist/cjs/index.js +5 -1
- package/package.json +6 -6
|
@@ -32,5 +32,8 @@ declare class ProviderPrivate extends ProviderBase {
|
|
|
32
32
|
protected providerName: IInjectedProviderNamesStrings;
|
|
33
33
|
request(data: unknown): Promise<unknown>;
|
|
34
34
|
notifyDefaultWalletChanged(params: IOneKeyWalletInfo): void;
|
|
35
|
+
notifyNetworkChanged(params: {
|
|
36
|
+
networkChangedText: string;
|
|
37
|
+
}): void;
|
|
35
38
|
}
|
|
36
39
|
export { ProviderPrivate };
|
package/dist/ProviderPrivate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IInjectedProviderNames, } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
-
import { ProviderBase, switchDefaultWalletNotification } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
|
+
import { ProviderBase, switchDefaultWalletNotification, switchNetworkNotification } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
3
|
import { consts } from '@onekeyfe/cross-inpage-provider-core';
|
|
4
4
|
const { WALLET_INFO_LOACAL_KEY_V5 } = consts;
|
|
5
5
|
const PROVIDER_EVENTS = {
|
|
@@ -7,6 +7,7 @@ const PROVIDER_EVENTS = {
|
|
|
7
7
|
};
|
|
8
8
|
const METHODS = {
|
|
9
9
|
wallet_events_ext_switch_changed: 'wallet_events_ext_switch_changed',
|
|
10
|
+
wallet_events_dapp_network_changed: 'wallet_events_dapp_network_changed'
|
|
10
11
|
};
|
|
11
12
|
class ProviderPrivate extends ProviderBase {
|
|
12
13
|
constructor(props) {
|
|
@@ -32,12 +33,12 @@ class ProviderPrivate extends ProviderBase {
|
|
|
32
33
|
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY_V5);
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
34
35
|
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
36
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
38
|
+
const { method, params } = payload;
|
|
39
|
+
if (method === METHODS.wallet_events_ext_switch_changed) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
41
|
+
if (!walletInfoLocal || (walletInfoLocal && walletInfoLocal.platformEnv.isExtension)) {
|
|
41
42
|
try {
|
|
42
43
|
localStorage.setItem(WALLET_INFO_LOACAL_KEY_V5, JSON.stringify(params));
|
|
43
44
|
this.notifyDefaultWalletChanged(params);
|
|
@@ -46,8 +47,11 @@ class ProviderPrivate extends ProviderBase {
|
|
|
46
47
|
console.error(e);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
50
|
+
}
|
|
51
|
+
else if (method === METHODS.wallet_events_dapp_network_changed) {
|
|
52
|
+
this.notifyNetworkChanged(params);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
51
55
|
}
|
|
52
56
|
catch (e) {
|
|
53
57
|
console.error(e);
|
|
@@ -64,5 +68,10 @@ class ProviderPrivate extends ProviderBase {
|
|
|
64
68
|
}
|
|
65
69
|
switchDefaultWalletNotification(isDefaultWallet);
|
|
66
70
|
}
|
|
71
|
+
notifyNetworkChanged(params) {
|
|
72
|
+
if (!params.networkChangedText)
|
|
73
|
+
return;
|
|
74
|
+
switchNetworkNotification(params.networkChangedText);
|
|
75
|
+
}
|
|
67
76
|
}
|
|
68
77
|
export { ProviderPrivate };
|
|
@@ -10,6 +10,7 @@ const PROVIDER_EVENTS = {
|
|
|
10
10
|
};
|
|
11
11
|
const METHODS = {
|
|
12
12
|
wallet_events_ext_switch_changed: 'wallet_events_ext_switch_changed',
|
|
13
|
+
wallet_events_dapp_network_changed: 'wallet_events_dapp_network_changed'
|
|
13
14
|
};
|
|
14
15
|
class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
15
16
|
constructor(props) {
|
|
@@ -35,12 +36,12 @@ class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
|
35
36
|
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY_V5);
|
|
36
37
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
37
38
|
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
39
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
41
|
+
const { method, params } = payload;
|
|
42
|
+
if (method === METHODS.wallet_events_ext_switch_changed) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
44
|
+
if (!walletInfoLocal || (walletInfoLocal && walletInfoLocal.platformEnv.isExtension)) {
|
|
44
45
|
try {
|
|
45
46
|
localStorage.setItem(WALLET_INFO_LOACAL_KEY_V5, JSON.stringify(params));
|
|
46
47
|
this.notifyDefaultWalletChanged(params);
|
|
@@ -49,8 +50,11 @@ class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
|
49
50
|
console.error(e);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
53
|
+
}
|
|
54
|
+
else if (method === METHODS.wallet_events_dapp_network_changed) {
|
|
55
|
+
this.notifyNetworkChanged(params);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
54
58
|
}
|
|
55
59
|
catch (e) {
|
|
56
60
|
console.error(e);
|
|
@@ -67,5 +71,10 @@ class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
|
67
71
|
}
|
|
68
72
|
(0, cross_inpage_provider_core_1.switchDefaultWalletNotification)(isDefaultWallet);
|
|
69
73
|
}
|
|
74
|
+
notifyNetworkChanged(params) {
|
|
75
|
+
if (!params.networkChangedText)
|
|
76
|
+
return;
|
|
77
|
+
(0, cross_inpage_provider_core_1.switchNetworkNotification)(params.networkChangedText);
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
exports.ProviderPrivate = ProviderPrivate;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-private-provider",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "2.0.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.0.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "2.0.
|
|
34
|
-
"@onekeyfe/extension-bridge-injected": "2.0.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "2.0.1",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.0.1",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "2.0.1",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "2.0.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "762c20dff522f3bdd67cedcb97a5c49a97c5e3fa"
|
|
37
37
|
}
|