@cowprotocol/widget-lib 0.6.0-RC.3 → 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 +53 -62
- package/package.json +2 -2
- package/types.d.ts +12 -5
- 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,31 +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 V(t) {
|
|
107
|
-
const n = S[t.env || "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);
|
|
108
100
|
return n + "/#" + e + "?" + s;
|
|
109
101
|
}
|
|
110
102
|
function A(t) {
|
|
111
|
-
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("/");
|
|
112
104
|
return `/${n}/widget/${i}/${r}`;
|
|
113
105
|
}
|
|
114
|
-
function
|
|
106
|
+
function I(t) {
|
|
115
107
|
const { sell: n, buy: e, theme: s } = t, i = new URLSearchParams();
|
|
116
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;
|
|
117
109
|
}
|
|
118
|
-
class
|
|
110
|
+
class S {
|
|
119
111
|
constructor() {
|
|
120
112
|
this.subscriptions = {};
|
|
121
113
|
}
|
|
@@ -131,17 +123,17 @@ class L {
|
|
|
131
123
|
this.subscriptions[n] && this.subscriptions[n].forEach((s) => s(e));
|
|
132
124
|
}
|
|
133
125
|
}
|
|
134
|
-
let
|
|
135
|
-
class
|
|
126
|
+
let V = 1;
|
|
127
|
+
class L {
|
|
136
128
|
constructor(n, e = []) {
|
|
137
|
-
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(
|
|
138
130
|
this.contentWindow,
|
|
139
|
-
|
|
131
|
+
h.EMIT_COW_EVENT,
|
|
140
132
|
(s) => this.eventEmitter.emit(s.event, s.payload)
|
|
141
133
|
);
|
|
142
134
|
}
|
|
143
135
|
stopListeningIframe() {
|
|
144
|
-
|
|
136
|
+
l(this.contentWindow, this.widgetListener);
|
|
145
137
|
}
|
|
146
138
|
updateListeners(n) {
|
|
147
139
|
for (const e of this.listeners)
|
|
@@ -151,42 +143,42 @@ class y {
|
|
|
151
143
|
this.eventEmitter.on(e);
|
|
152
144
|
}
|
|
153
145
|
}
|
|
154
|
-
const g = "640px",
|
|
155
|
-
function
|
|
146
|
+
const g = "640px", U = "450px", N = 20;
|
|
147
|
+
function H(t, n) {
|
|
156
148
|
const { params: e, provider: s, listeners: i } = n;
|
|
157
149
|
let r = s;
|
|
158
|
-
const o =
|
|
150
|
+
const o = b(e);
|
|
159
151
|
t.innerHTML = "", t.appendChild(o);
|
|
160
152
|
const { contentWindow: a } = o;
|
|
161
153
|
if (!a)
|
|
162
154
|
throw console.error("Iframe does not contain a window", o), new Error("Iframe does not contain a window!");
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const m = new
|
|
166
|
-
let f =
|
|
167
|
-
return o.addEventListener("load", () =>
|
|
168
|
-
updateParams: (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),
|
|
169
161
|
updateListeners: (c) => m.updateListeners(c),
|
|
170
162
|
updateProvider: (c) => {
|
|
171
|
-
r = c, f =
|
|
163
|
+
r = c, f = R(a, f, c);
|
|
172
164
|
},
|
|
173
165
|
destroy: () => {
|
|
174
|
-
m.stopListeningIframe(),
|
|
166
|
+
m.stopListeningIframe(), p.forEach((c) => window.removeEventListener("message", c)), t.removeChild(o);
|
|
175
167
|
}
|
|
176
168
|
};
|
|
177
169
|
}
|
|
178
|
-
function
|
|
170
|
+
function R(t, n, e) {
|
|
179
171
|
n && n.disconnect();
|
|
180
172
|
const s = n || new W(t);
|
|
181
173
|
return e && s.onConnect(e), s;
|
|
182
174
|
}
|
|
183
|
-
function
|
|
184
|
-
const { width: n =
|
|
185
|
-
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;
|
|
186
178
|
}
|
|
187
|
-
function
|
|
188
|
-
const s = !!e, i = A(n), r =
|
|
189
|
-
|
|
179
|
+
function w(t, n, e) {
|
|
180
|
+
const s = !!e, i = A(n), r = I(n).toString();
|
|
181
|
+
u(t, d.UPDATE_PARAMS, {
|
|
190
182
|
urlParams: {
|
|
191
183
|
pathname: i,
|
|
192
184
|
search: r
|
|
@@ -197,27 +189,26 @@ function l(t, n, e) {
|
|
|
197
189
|
hasProvider: s
|
|
198
190
|
});
|
|
199
191
|
}
|
|
200
|
-
function
|
|
201
|
-
const e =
|
|
202
|
-
|
|
192
|
+
function y(t, n) {
|
|
193
|
+
const e = E(window, h.ACTIVATE, () => {
|
|
194
|
+
l(window, e), u(t, d.UPDATE_APP_DATA, {
|
|
203
195
|
metaData: n ? { appCode: n } : void 0
|
|
204
196
|
});
|
|
205
197
|
});
|
|
206
198
|
return e;
|
|
207
199
|
}
|
|
208
|
-
function
|
|
209
|
-
return
|
|
210
|
-
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;
|
|
211
203
|
});
|
|
212
204
|
}
|
|
213
205
|
export {
|
|
214
|
-
S as COWSWAP_URLS,
|
|
215
206
|
_ as TradeType,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
207
|
+
h as WidgetMethodsEmit,
|
|
208
|
+
d as WidgetMethodsListen,
|
|
209
|
+
H as createCowSwapWidget,
|
|
210
|
+
E as listenToMessageFromWindow,
|
|
211
|
+
u as postMessageToWindow,
|
|
221
212
|
C as stopListeningToMessageFromWindow,
|
|
222
|
-
|
|
213
|
+
l as stopListeningWindowListener
|
|
223
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:
|
|
@@ -122,9 +121,13 @@ export interface CowSwapWidgetParams {
|
|
|
122
121
|
*/
|
|
123
122
|
tradeType?: TradeType;
|
|
124
123
|
/**
|
|
125
|
-
* The
|
|
124
|
+
* The base url of the widget implementation
|
|
125
|
+
*
|
|
126
|
+
* The parameter can have the URL directly, or an object with the environment property,
|
|
127
|
+
*
|
|
128
|
+
* The base URL will default to the production environment if not specified, so it will use https://swap.cow.fi by default.
|
|
126
129
|
*/
|
|
127
|
-
|
|
130
|
+
baseUrl?: string;
|
|
128
131
|
/**
|
|
129
132
|
* Sell token, and optionally the amount.
|
|
130
133
|
*/
|
|
@@ -163,9 +166,13 @@ export interface CowSwapWidgetParams {
|
|
|
163
166
|
*/
|
|
164
167
|
hideNetworkSelector?: boolean;
|
|
165
168
|
/**
|
|
166
|
-
*
|
|
169
|
+
* Defines the widget mode.
|
|
170
|
+
* - `true` (standalone mode): The widget is standalone, so it will use its own Ethereum provider. The user can connect from within the widget.
|
|
171
|
+
* - `false` (dapp mode): The widget is embedded in a dapp which is responsible of providing the Ethereum provider. Therefore, there won't be a connect button in the widget as this should happen in the host app.
|
|
172
|
+
*
|
|
173
|
+
* Defaults to standalone.
|
|
167
174
|
*/
|
|
168
|
-
|
|
175
|
+
standaloneMode?: boolean;
|
|
169
176
|
/**
|
|
170
177
|
* The theme of the widget UI.
|
|
171
178
|
*/
|
package/consts.d.ts
DELETED