@portal-hq/webview 3.0.6 → 4.0.0
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/lib/commonjs/index.js +4 -1
- package/lib/esm/index.js +4 -1
- package/package.json +5 -5
- package/src/index.tsx +9 -2
package/lib/commonjs/index.js
CHANGED
|
@@ -45,6 +45,7 @@ const react_native_webview_1 = __importDefault(require("react-native-webview"));
|
|
|
45
45
|
const loading_1 = __importDefault(require("./loading"));
|
|
46
46
|
const Webview = (0, react_1.memo)((0, react_1.forwardRef)(({ onNavigationStateChange, onSigningRequested, url }, webViewRef) => {
|
|
47
47
|
const Webview = () => {
|
|
48
|
+
var _a;
|
|
48
49
|
// Derive context.
|
|
49
50
|
const portal = (0, core_1.usePortal)();
|
|
50
51
|
// Derive refs.
|
|
@@ -54,6 +55,7 @@ const Webview = (0, react_1.memo)((0, react_1.forwardRef)(({ onNavigationStateCh
|
|
|
54
55
|
// Derive state.
|
|
55
56
|
const [currentUrl, setCurrentUrl] = (0, react_1.useState)(url);
|
|
56
57
|
const [walletAddress, setWalletAddress] = (0, react_1.useState)();
|
|
58
|
+
const [chainId, setChainId] = (0, react_1.useState)((_a = portal.chainId) !== null && _a !== void 0 ? _a : 11155111);
|
|
57
59
|
const source = (0, react_1.useMemo)(() => ({
|
|
58
60
|
uri: currentUrl,
|
|
59
61
|
}), [currentUrl]);
|
|
@@ -89,7 +91,7 @@ const Webview = (0, react_1.memo)((0, react_1.forwardRef)(({ onNavigationStateCh
|
|
|
89
91
|
const { method, params } = data;
|
|
90
92
|
switch (type) {
|
|
91
93
|
case 'portal_sign':
|
|
92
|
-
yield portal.request(method, params);
|
|
94
|
+
yield portal.request(method, params, `eip155:${chainId}`);
|
|
93
95
|
break;
|
|
94
96
|
}
|
|
95
97
|
});
|
|
@@ -108,6 +110,7 @@ const Webview = (0, react_1.memo)((0, react_1.forwardRef)(({ onNavigationStateCh
|
|
|
108
110
|
});
|
|
109
111
|
portal.on('chainChanged', ({ chainId }) => {
|
|
110
112
|
var _a;
|
|
113
|
+
setChainId(chainId);
|
|
111
114
|
(_a = webView.current) === null || _a === void 0 ? void 0 : _a.postMessage(JSON.stringify({
|
|
112
115
|
type: 'portal_chainChanged',
|
|
113
116
|
data: { chainId },
|
package/lib/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import WebView from 'react-native-webview';
|
|
|
17
17
|
import Loading from './loading';
|
|
18
18
|
const Webview = memo(forwardRef(({ onNavigationStateChange, onSigningRequested, url }, webViewRef) => {
|
|
19
19
|
const Webview = () => {
|
|
20
|
+
var _a;
|
|
20
21
|
// Derive context.
|
|
21
22
|
const portal = usePortal();
|
|
22
23
|
// Derive refs.
|
|
@@ -26,6 +27,7 @@ const Webview = memo(forwardRef(({ onNavigationStateChange, onSigningRequested,
|
|
|
26
27
|
// Derive state.
|
|
27
28
|
const [currentUrl, setCurrentUrl] = useState(url);
|
|
28
29
|
const [walletAddress, setWalletAddress] = useState();
|
|
30
|
+
const [chainId, setChainId] = useState((_a = portal.chainId) !== null && _a !== void 0 ? _a : 11155111);
|
|
29
31
|
const source = useMemo(() => ({
|
|
30
32
|
uri: currentUrl,
|
|
31
33
|
}), [currentUrl]);
|
|
@@ -61,7 +63,7 @@ const Webview = memo(forwardRef(({ onNavigationStateChange, onSigningRequested,
|
|
|
61
63
|
const { method, params } = data;
|
|
62
64
|
switch (type) {
|
|
63
65
|
case 'portal_sign':
|
|
64
|
-
yield portal.request(method, params);
|
|
66
|
+
yield portal.request(method, params, `eip155:${chainId}`);
|
|
65
67
|
break;
|
|
66
68
|
}
|
|
67
69
|
});
|
|
@@ -80,6 +82,7 @@ const Webview = memo(forwardRef(({ onNavigationStateChange, onSigningRequested,
|
|
|
80
82
|
});
|
|
81
83
|
portal.on('chainChanged', ({ chainId }) => {
|
|
82
84
|
var _a;
|
|
85
|
+
setChainId(chainId);
|
|
83
86
|
(_a = webView.current) === null || _a === void 0 ? void 0 : _a.postMessage(JSON.stringify({
|
|
84
87
|
type: 'portal_chainChanged',
|
|
85
88
|
data: { chainId },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/webview",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/esm/index",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"test": "jest --passWithNoTests"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@portal-hq/core": "^
|
|
22
|
-
"@portal-hq/injected-provider": "^
|
|
23
|
-
"@portal-hq/utils": "^
|
|
21
|
+
"@portal-hq/core": "^4.0.0",
|
|
22
|
+
"@portal-hq/injected-provider": "^4.0.0",
|
|
23
|
+
"@portal-hq/utils": "^4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/jest": "^29.2.0",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"react-native": "*",
|
|
37
37
|
"react-native-webview": "*"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a1c6f51ff156d3d1922cdaa29ee43fe4cfefd932"
|
|
40
40
|
}
|
package/src/index.tsx
CHANGED
|
@@ -37,7 +37,6 @@ const Webview = memo(
|
|
|
37
37
|
const Webview: FC = () => {
|
|
38
38
|
// Derive context.
|
|
39
39
|
const portal = usePortal()
|
|
40
|
-
|
|
41
40
|
// Derive refs.
|
|
42
41
|
const canGoBack = useRef<boolean>(false)
|
|
43
42
|
const initialized = useRef<boolean>(false)
|
|
@@ -46,6 +45,9 @@ const Webview = memo(
|
|
|
46
45
|
// Derive state.
|
|
47
46
|
const [currentUrl, setCurrentUrl] = useState<string>(url)
|
|
48
47
|
const [walletAddress, setWalletAddress] = useState<string>()
|
|
48
|
+
const [chainId, setChainId] = useState<number>(
|
|
49
|
+
portal.chainId ?? 11155111,
|
|
50
|
+
)
|
|
49
51
|
|
|
50
52
|
const source = useMemo(
|
|
51
53
|
(): WebViewSourceUri => ({
|
|
@@ -91,7 +93,11 @@ const Webview = memo(
|
|
|
91
93
|
|
|
92
94
|
switch (type) {
|
|
93
95
|
case 'portal_sign':
|
|
94
|
-
await portal.request(
|
|
96
|
+
await portal.request(
|
|
97
|
+
method,
|
|
98
|
+
params as unknown[],
|
|
99
|
+
`eip155:${chainId}`,
|
|
100
|
+
)
|
|
95
101
|
break
|
|
96
102
|
}
|
|
97
103
|
}
|
|
@@ -113,6 +119,7 @@ const Webview = memo(
|
|
|
113
119
|
})
|
|
114
120
|
|
|
115
121
|
portal.on('chainChanged', ({ chainId }: { chainId: number }) => {
|
|
122
|
+
setChainId(chainId)
|
|
116
123
|
webView.current?.postMessage(
|
|
117
124
|
JSON.stringify({
|
|
118
125
|
type: 'portal_chainChanged',
|