@cowprotocol/widget-react 0.5.0-RC.4 → 0.5.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.js +1 -1
- package/index.mjs +80 -90
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var V=Object.defineProperty;var b=(n,e,t)=>e in n?V(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var p=(n,e,t)=>(b(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),d=require("react"),S="cowSwapWidget";function R(n,e,t){const s={key:S,method:e,...typeof t=="object"?t:{}};n.postMessage(s,"*")}function P(n,e,t){const r=s=>{!N(s.data)||s.data.key!==S||s.data.method!==e||t(s.data)};return n.addEventListener("message",r),r}function N(n){return typeof n=="object"&&n!==null&&"key"in n&&"method"in n&&typeof n.key=="string"&&typeof n.method=="string"}function O(n,e,t){n.removeEventListener("message",t)}function _(n,e){n.removeEventListener("message",e)}var l=(n=>(n.ACTIVATE="ACTIVATE",n.UPDATE_HEIGHT="UPDATE_HEIGHT",n.EMIT_COW_EVENT="EMIT_COW_EVENT",n.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",n))(l||{}),w=(n=>(n.UPDATE_PARAMS="UPDATE_PARAMS",n.UPDATE_APP_DATA="UPDATE_APP_DATA",n.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",n.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",n))(w||{}),A=(n=>(n.SWAP="swap",n.LIMIT="limit",n.ADVANCED="advanced",n))(A||{});const F=["connect","disconnect","close","chainChanged","accountsChanged"];class H{constructor(e){p(this,"ethereumProvider",null);p(this,"requestWaitingForConnection",{});p(this,"processRpcCallFromWindow",({rpcRequest:e})=>{if(!this.ethereumProvider){e.id&&(this.requestWaitingForConnection[e.id]=e);return}this.processRpcRequest(e)});this.iframeWidow=e}disconnect(){this.ethereumProvider=null,O(window,l.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(e){this.ethereumProvider?this.disconnect():P(window,l.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=e,this.processPendingRequests(),F.forEach(t=>{e.on(t,r=>this.onProviderEvent(t,r))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(e=>{this.processRpcRequest(this.requestWaitingForConnection[e])}),this.requestWaitingForConnection={}}processRpcRequest(e){const{id:t,jsonrpc:r,method:s}=e;if(!this.ethereumProvider||!t)return;(s==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...e,id:t})).then(i=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:r,id:t,result:i}})).catch(i=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:r,id:t,error:i}}))}onProviderEvent(e,t){R(this.iframeWidow,w.PROVIDER_ON_EVENT,{event:e,params:t})}forwardRpcResponseToIframe(e){R(this.iframeWidow,w.PROVIDER_RPC_RESPONSE,e)}}const I="_";function M(n){const e=typeof n.baseUrl=="string"?n.baseUrl:"https://swap.cow.fi",t=L(n),r=y(n);return e+"/#"+t+"?"+r}function L(n){const{chainId:e=1,sell:t,buy:r,tradeType:s=A.SWAP}=n,c=[(t==null?void 0:t.asset)||I,(r==null?void 0:r.asset)||I].map(encodeURIComponent).join("/");return`/${e}/widget/${s}/${c}`}function y(n){const{sell:e,buy:t,theme:r}=n,s=new URLSearchParams;return e!=null&&e.amount&&s.append("sellAmount",e.amount),t!=null&&t.amount&&s.append("buyAmount",t.amount),r&&s.append("theme",typeof r=="string"?r:r.baseTheme),s}class q{constructor(){p(this,"subscriptions",{})}on(e){const{event:t,handler:r}=e;this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(r)}off(e){const{event:t,handler:r}=e;this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(s=>s!==r))}emit(e,t){this.subscriptions[e]&&this.subscriptions[e].forEach(r=>r(t))}}let x=1;class G{constructor(e,t=[]){p(this,"eventEmitter",new q);p(this,"listeners",[]);p(this,"widgetListener");p(this,"instanceNumber",x++);this.contentWindow=e,this.updateListeners(t),this.widgetListener=P(this.contentWindow,l.EMIT_COW_EVENT,r=>this.eventEmitter.emit(r.event,r.payload))}stopListeningIframe(){_(this.contentWindow,this.widgetListener)}updateListeners(e){for(const t of this.listeners)this.eventEmitter.off(t);this.listeners=e||[];for(const t of this.listeners)this.eventEmitter.on(t)}}const U="640px",$="450px",k=20;function T(n,e){const{params:t,provider:r,listeners:s}=e;let c=r;const i=j(t);n.innerHTML="",n.appendChild(i);const{contentWindow:a}=i;if(!a)throw console.error("Iframe does not contain a window",i),new Error("Iframe does not contain a window!");const m=[];m.push(Q(a,t.appCode)),m.push(J(i,t.height));const E=new G(window,s);let u=W(a,null,c);return i.addEventListener("load",()=>D(a,t,c)),{updateParams:o=>D(a,o,c),updateListeners:o=>E.updateListeners(o),updateProvider:o=>{c=o,u=W(a,u,o)},destroy:()=>{E.stopListeningIframe(),m.forEach(o=>window.removeEventListener("message",o)),n.removeChild(i)}}}function W(n,e,t){e&&e.disconnect();const r=e||new H(n);return t&&r.onConnect(t),r}function j(n){const{width:e=$,height:t=U}=n,r=document.createElement("iframe");return r.src=M(n),r.width=e,r.height=t,r.style.border="0",r}function D(n,e,t){const r=!!t,s=L(e),c=y(e).toString();R(n,w.UPDATE_PARAMS,{urlParams:{pathname:s,search:c},appParams:{...e},hasProvider:r})}function Q(n,e){const t=P(window,l.ACTIVATE,()=>{_(window,t),R(n,w.UPDATE_APP_DATA,{metaData:e?{appCode:e}:void 0})});return t}function J(n,e=U){return P(window,l.UPDATE_HEIGHT,t=>{n.style.height=t.height?`${t.height+k}px`:e})}function K(n){const{params:e,provider:t,listeners:r}=n,[s,c]=d.useState(null),i=d.useRef(null),a=d.useRef(t),m=d.useRef(r),E=d.useRef(null),u=d.useRef(null),o=d.useCallback((h,f)=>{try{console.log(`[WIDGET] ${h}`),f()}catch(v){const C=`Error ${h.toLowerCase()}`;console.error(`[WIDGET] ${C}`,v),c({message:C,error:v})}},[c]);return d.useEffect(()=>{if(!E.current||JSON.stringify(i.current)===JSON.stringify(e))return;const h=E.current,f=u.current;i.current=e,f===null?o("Creating a new widget",()=>{u.current=T(h,{params:e,provider:a.current,listeners:r}),m.current=r}):o("Updating the widget",()=>f.updateParams(e))},[e]),d.useEffect(()=>{if(!u.current||a.current===t)return;a.current=t;const h=E.current;h&&o("Updating the provider",()=>{var f;(f=u.current)==null||f.destroy(),u.current=T(h,{params:e,provider:a.current,listeners:r})})},[t]),d.useEffect(()=>{if(!u.current||m.current===r)return;const h=u.current;o("Updating the listeners",()=>h.updateListeners(r))},[r]),s?g.jsxs("div",{style:{color:"#ff3a3a"},children:[s.message,s.error.message&&g.jsx("pre",{style:{whiteSpace:"pre-wrap",fontSize:"0.75em"},children:s.error.message})]}):g.jsx("div",{ref:E})}exports.CowSwapWidget=K;exports.TradeType=A;exports.WidgetMethodsEmit=l;exports.WidgetMethodsListen=w;exports.createCowSwapWidget=T;exports.listenToMessageFromWindow=P;exports.postMessageToWindow=R;exports.stopListeningToMessageFromWindow=O;exports.stopListeningWindowListener=_;
|
package/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var V = Object.defineProperty;
|
|
2
2
|
var N = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
-
var
|
|
4
|
-
import { jsxs as b, jsx as
|
|
5
|
-
import { useState as H, useRef as
|
|
3
|
+
var h = (n, e, t) => (N(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { jsxs as b, jsx as A } from "react/jsx-runtime";
|
|
5
|
+
import { useState as H, useRef as l, useCallback as F, useEffect as T } from "react";
|
|
6
6
|
const W = "cowSwapWidget";
|
|
7
7
|
function P(n, e, t) {
|
|
8
8
|
const s = {
|
|
@@ -31,9 +31,9 @@ function M(n, e, t) {
|
|
|
31
31
|
function O(n, e) {
|
|
32
32
|
n.removeEventListener("message", e);
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var m = /* @__PURE__ */ ((n) => (n.ACTIVATE = "ACTIVATE", n.UPDATE_HEIGHT = "UPDATE_HEIGHT", n.EMIT_COW_EVENT = "EMIT_COW_EVENT", n.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", n))(m || {}), w = /* @__PURE__ */ ((n) => (n.UPDATE_PARAMS = "UPDATE_PARAMS", n.UPDATE_APP_DATA = "UPDATE_APP_DATA", n.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", n.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", n))(w || {}), S = /* @__PURE__ */ ((n) => (n.SWAP = "swap", n.LIMIT = "limit", n.ADVANCED = "advanced", n))(S || {});
|
|
35
35
|
const G = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
|
|
36
|
-
class
|
|
36
|
+
class x {
|
|
37
37
|
/**
|
|
38
38
|
* Creates an instance of IframeRpcProviderBridge.
|
|
39
39
|
* @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
|
|
@@ -44,10 +44,10 @@ class $ {
|
|
|
44
44
|
* The Ethereum provider instance.
|
|
45
45
|
* When is null the JSON-RPC bridge is disconnected from the Ethereum provider.
|
|
46
46
|
* */
|
|
47
|
-
|
|
47
|
+
h(this, "ethereumProvider", null);
|
|
48
48
|
/** Stored JSON-RPC requests, to queue them when disconnected. */
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
h(this, "requestWaitingForConnection", {});
|
|
50
|
+
h(this, "processRpcCallFromWindow", ({ rpcRequest: e }) => {
|
|
51
51
|
if (!this.ethereumProvider) {
|
|
52
52
|
e.id && (this.requestWaitingForConnection[e.id] = e);
|
|
53
53
|
return;
|
|
@@ -60,14 +60,14 @@ class $ {
|
|
|
60
60
|
* Disconnects the JSON-RPC bridge from the Ethereum provider.
|
|
61
61
|
*/
|
|
62
62
|
disconnect() {
|
|
63
|
-
this.ethereumProvider = null, M(window,
|
|
63
|
+
this.ethereumProvider = null, M(window, m.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
67
67
|
* @param newProvider - The Ethereum provider to connect.
|
|
68
68
|
*/
|
|
69
69
|
onConnect(e) {
|
|
70
|
-
this.ethereumProvider ? this.disconnect() : R(window,
|
|
70
|
+
this.ethereumProvider ? this.disconnect() : R(window, m.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), this.ethereumProvider = e, this.processPendingRequests(), G.forEach((t) => {
|
|
71
71
|
e.on(t, (r) => this.onProviderEvent(t, r));
|
|
72
72
|
});
|
|
73
73
|
}
|
|
@@ -85,12 +85,12 @@ class $ {
|
|
|
85
85
|
if (!this.ethereumProvider || !t)
|
|
86
86
|
return;
|
|
87
87
|
(s === "enable" ? this.ethereumProvider.enable() : this.ethereumProvider.request({ ...e, id: t })).then(
|
|
88
|
-
(
|
|
89
|
-
rpcResponse: { jsonrpc: r, id: t, result:
|
|
88
|
+
(i) => this.forwardRpcResponseToIframe({
|
|
89
|
+
rpcResponse: { jsonrpc: r, id: t, result: i }
|
|
90
90
|
})
|
|
91
91
|
).catch(
|
|
92
|
-
(
|
|
93
|
-
rpcResponse: { jsonrpc: r, id: t, error:
|
|
92
|
+
(i) => this.forwardRpcResponseToIframe({
|
|
93
|
+
rpcResponse: { jsonrpc: r, id: t, error: i }
|
|
94
94
|
})
|
|
95
95
|
);
|
|
96
96
|
}
|
|
@@ -107,31 +107,22 @@ class $ {
|
|
|
107
107
|
P(this.iframeWidow, w.PROVIDER_RPC_RESPONSE, e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const k = {
|
|
114
|
-
local: "http://localhost:3000",
|
|
115
|
-
prod: "https://swap.cow.fi",
|
|
116
|
-
dev: "https://dev.swap.cow.fi",
|
|
117
|
-
pr: x()
|
|
118
|
-
}, A = "_";
|
|
119
|
-
function Q(n) {
|
|
120
|
-
var s;
|
|
121
|
-
const e = typeof n.baseUrl == "string" ? n.baseUrl : k[((s = n.baseUrl) == null ? void 0 : s.environment) || "prod"], t = y(n), r = U(n);
|
|
110
|
+
const v = "_";
|
|
111
|
+
function $(n) {
|
|
112
|
+
const e = typeof n.baseUrl == "string" ? n.baseUrl : "https://swap.cow.fi", t = y(n), r = L(n);
|
|
122
113
|
return e + "/#" + t + "?" + r;
|
|
123
114
|
}
|
|
124
115
|
function y(n) {
|
|
125
|
-
const { chainId: e = 1, sell: t, buy: r, tradeType: s = S.SWAP } = n, c = [(t == null ? void 0 : t.asset) ||
|
|
116
|
+
const { chainId: e = 1, sell: t, buy: r, tradeType: s = S.SWAP } = n, c = [(t == null ? void 0 : t.asset) || v, (r == null ? void 0 : r.asset) || v].map(encodeURIComponent).join("/");
|
|
126
117
|
return `/${e}/widget/${s}/${c}`;
|
|
127
118
|
}
|
|
128
|
-
function
|
|
119
|
+
function L(n) {
|
|
129
120
|
const { sell: e, buy: t, theme: r } = n, s = new URLSearchParams();
|
|
130
121
|
return e != null && e.amount && s.append("sellAmount", e.amount), t != null && t.amount && s.append("buyAmount", t.amount), r && s.append("theme", typeof r == "string" ? r : r.baseTheme), s;
|
|
131
122
|
}
|
|
132
|
-
class
|
|
123
|
+
class k {
|
|
133
124
|
constructor() {
|
|
134
|
-
|
|
125
|
+
h(this, "subscriptions", {});
|
|
135
126
|
}
|
|
136
127
|
on(e) {
|
|
137
128
|
const { event: t, handler: r } = e;
|
|
@@ -145,16 +136,16 @@ class K {
|
|
|
145
136
|
this.subscriptions[e] && this.subscriptions[e].forEach((r) => r(t));
|
|
146
137
|
}
|
|
147
138
|
}
|
|
148
|
-
let
|
|
149
|
-
class
|
|
139
|
+
let Q = 1;
|
|
140
|
+
class j {
|
|
150
141
|
constructor(e, t = []) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
142
|
+
h(this, "eventEmitter", new k());
|
|
143
|
+
h(this, "listeners", []);
|
|
144
|
+
h(this, "widgetListener");
|
|
145
|
+
h(this, "instanceNumber", Q++);
|
|
155
146
|
this.contentWindow = e, this.updateListeners(t), this.widgetListener = R(
|
|
156
147
|
this.contentWindow,
|
|
157
|
-
|
|
148
|
+
m.EMIT_COW_EVENT,
|
|
158
149
|
(r) => this.eventEmitter.emit(r.event, r.payload)
|
|
159
150
|
);
|
|
160
151
|
}
|
|
@@ -169,41 +160,41 @@ class J {
|
|
|
169
160
|
this.eventEmitter.on(t);
|
|
170
161
|
}
|
|
171
162
|
}
|
|
172
|
-
const
|
|
163
|
+
const U = "640px", J = "450px", K = 20;
|
|
173
164
|
function C(n, e) {
|
|
174
165
|
const { params: t, provider: r, listeners: s } = e;
|
|
175
166
|
let c = r;
|
|
176
|
-
const
|
|
177
|
-
n.innerHTML = "", n.appendChild(
|
|
178
|
-
const { contentWindow: a } =
|
|
167
|
+
const i = Y(t);
|
|
168
|
+
n.innerHTML = "", n.appendChild(i);
|
|
169
|
+
const { contentWindow: a } = i;
|
|
179
170
|
if (!a)
|
|
180
|
-
throw console.error("Iframe does not contain a window",
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
let
|
|
185
|
-
return
|
|
186
|
-
updateParams: (
|
|
187
|
-
updateListeners: (
|
|
188
|
-
updateProvider: (
|
|
189
|
-
c =
|
|
171
|
+
throw console.error("Iframe does not contain a window", i), new Error("Iframe does not contain a window!");
|
|
172
|
+
const f = [];
|
|
173
|
+
f.push(z(a, t.appCode)), f.push(B(i, t.height));
|
|
174
|
+
const p = new j(window, s);
|
|
175
|
+
let u = I(a, null, c);
|
|
176
|
+
return i.addEventListener("load", () => D(a, t, c)), {
|
|
177
|
+
updateParams: (o) => D(a, o, c),
|
|
178
|
+
updateListeners: (o) => p.updateListeners(o),
|
|
179
|
+
updateProvider: (o) => {
|
|
180
|
+
c = o, u = I(a, u, o);
|
|
190
181
|
},
|
|
191
182
|
destroy: () => {
|
|
192
|
-
|
|
183
|
+
p.stopListeningIframe(), f.forEach((o) => window.removeEventListener("message", o)), n.removeChild(i);
|
|
193
184
|
}
|
|
194
185
|
};
|
|
195
186
|
}
|
|
196
187
|
function I(n, e, t) {
|
|
197
188
|
e && e.disconnect();
|
|
198
|
-
const r = e || new
|
|
189
|
+
const r = e || new x(n);
|
|
199
190
|
return t && r.onConnect(t), r;
|
|
200
191
|
}
|
|
201
|
-
function
|
|
202
|
-
const { width: e =
|
|
203
|
-
return r.src =
|
|
192
|
+
function Y(n) {
|
|
193
|
+
const { width: e = J, height: t = U } = n, r = document.createElement("iframe");
|
|
194
|
+
return r.src = $(n), r.width = e, r.height = t, r.style.border = "0", r;
|
|
204
195
|
}
|
|
205
196
|
function D(n, e, t) {
|
|
206
|
-
const r = !!t, s = y(e), c =
|
|
197
|
+
const r = !!t, s = y(e), c = L(e).toString();
|
|
207
198
|
P(n, w.UPDATE_PARAMS, {
|
|
208
199
|
urlParams: {
|
|
209
200
|
pathname: s,
|
|
@@ -215,62 +206,61 @@ function D(n, e, t) {
|
|
|
215
206
|
hasProvider: r
|
|
216
207
|
});
|
|
217
208
|
}
|
|
218
|
-
function
|
|
219
|
-
const t = R(window,
|
|
209
|
+
function z(n, e) {
|
|
210
|
+
const t = R(window, m.ACTIVATE, () => {
|
|
220
211
|
O(window, t), P(n, w.UPDATE_APP_DATA, {
|
|
221
212
|
metaData: e ? { appCode: e } : void 0
|
|
222
213
|
});
|
|
223
214
|
});
|
|
224
215
|
return t;
|
|
225
216
|
}
|
|
226
|
-
function
|
|
227
|
-
return R(window,
|
|
228
|
-
n.style.height = t.height ? `${t.height +
|
|
217
|
+
function B(n, e = U) {
|
|
218
|
+
return R(window, m.UPDATE_HEIGHT, (t) => {
|
|
219
|
+
n.style.height = t.height ? `${t.height + K}px` : e;
|
|
229
220
|
});
|
|
230
221
|
}
|
|
231
|
-
function
|
|
232
|
-
const { params: e, provider: t, listeners: r } = n, [s, c] = H(null),
|
|
233
|
-
(
|
|
222
|
+
function te(n) {
|
|
223
|
+
const { params: e, provider: t, listeners: r } = n, [s, c] = H(null), i = l(null), a = l(t), f = l(r), p = l(null), u = l(null), o = F(
|
|
224
|
+
(d, E) => {
|
|
234
225
|
try {
|
|
235
|
-
console.log(`[WIDGET] ${
|
|
236
|
-
} catch (
|
|
237
|
-
const _ = `Error ${
|
|
238
|
-
console.error(`[WIDGET] ${_}`,
|
|
226
|
+
console.log(`[WIDGET] ${d}`), E();
|
|
227
|
+
} catch (g) {
|
|
228
|
+
const _ = `Error ${d.toLowerCase()}`;
|
|
229
|
+
console.error(`[WIDGET] ${_}`, g), c({ message: _, error: g });
|
|
239
230
|
}
|
|
240
231
|
},
|
|
241
232
|
[c]
|
|
242
233
|
);
|
|
243
|
-
return
|
|
244
|
-
if (!
|
|
234
|
+
return T(() => {
|
|
235
|
+
if (!p.current || JSON.stringify(i.current) === JSON.stringify(e))
|
|
245
236
|
return;
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}) :
|
|
250
|
-
}, [e]),
|
|
251
|
-
if (!
|
|
237
|
+
const d = p.current, E = u.current;
|
|
238
|
+
i.current = e, E === null ? o("Creating a new widget", () => {
|
|
239
|
+
u.current = C(d, { params: e, provider: a.current, listeners: r }), f.current = r;
|
|
240
|
+
}) : o("Updating the widget", () => E.updateParams(e));
|
|
241
|
+
}, [e]), T(() => {
|
|
242
|
+
if (!u.current || a.current === t)
|
|
252
243
|
return;
|
|
253
244
|
a.current = t;
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
var
|
|
257
|
-
(
|
|
245
|
+
const d = p.current;
|
|
246
|
+
d && o("Updating the provider", () => {
|
|
247
|
+
var E;
|
|
248
|
+
(E = u.current) == null || E.destroy(), u.current = C(d, { params: e, provider: a.current, listeners: r });
|
|
258
249
|
});
|
|
259
|
-
}, [t]),
|
|
260
|
-
if (!
|
|
250
|
+
}, [t]), T(() => {
|
|
251
|
+
if (!u.current || f.current === r)
|
|
261
252
|
return;
|
|
262
|
-
const
|
|
263
|
-
|
|
253
|
+
const d = u.current;
|
|
254
|
+
o("Updating the listeners", () => d.updateListeners(r));
|
|
264
255
|
}, [r]), s ? /* @__PURE__ */ b("div", { style: { color: "#ff3a3a" }, children: [
|
|
265
256
|
s.message,
|
|
266
|
-
s.error.message && /* @__PURE__ */
|
|
267
|
-
] }) : /* @__PURE__ */
|
|
257
|
+
s.error.message && /* @__PURE__ */ A("pre", { style: { whiteSpace: "pre-wrap", fontSize: "0.75em" }, children: s.error.message })
|
|
258
|
+
] }) : /* @__PURE__ */ A("div", { ref: p });
|
|
268
259
|
}
|
|
269
260
|
export {
|
|
270
|
-
|
|
271
|
-
re as CowSwapWidget,
|
|
261
|
+
te as CowSwapWidget,
|
|
272
262
|
S as TradeType,
|
|
273
|
-
|
|
263
|
+
m as WidgetMethodsEmit,
|
|
274
264
|
w as WidgetMethodsListen,
|
|
275
265
|
C as createCowSwapWidget,
|
|
276
266
|
R as listenToMessageFromWindow,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/widget-react",
|
|
3
|
-
"version": "0.5.0
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your React application.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"react"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@cowprotocol/widget-lib": "^0.
|
|
25
|
+
"@cowprotocol/widget-lib": "^0.7.0"
|
|
26
26
|
}
|
|
27
27
|
}
|