@cowprotocol/widget-lib 0.1.3 → 0.1.4
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.iife.js +1 -1
- package/index.js +1 -1
- package/index.mjs +12 -12
- package/package.json +1 -1
package/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var cowSwapWidget=function(i){"use strict";const
|
|
1
|
+
var cowSwapWidget=function(i){"use strict";const g="2.0",l="*",m=["connect","disconnect","close","chainChanged","accountsChanged"];class f{constructor(t){this.contentWindow=t,this.ethereumProvider=null,this.requests={},this.processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(t){this.ethereumProvider=t,Object.keys(this.requests).forEach(e=>{this.processRequest(this.requests[e])}),this.requests={},m.forEach(e=>{t.on(e,n=>{this.postMessage({method:e,params:[n]})})})}processRequest(t){if(!this.ethereumProvider)return;(t.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(t)).then(n=>{this.postMessage({id:t.id,result:n})}).catch(n=>{this.postMessage({id:t.id,error:n})})}postMessage(t){this.contentWindow.postMessage({jsonrpc:g,...t},l)}}function E(){return typeof window>"u"||!window?"":`https://swap-dev-git-${window.location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const d={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:E()};var c=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(c||{});function v(s){const t=d[s.env||"prod"],e=h(s),n=u(s);return t+"/#"+e+"?"+n}function h(s){const{chainId:t=1,tradeAssets:e,tradeType:n=c.SWAP}=s,o=e?[e.sell.asset,e.buy.asset].map(encodeURIComponent).join("/"):"";return`/${t}/widget/${n}/${o}`}function u(s){const{tradeAssets:t,theme:e}=s,n=new URLSearchParams;if(t){const{sell:o,buy:a}=t;o.amount&&n.append("sellAmount",o.amount),a.amount&&n.append("buyAmount",a.amount)}return e&&n.append("theme",e),n}const r="cowSwapWidget",p="640px",y="450px";function W(s,t={}){const{provider:e}=t,n=P(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return S(o,t.appKey),A(n,t.height),e&&new f(o).onConnect(e),n.addEventListener("load",()=>{w(t,o)}),a=>w(a,o)}function P(s){const{width:t=y,height:e=p}=s,n=document.createElement("iframe");return n.src=v(s),n.width=t,n.height=e,n.style.border="0",n}function w(s,t){const e=h(s),n=u(s).toString();t.postMessage({key:r,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function S(s,t){window.addEventListener("message",e=>{e.data.key!==r||e.data.method!=="activate"||s.postMessage({key:r,method:"metaData",metaData:t?{appKey:t}:void 0},"*")})}function A(s,t=p){window.addEventListener("message",e=>{e.data.key!==r||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height}px`:t)})}return i.COWSWAP_URLS=d,i.TradeType=c,i.cowSwapWidget=W,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({});
|
package/index.js
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 w="2.0",g="*",l=["connect","disconnect","close","chainChanged","accountsChanged"];class m{constructor(t){this.contentWindow=t,this.ethereumProvider=null,this.requests={},this.processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(t){this.ethereumProvider=t,Object.keys(this.requests).forEach(e=>{this.processRequest(this.requests[e])}),this.requests={},l.forEach(e=>{t.on(e,n=>{this.postMessage({method:e,params:[n]})})})}processRequest(t){if(!this.ethereumProvider)return;(t.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(t)).then(n=>{this.postMessage({id:t.id,result:n})}).catch(n=>{this.postMessage({id:t.id,error:n})})}postMessage(t){this.contentWindow.postMessage({jsonrpc:w,...t},g)}}function f(){return typeof window>"u"||!window?"":`https://swap-dev-git-${window.location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const d={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:f()};var r=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(r||{});function E(s){const t=d[s.env||"prod"],e=h(s),n=u(s);return t+"/#"+e+"?"+n}function h(s){const{chainId:t=1,tradeAssets:e,tradeType:n=r.SWAP}=s,o=e?[e.sell.asset,e.buy.asset].map(encodeURIComponent).join("/"):"";return`/${t}/widget/${n}/${o}`}function u(s){const{tradeAssets:t,theme:e}=s,n=new URLSearchParams;if(t){const{sell:o,buy:i}=t;o.amount&&n.append("sellAmount",o.amount),i.amount&&n.append("buyAmount",i.amount)}return e&&n.append("theme",e),n}const a="cowSwapWidget",p="640px",v="450px";function y(s,t={}){const{provider:e}=t,n=P(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return W(o,t.appKey),A(n,t.height),e&&new m(o).onConnect(e),n.addEventListener("load",()=>{c(t,o)}),i=>c(i,o)}function P(s){const{width:t=v,height:e=p}=s,n=document.createElement("iframe");return n.src=E(s),n.width=t,n.height=e,n.style.border="0",n}function c(s,t){const e=h(s),n=u(s).toString();t.postMessage({key:a,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function W(s,t){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:t?{appKey:t}:void 0},"*")})}function A(s,t=p){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height}px`:t)})}exports.COWSWAP_URLS=d;exports.TradeType=r;exports.cowSwapWidget=y;
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
class
|
|
1
|
+
const p = "2.0", w = "*", m = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
|
|
2
|
+
class g {
|
|
3
3
|
/**
|
|
4
4
|
* Creates an instance of JsonRpcManager.
|
|
5
5
|
* @param contentWindow - The window for handling events.
|
|
@@ -22,7 +22,7 @@ class l {
|
|
|
22
22
|
onConnect(t) {
|
|
23
23
|
this.ethereumProvider = t, Object.keys(this.requests).forEach((e) => {
|
|
24
24
|
this.processRequest(this.requests[e]);
|
|
25
|
-
}), this.requests = {},
|
|
25
|
+
}), this.requests = {}, m.forEach((e) => {
|
|
26
26
|
t.on(e, (n) => {
|
|
27
27
|
this.postMessage({ method: e, params: [n] });
|
|
28
28
|
});
|
|
@@ -44,21 +44,21 @@ class l {
|
|
|
44
44
|
postMessage(t) {
|
|
45
45
|
this.contentWindow.postMessage(
|
|
46
46
|
{
|
|
47
|
-
jsonrpc:
|
|
47
|
+
jsonrpc: p,
|
|
48
48
|
...t
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
w
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
return `https://swap-dev-git-${location.hostname.replace("widget-configurator-git-", "").replace("-cowswap.vercel.app", "")}-cowswap.vercel.app`;
|
|
54
|
+
function l() {
|
|
55
|
+
return typeof window > "u" || !window ? "" : `https://swap-dev-git-${window.location.hostname.replace("widget-configurator-git-", "").replace("-cowswap.vercel.app", "")}-cowswap.vercel.app`;
|
|
56
56
|
}
|
|
57
57
|
const f = {
|
|
58
58
|
local: "http://localhost:3000",
|
|
59
59
|
prod: "https://swap.cow.fi",
|
|
60
60
|
dev: "https://dev.swap.cow.fi",
|
|
61
|
-
pr:
|
|
61
|
+
pr: l()
|
|
62
62
|
};
|
|
63
63
|
var c = /* @__PURE__ */ ((s) => (s.SWAP = "swap", s.LIMIT = "limit", s.ADVANCED = "advanced", s))(c || {});
|
|
64
64
|
function E(s) {
|
|
@@ -77,19 +77,19 @@ function h(s) {
|
|
|
77
77
|
}
|
|
78
78
|
return e && n.append("theme", e), n;
|
|
79
79
|
}
|
|
80
|
-
const a = "cowSwapWidget",
|
|
80
|
+
const a = "cowSwapWidget", u = "640px", v = "450px";
|
|
81
81
|
function A(s, t = {}) {
|
|
82
82
|
const { provider: e } = t, n = y(t);
|
|
83
83
|
s.innerHTML = "", s.appendChild(n);
|
|
84
84
|
const { contentWindow: o } = n;
|
|
85
85
|
if (!o)
|
|
86
86
|
throw new Error("Iframe does not contain a window!");
|
|
87
|
-
return P(o, t.appKey), W(n, t.height), e && new
|
|
87
|
+
return P(o, t.appKey), W(n, t.height), e && new g(o).onConnect(e), n.addEventListener("load", () => {
|
|
88
88
|
r(t, o);
|
|
89
89
|
}), (i) => r(i, o);
|
|
90
90
|
}
|
|
91
91
|
function y(s) {
|
|
92
|
-
const { width: t = v, height: e =
|
|
92
|
+
const { width: t = v, height: e = u } = s, n = document.createElement("iframe");
|
|
93
93
|
return n.src = E(s), n.width = t, n.height = e, n.style.border = "0", n;
|
|
94
94
|
}
|
|
95
95
|
function r(s, t) {
|
|
@@ -122,7 +122,7 @@ function P(s, t) {
|
|
|
122
122
|
);
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
function W(s, t =
|
|
125
|
+
function W(s, t = u) {
|
|
126
126
|
window.addEventListener("message", (e) => {
|
|
127
127
|
e.data.key !== a || e.data.method !== "iframeHeight" || (s.style.height = e.data.height ? `${e.data.height}px` : t);
|
|
128
128
|
});
|