@cowprotocol/widget-lib 0.2.0 → 0.2.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.iife.js CHANGED
@@ -1 +1 @@
1
- var cowSwapWidget=function(a){"use strict";const g="2.0",m="*",l=["connect","disconnect","close","chainChanged","accountsChanged"];class f{constructor(e){this.contentWindow=e,this.ethereumProvider=null,this.requests={},this.processEvent=t=>{t.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(t.data):this.requests[t.data.id]=t.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(t=>{this.processRequest(this.requests[t])}),this.requests={},l.forEach(t=>{e.on(t,n=>{this.postMessage({method:t,params:[n]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(n=>{this.postMessage({id:e.id,result:n})}).catch(n=>{this.postMessage({id:e.id,error:n})})}postMessage(e){this.contentWindow.postMessage({jsonrpc:g,...e},m)}}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 e=d[s.env||"prod"],t=h(s),n=u(s);return e+"/#"+t+"?"+n}function h(s){const{chainId:e=1,sell:t,buy:n,tradeType:o=c.SWAP}=s,i=[];t?.asset&&i.push(t.asset),n?.asset&&i.push(n.asset);const R=i.map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${R}`}function u(s){const{sell:e,buy:t,theme:n}=s,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),t?.amount&&o.append("buyAmount",t.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const r="cowSwapWidget",p="640px",y="450px",W=20;function P(s,e={}){const{provider:t}=e,n=S(e);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return T(o,e.appCode),A(n,e.height),t&&new f(o).onConnect(t),n.addEventListener("load",()=>{w(e,o)}),i=>w(i,o)}function S(s){const{width:e=y,height:t=p}=s,n=document.createElement("iframe");return n.src=v(s),n.width=e,n.height=t,n.style.border="0",n}function w(s,e){const t=h(s),n=u(s).toString();e.postMessage({key:r,method:"update",urlParams:{pathname:t,search:n},appParams:{...s,provider:void 0}},"*")}function T(s,e){window.addEventListener("message",t=>{t.data.key!==r||t.data.method!=="activate"||s.postMessage({key:r,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function A(s,e=p){window.addEventListener("message",t=>{t.data.key!==r||t.data.method!=="iframeHeight"||(s.style.height=t.data.height?`${t.data.height+W}px`:e)})}return a.COWSWAP_URLS=d,a.TradeType=c,a.cowSwapWidget=P,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),a}({});
1
+ var cowSwapWidget=function(i){"use strict";const m="2.0",l="*",f=["connect","disconnect","close","chainChanged","accountsChanged"];class E{constructor(e){this.contentWindow=e,this.ethereumProvider=null,this.requests={},this.processEvent=t=>{t.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(t.data):this.requests[t.data.id]=t.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(t=>{this.processRequest(this.requests[t])}),this.requests={},f.forEach(t=>{e.on(t,s=>{this.postMessage({method:t,params:[s]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(s=>{this.postMessage({id:e.id,result:s})}).catch(s=>{this.postMessage({id:e.id,error:s})})}postMessage(e){this.contentWindow.postMessage({jsonrpc:m,...e},l)}}function v(){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:v()};var c=(n=>(n.SWAP="swap",n.LIMIT="limit",n.ADVANCED="advanced",n))(c||{});const h="_";function y(n){const e=d[n.env||"prod"],t=u(n),s=p(n);return e+"/#"+t+"?"+s}function u(n){const{chainId:e=1,sell:t,buy:s,tradeType:o=c.SWAP}=n,r=[t?.asset||h,s?.asset||h].map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${r}`}function p(n){const{sell:e,buy:t,theme:s}=n,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),t?.amount&&o.append("buyAmount",t.amount),s&&o.append("theme",typeof s=="string"?s:s.baseTheme),o}const a="cowSwapWidget",w="640px",P="450px",W=20;function S(n,e={}){const{provider:t}=e,s=T(e);n.innerHTML="",n.appendChild(s);const{contentWindow:o}=s;if(!o)throw new Error("Iframe does not contain a window!");return A(o,e.appCode),M(s,e.height),t&&new E(o).onConnect(t),s.addEventListener("load",()=>{g(e,o)}),r=>g(r,o)}function T(n){const{width:e=P,height:t=w}=n,s=document.createElement("iframe");return s.src=y(n),s.width=e,s.height=t,s.style.border="0",s}function g(n,e){const t=u(n),s=p(n).toString();e.postMessage({key:a,method:"update",urlParams:{pathname:t,search:s},appParams:{...n,provider:void 0}},"*")}function A(n,e){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="activate"||n.postMessage({key:a,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function M(n,e=w){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="iframeHeight"||(n.style.height=t.data.height?`${t.data.height+W}px`:e)})}return i.COWSWAP_URLS=d,i.TradeType=c,i.cowSwapWidget=S,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 g="2.0",m="*",l=["connect","disconnect","close","chainChanged","accountsChanged"];class f{constructor(e){this.contentWindow=e,this.ethereumProvider=null,this.requests={},this.processEvent=t=>{t.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(t.data):this.requests[t.data.id]=t.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(t=>{this.processRequest(this.requests[t])}),this.requests={},l.forEach(t=>{e.on(t,n=>{this.postMessage({method:t,params:[n]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(n=>{this.postMessage({id:e.id,result:n})}).catch(n=>{this.postMessage({id:e.id,error:n})})}postMessage(e){this.contentWindow.postMessage({jsonrpc:g,...e},m)}}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 r=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(r||{});function v(s){const e=d[s.env||"prod"],t=h(s),n=u(s);return e+"/#"+t+"?"+n}function h(s){const{chainId:e=1,sell:t,buy:n,tradeType:o=r.SWAP}=s,i=[];t?.asset&&i.push(t.asset),n?.asset&&i.push(n.asset);const w=i.map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${w}`}function u(s){const{sell:e,buy:t,theme:n}=s,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),t?.amount&&o.append("buyAmount",t.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const a="cowSwapWidget",p="640px",y="450px",P=20;function W(s,e={}){const{provider:t}=e,n=S(e);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return T(o,e.appCode),A(n,e.height),t&&new f(o).onConnect(t),n.addEventListener("load",()=>{c(e,o)}),i=>c(i,o)}function S(s){const{width:e=y,height:t=p}=s,n=document.createElement("iframe");return n.src=v(s),n.width=e,n.height=t,n.style.border="0",n}function c(s,e){const t=h(s),n=u(s).toString();e.postMessage({key:a,method:"update",urlParams:{pathname:t,search:n},appParams:{...s,provider:void 0}},"*")}function T(s,e){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function A(s,e=p){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="iframeHeight"||(s.style.height=t.data.height?`${t.data.height+P}px`:e)})}exports.COWSWAP_URLS=d;exports.TradeType=r;exports.cowSwapWidget=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="2.0",m="*",l=["connect","disconnect","close","chainChanged","accountsChanged"];class f{constructor(e){this.contentWindow=e,this.ethereumProvider=null,this.requests={},this.processEvent=t=>{t.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(t.data):this.requests[t.data.id]=t.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(t=>{this.processRequest(this.requests[t])}),this.requests={},l.forEach(t=>{e.on(t,n=>{this.postMessage({method:t,params:[n]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(n=>{this.postMessage({id:e.id,result:n})}).catch(n=>{this.postMessage({id:e.id,error:n})})}postMessage(e){this.contentWindow.postMessage({jsonrpc:g,...e},m)}}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 h={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:E()};var r=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(r||{});const c="_";function v(s){const e=h[s.env||"prod"],t=u(s),n=p(s);return e+"/#"+t+"?"+n}function u(s){const{chainId:e=1,sell:t,buy:n,tradeType:o=r.SWAP}=s,i=[t?.asset||c,n?.asset||c].map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${i}`}function p(s){const{sell:e,buy:t,theme:n}=s,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),t?.amount&&o.append("buyAmount",t.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const a="cowSwapWidget",w="640px",y="450px",P=20;function W(s,e={}){const{provider:t}=e,n=S(e);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return T(o,e.appCode),A(n,e.height),t&&new f(o).onConnect(t),n.addEventListener("load",()=>{d(e,o)}),i=>d(i,o)}function S(s){const{width:e=y,height:t=w}=s,n=document.createElement("iframe");return n.src=v(s),n.width=e,n.height=t,n.style.border="0",n}function d(s,e){const t=u(s),n=p(s).toString();e.postMessage({key:a,method:"update",urlParams:{pathname:t,search:n},appParams:{...s,provider:void 0}},"*")}function T(s,e){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function A(s,e=w){window.addEventListener("message",t=>{t.data.key!==a||t.data.method!=="iframeHeight"||(s.style.height=t.data.height?`${t.data.height+P}px`:e)})}exports.COWSWAP_URLS=h;exports.TradeType=r;exports.cowSwapWidget=W;
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const w = "2.0", m = "*", g = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
2
- class f {
2
+ class l {
3
3
  /**
4
4
  * Creates an instance of JsonRpcManager.
5
5
  * @param contentWindow - The window for handling events.
@@ -51,47 +51,46 @@ class f {
51
51
  );
52
52
  }
53
53
  }
54
- function l() {
54
+ function f() {
55
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 E = {
58
58
  local: "http://localhost:3000",
59
59
  prod: "https://swap.cow.fi",
60
60
  dev: "https://dev.swap.cow.fi",
61
- pr: l()
61
+ pr: f()
62
62
  };
63
- var c = /* @__PURE__ */ ((s) => (s.SWAP = "swap", s.LIMIT = "limit", s.ADVANCED = "advanced", s))(c || {});
63
+ var d = /* @__PURE__ */ ((s) => (s.SWAP = "swap", s.LIMIT = "limit", s.ADVANCED = "advanced", s))(d || {});
64
+ const r = "_";
64
65
  function v(s) {
65
- const e = E[s.env || "prod"], t = d(s), n = h(s);
66
+ const e = E[s.env || "prod"], t = h(s), n = p(s);
66
67
  return e + "/#" + t + "?" + n;
67
68
  }
68
- function d(s) {
69
- const { chainId: e = 1, sell: t, buy: n, tradeType: o = c.SWAP } = s, i = [];
70
- t?.asset && i.push(t.asset), n?.asset && i.push(n.asset);
71
- const u = i.map(encodeURIComponent).join("/");
72
- return `/${e}/widget/${o}/${u}`;
73
- }
74
69
  function h(s) {
70
+ const { chainId: e = 1, sell: t, buy: n, tradeType: o = d.SWAP } = s, i = [t?.asset || r, n?.asset || r].map(encodeURIComponent).join("/");
71
+ return `/${e}/widget/${o}/${i}`;
72
+ }
73
+ function p(s) {
75
74
  const { sell: e, buy: t, theme: n } = s, o = new URLSearchParams();
76
75
  return e?.amount && o.append("sellAmount", e.amount), t?.amount && o.append("buyAmount", t.amount), n && o.append("theme", typeof n == "string" ? n : n.baseTheme), o;
77
76
  }
78
- const a = "cowSwapWidget", p = "640px", y = "450px", P = 20;
79
- function I(s, e = {}) {
77
+ const a = "cowSwapWidget", u = "640px", y = "450px", P = 20;
78
+ function M(s, e = {}) {
80
79
  const { provider: t } = e, n = W(e);
81
80
  s.innerHTML = "", s.appendChild(n);
82
81
  const { contentWindow: o } = n;
83
82
  if (!o)
84
83
  throw new Error("Iframe does not contain a window!");
85
- return A(o, e.appCode), R(n, e.height), t && new f(o).onConnect(t), n.addEventListener("load", () => {
86
- r(e, o);
87
- }), (i) => r(i, o);
84
+ return T(o, e.appCode), A(n, e.height), t && new l(o).onConnect(t), n.addEventListener("load", () => {
85
+ c(e, o);
86
+ }), (i) => c(i, o);
88
87
  }
89
88
  function W(s) {
90
- const { width: e = y, height: t = p } = s, n = document.createElement("iframe");
89
+ const { width: e = y, height: t = u } = s, n = document.createElement("iframe");
91
90
  return n.src = v(s), n.width = e, n.height = t, n.style.border = "0", n;
92
91
  }
93
- function r(s, e) {
94
- const t = d(s), n = h(s).toString();
92
+ function c(s, e) {
93
+ const t = h(s), n = p(s).toString();
95
94
  e.postMessage(
96
95
  {
97
96
  key: a,
@@ -108,7 +107,7 @@ function r(s, e) {
108
107
  "*"
109
108
  );
110
109
  }
111
- function A(s, e) {
110
+ function T(s, e) {
112
111
  window.addEventListener("message", (t) => {
113
112
  t.data.key !== a || t.data.method !== "activate" || s.postMessage(
114
113
  {
@@ -120,13 +119,13 @@ function A(s, e) {
120
119
  );
121
120
  });
122
121
  }
123
- function R(s, e = p) {
122
+ function A(s, e = u) {
124
123
  window.addEventListener("message", (t) => {
125
124
  t.data.key !== a || t.data.method !== "iframeHeight" || (s.style.height = t.data.height ? `${t.data.height + P}px` : e);
126
125
  });
127
126
  }
128
127
  export {
129
128
  E as COWSWAP_URLS,
130
- c as TradeType,
131
- I as cowSwapWidget
129
+ d as TradeType,
130
+ M as cowSwapWidget
132
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-lib",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",