@arcblock/bridge 3.0.8 → 3.0.10
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/index.js +40 -40
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import n from "./dsbridge.js";
|
|
2
2
|
const f = "1", g = {
|
|
3
3
|
register(...e) {
|
|
4
|
-
|
|
4
|
+
n.canUseBridge() ? n.register(...e) : console.warn("dsbridge is not available");
|
|
5
5
|
},
|
|
6
6
|
registerAsyn(...e) {
|
|
7
|
-
|
|
7
|
+
n.canUseBridge() ? n.registerAsyn(...e) : console.warn("dsbridge is not available");
|
|
8
8
|
},
|
|
9
9
|
call(...e) {
|
|
10
|
-
|
|
10
|
+
n.call(...e);
|
|
11
11
|
},
|
|
12
12
|
asyncCall(...e) {
|
|
13
|
-
return new Promise((s,
|
|
14
|
-
|
|
13
|
+
return new Promise((s, r) => {
|
|
14
|
+
n.call(...e, (a) => {
|
|
15
15
|
try {
|
|
16
16
|
const c = JSON.parse(a);
|
|
17
17
|
if (c.code === 0) {
|
|
18
|
-
const
|
|
19
|
-
s(
|
|
18
|
+
const o = JSON.parse(c.data);
|
|
19
|
+
s(o);
|
|
20
20
|
} else
|
|
21
|
-
|
|
21
|
+
r(new Error(c.error));
|
|
22
22
|
} catch {
|
|
23
23
|
s(a);
|
|
24
24
|
}
|
|
@@ -27,50 +27,50 @@ const f = "1", g = {
|
|
|
27
27
|
},
|
|
28
28
|
// 基本功能
|
|
29
29
|
shareMessage(e) {
|
|
30
|
-
const { content: s, imgUrl:
|
|
31
|
-
if (!s && !
|
|
30
|
+
const { content: s, imgUrl: r, success: a, fail: c } = e;
|
|
31
|
+
if (!s && !r) {
|
|
32
32
|
c("params error");
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
const t = JSON.parse(
|
|
37
|
-
t && t.code === 0 ? typeof a == "function" && a(
|
|
35
|
+
n.call("arcShare", JSON.stringify({ content: s, imgUrl: r }), (o) => {
|
|
36
|
+
const t = JSON.parse(o);
|
|
37
|
+
t && t.code === 0 ? typeof a == "function" && a(o) : typeof c == "function" && c(o);
|
|
38
38
|
});
|
|
39
39
|
},
|
|
40
40
|
showLoading() {
|
|
41
|
-
|
|
41
|
+
n.call("arcShowLoading");
|
|
42
42
|
},
|
|
43
43
|
hideLoading() {
|
|
44
|
-
|
|
44
|
+
n.call("arcHideLoading");
|
|
45
45
|
},
|
|
46
46
|
showToast(e) {
|
|
47
|
-
e && typeof e == "string" &&
|
|
47
|
+
e && typeof e == "string" && n.call("arcToast", e);
|
|
48
48
|
},
|
|
49
49
|
// 图片功能
|
|
50
50
|
chooseImgs(e) {
|
|
51
|
-
const { limit: s, success:
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
51
|
+
const { limit: s, success: r, fail: a } = e;
|
|
52
|
+
n.call("arcChooseImgs", JSON.stringify({ limit: s }), (c) => {
|
|
53
|
+
const o = JSON.parse(c);
|
|
54
|
+
o && o.code === 0 ? typeof r == "function" && r(c) : typeof a == "function" && a(c);
|
|
55
55
|
});
|
|
56
56
|
},
|
|
57
57
|
previewImgs(e) {
|
|
58
58
|
const { imgs: s } = e;
|
|
59
|
-
!s || s.length === 0 ||
|
|
59
|
+
!s || s.length === 0 || n.call("arcPreviewImgs", JSON.stringify(e));
|
|
60
60
|
},
|
|
61
61
|
// 钱包功能
|
|
62
62
|
isSetPWD(e) {
|
|
63
|
-
const { success: s, fail:
|
|
64
|
-
|
|
63
|
+
const { success: s, fail: r } = e;
|
|
64
|
+
n.call("arcIsSetPWD", "", (a) => {
|
|
65
65
|
const c = JSON.parse(a);
|
|
66
|
-
c && c.code === 0 ? typeof s == "function" && s(a) : typeof
|
|
66
|
+
c && c.code === 0 ? typeof s == "function" && s(a) : typeof r == "function" && r(a);
|
|
67
67
|
});
|
|
68
68
|
},
|
|
69
69
|
isCodeABOk(e) {
|
|
70
|
-
const { success: s, fail:
|
|
71
|
-
|
|
70
|
+
const { success: s, fail: r } = e;
|
|
71
|
+
n.call("arcIsCodeABOk", "", (a) => {
|
|
72
72
|
const c = JSON.parse(a);
|
|
73
|
-
c && c.code === 0 ? typeof s == "function" && s(a) : typeof
|
|
73
|
+
c && c.code === 0 ? typeof s == "function" && s(a) : typeof r == "function" && r(a);
|
|
74
74
|
});
|
|
75
75
|
},
|
|
76
76
|
/**
|
|
@@ -80,42 +80,42 @@ const f = "1", g = {
|
|
|
80
80
|
* @returns {Promise<any>}
|
|
81
81
|
*/
|
|
82
82
|
callArc(e, s = {}) {
|
|
83
|
-
return new Promise((
|
|
84
|
-
const
|
|
85
|
-
|
|
83
|
+
return new Promise((r, a) => {
|
|
84
|
+
const o = ["arc", e].join("__"), t = { ...s, _version: f };
|
|
85
|
+
n.call(o, t, (l) => {
|
|
86
86
|
try {
|
|
87
87
|
const i = JSON.parse(l);
|
|
88
|
-
if (
|
|
88
|
+
if (i?._version === f)
|
|
89
89
|
if (i.code === 0)
|
|
90
90
|
try {
|
|
91
91
|
const d = JSON.parse(i.data);
|
|
92
|
-
|
|
92
|
+
r(d);
|
|
93
93
|
} catch {
|
|
94
|
-
console.warn("Failed to parse result.data"),
|
|
94
|
+
console.warn("Failed to parse result.data"), r(i.data);
|
|
95
95
|
}
|
|
96
96
|
else
|
|
97
97
|
a(new Error(i.error));
|
|
98
98
|
else
|
|
99
|
-
|
|
99
|
+
r(i);
|
|
100
100
|
} catch {
|
|
101
|
-
console.warn("Failed to parse resString"),
|
|
101
|
+
console.warn("Failed to parse resString"), r(l);
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
},
|
|
106
106
|
registerBlocklet(e, s = () => {
|
|
107
107
|
}) {
|
|
108
|
-
if (
|
|
108
|
+
if (n.canUseBridge()) {
|
|
109
109
|
const a = ["blocklet", e].join("__");
|
|
110
|
-
|
|
111
|
-
const
|
|
110
|
+
n.registerAsyn(a, (...c) => {
|
|
111
|
+
const o = c.map((t) => {
|
|
112
112
|
try {
|
|
113
113
|
return JSON.parse(t);
|
|
114
114
|
} catch {
|
|
115
115
|
return t;
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
|
-
s(...
|
|
118
|
+
s(...o);
|
|
119
119
|
});
|
|
120
120
|
} else
|
|
121
121
|
console.warn("dsbridge is not available");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/bridge",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
4
4
|
"description": "a bridge sdk support all js api from DID Wallet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bridge",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
35
35
|
"jest": "^29.7.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "8e4b3b4f9cc52c8f1f1d270ab03a3c566073617a"
|
|
38
38
|
}
|