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