@cowprotocol/widget-react 3.2.1 → 3.2.3
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 +27 -27
- 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"),n=require("react");function m({params:e,provider:c,listeners:r,onReady:i,onLoadingError:f,enableSafeSdkBridge:t=!0}){const[a,d]=n.useState(null),y=n.useRef(null),l=n.useRef(c),p=n.useRef(r),R=n.useRef(t),h=n.useRef(null),o=n.useRef(null),u=n.useCallback((s,E)=>{try{console.log(`[WIDGET] ${s}`),E()}catch(g){const w=`Error ${s.toLowerCase()}`,W=g instanceof Error?g:new Error("Unknown CowSwapWidget error",{cause:g});console.error(`[WIDGET] ${w}`,W),d({message:w,error:W})}},[]);return
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@cowprotocol/widget-lib"),j=require("react/jsx-runtime"),n=require("react");function m({params:e,provider:c,listeners:r,onReady:i,onLoadingError:f,enableSafeSdkBridge:t=!0}){const[a,d]=n.useState(null),y=n.useRef(null),l=n.useRef(c),p=n.useRef(r),R=n.useRef(t),h=n.useRef(null),o=n.useRef(null),u=n.useCallback((s,E)=>{try{console.log(`[WIDGET] ${s}`),E()}catch(g){const w=`Error ${s.toLowerCase()}`,W=g instanceof Error?g:new Error("Unknown CowSwapWidget error",{cause:g});console.error(`[WIDGET] ${w}`,W),d({message:w,error:W})}},[]);return x({refs:{paramsRef:y,providerRef:l,listenersRef:p,enableSafeSdkBridgeRef:R,widgetHandlerRef:o},tryOrHandleError:u}),n.useEffect(()=>{const s=!!y.current&&D(y.current,e),E=R.current!==t;if(!h.current||!s&&!E&&JSON.stringify(y.current)===JSON.stringify(e))return;const g=h.current,w=o.current;y.current=e,R.current=t,w===null?u("Creating a new widget",()=>{o.current=v({container:g,params:e,provider:l.current,listeners:r,onReady:i,onLoadingError:f,enableSafeSdkBridge:t}),p.current=r}):E?u("Recreating the widget",()=>{w.destroy(),o.current=v({container:g,params:e,provider:l.current,listeners:r,onReady:i,onLoadingError:f,enableSafeSdkBridge:t}),p.current=r}):u("Updating the widget",()=>w.updateParams(e))},[e,t,u]),n.useEffect(()=>{if(!o.current||l.current===c)return;l.current=c;const s=h.current;s&&u("Updating the provider",()=>{o.current?.destroy(),o.current=v({container:s,params:e,provider:l.current,listeners:r,onReady:i,enableSafeSdkBridge:t}),R.current=t})},[i,c,u]),n.useEffect(()=>{if(!o.current||p.current===r)return;const s=o.current;u("Updating the listeners",()=>s.updateListeners(r))},[r,u]),a?j.jsx(C,{error:a}):j.jsx("div",{ref:h,id:O.WIDGET_CONTAINER_ID,style:{width:"100%",flex:"1 0 auto"}})}function D(e,c){const r=c.hooks??{},i=Object.keys(r),f=e.hooks??{},t=Object.keys(f);return i.some(a=>{const d=a;return r[d]!==f[d]})||t.some(a=>{const d=a;return r[d]!==f[d]})}function v({container:e,params:c,provider:r,listeners:i,onReady:f,onLoadingError:t,enableSafeSdkBridge:a}){return O.createCowSwapWidget(e,{params:c,provider:r,listeners:i,onReady:f,enableSafeSdkBridge:a,onLoadingError:t})}function x({refs:e,tryOrHandleError:c}){n.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&&(c("Destroy widget",()=>r.destroy()),e.widgetHandlerRef.current=null)},[])}function C({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=m;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
|
@@ -23,7 +23,7 @@ function _({
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
}, []);
|
|
26
|
-
return
|
|
26
|
+
return U({
|
|
27
27
|
refs: {
|
|
28
28
|
paramsRef: p,
|
|
29
29
|
providerRef: l,
|
|
@@ -33,7 +33,7 @@ function _({
|
|
|
33
33
|
},
|
|
34
34
|
tryOrHandleError: c
|
|
35
35
|
}), E(() => {
|
|
36
|
-
const u = !!p.current &&
|
|
36
|
+
const u = !!p.current && I(p.current, r), R = h.current !== t;
|
|
37
37
|
if (!m.current || !u && !R && JSON.stringify(p.current) === JSON.stringify(r))
|
|
38
38
|
return;
|
|
39
39
|
const a = m.current, g = o.current;
|
|
@@ -77,35 +77,12 @@ function _({
|
|
|
77
77
|
if (!o.current || y.current === e) return;
|
|
78
78
|
const u = o.current;
|
|
79
79
|
c("Updating the listeners", () => u.updateListeners(e));
|
|
80
|
-
}, [e, c]), f ? /* @__PURE__ */ D(
|
|
80
|
+
}, [e, c]), f ? /* @__PURE__ */ D(j, { error: f }) : /* @__PURE__ */ D("div", { ref: m, id: k, style: {
|
|
81
81
|
width: "100%",
|
|
82
82
|
flex: "1 0 auto"
|
|
83
83
|
} });
|
|
84
84
|
}
|
|
85
|
-
function I({
|
|
86
|
-
refs: r,
|
|
87
|
-
tryOrHandleError: n
|
|
88
|
-
}) {
|
|
89
|
-
E(() => () => {
|
|
90
|
-
r.paramsRef.current = null, r.providerRef.current = void 0, r.listenersRef.current = void 0, r.enableSafeSdkBridgeRef.current = !0;
|
|
91
|
-
const e = r.widgetHandlerRef.current;
|
|
92
|
-
e && (n("Destroy widget", () => e.destroy()), r.widgetHandlerRef.current = null);
|
|
93
|
-
}, []);
|
|
94
|
-
}
|
|
95
|
-
function U({
|
|
96
|
-
error: r
|
|
97
|
-
}) {
|
|
98
|
-
return /* @__PURE__ */ x("div", { style: {
|
|
99
|
-
color: "#ff3a3a"
|
|
100
|
-
}, children: [
|
|
101
|
-
r.message,
|
|
102
|
-
r.error.message && /* @__PURE__ */ D("pre", { style: {
|
|
103
|
-
whiteSpace: "pre-wrap",
|
|
104
|
-
fontSize: "0.75em"
|
|
105
|
-
}, children: r.error.message })
|
|
106
|
-
] });
|
|
107
|
-
}
|
|
108
|
-
function j(r, n) {
|
|
85
|
+
function I(r, n) {
|
|
109
86
|
const e = n.hooks ?? {}, s = Object.keys(e), i = r.hooks ?? {}, t = Object.keys(i);
|
|
110
87
|
return s.some((f) => {
|
|
111
88
|
const d = f;
|
|
@@ -133,6 +110,29 @@ function v({
|
|
|
133
110
|
onLoadingError: t
|
|
134
111
|
});
|
|
135
112
|
}
|
|
113
|
+
function U({
|
|
114
|
+
refs: r,
|
|
115
|
+
tryOrHandleError: n
|
|
116
|
+
}) {
|
|
117
|
+
E(() => () => {
|
|
118
|
+
r.paramsRef.current = null, r.providerRef.current = void 0, r.listenersRef.current = void 0, r.enableSafeSdkBridgeRef.current = !0;
|
|
119
|
+
const e = r.widgetHandlerRef.current;
|
|
120
|
+
e && (n("Destroy widget", () => e.destroy()), r.widgetHandlerRef.current = null);
|
|
121
|
+
}, []);
|
|
122
|
+
}
|
|
123
|
+
function j({
|
|
124
|
+
error: r
|
|
125
|
+
}) {
|
|
126
|
+
return /* @__PURE__ */ x("div", { style: {
|
|
127
|
+
color: "#ff3a3a"
|
|
128
|
+
}, children: [
|
|
129
|
+
r.message,
|
|
130
|
+
r.error.message && /* @__PURE__ */ D("pre", { style: {
|
|
131
|
+
whiteSpace: "pre-wrap",
|
|
132
|
+
fontSize: "0.75em"
|
|
133
|
+
}, children: r.error.message })
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
136
|
export {
|
|
137
137
|
_ as CowSwapWidget
|
|
138
138
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/widget-react",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
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.4.
|
|
18
|
+
"@cowprotocol/events": "^4.8.1",
|
|
19
|
+
"@cowprotocol/types": "^4.6.0",
|
|
20
|
+
"@cowprotocol/widget-lib": "^4.4.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@testing-library/dom": "10.4.1",
|