@cowprotocol/widget-lib
Advanced tools
Comparing version
@@ -1,1 +0,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}({}); | ||
var cowSwapWidget=function(i){"use strict";const m="2.0",f="*",l=["connect","disconnect","close","chainChanged","accountsChanged"];class E{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:m,...t},f)}}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=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(c||{});const h="_";function P(s){const t=d[s.env||"prod"],e=u(s),n=p(s);return t+"/#"+e+"?"+n}function u(s){const{chainId:t=1,sell:e,buy:n,tradeType:o=c.SWAP}=s,r=[(e==null?void 0:e.asset)||h,(n==null?void 0:n.asset)||h].map(encodeURIComponent).join("/");return`/${t}/widget/${o}/${r}`}function p(s){const{sell:t,buy:e,theme:n}=s,o=new URLSearchParams;return t!=null&&t.amount&&o.append("sellAmount",t.amount),e!=null&&e.amount&&o.append("buyAmount",e.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const a="cowSwapWidget",w="640px",W="450px",S=20;function y(s,t={}){const{provider:e}=t,n=T(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return A(o,t.appCode),M(n,t.height),e&&new E(o).onConnect(e),n.addEventListener("load",()=>{g(t,o)}),r=>g(r,o)}function T(s){const{width:t=W,height:e=w}=s,n=document.createElement("iframe");return n.src=P(s),n.width=t,n.height=e,n.style.border="0",n}function g(s,t){const e=u(s),n=p(s).toString();t.postMessage({key:a,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function A(s,t){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:t?{appCode:t}:void 0},"*")})}function M(s,t=w){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height+S}px`:t)})}return i.COWSWAP_URLS=d,i.TradeType=c,i.cowSwapWidget=y,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({}); |
@@ -1,1 +0,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; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="2.0",m="*",f=["connect","disconnect","close","chainChanged","accountsChanged"];class l{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={},f.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},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 t=h[s.env||"prod"],e=p(s),n=u(s);return t+"/#"+e+"?"+n}function p(s){const{chainId:t=1,sell:e,buy:n,tradeType:o=r.SWAP}=s,i=[(e==null?void 0:e.asset)||c,(n==null?void 0:n.asset)||c].map(encodeURIComponent).join("/");return`/${t}/widget/${o}/${i}`}function u(s){const{sell:t,buy:e,theme:n}=s,o=new URLSearchParams;return t!=null&&t.amount&&o.append("sellAmount",t.amount),e!=null&&e.amount&&o.append("buyAmount",e.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const a="cowSwapWidget",w="640px",P="450px",W=20;function y(s,t={}){const{provider:e}=t,n=S(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return T(o,t.appCode),A(n,t.height),e&&new l(o).onConnect(e),n.addEventListener("load",()=>{d(t,o)}),i=>d(i,o)}function S(s){const{width:t=P,height:e=w}=s,n=document.createElement("iframe");return n.src=v(s),n.width=t,n.height=e,n.style.border="0",n}function d(s,t){const e=p(s),n=u(s).toString();t.postMessage({key:a,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function T(s,t){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:t?{appCode:t}:void 0},"*")})}function A(s,t=w){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height+W}px`:t)})}exports.COWSWAP_URLS=h;exports.TradeType=r;exports.cowSwapWidget=y; |
{ | ||
"name": "@cowprotocol/widget-lib", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your website.", |
@@ -54,6 +54,11 @@ import type { SupportedChainId } from '@cowprotocol/cow-sdk'; | ||
baseTheme: CowSwapTheme; | ||
primaryColor: string; | ||
screenBackground: string; | ||
widgetBackground: string; | ||
textColor: string; | ||
primary: string; | ||
background: string; | ||
paper: string; | ||
text: string; | ||
danger: string; | ||
warning: string; | ||
alert: string; | ||
info: string; | ||
success: string; | ||
} | ||
@@ -83,2 +88,6 @@ interface CowSwapWidgetConfig { | ||
/** | ||
* The token lists urls to use in the widget | ||
*/ | ||
tokenLists: string[]; | ||
/** | ||
* Swap, Limit or Advanced (Twap). | ||
@@ -85,0 +94,0 @@ */ |
Sorry, the diff of this file is not supported yet
18245
1.82%347
2.66%