@cowprotocol/widget-lib 2.3.0 → 3.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/const.d.ts +1 -0
- package/index.cjs +1 -1
- package/index.js +68 -67
- package/package.json +1 -1
package/const.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const COWSWAP_ORIGIN = "https://swap.cow.finance";
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("@cowprotocol/iframe-transport"),b=require("@cowprotocol/events");var c=(e=>(e.ACTIVATE="ACTIVATE",e.READY="READY",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.SET_FULL_HEIGHT="SET_FULL_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.INTERCEPT_WINDOW_OPEN="INTERCEPT_WINDOW_OPEN",e.PROCESS_HOOK="PROCESS_HOOK",e))(c||{}),T=(e=>(e.UPDATE_PARAMS="UPDATE_PARAMS",e.UPDATE_APP_DATA="UPDATE_APP_DATA",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e.HOOK_RESULT="HOOK_RESULT",e))(T||{}),E=(e=>(e.ON_BEFORE_APPROVAL="ON_BEFORE_APPROVAL",e.ON_BEFORE_TRADE="ON_BEFORE_TRADE",e.ON_BEFORE_WRAP_UNWRAP="ON_BEFORE_WRAP_UNWRAP",e.ON_BEFORE_ORDER_CANCEL="ON_BEFORE_ORDER_CANCEL",e.ON_BEFORE_ORDERS_CANCEL="ON_BEFORE_ORDERS_CANCEL",e))(E||{}),P=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(P||{});const U=["primary","background","paper","text","danger","warning","alert","info","success"],s=new L.IframeTransport("cowSwapWidget");class y{constructor(t,n,o=[]){this.contentWindow=t,this.updateListeners(o),this.widgetListener=s.listenToMessageFromWindow(this.contentWindow,c.EMIT_COW_EVENT,r=>this.eventEmitter.emit(r.event,r.payload),n)}eventEmitter=new b.SimpleCowEventEmitter;listeners=[];widgetListener;stopListeningIframe(){s.stopListeningWindowListener(this.contentWindow,this.widgetListener)}updateListeners(t){for(const n of this.listeners)this.eventEmitter.off(n);this.listeners=t||[];for(const n of this.listeners)this.eventEmitter.on(n)}}class H{constructor(t,n){this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=o=>{F(o.data)&&(typeof window<"u"&&o.origin===window.location.origin||(B(o.data)?this.appWindow.parent.postMessage(o.data,"*"):M(o.data)&&this.iframeWidow.postMessage(o.data,"*")))},this.startListening()}forwardSdkMessage;startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function F(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function B(e){return"method"in e&&typeof e.method=="string"&&"params"in e&&"env"in e&&typeof e.env=="object"&&e.env!==null&&"sdkVersion"in e.env}function M(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function V(e="Default",t="#1c5dbf",...n){console.debug(`%c [COW][${e}]`,`font-weight: bold; color: ${t}`,...n)}function k(...e){V("Widget","#47aba8",...e)}const j="https://swap.cow.finance";function I(e){return!!(e&&typeof e=="object")}const C="_";function G(e){const t=typeof e.baseUrl=="string"?e.baseUrl:j,n=W(e);return t+"/#"+n+"?"+v(e)}function W(e){const{chainId:t=1,sell:n,buy:o,tradeType:r=P.SWAP}=e,a=[n?.asset||C,o?.asset||C].map(encodeURIComponent).join("/");return`/${t}/widget/${r}/${a}`}function v(e){const t=new URLSearchParams;return Y(K($(Q(x(t,e),e),e),e),e)}function x(e,t){const{sell:n,buy:o}=t;return n?.amount&&e.append("sellAmount",n.amount),o?.amount&&e.append("buyAmount",o.amount),e}function Q(e,t){const n=t.theme;return n?(I(n)?(e.append("palette",encodeURIComponent(JSON.stringify(n))),e.append("theme",n.baseTheme)):(e.append("palette","null"),e.append("theme",n)),e):(e.append("palette","null"),e)}function $(e,t){return t.targetChainId&&e.append("targetChainId",t.targetChainId.toString()),e}function K(e,t){return t.locale&&e.append("lng",t.locale),e}function Y(e,t){return J(t.hooks)?e.append("hooksEnabled","true"):e.delete("hooksEnabled"),e}function J(e){return!!e&&Object.values(e).some(Boolean)}const N="640px",X="450px",z=20,Z={updateParams:()=>{},updateListeners:()=>{},updateProvider:()=>{},destroy:()=>{}};function q(e,t){const{params:n,provider:o,listeners:r,onReady:a}=t;let f=o,w=n;if(typeof window>"u")return Z;const d=ee(n),i=te(d);k("Resolved trusted iframe origin",{iframeOrigin:i});const p=[];a&&p.push(oe(d.contentWindow||window,i,a)),e.innerHTML="",e.appendChild(d);const{contentWindow:u}=d;if(!u)throw console.error("Iframe does not contain a window",d),new Error("Iframe does not contain a window!");p.push(ne(u,i,n.appCode)),p.push(...ae(d,i,n.height,n.maxHeight)),p.push(re(i));let R=null;function h(){u&&(R&&window.removeEventListener("message",R),R=ce(u,i,w.hooks),p.push(R))}h();const g=new y(window,i,r);let A=m(u,i,null,f);d.addEventListener("load",()=>{S(u,i,w,f)});const D=new H(window,u);return{updateParams:l=>{w=l,S(u,i,w,f),h()},updateListeners:l=>g.updateListeners(l),updateProvider:l=>{f=l,A=m(u,i,A,l)},destroy:()=>{A.disconnect(),g.stopListeningIframe(),p.forEach(l=>window.removeEventListener("message",l)),D.stopListening(),e.removeChild(d)}}}function m(e,t,n,o){n&&n.disconnect();const r=n||new L.IframeRpcProviderBridge(e,t);return o&&r.onConnect(o),r}function ee(e){const{width:t=X,height:n=N}=e,o=document.createElement("iframe");return o.src=G(e),o.width=t,o.height=n,o.style.border="0",o.allow="clipboard-read; clipboard-write",o}function te(e){return new URL(e.src).origin}function S(e,t,n,o){const r=!!o,a=W(n),f=v(n).toString(),{theme:w,hooks:d,...i}=n;s.postMessageToWindow(e,T.UPDATE_PARAMS,{urlParams:{pathname:a,search:f},appParams:i,hasProvider:r},t)}function ne(e,t,n){return s.listenToMessageFromWindow(window,c.ACTIVATE,()=>{s.postMessageToWindow(e,T.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0},t)},t)}function oe(e,t,n){let o=!1;return s.listenToMessageFromWindow(window,c.READY,()=>{o||(o=!0,n())},t)}function re(e){return s.listenToMessageFromWindow(window,c.INTERCEPT_WINDOW_OPEN,({href:t,rel:n,target:o})=>{const r=ie(t.toString(),e);r&&se(r)&&window.open(r,o,n)},e)}function ie(e,t){const n=e.trim();if(!n)return null;try{return new URL(n,t).toString()}catch{return null}}function se(e){try{const t=new URL(e).protocol;return t==="http:"||t==="https:"}catch{return!1}}function ae(e,t,n=N,o){return[s.listenToMessageFromWindow(window,c.UPDATE_HEIGHT,r=>{const a=r.height?r.height+z:void 0;e.style.height=a?`${o?Math.min(a,o):a}px`:n},t),s.listenToMessageFromWindow(window,c.SET_FULL_HEIGHT,({isUpToSmall:r})=>{e.style.height=r?n:`${o||document.body.offsetHeight}px`},t)]}const de={[E.ON_BEFORE_APPROVAL]:(e,t)=>t?.onBeforeApproval?t.onBeforeApproval(e):!0,[E.ON_BEFORE_TRADE]:(e,t)=>t?.onBeforeTrade?t.onBeforeTrade(e):!0,[E.ON_BEFORE_WRAP_UNWRAP]:(e,t)=>t?.onBeforeWrapOrUnwrap?t.onBeforeWrapOrUnwrap(e):!0,[E.ON_BEFORE_ORDER_CANCEL]:(e,t)=>t?.onBeforeOrderCancel?t.onBeforeOrderCancel(e):!0,[E.ON_BEFORE_ORDERS_CANCEL]:(e,t)=>t?.onBeforeOrdersCancel?t.onBeforeOrdersCancel(e):!0};function ue(e,t){return de[e.event](e.payload,t)}function ce(e,t,n){return s.listenToMessageFromWindow(window,c.PROCESS_HOOK,async o=>{let r=!1;try{r=await ue(o,n)}catch{}s.postMessageToWindow(e,T.HOOK_RESULT,{id:o.id,result:r},t)},t)}const le=Object.values(P);function Ee(e,t,n){if(_(e)){const o=e[n];return O(o)?o[t]:o}if(O(e)){const o=e[t];return _(o)?o[n]:o}return e}function _(e){return typeof e!="object"?!1:Object.keys(e).every(t=>le.includes(t))}const fe=/^\d+$/;function O(e){return typeof e!="object"?!1:Object.keys(e).every(t=>fe.test(t))}function pe(e){return _(e)?Object.values(e).flatMap(t=>O(t)?Object.values(t):[t]):O(e)?Object.values(e).flatMap(t=>_(t)?Object.values(t):[t]):[e]}exports.TradeType=P;exports.WIDGET_PALETTE_COLORS=U;exports.WidgetHookEvents=E;exports.WidgetMethodsEmit=c;exports.WidgetMethodsListen=T;exports.createCowSwapWidget=q;exports.isCowSwapWidgetPalette=I;exports.isPerNetworkConfig=O;exports.isPerTradeTypeConfig=_;exports.resolveFlexibleConfig=Ee;exports.resolveFlexibleConfigValues=pe;exports.widgetIframeTransport=s;
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IframeTransport as
|
|
1
|
+
import { IframeTransport as v, IframeRpcProviderBridge as D } from "@cowprotocol/iframe-transport";
|
|
2
2
|
import { SimpleCowEventEmitter as U } from "@cowprotocol/events";
|
|
3
3
|
var l = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.READY = "READY", e.UPDATE_HEIGHT = "UPDATE_HEIGHT", e.SET_FULL_HEIGHT = "SET_FULL_HEIGHT", e.EMIT_COW_EVENT = "EMIT_COW_EVENT", e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e.INTERCEPT_WINDOW_OPEN = "INTERCEPT_WINDOW_OPEN", e.PROCESS_HOOK = "PROCESS_HOOK", e))(l || {}), T = /* @__PURE__ */ ((e) => (e.UPDATE_PARAMS = "UPDATE_PARAMS", e.UPDATE_APP_DATA = "UPDATE_APP_DATA", e.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", e.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", e.HOOK_RESULT = "HOOK_RESULT", e))(T || {}), p = /* @__PURE__ */ ((e) => (e.ON_BEFORE_APPROVAL = "ON_BEFORE_APPROVAL", e.ON_BEFORE_TRADE = "ON_BEFORE_TRADE", e.ON_BEFORE_WRAP_UNWRAP = "ON_BEFORE_WRAP_UNWRAP", e.ON_BEFORE_ORDER_CANCEL = "ON_BEFORE_ORDER_CANCEL", e.ON_BEFORE_ORDERS_CANCEL = "ON_BEFORE_ORDERS_CANCEL", e))(p || {}), A = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e.YIELD = "yield", e))(A || {});
|
|
4
|
-
const
|
|
4
|
+
const pe = ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"], s = new v("cowSwapWidget");
|
|
5
5
|
class b {
|
|
6
6
|
constructor(n, t, o = []) {
|
|
7
7
|
this.contentWindow = n, this.updateListeners(o), this.widgetListener = s.listenToMessageFromWindow(this.contentWindow, l.EMIT_COW_EVENT, (r) => this.eventEmitter.emit(r.event, r.payload), t);
|
|
@@ -49,51 +49,52 @@ function M(e = "Default", n = "#1c5dbf", ...t) {
|
|
|
49
49
|
function V(...e) {
|
|
50
50
|
M("Widget", "#47aba8", ...e);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
const k = "https://swap.cow.finance";
|
|
53
|
+
function j(e) {
|
|
53
54
|
return !!(e && typeof e == "object");
|
|
54
55
|
}
|
|
55
|
-
const
|
|
56
|
-
function
|
|
57
|
-
const n = typeof e.baseUrl == "string" ? e.baseUrl :
|
|
58
|
-
return n + "/#" + t + "?" +
|
|
56
|
+
const m = "_";
|
|
57
|
+
function G(e) {
|
|
58
|
+
const n = typeof e.baseUrl == "string" ? e.baseUrl : k, t = I(e);
|
|
59
|
+
return n + "/#" + t + "?" + S(e);
|
|
59
60
|
}
|
|
60
|
-
function
|
|
61
|
+
function I(e) {
|
|
61
62
|
const {
|
|
62
63
|
chainId: n = 1,
|
|
63
64
|
sell: t,
|
|
64
65
|
buy: o,
|
|
65
66
|
tradeType: r = A.SWAP
|
|
66
|
-
} = e, a = [t?.asset ||
|
|
67
|
+
} = e, a = [t?.asset || m, o?.asset || m].map(encodeURIComponent).join("/");
|
|
67
68
|
return `/${n}/widget/${r}/${a}`;
|
|
68
69
|
}
|
|
69
|
-
function
|
|
70
|
+
function S(e) {
|
|
70
71
|
const n = new URLSearchParams();
|
|
71
|
-
return K($(Q(x(
|
|
72
|
+
return Y(K($(Q(x(n, e), e), e), e), e);
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
+
function x(e, n) {
|
|
74
75
|
const {
|
|
75
76
|
sell: t,
|
|
76
77
|
buy: o
|
|
77
78
|
} = n;
|
|
78
79
|
return t?.amount && e.append("sellAmount", t.amount), o?.amount && e.append("buyAmount", o.amount), e;
|
|
79
80
|
}
|
|
80
|
-
function
|
|
81
|
+
function Q(e, n) {
|
|
81
82
|
const t = n.theme;
|
|
82
|
-
return t ? (
|
|
83
|
+
return t ? (j(t) ? (e.append("palette", encodeURIComponent(JSON.stringify(t))), e.append("theme", t.baseTheme)) : (e.append("palette", "null"), e.append("theme", t)), e) : (e.append("palette", "null"), e);
|
|
83
84
|
}
|
|
84
|
-
function
|
|
85
|
+
function $(e, n) {
|
|
85
86
|
return n.targetChainId && e.append("targetChainId", n.targetChainId.toString()), e;
|
|
86
87
|
}
|
|
87
|
-
function
|
|
88
|
+
function K(e, n) {
|
|
88
89
|
return n.locale && e.append("lng", n.locale), e;
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
-
return
|
|
91
|
+
function Y(e, n) {
|
|
92
|
+
return J(n.hooks) ? e.append("hooksEnabled", "true") : e.delete("hooksEnabled"), e;
|
|
92
93
|
}
|
|
93
|
-
function
|
|
94
|
+
function J(e) {
|
|
94
95
|
return !!e && Object.values(e).some(Boolean);
|
|
95
96
|
}
|
|
96
|
-
const N = "640px",
|
|
97
|
+
const N = "640px", X = "450px", z = 20, Z = {
|
|
97
98
|
updateParams: () => {
|
|
98
99
|
},
|
|
99
100
|
updateListeners: () => {
|
|
@@ -103,7 +104,7 @@ const N = "640px", J = "450px", X = 20, z = {
|
|
|
103
104
|
destroy: () => {
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
|
-
function
|
|
107
|
+
function we(e, n) {
|
|
107
108
|
const {
|
|
108
109
|
params: t,
|
|
109
110
|
provider: o,
|
|
@@ -111,60 +112,60 @@ function pe(e, n) {
|
|
|
111
112
|
onReady: a
|
|
112
113
|
} = n;
|
|
113
114
|
let E = o, w = t;
|
|
114
|
-
if (typeof window > "u") return
|
|
115
|
-
const d =
|
|
115
|
+
if (typeof window > "u") return Z;
|
|
116
|
+
const d = q(t), i = ee(d);
|
|
116
117
|
V("Resolved trusted iframe origin", {
|
|
117
118
|
iframeOrigin: i
|
|
118
119
|
});
|
|
119
120
|
const f = [];
|
|
120
|
-
a && f.push(
|
|
121
|
+
a && f.push(te(d.contentWindow || window, i, a)), e.innerHTML = "", e.appendChild(d);
|
|
121
122
|
const {
|
|
122
|
-
contentWindow:
|
|
123
|
+
contentWindow: c
|
|
123
124
|
} = d;
|
|
124
|
-
if (!
|
|
125
|
+
if (!c)
|
|
125
126
|
throw console.error("Iframe does not contain a window", d), new Error("Iframe does not contain a window!");
|
|
126
|
-
f.push(
|
|
127
|
+
f.push(ne(c, i, t.appCode)), f.push(...se(d, i, t.height, t.maxHeight)), f.push(oe(i));
|
|
127
128
|
let _ = null;
|
|
128
129
|
function h() {
|
|
129
|
-
|
|
130
|
+
c && (_ && window.removeEventListener("message", _), _ = ce(c, i, w.hooks), f.push(_));
|
|
130
131
|
}
|
|
131
132
|
h();
|
|
132
|
-
const
|
|
133
|
-
let P = g(
|
|
133
|
+
const C = new b(window, i, r);
|
|
134
|
+
let P = g(c, i, null, E);
|
|
134
135
|
d.addEventListener("load", () => {
|
|
135
|
-
L(
|
|
136
|
+
L(c, i, w, E);
|
|
136
137
|
});
|
|
137
|
-
const
|
|
138
|
+
const W = new H(window, c);
|
|
138
139
|
return {
|
|
139
|
-
updateParams: (
|
|
140
|
-
w =
|
|
140
|
+
updateParams: (u) => {
|
|
141
|
+
w = u, L(c, i, w, E), h();
|
|
141
142
|
},
|
|
142
|
-
updateListeners: (
|
|
143
|
-
updateProvider: (
|
|
144
|
-
E =
|
|
143
|
+
updateListeners: (u) => C.updateListeners(u),
|
|
144
|
+
updateProvider: (u) => {
|
|
145
|
+
E = u, P = g(c, i, P, u);
|
|
145
146
|
},
|
|
146
147
|
destroy: () => {
|
|
147
|
-
P.disconnect(),
|
|
148
|
+
P.disconnect(), C.stopListeningIframe(), f.forEach((u) => window.removeEventListener("message", u)), W.stopListening(), e.removeChild(d);
|
|
148
149
|
}
|
|
149
150
|
};
|
|
150
151
|
}
|
|
151
152
|
function g(e, n, t, o) {
|
|
152
153
|
t && t.disconnect();
|
|
153
|
-
const r = t || new
|
|
154
|
+
const r = t || new D(e, n);
|
|
154
155
|
return o && r.onConnect(o), r;
|
|
155
156
|
}
|
|
156
|
-
function
|
|
157
|
+
function q(e) {
|
|
157
158
|
const {
|
|
158
|
-
width: n =
|
|
159
|
+
width: n = X,
|
|
159
160
|
height: t = N
|
|
160
161
|
} = e, o = document.createElement("iframe");
|
|
161
|
-
return o.src =
|
|
162
|
+
return o.src = G(e), o.width = n, o.height = t, o.style.border = "0", o.allow = "clipboard-read; clipboard-write", o;
|
|
162
163
|
}
|
|
163
|
-
function
|
|
164
|
+
function ee(e) {
|
|
164
165
|
return new URL(e.src).origin;
|
|
165
166
|
}
|
|
166
167
|
function L(e, n, t, o) {
|
|
167
|
-
const r = !!o, a =
|
|
168
|
+
const r = !!o, a = I(t), E = S(t).toString(), {
|
|
168
169
|
theme: w,
|
|
169
170
|
hooks: d,
|
|
170
171
|
...i
|
|
@@ -178,7 +179,7 @@ function L(e, n, t, o) {
|
|
|
178
179
|
hasProvider: r
|
|
179
180
|
}, n);
|
|
180
181
|
}
|
|
181
|
-
function
|
|
182
|
+
function ne(e, n, t) {
|
|
182
183
|
return s.listenToMessageFromWindow(window, l.ACTIVATE, () => {
|
|
183
184
|
s.postMessageToWindow(e, T.UPDATE_APP_DATA, {
|
|
184
185
|
metaData: t ? {
|
|
@@ -187,23 +188,23 @@ function ee(e, n, t) {
|
|
|
187
188
|
}, n);
|
|
188
189
|
}, n);
|
|
189
190
|
}
|
|
190
|
-
function
|
|
191
|
+
function te(e, n, t) {
|
|
191
192
|
let o = !1;
|
|
192
193
|
return s.listenToMessageFromWindow(window, l.READY, () => {
|
|
193
194
|
o || (o = !0, t());
|
|
194
195
|
}, n);
|
|
195
196
|
}
|
|
196
|
-
function
|
|
197
|
+
function oe(e) {
|
|
197
198
|
return s.listenToMessageFromWindow(window, l.INTERCEPT_WINDOW_OPEN, ({
|
|
198
199
|
href: n,
|
|
199
200
|
rel: t,
|
|
200
201
|
target: o
|
|
201
202
|
}) => {
|
|
202
|
-
const r =
|
|
203
|
-
r &&
|
|
203
|
+
const r = re(n.toString(), e);
|
|
204
|
+
r && ie(r) && window.open(r, o, t);
|
|
204
205
|
}, e);
|
|
205
206
|
}
|
|
206
|
-
function
|
|
207
|
+
function re(e, n) {
|
|
207
208
|
const t = e.trim();
|
|
208
209
|
if (!t)
|
|
209
210
|
return null;
|
|
@@ -213,7 +214,7 @@ function oe(e, n) {
|
|
|
213
214
|
return null;
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
|
-
function
|
|
217
|
+
function ie(e) {
|
|
217
218
|
try {
|
|
218
219
|
const n = new URL(e).protocol;
|
|
219
220
|
return n === "http:" || n === "https:";
|
|
@@ -221,9 +222,9 @@ function re(e) {
|
|
|
221
222
|
return !1;
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
|
-
function
|
|
225
|
+
function se(e, n, t = N, o) {
|
|
225
226
|
return [s.listenToMessageFromWindow(window, l.UPDATE_HEIGHT, (r) => {
|
|
226
|
-
const a = r.height ? r.height +
|
|
227
|
+
const a = r.height ? r.height + z : void 0;
|
|
227
228
|
e.style.height = a ? `${o ? Math.min(a, o) : a}px` : t;
|
|
228
229
|
}, n), s.listenToMessageFromWindow(window, l.SET_FULL_HEIGHT, ({
|
|
229
230
|
isUpToSmall: r
|
|
@@ -231,21 +232,21 @@ function ie(e, n, t = N, o) {
|
|
|
231
232
|
e.style.height = r ? t : `${o || document.body.offsetHeight}px`;
|
|
232
233
|
}, n)];
|
|
233
234
|
}
|
|
234
|
-
const
|
|
235
|
+
const ae = {
|
|
235
236
|
[p.ON_BEFORE_APPROVAL]: (e, n) => n?.onBeforeApproval ? n.onBeforeApproval(e) : !0,
|
|
236
237
|
[p.ON_BEFORE_TRADE]: (e, n) => n?.onBeforeTrade ? n.onBeforeTrade(e) : !0,
|
|
237
238
|
[p.ON_BEFORE_WRAP_UNWRAP]: (e, n) => n?.onBeforeWrapOrUnwrap ? n.onBeforeWrapOrUnwrap(e) : !0,
|
|
238
239
|
[p.ON_BEFORE_ORDER_CANCEL]: (e, n) => n?.onBeforeOrderCancel ? n.onBeforeOrderCancel(e) : !0,
|
|
239
240
|
[p.ON_BEFORE_ORDERS_CANCEL]: (e, n) => n?.onBeforeOrdersCancel ? n.onBeforeOrdersCancel(e) : !0
|
|
240
241
|
};
|
|
241
|
-
function
|
|
242
|
-
return
|
|
242
|
+
function de(e, n) {
|
|
243
|
+
return ae[e.event](e.payload, n);
|
|
243
244
|
}
|
|
244
|
-
function
|
|
245
|
+
function ce(e, n, t) {
|
|
245
246
|
return s.listenToMessageFromWindow(window, l.PROCESS_HOOK, async (o) => {
|
|
246
247
|
let r = !1;
|
|
247
248
|
try {
|
|
248
|
-
r = await
|
|
249
|
+
r = await de(o, t);
|
|
249
250
|
} catch {
|
|
250
251
|
}
|
|
251
252
|
s.postMessageToWindow(e, T.HOOK_RESULT, {
|
|
@@ -255,7 +256,7 @@ function de(e, n, t) {
|
|
|
255
256
|
}, n);
|
|
256
257
|
}
|
|
257
258
|
const ue = Object.values(A);
|
|
258
|
-
function
|
|
259
|
+
function _e(e, n, t) {
|
|
259
260
|
if (O(e)) {
|
|
260
261
|
const o = e[t];
|
|
261
262
|
return R(o) ? o[n] : o;
|
|
@@ -269,24 +270,24 @@ function we(e, n, t) {
|
|
|
269
270
|
function O(e) {
|
|
270
271
|
return typeof e != "object" ? !1 : Object.keys(e).every((n) => ue.includes(n));
|
|
271
272
|
}
|
|
272
|
-
const
|
|
273
|
+
const le = /^\d+$/;
|
|
273
274
|
function R(e) {
|
|
274
|
-
return typeof e != "object" ? !1 : Object.keys(e).every((n) =>
|
|
275
|
+
return typeof e != "object" ? !1 : Object.keys(e).every((n) => le.test(n));
|
|
275
276
|
}
|
|
276
|
-
function
|
|
277
|
+
function Oe(e) {
|
|
277
278
|
return O(e) ? Object.values(e).flatMap((n) => R(n) ? Object.values(n) : [n]) : R(e) ? Object.values(e).flatMap((n) => O(n) ? Object.values(n) : [n]) : [e];
|
|
278
279
|
}
|
|
279
280
|
export {
|
|
280
281
|
A as TradeType,
|
|
281
|
-
|
|
282
|
+
pe as WIDGET_PALETTE_COLORS,
|
|
282
283
|
p as WidgetHookEvents,
|
|
283
284
|
l as WidgetMethodsEmit,
|
|
284
285
|
T as WidgetMethodsListen,
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
we as createCowSwapWidget,
|
|
287
|
+
j as isCowSwapWidgetPalette,
|
|
287
288
|
R as isPerNetworkConfig,
|
|
288
289
|
O as isPerTradeTypeConfig,
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
_e as resolveFlexibleConfig,
|
|
291
|
+
Oe as resolveFlexibleConfigValues,
|
|
291
292
|
s as widgetIframeTransport
|
|
292
293
|
};
|