@cowprotocol/widget-react 3.2.11 → 3.3.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/index.cjs +1 -1
- package/index.js +81 -77
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@cowprotocol/widget-lib"),j=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@cowprotocol/widget-lib"),j=require("react/jsx-runtime"),t=require("react");function D({params:e,provider:u,listeners:r,onReady:f,onLoadingError:c,enableSafeSdkBridge:n=!0}){const[l,a]=t.useState(null),y=t.useRef(null),d=t.useRef(u),R=t.useRef(r),p=t.useRef(n),h=t.useRef(null),o=t.useRef(null),W=t.useRef(c);t.useEffect(()=>{W.current=c},[c]);const s=t.useCallback((i,E)=>{try{console.log(`[WIDGET] ${i}`),E()}catch(g){const w=`Error ${i.toLowerCase()}`,m=g instanceof Error?g:new Error("Unknown CowSwapWidget error",{cause:g});console.error(`[WIDGET] ${w}`,m),a({message:w,error:m}),W.current?.()}},[]);return C({refs:{paramsRef:y,providerRef:d,listenersRef:R,enableSafeSdkBridgeRef:p,widgetHandlerRef:o},tryOrHandleError:s}),t.useEffect(()=>{const i=!!y.current&&x(y.current,e),E=p.current!==n;if(!h.current||!i&&!E&&JSON.stringify(y.current)===JSON.stringify(e))return;const g=h.current,w=o.current;y.current=e,p.current=n,w===null?s("Creating a new widget",()=>{o.current=v({container:g,params:e,provider:d.current,listeners:r,onReady:f,onLoadingError:c,enableSafeSdkBridge:n}),R.current=r}):E?s("Recreating the widget",()=>{w.destroy(),o.current=v({container:g,params:e,provider:d.current,listeners:r,onReady:f,onLoadingError:c,enableSafeSdkBridge:n}),R.current=r}):s("Updating the widget",()=>w.updateParams(e))},[e,n,s]),t.useEffect(()=>{if(!o.current||d.current===u)return;d.current=u;const i=h.current;i&&s("Updating the provider",()=>{o.current?.destroy(),o.current=v({container:i,params:e,provider:d.current,listeners:r,onReady:f,enableSafeSdkBridge:n}),p.current=n})},[f,u,s]),t.useEffect(()=>{if(!o.current||R.current===r)return;const i=o.current;s("Updating the listeners",()=>i.updateListeners(r))},[r,s]),l?j.jsx(H,{error:l}):j.jsx("div",{ref:h,id:O.WIDGET_CONTAINER_ID,style:{width:"100%",flex:"1 0 auto"}})}function x(e,u){const r=u.hooks??{},f=Object.keys(r),c=e.hooks??{},n=Object.keys(c);return f.some(l=>{const a=l;return r[a]!==c[a]})||n.some(l=>{const a=l;return r[a]!==c[a]})}function v({container:e,params:u,provider:r,listeners:f,onReady:c,onLoadingError:n,enableSafeSdkBridge:l}){return O.createCowSwapWidget(e,{params:u,provider:r,listeners:f,onReady:c,enableSafeSdkBridge:l,onLoadingError:n})}function C({refs:e,tryOrHandleError:u}){t.useEffect(()=>()=>{e.paramsRef.current=null,e.providerRef.current=void 0,e.listenersRef.current=void 0,e.enableSafeSdkBridgeRef.current=!0;const r=e.widgetHandlerRef.current;r&&(u("Destroy widget",()=>r.destroy()),e.widgetHandlerRef.current=null)},[])}function H({error:e}){return j.jsxs("div",{style:{color:"#ff3a3a"},children:[e.message,e.error.message&&j.jsx("pre",{style:{whiteSpace:"pre-wrap",fontSize:"0.75em"},children:e.error.message})]})}exports.CowSwapWidget=D;Object.keys(O).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>O[e]})});
|
package/index.js
CHANGED
|
@@ -1,138 +1,142 @@
|
|
|
1
|
-
import { WIDGET_CONTAINER_ID as
|
|
1
|
+
import { WIDGET_CONTAINER_ID as H, createCowSwapWidget as x } from "@cowprotocol/widget-lib";
|
|
2
2
|
export * from "@cowprotocol/widget-lib";
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { useState as
|
|
5
|
-
function
|
|
3
|
+
import { jsx as W, jsxs as C } from "react/jsx-runtime";
|
|
4
|
+
import { useState as O, useRef as d, useEffect as y, useCallback as I } from "react";
|
|
5
|
+
function $({
|
|
6
6
|
params: r,
|
|
7
|
-
provider:
|
|
7
|
+
provider: c,
|
|
8
8
|
listeners: e,
|
|
9
|
-
onReady:
|
|
10
|
-
onLoadingError:
|
|
9
|
+
onReady: i,
|
|
10
|
+
onLoadingError: n,
|
|
11
11
|
enableSafeSdkBridge: t = !0
|
|
12
12
|
}) {
|
|
13
|
-
const [f,
|
|
13
|
+
const [f, l] = O(null), p = d(null), a = d(c), h = d(e), m = d(t), R = d(null), o = d(null), k = d(n);
|
|
14
|
+
y(() => {
|
|
15
|
+
k.current = n;
|
|
16
|
+
}, [n]);
|
|
17
|
+
const u = I((s, v) => {
|
|
14
18
|
try {
|
|
15
|
-
console.log(`[WIDGET] ${
|
|
16
|
-
} catch (
|
|
17
|
-
const g = `Error ${
|
|
18
|
-
cause:
|
|
19
|
+
console.log(`[WIDGET] ${s}`), v();
|
|
20
|
+
} catch (w) {
|
|
21
|
+
const g = `Error ${s.toLowerCase()}`, E = w instanceof Error ? w : new Error("Unknown CowSwapWidget error", {
|
|
22
|
+
cause: w
|
|
19
23
|
});
|
|
20
|
-
console.error(`[WIDGET] ${g}`,
|
|
24
|
+
console.error(`[WIDGET] ${g}`, E), l({
|
|
21
25
|
message: g,
|
|
22
|
-
error:
|
|
23
|
-
});
|
|
26
|
+
error: E
|
|
27
|
+
}), k.current?.();
|
|
24
28
|
}
|
|
25
29
|
}, []);
|
|
26
|
-
return
|
|
30
|
+
return j({
|
|
27
31
|
refs: {
|
|
28
32
|
paramsRef: p,
|
|
29
|
-
providerRef:
|
|
30
|
-
listenersRef:
|
|
31
|
-
enableSafeSdkBridgeRef:
|
|
33
|
+
providerRef: a,
|
|
34
|
+
listenersRef: h,
|
|
35
|
+
enableSafeSdkBridgeRef: m,
|
|
32
36
|
widgetHandlerRef: o
|
|
33
37
|
},
|
|
34
|
-
tryOrHandleError:
|
|
35
|
-
}),
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
38
|
+
tryOrHandleError: u
|
|
39
|
+
}), y(() => {
|
|
40
|
+
const s = !!p.current && U(p.current, r), v = m.current !== t;
|
|
41
|
+
if (!R.current || !s && !v && JSON.stringify(p.current) === JSON.stringify(r))
|
|
38
42
|
return;
|
|
39
|
-
const
|
|
40
|
-
p.current = r,
|
|
41
|
-
o.current =
|
|
42
|
-
container:
|
|
43
|
+
const w = R.current, g = o.current;
|
|
44
|
+
p.current = r, m.current = t, g === null ? u("Creating a new widget", () => {
|
|
45
|
+
o.current = D({
|
|
46
|
+
container: w,
|
|
43
47
|
params: r,
|
|
44
|
-
provider:
|
|
48
|
+
provider: a.current,
|
|
45
49
|
listeners: e,
|
|
46
|
-
onReady:
|
|
47
|
-
onLoadingError:
|
|
50
|
+
onReady: i,
|
|
51
|
+
onLoadingError: n,
|
|
48
52
|
enableSafeSdkBridge: t
|
|
49
|
-
}),
|
|
50
|
-
}) :
|
|
51
|
-
g.destroy(), o.current =
|
|
52
|
-
container:
|
|
53
|
+
}), h.current = e;
|
|
54
|
+
}) : v ? u("Recreating the widget", () => {
|
|
55
|
+
g.destroy(), o.current = D({
|
|
56
|
+
container: w,
|
|
53
57
|
params: r,
|
|
54
|
-
provider:
|
|
58
|
+
provider: a.current,
|
|
55
59
|
listeners: e,
|
|
56
|
-
onReady:
|
|
57
|
-
onLoadingError:
|
|
60
|
+
onReady: i,
|
|
61
|
+
onLoadingError: n,
|
|
58
62
|
enableSafeSdkBridge: t
|
|
59
|
-
}),
|
|
60
|
-
}) :
|
|
61
|
-
}, [r, t,
|
|
62
|
-
if (!o.current ||
|
|
63
|
+
}), h.current = e;
|
|
64
|
+
}) : u("Updating the widget", () => g.updateParams(r));
|
|
65
|
+
}, [r, t, u]), y(() => {
|
|
66
|
+
if (!o.current || a.current === c)
|
|
63
67
|
return;
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
o.current?.destroy(), o.current =
|
|
68
|
-
container:
|
|
68
|
+
a.current = c;
|
|
69
|
+
const s = R.current;
|
|
70
|
+
s && u("Updating the provider", () => {
|
|
71
|
+
o.current?.destroy(), o.current = D({
|
|
72
|
+
container: s,
|
|
69
73
|
params: r,
|
|
70
|
-
provider:
|
|
74
|
+
provider: a.current,
|
|
71
75
|
listeners: e,
|
|
72
|
-
onReady:
|
|
76
|
+
onReady: i,
|
|
73
77
|
enableSafeSdkBridge: t
|
|
74
|
-
}),
|
|
78
|
+
}), m.current = t;
|
|
75
79
|
});
|
|
76
|
-
}, [
|
|
77
|
-
if (!o.current ||
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
}, [e,
|
|
80
|
+
}, [i, c, u]), y(() => {
|
|
81
|
+
if (!o.current || h.current === e) return;
|
|
82
|
+
const s = o.current;
|
|
83
|
+
u("Updating the listeners", () => s.updateListeners(e));
|
|
84
|
+
}, [e, u]), f ? /* @__PURE__ */ W(N, { error: f }) : /* @__PURE__ */ W("div", { ref: R, id: H, style: {
|
|
81
85
|
width: "100%",
|
|
82
86
|
flex: "1 0 auto"
|
|
83
87
|
} });
|
|
84
88
|
}
|
|
85
|
-
function
|
|
86
|
-
const e =
|
|
87
|
-
return
|
|
88
|
-
const
|
|
89
|
-
return e[
|
|
89
|
+
function U(r, c) {
|
|
90
|
+
const e = c.hooks ?? {}, i = Object.keys(e), n = r.hooks ?? {}, t = Object.keys(n);
|
|
91
|
+
return i.some((f) => {
|
|
92
|
+
const l = f;
|
|
93
|
+
return e[l] !== n[l];
|
|
90
94
|
}) || t.some((f) => {
|
|
91
|
-
const
|
|
92
|
-
return e[
|
|
95
|
+
const l = f;
|
|
96
|
+
return e[l] !== n[l];
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
|
-
function
|
|
99
|
+
function D({
|
|
96
100
|
container: r,
|
|
97
|
-
params:
|
|
101
|
+
params: c,
|
|
98
102
|
provider: e,
|
|
99
|
-
listeners:
|
|
100
|
-
onReady:
|
|
103
|
+
listeners: i,
|
|
104
|
+
onReady: n,
|
|
101
105
|
onLoadingError: t,
|
|
102
106
|
enableSafeSdkBridge: f
|
|
103
107
|
}) {
|
|
104
|
-
return
|
|
105
|
-
params:
|
|
108
|
+
return x(r, {
|
|
109
|
+
params: c,
|
|
106
110
|
provider: e,
|
|
107
|
-
listeners:
|
|
108
|
-
onReady:
|
|
111
|
+
listeners: i,
|
|
112
|
+
onReady: n,
|
|
109
113
|
enableSafeSdkBridge: f,
|
|
110
114
|
onLoadingError: t
|
|
111
115
|
});
|
|
112
116
|
}
|
|
113
|
-
function
|
|
117
|
+
function j({
|
|
114
118
|
refs: r,
|
|
115
|
-
tryOrHandleError:
|
|
119
|
+
tryOrHandleError: c
|
|
116
120
|
}) {
|
|
117
|
-
|
|
121
|
+
y(() => () => {
|
|
118
122
|
r.paramsRef.current = null, r.providerRef.current = void 0, r.listenersRef.current = void 0, r.enableSafeSdkBridgeRef.current = !0;
|
|
119
123
|
const e = r.widgetHandlerRef.current;
|
|
120
|
-
e && (
|
|
124
|
+
e && (c("Destroy widget", () => e.destroy()), r.widgetHandlerRef.current = null);
|
|
121
125
|
}, []);
|
|
122
126
|
}
|
|
123
|
-
function
|
|
127
|
+
function N({
|
|
124
128
|
error: r
|
|
125
129
|
}) {
|
|
126
|
-
return /* @__PURE__ */
|
|
130
|
+
return /* @__PURE__ */ C("div", { style: {
|
|
127
131
|
color: "#ff3a3a"
|
|
128
132
|
}, children: [
|
|
129
133
|
r.message,
|
|
130
|
-
r.error.message && /* @__PURE__ */
|
|
134
|
+
r.error.message && /* @__PURE__ */ W("pre", { style: {
|
|
131
135
|
whiteSpace: "pre-wrap",
|
|
132
136
|
fontSize: "0.75em"
|
|
133
137
|
}, children: r.error.message })
|
|
134
138
|
] });
|
|
135
139
|
}
|
|
136
140
|
export {
|
|
137
|
-
|
|
141
|
+
$ as CowSwapWidget
|
|
138
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/widget-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your React application.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@cowprotocol/events": "^4.
|
|
19
|
-
"@cowprotocol/types": "^4.
|
|
20
|
-
"@cowprotocol/widget-lib": "^4.
|
|
18
|
+
"@cowprotocol/events": "^4.17.0",
|
|
19
|
+
"@cowprotocol/types": "^4.14.0",
|
|
20
|
+
"@cowprotocol/widget-lib": "^4.11.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@testing-library/dom": "10.4.1",
|