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