@cowprotocol/widget-lib 0.6.0-RC.4 → 0.6.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.d.ts +0 -1
- package/index.iife.js +1 -1
- package/index.js +1 -1
- package/index.mjs +54 -64
- package/package.json +2 -2
- package/types.d.ts +1 -4
- package/consts.d.ts +0 -2
package/index.d.ts
CHANGED
package/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var cowSwapWidget=function(o){"use strict";const
|
|
1
|
+
var cowSwapWidget=function(o){"use strict";const w="cowSwapWidget";function E(t,n,e){const i={key:w,method:n,...typeof e=="object"?e:{}};t.postMessage(i,"*")}function p(t,n,e){const s=i=>{!W(i.data)||i.data.key!==w||i.data.method!==n||e(i.data)};return t.addEventListener("message",s),s}function W(t){return typeof t=="object"&&t!==null&&"key"in t&&"method"in t&&typeof t.key=="string"&&typeof t.method=="string"}function T(t,n,e){t.removeEventListener("message",e)}function m(t,n){t.removeEventListener("message",n)}var d=(t=>(t.ACTIVATE="ACTIVATE",t.UPDATE_HEIGHT="UPDATE_HEIGHT",t.EMIT_COW_EVENT="EMIT_COW_EVENT",t.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",t))(d||{}),h=(t=>(t.UPDATE_PARAMS="UPDATE_PARAMS",t.UPDATE_APP_DATA="UPDATE_APP_DATA",t.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",t.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",t))(h||{}),f=(t=>(t.SWAP="swap",t.LIMIT="limit",t.ADVANCED="advanced",t))(f||{});const D=["connect","disconnect","close","chainChanged","accountsChanged"];class O{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:e})=>{if(!this.ethereumProvider){e.id&&(this.requestWaitingForConnection[e.id]=e);return}this.processRpcRequest(e)}}disconnect(){this.ethereumProvider=null,T(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():p(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),D.forEach(e=>{n.on(e,s=>this.onProviderEvent(e,s))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:e,jsonrpc:s,method:i}=n;if(!this.ethereumProvider||!e)return;(i==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:e})).then(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:e,result:r}})).catch(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:e,error:r}}))}onProviderEvent(n,e){E(this.iframeWidow,h.PROVIDER_ON_EVENT,{event:n,params:e})}forwardRpcResponseToIframe(n){E(this.iframeWidow,h.PROVIDER_RPC_RESPONSE,n)}}const R="_";function S(t){const n=typeof t.baseUrl=="string"?t.baseUrl:"https://swap.cow.fi",e=l(t),s=_(t);return n+"/#"+e+"?"+s}function l(t){const{chainId:n=1,sell:e,buy:s,tradeType:i=f.SWAP}=t,c=[(e==null?void 0:e.asset)||R,(s==null?void 0:s.asset)||R].map(encodeURIComponent).join("/");return`/${n}/widget/${i}/${c}`}function _(t){const{sell:n,buy:e,theme:s}=t,i=new URLSearchParams;return n!=null&&n.amount&&i.append("sellAmount",n.amount),e!=null&&e.amount&&i.append("buyAmount",e.amount),s&&i.append("theme",typeof s=="string"?s:s.baseTheme),i}class L{constructor(){this.subscriptions={}}on(n){const{event:e,handler:s}=n;this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push(s)}off(n){const{event:e,handler:s}=n;this.subscriptions[e]&&(this.subscriptions[e]=this.subscriptions[e].filter(i=>i!==s))}emit(n,e){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(e))}}let V=1;class U{constructor(n,e=[]){this.contentWindow=n,this.eventEmitter=new L,this.listeners=[],this.instanceNumber=V++,this.updateListeners(e),this.widgetListener=p(this.contentWindow,d.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){m(this.contentWindow,this.widgetListener)}updateListeners(n){for(const e of this.listeners)this.eventEmitter.off(e);this.listeners=n||[];for(const e of this.listeners)this.eventEmitter.on(e)}}const g="640px",y="450px",b=20;function F(t,n){const{params:e,provider:s,listeners:i}=n;let c=s;const r=N(e);t.innerHTML="",t.appendChild(r);const{contentWindow:u}=r;if(!u)throw console.error("Iframe does not contain a window",r),new Error("Iframe does not contain a window!");const P=[];P.push(H(u,e.appCode)),P.push(M(r,e.height));const I=new U(window,i);let C=A(u,null,c);return r.addEventListener("load",()=>v(u,e,c)),{updateParams:a=>v(u,a,c),updateListeners:a=>I.updateListeners(a),updateProvider:a=>{c=a,C=A(u,C,a)},destroy:()=>{I.stopListeningIframe(),P.forEach(a=>window.removeEventListener("message",a)),t.removeChild(r)}}}function A(t,n,e){n&&n.disconnect();const s=n||new O(t);return e&&s.onConnect(e),s}function N(t){const{width:n=y,height:e=g}=t,s=document.createElement("iframe");return s.src=S(t),s.width=n,s.height=e,s.style.border="0",s}function v(t,n,e){const s=!!e,i=l(n),c=_(n).toString();E(t,h.UPDATE_PARAMS,{urlParams:{pathname:i,search:c},appParams:{...n},hasProvider:s})}function H(t,n){const e=p(window,d.ACTIVATE,()=>{m(window,e),E(t,h.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return e}function M(t,n=g){return p(window,d.UPDATE_HEIGHT,e=>{t.style.height=e.height?`${e.height+b}px`:n})}return o.TradeType=f,o.WidgetMethodsEmit=d,o.WidgetMethodsListen=h,o.createCowSwapWidget=F,o.listenToMessageFromWindow=p,o.postMessageToWindow=E,o.stopListeningToMessageFromWindow=T,o.stopListeningWindowListener=m,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _="cowSwapWidget";function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _="cowSwapWidget";function u(t,n,e){const i={key:_,method:n,...typeof e=="object"?e:{}};t.postMessage(i,"*")}function E(t,n,e){const s=i=>{!C(i.data)||i.data.key!==_||i.data.method!==n||e(i.data)};return t.addEventListener("message",s),s}function C(t){return typeof t=="object"&&t!==null&&"key"in t&&"method"in t&&typeof t.key=="string"&&typeof t.method=="string"}function g(t,n,e){t.removeEventListener("message",e)}function m(t,n){t.removeEventListener("message",n)}var a=(t=>(t.ACTIVATE="ACTIVATE",t.UPDATE_HEIGHT="UPDATE_HEIGHT",t.EMIT_COW_EVENT="EMIT_COW_EVENT",t.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",t))(a||{}),h=(t=>(t.UPDATE_PARAMS="UPDATE_PARAMS",t.UPDATE_APP_DATA="UPDATE_APP_DATA",t.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",t.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",t))(h||{}),f=(t=>(t.SWAP="swap",t.LIMIT="limit",t.ADVANCED="advanced",t))(f||{});const W=["connect","disconnect","close","chainChanged","accountsChanged"];class D{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:e})=>{if(!this.ethereumProvider){e.id&&(this.requestWaitingForConnection[e.id]=e);return}this.processRpcRequest(e)}}disconnect(){this.ethereumProvider=null,g(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():E(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),W.forEach(e=>{n.on(e,s=>this.onProviderEvent(e,s))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:e,jsonrpc:s,method:i}=n;if(!this.ethereumProvider||!e)return;(i==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:e})).then(o=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:e,result:o}})).catch(o=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:e,error:o}}))}onProviderEvent(n,e){u(this.iframeWidow,h.PROVIDER_ON_EVENT,{event:n,params:e})}forwardRpcResponseToIframe(n){u(this.iframeWidow,h.PROVIDER_RPC_RESPONSE,n)}}const T="_";function O(t){const n=typeof t.baseUrl=="string"?t.baseUrl:"https://swap.cow.fi",e=A(t),s=I(t);return n+"/#"+e+"?"+s}function A(t){const{chainId:n=1,sell:e,buy:s,tradeType:i=f.SWAP}=t,r=[(e==null?void 0:e.asset)||T,(s==null?void 0:s.asset)||T].map(encodeURIComponent).join("/");return`/${n}/widget/${i}/${r}`}function I(t){const{sell:n,buy:e,theme:s}=t,i=new URLSearchParams;return n!=null&&n.amount&&i.append("sellAmount",n.amount),e!=null&&e.amount&&i.append("buyAmount",e.amount),s&&i.append("theme",typeof s=="string"?s:s.baseTheme),i}class S{constructor(){this.subscriptions={}}on(n){const{event:e,handler:s}=n;this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push(s)}off(n){const{event:e,handler:s}=n;this.subscriptions[e]&&(this.subscriptions[e]=this.subscriptions[e].filter(i=>i!==s))}emit(n,e){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(e))}}let L=1;class V{constructor(n,e=[]){this.contentWindow=n,this.eventEmitter=new S,this.listeners=[],this.instanceNumber=L++,this.updateListeners(e),this.widgetListener=E(this.contentWindow,a.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){m(this.contentWindow,this.widgetListener)}updateListeners(n){for(const e of this.listeners)this.eventEmitter.off(e);this.listeners=n||[];for(const e of this.listeners)this.eventEmitter.on(e)}}const v="640px",U="450px",y=20;function b(t,n){const{params:e,provider:s,listeners:i}=n;let r=s;const o=F(e);t.innerHTML="",t.appendChild(o);const{contentWindow:d}=o;if(!d)throw console.error("Iframe does not contain a window",o),new Error("Iframe does not contain a window!");const p=[];p.push(N(d,e.appCode)),p.push(H(o,e.height));const P=new V(window,i);let w=R(d,null,r);return o.addEventListener("load",()=>l(d,e,r)),{updateParams:c=>l(d,c,r),updateListeners:c=>P.updateListeners(c),updateProvider:c=>{r=c,w=R(d,w,c)},destroy:()=>{P.stopListeningIframe(),p.forEach(c=>window.removeEventListener("message",c)),t.removeChild(o)}}}function R(t,n,e){n&&n.disconnect();const s=n||new D(t);return e&&s.onConnect(e),s}function F(t){const{width:n=U,height:e=v}=t,s=document.createElement("iframe");return s.src=O(t),s.width=n,s.height=e,s.style.border="0",s}function l(t,n,e){const s=!!e,i=A(n),r=I(n).toString();u(t,h.UPDATE_PARAMS,{urlParams:{pathname:i,search:r},appParams:{...n},hasProvider:s})}function N(t,n){const e=E(window,a.ACTIVATE,()=>{m(window,e),u(t,h.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return e}function H(t,n=v){return E(window,a.UPDATE_HEIGHT,e=>{t.style.height=e.height?`${e.height+y}px`:n})}exports.TradeType=f;exports.WidgetMethodsEmit=a;exports.WidgetMethodsListen=h;exports.createCowSwapWidget=b;exports.listenToMessageFromWindow=E;exports.postMessageToWindow=u;exports.stopListeningToMessageFromWindow=g;exports.stopListeningWindowListener=m;
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const T = "cowSwapWidget";
|
|
2
|
+
function u(t, n, e) {
|
|
3
3
|
const i = {
|
|
4
|
-
key:
|
|
4
|
+
key: T,
|
|
5
5
|
method: n,
|
|
6
6
|
...typeof e == "object" ? e : {}
|
|
7
7
|
};
|
|
@@ -11,22 +11,22 @@ function p(t, n, e) {
|
|
|
11
11
|
// TODO: Change to CoW specific origin in production. https://github.com/cowprotocol/cowswap/issues/3828
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function E(t, n, e) {
|
|
15
15
|
const s = (i) => {
|
|
16
|
-
!
|
|
16
|
+
!v(i.data) || i.data.key !== T || i.data.method !== n || e(i.data);
|
|
17
17
|
};
|
|
18
18
|
return t.addEventListener("message", s), s;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function v(t) {
|
|
21
21
|
return typeof t == "object" && t !== null && "key" in t && "method" in t && typeof t.key == "string" && typeof t.method == "string";
|
|
22
22
|
}
|
|
23
23
|
function C(t, n, e) {
|
|
24
24
|
t.removeEventListener("message", e);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function l(t, n) {
|
|
27
27
|
t.removeEventListener("message", n);
|
|
28
28
|
}
|
|
29
|
-
var
|
|
29
|
+
var h = /* @__PURE__ */ ((t) => (t.ACTIVATE = "ACTIVATE", t.UPDATE_HEIGHT = "UPDATE_HEIGHT", t.EMIT_COW_EVENT = "EMIT_COW_EVENT", t.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", t))(h || {}), d = /* @__PURE__ */ ((t) => (t.UPDATE_PARAMS = "UPDATE_PARAMS", t.UPDATE_APP_DATA = "UPDATE_APP_DATA", t.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", t.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", t))(d || {}), _ = /* @__PURE__ */ ((t) => (t.SWAP = "swap", t.LIMIT = "limit", t.ADVANCED = "advanced", t))(_ || {});
|
|
30
30
|
const D = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
|
|
31
31
|
class W {
|
|
32
32
|
/**
|
|
@@ -47,14 +47,14 @@ class W {
|
|
|
47
47
|
* Disconnects the JSON-RPC bridge from the Ethereum provider.
|
|
48
48
|
*/
|
|
49
49
|
disconnect() {
|
|
50
|
-
this.ethereumProvider = null, C(window,
|
|
50
|
+
this.ethereumProvider = null, C(window, h.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
54
54
|
* @param newProvider - The Ethereum provider to connect.
|
|
55
55
|
*/
|
|
56
56
|
onConnect(n) {
|
|
57
|
-
this.ethereumProvider ? this.disconnect() :
|
|
57
|
+
this.ethereumProvider ? this.disconnect() : E(window, h.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), this.ethereumProvider = n, this.processPendingRequests(), D.forEach((e) => {
|
|
58
58
|
n.on(e, (s) => this.onProviderEvent(e, s));
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -82,7 +82,7 @@ class W {
|
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
onProviderEvent(n, e) {
|
|
85
|
-
|
|
85
|
+
u(this.iframeWidow, d.PROVIDER_ON_EVENT, {
|
|
86
86
|
event: n,
|
|
87
87
|
params: e
|
|
88
88
|
});
|
|
@@ -91,32 +91,23 @@ class W {
|
|
|
91
91
|
* Forward a JSON-RPC message to the content window.
|
|
92
92
|
*/
|
|
93
93
|
forwardRpcResponseToIframe(n) {
|
|
94
|
-
|
|
94
|
+
u(this.iframeWidow, d.PROVIDER_RPC_RESPONSE, n);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const S = {
|
|
101
|
-
local: "http://localhost:3000",
|
|
102
|
-
prod: "https://swap.cow.fi",
|
|
103
|
-
dev: "https://dev.swap.cow.fi",
|
|
104
|
-
pr: O()
|
|
105
|
-
}, w = "_";
|
|
106
|
-
function U(t) {
|
|
107
|
-
var i;
|
|
108
|
-
const n = typeof t.baseUrl == "string" ? t.baseUrl : S[((i = t.baseUrl) == null ? void 0 : i.environment) || "prod"], e = A(t), s = v(t);
|
|
97
|
+
const P = "_";
|
|
98
|
+
function O(t) {
|
|
99
|
+
const n = typeof t.baseUrl == "string" ? t.baseUrl : "https://swap.cow.fi", e = A(t), s = I(t);
|
|
109
100
|
return n + "/#" + e + "?" + s;
|
|
110
101
|
}
|
|
111
102
|
function A(t) {
|
|
112
|
-
const { chainId: n = 1, sell: e, buy: s, tradeType: i = _.SWAP } = t, r = [(e == null ? void 0 : e.asset) ||
|
|
103
|
+
const { chainId: n = 1, sell: e, buy: s, tradeType: i = _.SWAP } = t, r = [(e == null ? void 0 : e.asset) || P, (s == null ? void 0 : s.asset) || P].map(encodeURIComponent).join("/");
|
|
113
104
|
return `/${n}/widget/${i}/${r}`;
|
|
114
105
|
}
|
|
115
|
-
function
|
|
106
|
+
function I(t) {
|
|
116
107
|
const { sell: n, buy: e, theme: s } = t, i = new URLSearchParams();
|
|
117
108
|
return n != null && n.amount && i.append("sellAmount", n.amount), e != null && e.amount && i.append("buyAmount", e.amount), s && i.append("theme", typeof s == "string" ? s : s.baseTheme), i;
|
|
118
109
|
}
|
|
119
|
-
class
|
|
110
|
+
class S {
|
|
120
111
|
constructor() {
|
|
121
112
|
this.subscriptions = {};
|
|
122
113
|
}
|
|
@@ -132,17 +123,17 @@ class V {
|
|
|
132
123
|
this.subscriptions[n] && this.subscriptions[n].forEach((s) => s(e));
|
|
133
124
|
}
|
|
134
125
|
}
|
|
135
|
-
let
|
|
136
|
-
class
|
|
126
|
+
let V = 1;
|
|
127
|
+
class L {
|
|
137
128
|
constructor(n, e = []) {
|
|
138
|
-
this.contentWindow = n, this.eventEmitter = new
|
|
129
|
+
this.contentWindow = n, this.eventEmitter = new S(), this.listeners = [], this.instanceNumber = V++, this.updateListeners(e), this.widgetListener = E(
|
|
139
130
|
this.contentWindow,
|
|
140
|
-
|
|
131
|
+
h.EMIT_COW_EVENT,
|
|
141
132
|
(s) => this.eventEmitter.emit(s.event, s.payload)
|
|
142
133
|
);
|
|
143
134
|
}
|
|
144
135
|
stopListeningIframe() {
|
|
145
|
-
|
|
136
|
+
l(this.contentWindow, this.widgetListener);
|
|
146
137
|
}
|
|
147
138
|
updateListeners(n) {
|
|
148
139
|
for (const e of this.listeners)
|
|
@@ -152,42 +143,42 @@ class y {
|
|
|
152
143
|
this.eventEmitter.on(e);
|
|
153
144
|
}
|
|
154
145
|
}
|
|
155
|
-
const g = "640px",
|
|
156
|
-
function
|
|
146
|
+
const g = "640px", U = "450px", N = 20;
|
|
147
|
+
function H(t, n) {
|
|
157
148
|
const { params: e, provider: s, listeners: i } = n;
|
|
158
149
|
let r = s;
|
|
159
|
-
const o =
|
|
150
|
+
const o = b(e);
|
|
160
151
|
t.innerHTML = "", t.appendChild(o);
|
|
161
152
|
const { contentWindow: a } = o;
|
|
162
153
|
if (!a)
|
|
163
154
|
throw console.error("Iframe does not contain a window", o), new Error("Iframe does not contain a window!");
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
let
|
|
168
|
-
return o.addEventListener("load", () =>
|
|
169
|
-
updateParams: (c) =>
|
|
170
|
-
updateListeners: (c) =>
|
|
155
|
+
const p = [];
|
|
156
|
+
p.push(y(a, e.appCode)), p.push(F(o, e.height));
|
|
157
|
+
const m = new L(window, i);
|
|
158
|
+
let f = R(a, null, r);
|
|
159
|
+
return o.addEventListener("load", () => w(a, e, r)), {
|
|
160
|
+
updateParams: (c) => w(a, c, r),
|
|
161
|
+
updateListeners: (c) => m.updateListeners(c),
|
|
171
162
|
updateProvider: (c) => {
|
|
172
|
-
r = c,
|
|
163
|
+
r = c, f = R(a, f, c);
|
|
173
164
|
},
|
|
174
165
|
destroy: () => {
|
|
175
|
-
|
|
166
|
+
m.stopListeningIframe(), p.forEach((c) => window.removeEventListener("message", c)), t.removeChild(o);
|
|
176
167
|
}
|
|
177
168
|
};
|
|
178
169
|
}
|
|
179
|
-
function
|
|
170
|
+
function R(t, n, e) {
|
|
180
171
|
n && n.disconnect();
|
|
181
172
|
const s = n || new W(t);
|
|
182
173
|
return e && s.onConnect(e), s;
|
|
183
174
|
}
|
|
184
|
-
function
|
|
185
|
-
const { width: n =
|
|
186
|
-
return s.src =
|
|
175
|
+
function b(t) {
|
|
176
|
+
const { width: n = U, height: e = g } = t, s = document.createElement("iframe");
|
|
177
|
+
return s.src = O(t), s.width = n, s.height = e, s.style.border = "0", s;
|
|
187
178
|
}
|
|
188
|
-
function
|
|
189
|
-
const s = !!e, i = A(n), r =
|
|
190
|
-
|
|
179
|
+
function w(t, n, e) {
|
|
180
|
+
const s = !!e, i = A(n), r = I(n).toString();
|
|
181
|
+
u(t, d.UPDATE_PARAMS, {
|
|
191
182
|
urlParams: {
|
|
192
183
|
pathname: i,
|
|
193
184
|
search: r
|
|
@@ -198,27 +189,26 @@ function l(t, n, e) {
|
|
|
198
189
|
hasProvider: s
|
|
199
190
|
});
|
|
200
191
|
}
|
|
201
|
-
function
|
|
202
|
-
const e =
|
|
203
|
-
|
|
192
|
+
function y(t, n) {
|
|
193
|
+
const e = E(window, h.ACTIVATE, () => {
|
|
194
|
+
l(window, e), u(t, d.UPDATE_APP_DATA, {
|
|
204
195
|
metaData: n ? { appCode: n } : void 0
|
|
205
196
|
});
|
|
206
197
|
});
|
|
207
198
|
return e;
|
|
208
199
|
}
|
|
209
|
-
function
|
|
210
|
-
return
|
|
211
|
-
t.style.height = e.height ? `${e.height +
|
|
200
|
+
function F(t, n = g) {
|
|
201
|
+
return E(window, h.UPDATE_HEIGHT, (e) => {
|
|
202
|
+
t.style.height = e.height ? `${e.height + N}px` : n;
|
|
212
203
|
});
|
|
213
204
|
}
|
|
214
205
|
export {
|
|
215
|
-
S as COWSWAP_URLS,
|
|
216
206
|
_ as TradeType,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
207
|
+
h as WidgetMethodsEmit,
|
|
208
|
+
d as WidgetMethodsListen,
|
|
209
|
+
H as createCowSwapWidget,
|
|
210
|
+
E as listenToMessageFromWindow,
|
|
211
|
+
u as postMessageToWindow,
|
|
222
212
|
C as stopListeningToMessageFromWindow,
|
|
223
|
-
|
|
213
|
+
l as stopListeningWindowListener
|
|
224
214
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/widget-lib",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your website.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"widget-lib"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cowprotocol/events": "^0.1.0
|
|
24
|
+
"@cowprotocol/events": "^0.1.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/types.d.ts
CHANGED
|
@@ -42,7 +42,6 @@ export interface EthereumProvider {
|
|
|
42
42
|
*/
|
|
43
43
|
enable(): Promise<void>;
|
|
44
44
|
}
|
|
45
|
-
export type CowSwapWidgetEnv = 'local' | 'prod' | 'dev' | 'pr';
|
|
46
45
|
export type CowSwapTheme = 'dark' | 'light';
|
|
47
46
|
/**
|
|
48
47
|
*Trade asset parameters, for example:
|
|
@@ -128,9 +127,7 @@ export interface CowSwapWidgetParams {
|
|
|
128
127
|
*
|
|
129
128
|
* The base URL will default to the production environment if not specified, so it will use https://swap.cow.fi by default.
|
|
130
129
|
*/
|
|
131
|
-
baseUrl?: string
|
|
132
|
-
environment?: CowSwapWidgetEnv;
|
|
133
|
-
};
|
|
130
|
+
baseUrl?: string;
|
|
134
131
|
/**
|
|
135
132
|
* Sell token, and optionally the amount.
|
|
136
133
|
*/
|
package/consts.d.ts
DELETED