@cowprotocol/widget-lib 0.18.0 → 0.20.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.iife.js CHANGED
@@ -1 +1 @@
1
- var cowSwapWidget=function(E){"use strict";var fe=Object.defineProperty;var de=(E,T,R)=>T in E?fe(E,T,{enumerable:!0,configurable:!0,writable:!0,value:R}):E[T]=R;var P=(E,T,R)=>(de(E,typeof T!="symbol"?T+"":T,R),R);class T{constructor(n){this.key=n}postMessageToWindow(n,t,s){const p=typeof s=="object"?s:{},l={key:this.key,method:t,...p};n.postMessage(l,"*")}listenToMessageFromWindow(n,t,s){const p=l=>{!R(l.data)||l.data.key!==this.key||l.data.method!==t||s(l.data)};return n.addEventListener("message",p),p}stopListeningToMessageFromWindow(n,t,s){n.removeEventListener("message",s)}stopListeningWindowListener(n,t){n.removeEventListener("message",t)}}function R(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}var O=(e=>(e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(O||{});const W=new T("cowSwapIframeRpcProviderTransport"),H=["connect","disconnect","close","chainChanged","accountsChanged"];class x{constructor(n){P(this,"ethereumProvider",null);P(this,"requestWaitingForConnection",{});P(this,"processRpcCallFromWindow",({rpcRequest:n})=>{if(!this.ethereumProvider){n.id&&(this.requestWaitingForConnection[n.id]=n);return}this.processRpcRequest(n)});this.iframeWidow=n}disconnect(){this.ethereumProvider=null,W.stopListeningToMessageFromWindow(window,O.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():W.listenToMessageFromWindow(window,O.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),H.forEach(t=>{n.on(t,s=>this.onProviderEvent(t,s))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:t,jsonrpc:s,method:p}=n;if(!this.ethereumProvider||!t)return;(p==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(_=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:_}})).catch(_=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:_}}))}onProviderEvent(n,t){W.postMessageToWindow(this.iframeWidow,O.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){W.postMessageToWindow(this.iframeWidow,O.PROVIDER_RPC_RESPONSE,n)}}var G={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function p(c,r,i){this.fn=c,this.context=r,this.once=i||!1}function l(c,r,i,o,w){if(typeof i!="function")throw new TypeError("The listener must be a function");var f=new p(i,o||c,w),d=t?t+r:r;return c._events[d]?c._events[d].fn?c._events[d]=[c._events[d],f]:c._events[d].push(f):(c._events[d]=f,c._eventsCount++),c}function _(c,r){--c._eventsCount===0?c._events=new s:delete c._events[r]}function u(){this._events=new s,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],i,o;if(this._eventsCount===0)return r;for(o in i=this._events)n.call(i,o)&&r.push(t?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(i)):r},u.prototype.listeners=function(r){var i=t?t+r:r,o=this._events[i];if(!o)return[];if(o.fn)return[o.fn];for(var w=0,f=o.length,d=new Array(f);w<f;w++)d[w]=o[w].fn;return d},u.prototype.listenerCount=function(r){var i=t?t+r:r,o=this._events[i];return o?o.fn?1:o.length:0},u.prototype.emit=function(r,i,o,w,f,d){var v=t?t+r:r;if(!this._events[v])return!1;var a=this._events[v],g=arguments.length,y,h;if(a.fn){switch(a.once&&this.removeListener(r,a.fn,void 0,!0),g){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,i),!0;case 3:return a.fn.call(a.context,i,o),!0;case 4:return a.fn.call(a.context,i,o,w),!0;case 5:return a.fn.call(a.context,i,o,w,f),!0;case 6:return a.fn.call(a.context,i,o,w,f,d),!0}for(h=1,y=new Array(g-1);h<g;h++)y[h-1]=arguments[h];a.fn.apply(a.context,y)}else{var ue=a.length,I;for(h=0;h<ue;h++)switch(a[h].once&&this.removeListener(r,a[h].fn,void 0,!0),g){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,i);break;case 3:a[h].fn.call(a[h].context,i,o);break;case 4:a[h].fn.call(a[h].context,i,o,w);break;default:if(!y)for(I=1,y=new Array(g-1);I<g;I++)y[I-1]=arguments[I];a[h].fn.apply(a[h].context,y)}}return!0},u.prototype.on=function(r,i,o){return l(this,r,i,o,!1)},u.prototype.once=function(r,i,o){return l(this,r,i,o,!0)},u.prototype.removeListener=function(r,i,o,w){var f=t?t+r:r;if(!this._events[f])return this;if(!i)return _(this,f),this;var d=this._events[f];if(d.fn)d.fn===i&&(!w||d.once)&&(!o||d.context===o)&&_(this,f);else{for(var v=0,a=[],g=d.length;v<g;v++)(d[v].fn!==i||w&&!d[v].once||o&&d[v].context!==o)&&a.push(d[v]);a.length?this._events[f]=a.length===1?a[0]:a:_(this,f)}return this},u.prototype.removeAllListeners=function(r){var i;return r?(i=t?t+r:r,this._events[i]&&_(this,i)):(this._events=new s,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=t,u.EventEmitter=u,e.exports=u})(G);class Q{constructor(){P(this,"subscriptions",{})}on(n){const{event:t,handler:s}=n;return this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(s),n}off(n){const{event:t,handler:s}=n;return this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(p=>p!==s)),n}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(t))}}var C=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.SET_FULL_HEIGHT="SET_FULL_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.INTERCEPT_WINDOW_OPEN="INTERCEPT_WINDOW_OPEN",e))(C||{}),S=(e=>(e.UPDATE_PARAMS="UPDATE_PARAMS",e.UPDATE_APP_DATA="UPDATE_APP_DATA",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(S||{}),A=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(A||{});const j=["primary","background","paper","text","danger","warning","alert","info","success"],m=new T("cowSwapWidget");class ${constructor(n,t=[]){P(this,"eventEmitter",new Q);P(this,"listeners",[]);P(this,"widgetListener");this.contentWindow=n,this.updateListeners(t),this.widgetListener=m.listenToMessageFromWindow(this.contentWindow,C.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){m.stopListeningWindowListener(this.contentWindow,this.widgetListener)}updateListeners(n){for(const t of this.listeners)this.eventEmitter.off(t);this.listeners=n||[];for(const t of this.listeners)this.eventEmitter.on(t)}}class B{constructor(n,t){P(this,"forwardSdkMessage");this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=s=>{q(s.data)&&s.origin!==window.location.origin&&(Y(s.data)?this.appWindow.parent.postMessage(s.data,"*"):z(s.data)&&this.iframeWidow.postMessage(s.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function q(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function Y(e){return"method"in e&&typeof e.method=="string"&&"params"in e&&"env"in e&&typeof e.env=="object"&&e.env!==null&&"sdkVersion"in e.env}function z(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function b(e){return!!(e&&typeof e=="object")}const N="_";function J(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=M(e);return n+"/#"+t+"?"+V(e)}function M(e){const{chainId:n=1,sell:t,buy:s,tradeType:p=A.SWAP}=e,l=[(t==null?void 0:t.asset)||N,(s==null?void 0:s.asset)||N].map(encodeURIComponent).join("/");return`/${n}/widget/${p}/${l}`}function V(e){const n=new URLSearchParams;return X(K(n,e),e)}function K(e,n){const{sell:t,buy:s}=n;return t!=null&&t.amount&&e.append("sellAmount",t.amount),s!=null&&s.amount&&e.append("buyAmount",s.amount),e}function X(e,n){const t=n.theme;return t?(b(t)?(e.append("palette",encodeURIComponent(JSON.stringify(t))),e.append("theme",t.baseTheme)):(e.append("palette","null"),e.append("theme",t)),e):(e.append("palette","null"),e)}const F="640px",Z="450px",ee=20;function te(e,n){const{params:t,provider:s,listeners:p}=n;let l=s,_=t;const u=ne(t);e.innerHTML="",e.appendChild(u);const{contentWindow:c}=u;if(!c)throw console.error("Iframe does not contain a window",u),new Error("Iframe does not contain a window!");const r=[];r.push(se(c,t.appCode)),r.push(...ie(u,t.height,t.maxHeight)),r.push(re());const i=new $(window,p);let o=U(c,null,l);u.addEventListener("load",()=>k(c,_,l));const w=new B(window,c);return{updateParams:f=>{_=f,k(c,_,l)},updateListeners:f=>i.updateListeners(f),updateProvider:f=>{l=f,o=U(c,o,f)},destroy:()=>{o.disconnect(),i.stopListeningIframe(),r.forEach(f=>window.removeEventListener("message",f)),w.stopListening(),e.removeChild(u)}}}function U(e,n,t){n&&n.disconnect();const s=n||new x(e);return t&&s.onConnect(t),s}function ne(e){const{width:n=Z,height:t=F}=e,s=document.createElement("iframe");return s.src=J(e),s.width=n,s.height=t,s.style.border="0",s.allow="clipboard-read; clipboard-write",s}function k(e,n,t){const s=!!t,p=M(n),l=V(n).toString(),{theme:_,...u}=n;m.postMessageToWindow(e,S.UPDATE_PARAMS,{urlParams:{pathname:p,search:l},appParams:u,hasProvider:s})}function se(e,n){return m.listenToMessageFromWindow(window,C.ACTIVATE,()=>{m.postMessageToWindow(e,S.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})})}function re(){return m.listenToMessageFromWindow(window,C.INTERCEPT_WINDOW_OPEN,({href:e,rel:n,target:t})=>{const s=e.toString();if(!s.startsWith("http")&&s.match(/^[a-zA-Z0-9]+:\/\//)){window.open(s,t,n);return}})}function ie(e,n=F,t){return[m.listenToMessageFromWindow(window,C.UPDATE_HEIGHT,s=>{const p=s.height?s.height+ee:void 0;e.style.height=p?`${t?Math.min(p,t):p}px`:n}),m.listenToMessageFromWindow(window,C.SET_FULL_HEIGHT,({isUpToSmall:s})=>{e.style.height=s?n:`${t||document.body.offsetHeight}px`})]}const oe=Object.values(A);function ae(e,n,t){if(L(e)){const s=e[t];return D(s)?s[n]:s}if(D(e)){const s=e[n];return L(s)?s[t]:s}return e}function L(e){return typeof e!="object"?!1:Object.keys(e).every(n=>oe.includes(n))}const ce=/^\d+$/;function D(e){return typeof e!="object"?!1:Object.keys(e).every(n=>typeof n=="number"||ce.test(n))}return E.TradeType=A,E.WIDGET_PALETTE_COLORS=j,E.WidgetMethodsEmit=C,E.WidgetMethodsListen=S,E.createCowSwapWidget=te,E.isCowSwapWidgetPalette=b,E.isPerNetworkConfig=D,E.isPerTradeTypeConfig=L,E.resolveFlexibleConfig=ae,E.widgetIframeTransport=m,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),E}({});
1
+ var cowSwapWidget=function(E){"use strict";var we=Object.defineProperty;var _e=(E,T,W)=>T in E?we(E,T,{enumerable:!0,configurable:!0,writable:!0,value:W}):E[T]=W;var P=(E,T,W)=>_e(E,typeof T!="symbol"?T+"":T,W);class T{constructor(n){this.key=n}postMessageToWindow(n,t,s){const p=typeof s=="object"?s:{},l={key:this.key,method:t,...p};n.postMessage(l,"*")}listenToMessageFromWindow(n,t,s){const p=l=>{!W(l.data)||l.data.key!==this.key||l.data.method!==t||s(l.data)};return n.addEventListener("message",p),p}stopListeningToMessageFromWindow(n,t,s){n.removeEventListener("message",s)}stopListeningWindowListener(n,t){n.removeEventListener("message",t)}}function W(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}var v=(e=>(e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e.SEND_PROVIDER_META_INFO="SEND_PROVIDER_META_INFO",e.REQUEST_PROVIDER_META_INFO="REQUEST_PROVIDER_META_INFO",e))(v||{});const I=new T("cowSwapIframeRpcProviderTransport");function G(e){var n,t;if(e.isWalletConnect)return(t=(n=e==null?void 0:e.session)==null?void 0:n.peer)==null?void 0:t.metadata}function j(e,n){var t;return(t=n.find(s=>s.provider===e))==null?void 0:t.info}const q=["connect","disconnect","close","chainChanged","accountsChanged"],N=[];window.addEventListener("eip6963:announceProvider",e=>{const n=e;N.push(n.detail)});class ${constructor(n){P(this,"ethereumProvider",null);P(this,"requestWaitingForConnection",{});P(this,"processRpcCallFromWindow",({rpcRequest:n})=>{if(!this.ethereumProvider){n.id&&(this.requestWaitingForConnection[n.id]=n);return}this.processRpcRequest(n)});P(this,"processProviderMetaInfoRequest",()=>{if(!this.ethereumProvider)return;const n=j(this.ethereumProvider,N),t=G(this.ethereumProvider);I.postMessageToWindow(this.iframeWidow,v.SEND_PROVIDER_META_INFO,{providerEip6963Info:n,providerWcMetadata:t})});this.iframeWidow=n}disconnect(){this.ethereumProvider=null,I.stopListeningToMessageFromWindow(window,v.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),I.stopListeningToMessageFromWindow(window,v.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest)}onConnect(n){this.ethereumProvider?this.disconnect():I.listenToMessageFromWindow(window,v.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),q.forEach(t=>{n.on(t,s=>this.onProviderEvent(t,s))}),I.listenToMessageFromWindow(window,v.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest)}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:t,jsonrpc:s,method:p}=n;if(!this.ethereumProvider||!t)return;(p==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(_=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:_}})).catch(_=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:_}}))}onProviderEvent(n,t){I.postMessageToWindow(this.iframeWidow,v.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){I.postMessageToWindow(this.iframeWidow,v.PROVIDER_RPC_RESPONSE,n)}}var D={exports:{}},b;function B(){return b||(b=1,function(e){var n=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function p(c,r,i){this.fn=c,this.context=r,this.once=i||!1}function l(c,r,i,o,w){if(typeof i!="function")throw new TypeError("The listener must be a function");var d=new p(i,o||c,w),f=t?t+r:r;return c._events[f]?c._events[f].fn?c._events[f]=[c._events[f],d]:c._events[f].push(d):(c._events[f]=d,c._eventsCount++),c}function _(c,r){--c._eventsCount===0?c._events=new s:delete c._events[r]}function u(){this._events=new s,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],i,o;if(this._eventsCount===0)return r;for(o in i=this._events)n.call(i,o)&&r.push(t?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(i)):r},u.prototype.listeners=function(r){var i=t?t+r:r,o=this._events[i];if(!o)return[];if(o.fn)return[o.fn];for(var w=0,d=o.length,f=new Array(d);w<d;w++)f[w]=o[w].fn;return f},u.prototype.listenerCount=function(r){var i=t?t+r:r,o=this._events[i];return o?o.fn?1:o.length:0},u.prototype.emit=function(r,i,o,w,d,f){var m=t?t+r:r;if(!this._events[m])return!1;var a=this._events[m],g=arguments.length,C,h;if(a.fn){switch(a.once&&this.removeListener(r,a.fn,void 0,!0),g){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,i),!0;case 3:return a.fn.call(a.context,i,o),!0;case 4:return a.fn.call(a.context,i,o,w),!0;case 5:return a.fn.call(a.context,i,o,w,d),!0;case 6:return a.fn.call(a.context,i,o,w,d,f),!0}for(h=1,C=new Array(g-1);h<g;h++)C[h-1]=arguments[h];a.fn.apply(a.context,C)}else{var Ee=a.length,S;for(h=0;h<Ee;h++)switch(a[h].once&&this.removeListener(r,a[h].fn,void 0,!0),g){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,i);break;case 3:a[h].fn.call(a[h].context,i,o);break;case 4:a[h].fn.call(a[h].context,i,o,w);break;default:if(!C)for(S=1,C=new Array(g-1);S<g;S++)C[S-1]=arguments[S];a[h].fn.apply(a[h].context,C)}}return!0},u.prototype.on=function(r,i,o){return l(this,r,i,o,!1)},u.prototype.once=function(r,i,o){return l(this,r,i,o,!0)},u.prototype.removeListener=function(r,i,o,w){var d=t?t+r:r;if(!this._events[d])return this;if(!i)return _(this,d),this;var f=this._events[d];if(f.fn)f.fn===i&&(!w||f.once)&&(!o||f.context===o)&&_(this,d);else{for(var m=0,a=[],g=f.length;m<g;m++)(f[m].fn!==i||w&&!f[m].once||o&&f[m].context!==o)&&a.push(f[m]);a.length?this._events[d]=a.length===1?a[0]:a:_(this,d)}return this},u.prototype.removeAllListeners=function(r){var i;return r?(i=t?t+r:r,this._events[i]&&_(this,i)):(this._events=new s,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=t,u.EventEmitter=u,e.exports=u}(D)),D.exports}B();class Y{constructor(){P(this,"subscriptions",{})}on(n){const{event:t,handler:s}=n;return this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(s),n}off(n){const{event:t,handler:s}=n;return this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(p=>p!==s)),n}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(t))}}var O=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.SET_FULL_HEIGHT="SET_FULL_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.INTERCEPT_WINDOW_OPEN="INTERCEPT_WINDOW_OPEN",e))(O||{}),y=(e=>(e.UPDATE_PARAMS="UPDATE_PARAMS",e.UPDATE_APP_DATA="UPDATE_APP_DATA",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(y||{}),A=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(A||{});const z=["primary","background","paper","text","danger","warning","alert","info","success"],R=new T("cowSwapWidget");class J{constructor(n,t=[]){P(this,"eventEmitter",new Y);P(this,"listeners",[]);P(this,"widgetListener");this.contentWindow=n,this.updateListeners(t),this.widgetListener=R.listenToMessageFromWindow(this.contentWindow,O.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){R.stopListeningWindowListener(this.contentWindow,this.widgetListener)}updateListeners(n){for(const t of this.listeners)this.eventEmitter.off(t);this.listeners=n||[];for(const t of this.listeners)this.eventEmitter.on(t)}}class K{constructor(n,t){P(this,"forwardSdkMessage");this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=s=>{X(s.data)&&s.origin!==window.location.origin&&(Z(s.data)?this.appWindow.parent.postMessage(s.data,"*"):ee(s.data)&&this.iframeWidow.postMessage(s.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function X(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function Z(e){return"method"in e&&typeof e.method=="string"&&"params"in e&&"env"in e&&typeof e.env=="object"&&e.env!==null&&"sdkVersion"in e.env}function ee(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function V(e){return!!(e&&typeof e=="object")}const F="_";function te(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=U(e);return n+"/#"+t+"?"+k(e)}function U(e){const{chainId:n=1,sell:t,buy:s,tradeType:p=A.SWAP}=e,l=[(t==null?void 0:t.asset)||F,(s==null?void 0:s.asset)||F].map(encodeURIComponent).join("/");return`/${n}/widget/${p}/${l}`}function k(e){const n=new URLSearchParams;return re(se(ne(n,e),e),e)}function ne(e,n){const{sell:t,buy:s}=n;return t!=null&&t.amount&&e.append("sellAmount",t.amount),s!=null&&s.amount&&e.append("buyAmount",s.amount),e}function se(e,n){const t=n.theme;return t?(V(t)?(e.append("palette",encodeURIComponent(JSON.stringify(t))),e.append("theme",t.baseTheme)):(e.append("palette","null"),e.append("theme",t)),e):(e.append("palette","null"),e)}function re(e,n){return n.targetChainId&&e.append("targetChainId",n.targetChainId.toString()),e}const H="640px",ie="450px",oe=20;function ae(e,n){const{params:t,provider:s,listeners:p}=n;let l=s,_=t;const u=ce(t);e.innerHTML="",e.appendChild(u);const{contentWindow:c}=u;if(!c)throw console.error("Iframe does not contain a window",u),new Error("Iframe does not contain a window!");const r=[];r.push(ue(c,t.appCode)),r.push(...fe(u,t.height,t.maxHeight)),r.push(de());const i=new J(window,p);let o=x(c,null,l);u.addEventListener("load",()=>Q(c,_,l));const w=new K(window,c);return{updateParams:d=>{_=d,Q(c,_,l)},updateListeners:d=>i.updateListeners(d),updateProvider:d=>{l=d,o=x(c,o,d)},destroy:()=>{o.disconnect(),i.stopListeningIframe(),r.forEach(d=>window.removeEventListener("message",d)),w.stopListening(),e.removeChild(u)}}}function x(e,n,t){n&&n.disconnect();const s=n||new $(e);return t&&s.onConnect(t),s}function ce(e){const{width:n=ie,height:t=H}=e,s=document.createElement("iframe");return s.src=te(e),s.width=n,s.height=t,s.style.border="0",s.allow="clipboard-read; clipboard-write",s}function Q(e,n,t){const s=!!t,p=U(n),l=k(n).toString(),{theme:_,...u}=n;R.postMessageToWindow(e,y.UPDATE_PARAMS,{urlParams:{pathname:p,search:l},appParams:u,hasProvider:s})}function ue(e,n){return R.listenToMessageFromWindow(window,O.ACTIVATE,()=>{R.postMessageToWindow(e,y.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})})}function de(){return R.listenToMessageFromWindow(window,O.INTERCEPT_WINDOW_OPEN,({href:e,rel:n,target:t})=>{const s=e.toString();if(!s.startsWith("http")&&s.match(/^[a-zA-Z0-9]+:\/\//)){window.open(s,t,n);return}})}function fe(e,n=H,t){return[R.listenToMessageFromWindow(window,O.UPDATE_HEIGHT,s=>{const p=s.height?s.height+oe:void 0;e.style.height=p?`${t?Math.min(p,t):p}px`:n}),R.listenToMessageFromWindow(window,O.SET_FULL_HEIGHT,({isUpToSmall:s})=>{e.style.height=s?n:`${t||document.body.offsetHeight}px`})]}const pe=Object.values(A);function he(e,n,t){if(L(e)){const s=e[t];return M(s)?s[n]:s}if(M(e)){const s=e[n];return L(s)?s[t]:s}return e}function L(e){return typeof e!="object"?!1:Object.keys(e).every(n=>pe.includes(n))}const le=/^\d+$/;function M(e){return typeof e!="object"?!1:Object.keys(e).every(n=>typeof n=="number"||le.test(n))}return E.TradeType=A,E.WIDGET_PALETTE_COLORS=z,E.WidgetMethodsEmit=O,E.WidgetMethodsListen=y,E.createCowSwapWidget=ae,E.isCowSwapWidgetPalette=V,E.isPerNetworkConfig=M,E.isPerTradeTypeConfig=L,E.resolveFlexibleConfig=he,E.widgetIframeTransport=R,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),E}({});
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var x=(e,n,t)=>n in e?k(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var T=(e,n,t)=>(x(e,typeof n!="symbol"?n+"":n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class b{constructor(n){this.key=n}postMessageToWindow(n,t,s){const d=typeof s=="object"?s:{},l={key:this.key,method:t,...d};n.postMessage(l,"*")}listenToMessageFromWindow(n,t,s){const d=l=>{!H(l.data)||l.data.key!==this.key||l.data.method!==t||s(l.data)};return n.addEventListener("message",d),d}stopListeningToMessageFromWindow(n,t,s){n.removeEventListener("message",s)}stopListeningWindowListener(n,t){n.removeEventListener("message",t)}}function H(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}var C=(e=>(e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(C||{});const y=new b("cowSwapIframeRpcProviderTransport"),G=["connect","disconnect","close","chainChanged","accountsChanged"];class Q{constructor(n){T(this,"ethereumProvider",null);T(this,"requestWaitingForConnection",{});T(this,"processRpcCallFromWindow",({rpcRequest:n})=>{if(!this.ethereumProvider){n.id&&(this.requestWaitingForConnection[n.id]=n);return}this.processRpcRequest(n)});this.iframeWidow=n}disconnect(){this.ethereumProvider=null,y.stopListeningToMessageFromWindow(window,C.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():y.listenToMessageFromWindow(window,C.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),G.forEach(t=>{n.on(t,s=>this.onProviderEvent(t,s))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:t,jsonrpc:s,method:d}=n;if(!this.ethereumProvider||!t)return;(d==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(w=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:w}})).catch(w=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:w}}))}onProviderEvent(n,t){y.postMessageToWindow(this.iframeWidow,C.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){y.postMessageToWindow(this.iframeWidow,C.PROVIDER_RPC_RESPONSE,n)}}var j={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function d(c,r,o){this.fn=c,this.context=r,this.once=o||!1}function l(c,r,o,i,E){if(typeof o!="function")throw new TypeError("The listener must be a function");var f=new d(o,i||c,E),p=t?t+r:r;return c._events[p]?c._events[p].fn?c._events[p]=[c._events[p],f]:c._events[p].push(f):(c._events[p]=f,c._eventsCount++),c}function w(c,r){--c._eventsCount===0?c._events=new s:delete c._events[r]}function u(){this._events=new s,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],o,i;if(this._eventsCount===0)return r;for(i in o=this._events)n.call(o,i)&&r.push(t?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(o)):r},u.prototype.listeners=function(r){var o=t?t+r:r,i=this._events[o];if(!i)return[];if(i.fn)return[i.fn];for(var E=0,f=i.length,p=new Array(f);E<f;E++)p[E]=i[E].fn;return p},u.prototype.listenerCount=function(r){var o=t?t+r:r,i=this._events[o];return i?i.fn?1:i.length:0},u.prototype.emit=function(r,o,i,E,f,p){var _=t?t+r:r;if(!this._events[_])return!1;var a=this._events[_],P=arguments.length,v,h;if(a.fn){switch(a.once&&this.removeListener(r,a.fn,void 0,!0),P){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,o),!0;case 3:return a.fn.call(a.context,o,i),!0;case 4:return a.fn.call(a.context,o,i,E),!0;case 5:return a.fn.call(a.context,o,i,E,f),!0;case 6:return a.fn.call(a.context,o,i,E,f,p),!0}for(h=1,v=new Array(P-1);h<P;h++)v[h-1]=arguments[h];a.fn.apply(a.context,v)}else{var U=a.length,R;for(h=0;h<U;h++)switch(a[h].once&&this.removeListener(r,a[h].fn,void 0,!0),P){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,o);break;case 3:a[h].fn.call(a[h].context,o,i);break;case 4:a[h].fn.call(a[h].context,o,i,E);break;default:if(!v)for(R=1,v=new Array(P-1);R<P;R++)v[R-1]=arguments[R];a[h].fn.apply(a[h].context,v)}}return!0},u.prototype.on=function(r,o,i){return l(this,r,o,i,!1)},u.prototype.once=function(r,o,i){return l(this,r,o,i,!0)},u.prototype.removeListener=function(r,o,i,E){var f=t?t+r:r;if(!this._events[f])return this;if(!o)return w(this,f),this;var p=this._events[f];if(p.fn)p.fn===o&&(!E||p.once)&&(!i||p.context===i)&&w(this,f);else{for(var _=0,a=[],P=p.length;_<P;_++)(p[_].fn!==o||E&&!p[_].once||i&&p[_].context!==i)&&a.push(p[_]);a.length?this._events[f]=a.length===1?a[0]:a:w(this,f)}return this},u.prototype.removeAllListeners=function(r){var o;return r?(o=t?t+r:r,this._events[o]&&w(this,o)):(this._events=new s,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=t,u.EventEmitter=u,e.exports=u})(j);class ${constructor(){T(this,"subscriptions",{})}on(n){const{event:t,handler:s}=n;return this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(s),n}off(n){const{event:t,handler:s}=n;return this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(d=>d!==s)),n}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(t))}}var g=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.SET_FULL_HEIGHT="SET_FULL_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.INTERCEPT_WINDOW_OPEN="INTERCEPT_WINDOW_OPEN",e))(g||{}),O=(e=>(e.UPDATE_PARAMS="UPDATE_PARAMS",e.UPDATE_APP_DATA="UPDATE_APP_DATA",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(O||{}),I=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(I||{});const B=["primary","background","paper","text","danger","warning","alert","info","success"],m=new b("cowSwapWidget");class q{constructor(n,t=[]){T(this,"eventEmitter",new $);T(this,"listeners",[]);T(this,"widgetListener");this.contentWindow=n,this.updateListeners(t),this.widgetListener=m.listenToMessageFromWindow(this.contentWindow,g.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){m.stopListeningWindowListener(this.contentWindow,this.widgetListener)}updateListeners(n){for(const t of this.listeners)this.eventEmitter.off(t);this.listeners=n||[];for(const t of this.listeners)this.eventEmitter.on(t)}}class Y{constructor(n,t){T(this,"forwardSdkMessage");this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=s=>{z(s.data)&&s.origin!==window.location.origin&&(J(s.data)?this.appWindow.parent.postMessage(s.data,"*"):K(s.data)&&this.iframeWidow.postMessage(s.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function z(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function J(e){return"method"in e&&typeof e.method=="string"&&"params"in e&&"env"in e&&typeof e.env=="object"&&e.env!==null&&"sdkVersion"in e.env}function K(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function N(e){return!!(e&&typeof e=="object")}const A="_";function X(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=M(e);return n+"/#"+t+"?"+V(e)}function M(e){const{chainId:n=1,sell:t,buy:s,tradeType:d=I.SWAP}=e,l=[(t==null?void 0:t.asset)||A,(s==null?void 0:s.asset)||A].map(encodeURIComponent).join("/");return`/${n}/widget/${d}/${l}`}function V(e){const n=new URLSearchParams;return ee(Z(n,e),e)}function Z(e,n){const{sell:t,buy:s}=n;return t!=null&&t.amount&&e.append("sellAmount",t.amount),s!=null&&s.amount&&e.append("buyAmount",s.amount),e}function ee(e,n){const t=n.theme;return t?(N(t)?(e.append("palette",encodeURIComponent(JSON.stringify(t))),e.append("theme",t.baseTheme)):(e.append("palette","null"),e.append("theme",t)),e):(e.append("palette","null"),e)}const F="640px",te="450px",ne=20;function se(e,n){const{params:t,provider:s,listeners:d}=n;let l=s,w=t;const u=re(t);e.innerHTML="",e.appendChild(u);const{contentWindow:c}=u;if(!c)throw console.error("Iframe does not contain a window",u),new Error("Iframe does not contain a window!");const r=[];r.push(oe(c,t.appCode)),r.push(...ae(u,t.height,t.maxHeight)),r.push(ie());const o=new q(window,d);let i=L(c,null,l);u.addEventListener("load",()=>D(c,w,l));const E=new Y(window,c);return{updateParams:f=>{w=f,D(c,w,l)},updateListeners:f=>o.updateListeners(f),updateProvider:f=>{l=f,i=L(c,i,f)},destroy:()=>{i.disconnect(),o.stopListeningIframe(),r.forEach(f=>window.removeEventListener("message",f)),E.stopListening(),e.removeChild(u)}}}function L(e,n,t){n&&n.disconnect();const s=n||new Q(e);return t&&s.onConnect(t),s}function re(e){const{width:n=te,height:t=F}=e,s=document.createElement("iframe");return s.src=X(e),s.width=n,s.height=t,s.style.border="0",s.allow="clipboard-read; clipboard-write",s}function D(e,n,t){const s=!!t,d=M(n),l=V(n).toString(),{theme:w,...u}=n;m.postMessageToWindow(e,O.UPDATE_PARAMS,{urlParams:{pathname:d,search:l},appParams:u,hasProvider:s})}function oe(e,n){return m.listenToMessageFromWindow(window,g.ACTIVATE,()=>{m.postMessageToWindow(e,O.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})})}function ie(){return m.listenToMessageFromWindow(window,g.INTERCEPT_WINDOW_OPEN,({href:e,rel:n,target:t})=>{const s=e.toString();if(!s.startsWith("http")&&s.match(/^[a-zA-Z0-9]+:\/\//)){window.open(s,t,n);return}})}function ae(e,n=F,t){return[m.listenToMessageFromWindow(window,g.UPDATE_HEIGHT,s=>{const d=s.height?s.height+ne:void 0;e.style.height=d?`${t?Math.min(d,t):d}px`:n}),m.listenToMessageFromWindow(window,g.SET_FULL_HEIGHT,({isUpToSmall:s})=>{e.style.height=s?n:`${t||document.body.offsetHeight}px`})]}const ce=Object.values(I);function ue(e,n,t){if(W(e)){const s=e[t];return S(s)?s[n]:s}if(S(e)){const s=e[n];return W(s)?s[t]:s}return e}function W(e){return typeof e!="object"?!1:Object.keys(e).every(n=>ce.includes(n))}const fe=/^\d+$/;function S(e){return typeof e!="object"?!1:Object.keys(e).every(n=>typeof n=="number"||fe.test(n))}exports.TradeType=I;exports.WIDGET_PALETTE_COLORS=B;exports.WidgetMethodsEmit=g;exports.WidgetMethodsListen=O;exports.createCowSwapWidget=se;exports.isCowSwapWidgetPalette=N;exports.isPerNetworkConfig=S;exports.isPerTradeTypeConfig=W;exports.resolveFlexibleConfig=ue;exports.widgetIframeTransport=m;
1
+ "use strict";var Q=Object.defineProperty;var G=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _=(e,t,n)=>G(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class b{constructor(t){this.key=t}postMessageToWindow(t,n,s){const p=typeof s=="object"?s:{},l={key:this.key,method:n,...p};t.postMessage(l,"*")}listenToMessageFromWindow(t,n,s){const p=l=>{!j(l.data)||l.data.key!==this.key||l.data.method!==n||s(l.data)};return t.addEventListener("message",p),p}stopListeningToMessageFromWindow(t,n,s){t.removeEventListener("message",s)}stopListeningWindowListener(t,n){t.removeEventListener("message",n)}}function j(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}var m=(e=>(e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e.SEND_PROVIDER_META_INFO="SEND_PROVIDER_META_INFO",e.REQUEST_PROVIDER_META_INFO="REQUEST_PROVIDER_META_INFO",e))(m||{});const g=new b("cowSwapIframeRpcProviderTransport");function q(e){var t,n;if(e.isWalletConnect)return(n=(t=e==null?void 0:e.session)==null?void 0:t.peer)==null?void 0:n.metadata}function $(e,t){var n;return(n=t.find(s=>s.provider===e))==null?void 0:n.info}const B=["connect","disconnect","close","chainChanged","accountsChanged"],V=[];window.addEventListener("eip6963:announceProvider",e=>{const t=e;V.push(t.detail)});class Y{constructor(t){_(this,"ethereumProvider",null);_(this,"requestWaitingForConnection",{});_(this,"processRpcCallFromWindow",({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)});_(this,"processProviderMetaInfoRequest",()=>{if(!this.ethereumProvider)return;const t=$(this.ethereumProvider,V),n=q(this.ethereumProvider);g.postMessageToWindow(this.iframeWidow,m.SEND_PROVIDER_META_INFO,{providerEip6963Info:t,providerWcMetadata:n})});this.iframeWidow=t}disconnect(){this.ethereumProvider=null,g.stopListeningToMessageFromWindow(window,m.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),g.stopListeningToMessageFromWindow(window,m.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest)}onConnect(t){this.ethereumProvider?this.disconnect():g.listenToMessageFromWindow(window,m.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=t,this.processPendingRequests(),B.forEach(n=>{t.on(n,s=>this.onProviderEvent(n,s))}),g.listenToMessageFromWindow(window,m.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest)}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(t=>{this.processRpcRequest(this.requestWaitingForConnection[t])}),this.requestWaitingForConnection={}}processRpcRequest(t){const{id:n,jsonrpc:s,method:p}=t;if(!this.ethereumProvider||!n)return;(p==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...t,id:n})).then(w=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:n,result:w}})).catch(w=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:n,error:w}}))}onProviderEvent(t,n){g.postMessageToWindow(this.iframeWidow,m.PROVIDER_ON_EVENT,{event:t,params:n})}forwardRpcResponseToIframe(t){g.postMessageToWindow(this.iframeWidow,m.PROVIDER_RPC_RESPONSE,t)}}var S={exports:{}},D;function z(){return D||(D=1,function(e){var t=Object.prototype.hasOwnProperty,n="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(n=!1));function p(c,r,o){this.fn=c,this.context=r,this.once=o||!1}function l(c,r,o,i,E){if(typeof o!="function")throw new TypeError("The listener must be a function");var d=new p(o,i||c,E),f=n?n+r:r;return c._events[f]?c._events[f].fn?c._events[f]=[c._events[f],d]:c._events[f].push(d):(c._events[f]=d,c._eventsCount++),c}function w(c,r){--c._eventsCount===0?c._events=new s:delete c._events[r]}function u(){this._events=new s,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],o,i;if(this._eventsCount===0)return r;for(i in o=this._events)t.call(o,i)&&r.push(n?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(o)):r},u.prototype.listeners=function(r){var o=n?n+r:r,i=this._events[o];if(!i)return[];if(i.fn)return[i.fn];for(var E=0,d=i.length,f=new Array(d);E<d;E++)f[E]=i[E].fn;return f},u.prototype.listenerCount=function(r){var o=n?n+r:r,i=this._events[o];return i?i.fn?1:i.length:0},u.prototype.emit=function(r,o,i,E,d,f){var T=n?n+r:r;if(!this._events[T])return!1;var a=this._events[T],R=arguments.length,v,h;if(a.fn){switch(a.once&&this.removeListener(r,a.fn,void 0,!0),R){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,o),!0;case 3:return a.fn.call(a.context,o,i),!0;case 4:return a.fn.call(a.context,o,i,E),!0;case 5:return a.fn.call(a.context,o,i,E,d),!0;case 6:return a.fn.call(a.context,o,i,E,d,f),!0}for(h=1,v=new Array(R-1);h<R;h++)v[h-1]=arguments[h];a.fn.apply(a.context,v)}else{var H=a.length,O;for(h=0;h<H;h++)switch(a[h].once&&this.removeListener(r,a[h].fn,void 0,!0),R){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,o);break;case 3:a[h].fn.call(a[h].context,o,i);break;case 4:a[h].fn.call(a[h].context,o,i,E);break;default:if(!v)for(O=1,v=new Array(R-1);O<R;O++)v[O-1]=arguments[O];a[h].fn.apply(a[h].context,v)}}return!0},u.prototype.on=function(r,o,i){return l(this,r,o,i,!1)},u.prototype.once=function(r,o,i){return l(this,r,o,i,!0)},u.prototype.removeListener=function(r,o,i,E){var d=n?n+r:r;if(!this._events[d])return this;if(!o)return w(this,d),this;var f=this._events[d];if(f.fn)f.fn===o&&(!E||f.once)&&(!i||f.context===i)&&w(this,d);else{for(var T=0,a=[],R=f.length;T<R;T++)(f[T].fn!==o||E&&!f[T].once||i&&f[T].context!==i)&&a.push(f[T]);a.length?this._events[d]=a.length===1?a[0]:a:w(this,d)}return this},u.prototype.removeAllListeners=function(r){var o;return r?(o=n?n+r:r,this._events[o]&&w(this,o)):(this._events=new s,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=n,u.EventEmitter=u,e.exports=u}(S)),S.exports}z();class J{constructor(){_(this,"subscriptions",{})}on(t){const{event:n,handler:s}=t;return this.subscriptions[n]||(this.subscriptions[n]=[]),this.subscriptions[n].push(s),t}off(t){const{event:n,handler:s}=t;return this.subscriptions[n]&&(this.subscriptions[n]=this.subscriptions[n].filter(p=>p!==s)),t}emit(t,n){this.subscriptions[t]&&this.subscriptions[t].forEach(s=>s(n))}}var I=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.SET_FULL_HEIGHT="SET_FULL_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e.INTERCEPT_WINDOW_OPEN="INTERCEPT_WINDOW_OPEN",e))(I||{}),C=(e=>(e.UPDATE_PARAMS="UPDATE_PARAMS",e.UPDATE_APP_DATA="UPDATE_APP_DATA",e.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",e.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",e))(C||{}),W=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(W||{});const K=["primary","background","paper","text","danger","warning","alert","info","success"],P=new b("cowSwapWidget");class X{constructor(t,n=[]){_(this,"eventEmitter",new J);_(this,"listeners",[]);_(this,"widgetListener");this.contentWindow=t,this.updateListeners(n),this.widgetListener=P.listenToMessageFromWindow(this.contentWindow,I.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){P.stopListeningWindowListener(this.contentWindow,this.widgetListener)}updateListeners(t){for(const n of this.listeners)this.eventEmitter.off(n);this.listeners=t||[];for(const n of this.listeners)this.eventEmitter.on(n)}}class Z{constructor(t,n){_(this,"forwardSdkMessage");this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=s=>{ee(s.data)&&s.origin!==window.location.origin&&(te(s.data)?this.appWindow.parent.postMessage(s.data,"*"):ne(s.data)&&this.iframeWidow.postMessage(s.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function ee(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function te(e){return"method"in e&&typeof e.method=="string"&&"params"in e&&"env"in e&&typeof e.env=="object"&&e.env!==null&&"sdkVersion"in e.env}function ne(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function F(e){return!!(e&&typeof e=="object")}const L="_";function se(e){const t=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",n=U(e);return t+"/#"+n+"?"+x(e)}function U(e){const{chainId:t=1,sell:n,buy:s,tradeType:p=W.SWAP}=e,l=[(n==null?void 0:n.asset)||L,(s==null?void 0:s.asset)||L].map(encodeURIComponent).join("/");return`/${t}/widget/${p}/${l}`}function x(e){const t=new URLSearchParams;return ie(oe(re(t,e),e),e)}function re(e,t){const{sell:n,buy:s}=t;return n!=null&&n.amount&&e.append("sellAmount",n.amount),s!=null&&s.amount&&e.append("buyAmount",s.amount),e}function oe(e,t){const n=t.theme;return n?(F(n)?(e.append("palette",encodeURIComponent(JSON.stringify(n))),e.append("theme",n.baseTheme)):(e.append("palette","null"),e.append("theme",n)),e):(e.append("palette","null"),e)}function ie(e,t){return t.targetChainId&&e.append("targetChainId",t.targetChainId.toString()),e}const k="640px",ae="450px",ce=20;function ue(e,t){const{params:n,provider:s,listeners:p}=t;let l=s,w=n;const u=de(n);e.innerHTML="",e.appendChild(u);const{contentWindow:c}=u;if(!c)throw console.error("Iframe does not contain a window",u),new Error("Iframe does not contain a window!");const r=[];r.push(fe(c,n.appCode)),r.push(...he(u,n.height,n.maxHeight)),r.push(pe());const o=new X(window,p);let i=M(c,null,l);u.addEventListener("load",()=>N(c,w,l));const E=new Z(window,c);return{updateParams:d=>{w=d,N(c,w,l)},updateListeners:d=>o.updateListeners(d),updateProvider:d=>{l=d,i=M(c,i,d)},destroy:()=>{i.disconnect(),o.stopListeningIframe(),r.forEach(d=>window.removeEventListener("message",d)),E.stopListening(),e.removeChild(u)}}}function M(e,t,n){t&&t.disconnect();const s=t||new Y(e);return n&&s.onConnect(n),s}function de(e){const{width:t=ae,height:n=k}=e,s=document.createElement("iframe");return s.src=se(e),s.width=t,s.height=n,s.style.border="0",s.allow="clipboard-read; clipboard-write",s}function N(e,t,n){const s=!!n,p=U(t),l=x(t).toString(),{theme:w,...u}=t;P.postMessageToWindow(e,C.UPDATE_PARAMS,{urlParams:{pathname:p,search:l},appParams:u,hasProvider:s})}function fe(e,t){return P.listenToMessageFromWindow(window,I.ACTIVATE,()=>{P.postMessageToWindow(e,C.UPDATE_APP_DATA,{metaData:t?{appCode:t}:void 0})})}function pe(){return P.listenToMessageFromWindow(window,I.INTERCEPT_WINDOW_OPEN,({href:e,rel:t,target:n})=>{const s=e.toString();if(!s.startsWith("http")&&s.match(/^[a-zA-Z0-9]+:\/\//)){window.open(s,n,t);return}})}function he(e,t=k,n){return[P.listenToMessageFromWindow(window,I.UPDATE_HEIGHT,s=>{const p=s.height?s.height+ce:void 0;e.style.height=p?`${n?Math.min(p,n):p}px`:t}),P.listenToMessageFromWindow(window,I.SET_FULL_HEIGHT,({isUpToSmall:s})=>{e.style.height=s?t:`${n||document.body.offsetHeight}px`})]}const le=Object.values(W);function Ee(e,t,n){if(y(e)){const s=e[n];return A(s)?s[t]:s}if(A(e)){const s=e[t];return y(s)?s[n]:s}return e}function y(e){return typeof e!="object"?!1:Object.keys(e).every(t=>le.includes(t))}const we=/^\d+$/;function A(e){return typeof e!="object"?!1:Object.keys(e).every(t=>typeof t=="number"||we.test(t))}exports.TradeType=W;exports.WIDGET_PALETTE_COLORS=K;exports.WidgetMethodsEmit=I;exports.WidgetMethodsListen=C;exports.createCowSwapWidget=ue;exports.isCowSwapWidgetPalette=F;exports.isPerNetworkConfig=A;exports.isPerTradeTypeConfig=y;exports.resolveFlexibleConfig=Ee;exports.widgetIframeTransport=P;
package/index.mjs CHANGED
@@ -1,257 +1,300 @@
1
- var F = Object.defineProperty;
2
- var k = (e, n, t) => n in e ? F(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var m = (e, n, t) => (k(e, typeof n != "symbol" ? n + "" : n, t), t);
1
+ var H = Object.defineProperty;
2
+ var Q = (e, t, n) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var w = (e, t, n) => Q(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  class b {
5
- constructor(n) {
6
- this.key = n;
5
+ constructor(t) {
6
+ this.key = t;
7
7
  }
8
- postMessageToWindow(n, t, s) {
9
- const d = typeof s == "object" ? s : {}, l = {
8
+ // TODO: Add proper return type annotation
9
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
10
+ postMessageToWindow(t, n, s) {
11
+ const p = typeof s == "object" ? s : {}, l = {
10
12
  key: this.key,
11
- method: t,
12
- ...d
13
+ method: n,
14
+ ...p
13
15
  };
14
- n.postMessage(
16
+ t.postMessage(
15
17
  l,
16
18
  "*"
17
19
  // TODO: Change to CoW specific origin in production. https://github.com/cowprotocol/cowswap/issues/3828
18
20
  );
19
21
  }
20
- listenToMessageFromWindow(n, t, s) {
21
- const d = (l) => {
22
- !x(l.data) || l.data.key !== this.key || l.data.method !== t || s(l.data);
22
+ listenToMessageFromWindow(t, n, s) {
23
+ const p = (l) => {
24
+ !G(l.data) || l.data.key !== this.key || l.data.method !== n || s(l.data);
23
25
  };
24
- return n.addEventListener("message", d), d;
26
+ return t.addEventListener("message", p), p;
25
27
  }
26
- stopListeningToMessageFromWindow(n, t, s) {
27
- n.removeEventListener("message", s);
28
+ // TODO: Add proper return type annotation
29
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
30
+ stopListeningToMessageFromWindow(t, n, s) {
31
+ t.removeEventListener("message", s);
28
32
  }
29
- stopListeningWindowListener(n, t) {
30
- n.removeEventListener("message", t);
33
+ // TODO: Add proper return type annotation
34
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
35
+ stopListeningWindowListener(t, n) {
36
+ t.removeEventListener("message", n);
31
37
  }
32
38
  }
33
- function x(e) {
39
+ function G(e) {
34
40
  return typeof e == "object" && e !== null && "key" in e && "method" in e && typeof e.key == "string" && typeof e.method == "string";
35
41
  }
36
- var I = /* @__PURE__ */ ((e) => (e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", e.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", e))(I || {});
37
- const O = new b(
42
+ var P = /* @__PURE__ */ ((e) => (e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", e.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", e.SEND_PROVIDER_META_INFO = "SEND_PROVIDER_META_INFO", e.REQUEST_PROVIDER_META_INFO = "REQUEST_PROVIDER_META_INFO", e))(P || {});
43
+ const g = new b(
38
44
  "cowSwapIframeRpcProviderTransport"
39
- ), H = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
40
- class G {
45
+ );
46
+ function q(e) {
47
+ var t, n;
48
+ if (e.isWalletConnect)
49
+ return (n = (t = e == null ? void 0 : e.session) == null ? void 0 : t.peer) == null ? void 0 : n.metadata;
50
+ }
51
+ function j(e, t) {
52
+ var n;
53
+ return (n = t.find((s) => s.provider === e)) == null ? void 0 : n.info;
54
+ }
55
+ const $ = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"], V = [];
56
+ window.addEventListener("eip6963:announceProvider", (e) => {
57
+ const t = e;
58
+ V.push(t.detail);
59
+ });
60
+ class B {
41
61
  /**
42
62
  * Creates an instance of IframeRpcProviderBridge.
43
63
  * @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
44
64
  * Also it will receive some special RPC events coming from the wallet, like connect/chainChanged,accountChanged
45
65
  */
46
- constructor(n) {
66
+ constructor(t) {
47
67
  /**
48
68
  * The Ethereum provider instance.
49
69
  * When is null the JSON-RPC bridge is disconnected from the Ethereum provider.
50
70
  * */
51
- m(this, "ethereumProvider", null);
71
+ w(this, "ethereumProvider", null);
52
72
  /** Stored JSON-RPC requests, to queue them when disconnected. */
53
- m(this, "requestWaitingForConnection", {});
54
- m(this, "processRpcCallFromWindow", ({ rpcRequest: n }) => {
73
+ w(this, "requestWaitingForConnection", {});
74
+ w(this, "processRpcCallFromWindow", ({ rpcRequest: t }) => {
55
75
  if (!this.ethereumProvider) {
56
- n.id && (this.requestWaitingForConnection[n.id] = n);
76
+ t.id && (this.requestWaitingForConnection[t.id] = t);
57
77
  return;
58
78
  }
59
- this.processRpcRequest(n);
79
+ this.processRpcRequest(t);
80
+ });
81
+ w(this, "processProviderMetaInfoRequest", () => {
82
+ if (!this.ethereumProvider) return;
83
+ const t = j(this.ethereumProvider, V), n = q(this.ethereumProvider);
84
+ g.postMessageToWindow(this.iframeWidow, P.SEND_PROVIDER_META_INFO, {
85
+ providerEip6963Info: t,
86
+ providerWcMetadata: n
87
+ });
60
88
  });
61
- this.iframeWidow = n;
89
+ this.iframeWidow = t;
62
90
  }
63
91
  /**
64
92
  * Disconnects the JSON-RPC bridge from the Ethereum provider.
65
93
  */
94
+ // TODO: Add proper return type annotation
95
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
66
96
  disconnect() {
67
- this.ethereumProvider = null, O.stopListeningToMessageFromWindow(
97
+ this.ethereumProvider = null, g.stopListeningToMessageFromWindow(
68
98
  window,
69
- I.PROVIDER_RPC_REQUEST,
99
+ P.PROVIDER_RPC_REQUEST,
70
100
  this.processRpcCallFromWindow
101
+ ), g.stopListeningToMessageFromWindow(
102
+ window,
103
+ P.REQUEST_PROVIDER_META_INFO,
104
+ this.processProviderMetaInfoRequest
71
105
  );
72
106
  }
73
107
  /**
74
108
  * Handles the 'connect' event and sets up event listeners for Ethereum provider events.
75
109
  * @param newProvider - The Ethereum provider to connect.
76
110
  */
77
- onConnect(n) {
78
- this.ethereumProvider ? this.disconnect() : O.listenToMessageFromWindow(
111
+ // TODO: Add proper return type annotation
112
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
113
+ onConnect(t) {
114
+ this.ethereumProvider ? this.disconnect() : g.listenToMessageFromWindow(
79
115
  window,
80
- I.PROVIDER_RPC_REQUEST,
116
+ P.PROVIDER_RPC_REQUEST,
81
117
  this.processRpcCallFromWindow
82
- ), this.ethereumProvider = n, this.processPendingRequests(), H.forEach((t) => {
83
- n.on(t, (s) => this.onProviderEvent(t, s));
84
- });
118
+ ), this.ethereumProvider = t, this.processPendingRequests(), $.forEach((n) => {
119
+ t.on(n, (s) => this.onProviderEvent(n, s));
120
+ }), g.listenToMessageFromWindow(
121
+ window,
122
+ P.REQUEST_PROVIDER_META_INFO,
123
+ this.processProviderMetaInfoRequest
124
+ );
85
125
  }
126
+ // TODO: Add proper return type annotation
127
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
86
128
  processPendingRequests() {
87
- Object.keys(this.requestWaitingForConnection).forEach((n) => {
88
- this.processRpcRequest(this.requestWaitingForConnection[n]);
129
+ Object.keys(this.requestWaitingForConnection).forEach((t) => {
130
+ this.processRpcRequest(this.requestWaitingForConnection[t]);
89
131
  }), this.requestWaitingForConnection = {};
90
132
  }
91
133
  /**
92
134
  * Processes a JSON-RPC request and sends appropriate response or error via the content window.
93
135
  * @param request - The JSON-RPC request to be processed.
94
136
  */
95
- processRpcRequest(n) {
96
- const { id: t, jsonrpc: s, method: d } = n;
97
- if (!this.ethereumProvider || !t)
137
+ // TODO: Add proper return type annotation
138
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
139
+ processRpcRequest(t) {
140
+ const { id: n, jsonrpc: s, method: p } = t;
141
+ if (!this.ethereumProvider || !n)
98
142
  return;
99
- (d === "enable" ? this.ethereumProvider.enable() : this.ethereumProvider.request({ ...n, id: t })).then(
100
- (w) => this.forwardRpcResponseToIframe({
101
- rpcResponse: { jsonrpc: s, id: t, result: w }
143
+ (p === "enable" ? this.ethereumProvider.enable() : this.ethereumProvider.request({ ...t, id: n })).then(
144
+ (_) => this.forwardRpcResponseToIframe({
145
+ rpcResponse: { jsonrpc: s, id: n, result: _ }
102
146
  })
103
147
  ).catch(
104
- (w) => this.forwardRpcResponseToIframe({
105
- rpcResponse: { jsonrpc: s, id: t, error: w }
148
+ (_) => this.forwardRpcResponseToIframe({
149
+ rpcResponse: { jsonrpc: s, id: n, error: _ }
106
150
  })
107
151
  );
108
152
  }
109
- onProviderEvent(n, t) {
110
- O.postMessageToWindow(this.iframeWidow, I.PROVIDER_ON_EVENT, {
111
- event: n,
112
- params: t
153
+ onProviderEvent(t, n) {
154
+ g.postMessageToWindow(this.iframeWidow, P.PROVIDER_ON_EVENT, {
155
+ event: t,
156
+ params: n
113
157
  });
114
158
  }
115
159
  /**
116
160
  * Forward a JSON-RPC message to the content window.
117
161
  */
118
- forwardRpcResponseToIframe(n) {
119
- O.postMessageToWindow(
162
+ // TODO: Add proper return type annotation
163
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
164
+ forwardRpcResponseToIframe(t) {
165
+ g.postMessageToWindow(
120
166
  this.iframeWidow,
121
- I.PROVIDER_RPC_RESPONSE,
122
- n
167
+ P.PROVIDER_RPC_RESPONSE,
168
+ t
123
169
  );
124
170
  }
125
171
  }
126
- var Q = { exports: {} };
127
- (function(e) {
128
- var n = Object.prototype.hasOwnProperty, t = "~";
129
- function s() {
130
- }
131
- Object.create && (s.prototype = /* @__PURE__ */ Object.create(null), new s().__proto__ || (t = !1));
132
- function d(c, r, o) {
133
- this.fn = c, this.context = r, this.once = o || !1;
134
- }
135
- function l(c, r, o, i, E) {
136
- if (typeof o != "function")
137
- throw new TypeError("The listener must be a function");
138
- var f = new d(o, i || c, E), p = t ? t + r : r;
139
- return c._events[p] ? c._events[p].fn ? c._events[p] = [c._events[p], f] : c._events[p].push(f) : (c._events[p] = f, c._eventsCount++), c;
140
- }
141
- function w(c, r) {
142
- --c._eventsCount === 0 ? c._events = new s() : delete c._events[r];
143
- }
144
- function u() {
145
- this._events = new s(), this._eventsCount = 0;
146
- }
147
- u.prototype.eventNames = function() {
148
- var r = [], o, i;
149
- if (this._eventsCount === 0)
150
- return r;
151
- for (i in o = this._events)
152
- n.call(o, i) && r.push(t ? i.slice(1) : i);
153
- return Object.getOwnPropertySymbols ? r.concat(Object.getOwnPropertySymbols(o)) : r;
154
- }, u.prototype.listeners = function(r) {
155
- var o = t ? t + r : r, i = this._events[o];
156
- if (!i)
157
- return [];
158
- if (i.fn)
159
- return [i.fn];
160
- for (var E = 0, f = i.length, p = new Array(f); E < f; E++)
161
- p[E] = i[E].fn;
162
- return p;
163
- }, u.prototype.listenerCount = function(r) {
164
- var o = t ? t + r : r, i = this._events[o];
165
- return i ? i.fn ? 1 : i.length : 0;
166
- }, u.prototype.emit = function(r, o, i, E, f, p) {
167
- var _ = t ? t + r : r;
168
- if (!this._events[_])
169
- return !1;
170
- var a = this._events[_], T = arguments.length, P, h;
171
- if (a.fn) {
172
- switch (a.once && this.removeListener(r, a.fn, void 0, !0), T) {
173
- case 1:
174
- return a.fn.call(a.context), !0;
175
- case 2:
176
- return a.fn.call(a.context, o), !0;
177
- case 3:
178
- return a.fn.call(a.context, o, i), !0;
179
- case 4:
180
- return a.fn.call(a.context, o, i, E), !0;
181
- case 5:
182
- return a.fn.call(a.context, o, i, E, f), !0;
183
- case 6:
184
- return a.fn.call(a.context, o, i, E, f, p), !0;
185
- }
186
- for (h = 1, P = new Array(T - 1); h < T; h++)
187
- P[h - 1] = arguments[h];
188
- a.fn.apply(a.context, P);
189
- } else {
190
- var U = a.length, g;
191
- for (h = 0; h < U; h++)
192
- switch (a[h].once && this.removeListener(r, a[h].fn, void 0, !0), T) {
172
+ var C = { exports: {} }, S;
173
+ function Y() {
174
+ return S || (S = 1, function(e) {
175
+ var t = Object.prototype.hasOwnProperty, n = "~";
176
+ function s() {
177
+ }
178
+ Object.create && (s.prototype = /* @__PURE__ */ Object.create(null), new s().__proto__ || (n = !1));
179
+ function p(c, r, o) {
180
+ this.fn = c, this.context = r, this.once = o || !1;
181
+ }
182
+ function l(c, r, o, i, E) {
183
+ if (typeof o != "function")
184
+ throw new TypeError("The listener must be a function");
185
+ var d = new p(o, i || c, E), f = n ? n + r : r;
186
+ return c._events[f] ? c._events[f].fn ? c._events[f] = [c._events[f], d] : c._events[f].push(d) : (c._events[f] = d, c._eventsCount++), c;
187
+ }
188
+ function _(c, r) {
189
+ --c._eventsCount === 0 ? c._events = new s() : delete c._events[r];
190
+ }
191
+ function u() {
192
+ this._events = new s(), this._eventsCount = 0;
193
+ }
194
+ u.prototype.eventNames = function() {
195
+ var r = [], o, i;
196
+ if (this._eventsCount === 0) return r;
197
+ for (i in o = this._events)
198
+ t.call(o, i) && r.push(n ? i.slice(1) : i);
199
+ return Object.getOwnPropertySymbols ? r.concat(Object.getOwnPropertySymbols(o)) : r;
200
+ }, u.prototype.listeners = function(r) {
201
+ var o = n ? n + r : r, i = this._events[o];
202
+ if (!i) return [];
203
+ if (i.fn) return [i.fn];
204
+ for (var E = 0, d = i.length, f = new Array(d); E < d; E++)
205
+ f[E] = i[E].fn;
206
+ return f;
207
+ }, u.prototype.listenerCount = function(r) {
208
+ var o = n ? n + r : r, i = this._events[o];
209
+ return i ? i.fn ? 1 : i.length : 0;
210
+ }, u.prototype.emit = function(r, o, i, E, d, f) {
211
+ var T = n ? n + r : r;
212
+ if (!this._events[T]) return !1;
213
+ var a = this._events[T], R = arguments.length, v, h;
214
+ if (a.fn) {
215
+ switch (a.once && this.removeListener(r, a.fn, void 0, !0), R) {
193
216
  case 1:
194
- a[h].fn.call(a[h].context);
195
- break;
217
+ return a.fn.call(a.context), !0;
196
218
  case 2:
197
- a[h].fn.call(a[h].context, o);
198
- break;
219
+ return a.fn.call(a.context, o), !0;
199
220
  case 3:
200
- a[h].fn.call(a[h].context, o, i);
201
- break;
221
+ return a.fn.call(a.context, o, i), !0;
202
222
  case 4:
203
- a[h].fn.call(a[h].context, o, i, E);
204
- break;
205
- default:
206
- if (!P)
207
- for (g = 1, P = new Array(T - 1); g < T; g++)
208
- P[g - 1] = arguments[g];
209
- a[h].fn.apply(a[h].context, P);
223
+ return a.fn.call(a.context, o, i, E), !0;
224
+ case 5:
225
+ return a.fn.call(a.context, o, i, E, d), !0;
226
+ case 6:
227
+ return a.fn.call(a.context, o, i, E, d, f), !0;
210
228
  }
211
- }
212
- return !0;
213
- }, u.prototype.on = function(r, o, i) {
214
- return l(this, r, o, i, !1);
215
- }, u.prototype.once = function(r, o, i) {
216
- return l(this, r, o, i, !0);
217
- }, u.prototype.removeListener = function(r, o, i, E) {
218
- var f = t ? t + r : r;
219
- if (!this._events[f])
229
+ for (h = 1, v = new Array(R - 1); h < R; h++)
230
+ v[h - 1] = arguments[h];
231
+ a.fn.apply(a.context, v);
232
+ } else {
233
+ var k = a.length, O;
234
+ for (h = 0; h < k; h++)
235
+ switch (a[h].once && this.removeListener(r, a[h].fn, void 0, !0), R) {
236
+ case 1:
237
+ a[h].fn.call(a[h].context);
238
+ break;
239
+ case 2:
240
+ a[h].fn.call(a[h].context, o);
241
+ break;
242
+ case 3:
243
+ a[h].fn.call(a[h].context, o, i);
244
+ break;
245
+ case 4:
246
+ a[h].fn.call(a[h].context, o, i, E);
247
+ break;
248
+ default:
249
+ if (!v) for (O = 1, v = new Array(R - 1); O < R; O++)
250
+ v[O - 1] = arguments[O];
251
+ a[h].fn.apply(a[h].context, v);
252
+ }
253
+ }
254
+ return !0;
255
+ }, u.prototype.on = function(r, o, i) {
256
+ return l(this, r, o, i, !1);
257
+ }, u.prototype.once = function(r, o, i) {
258
+ return l(this, r, o, i, !0);
259
+ }, u.prototype.removeListener = function(r, o, i, E) {
260
+ var d = n ? n + r : r;
261
+ if (!this._events[d]) return this;
262
+ if (!o)
263
+ return _(this, d), this;
264
+ var f = this._events[d];
265
+ if (f.fn)
266
+ f.fn === o && (!E || f.once) && (!i || f.context === i) && _(this, d);
267
+ else {
268
+ for (var T = 0, a = [], R = f.length; T < R; T++)
269
+ (f[T].fn !== o || E && !f[T].once || i && f[T].context !== i) && a.push(f[T]);
270
+ a.length ? this._events[d] = a.length === 1 ? a[0] : a : _(this, d);
271
+ }
220
272
  return this;
221
- if (!o)
222
- return w(this, f), this;
223
- var p = this._events[f];
224
- if (p.fn)
225
- p.fn === o && (!E || p.once) && (!i || p.context === i) && w(this, f);
226
- else {
227
- for (var _ = 0, a = [], T = p.length; _ < T; _++)
228
- (p[_].fn !== o || E && !p[_].once || i && p[_].context !== i) && a.push(p[_]);
229
- a.length ? this._events[f] = a.length === 1 ? a[0] : a : w(this, f);
230
- }
231
- return this;
232
- }, u.prototype.removeAllListeners = function(r) {
233
- var o;
234
- return r ? (o = t ? t + r : r, this._events[o] && w(this, o)) : (this._events = new s(), this._eventsCount = 0), this;
235
- }, u.prototype.off = u.prototype.removeListener, u.prototype.addListener = u.prototype.on, u.prefixed = t, u.EventEmitter = u, e.exports = u;
236
- })(Q);
237
- class j {
273
+ }, u.prototype.removeAllListeners = function(r) {
274
+ var o;
275
+ return r ? (o = n ? n + r : r, this._events[o] && _(this, o)) : (this._events = new s(), this._eventsCount = 0), this;
276
+ }, u.prototype.off = u.prototype.removeListener, u.prototype.addListener = u.prototype.on, u.prefixed = n, u.EventEmitter = u, e.exports = u;
277
+ }(C)), C.exports;
278
+ }
279
+ Y();
280
+ class z {
238
281
  constructor() {
239
- m(this, "subscriptions", {});
282
+ w(this, "subscriptions", {});
240
283
  }
241
- on(n) {
242
- const { event: t, handler: s } = n;
243
- return this.subscriptions[t] || (this.subscriptions[t] = []), this.subscriptions[t].push(s), n;
284
+ on(t) {
285
+ const { event: n, handler: s } = t;
286
+ return this.subscriptions[n] || (this.subscriptions[n] = []), this.subscriptions[n].push(s), t;
244
287
  }
245
- off(n) {
246
- const { event: t, handler: s } = n;
247
- return this.subscriptions[t] && (this.subscriptions[t] = this.subscriptions[t].filter((d) => d !== s)), n;
288
+ off(t) {
289
+ const { event: n, handler: s } = t;
290
+ return this.subscriptions[n] && (this.subscriptions[n] = this.subscriptions[n].filter((p) => p !== s)), t;
248
291
  }
249
- emit(n, t) {
250
- this.subscriptions[n] && this.subscriptions[n].forEach((s) => s(t));
292
+ emit(t, n) {
293
+ this.subscriptions[t] && this.subscriptions[t].forEach((s) => s(n));
251
294
  }
252
295
  }
253
- var R = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.UPDATE_HEIGHT = "UPDATE_HEIGHT", e.SET_FULL_HEIGHT = "SET_FULL_HEIGHT", e.EMIT_COW_EVENT = "EMIT_COW_EVENT", e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e.INTERCEPT_WINDOW_OPEN = "INTERCEPT_WINDOW_OPEN", e))(R || {}), y = /* @__PURE__ */ ((e) => (e.UPDATE_PARAMS = "UPDATE_PARAMS", e.UPDATE_APP_DATA = "UPDATE_APP_DATA", e.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", e.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", e))(y || {}), C = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e.YIELD = "yield", e))(C || {});
254
- const ue = [
296
+ var I = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.UPDATE_HEIGHT = "UPDATE_HEIGHT", e.SET_FULL_HEIGHT = "SET_FULL_HEIGHT", e.EMIT_COW_EVENT = "EMIT_COW_EVENT", e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e.INTERCEPT_WINDOW_OPEN = "INTERCEPT_WINDOW_OPEN", e))(I || {}), A = /* @__PURE__ */ ((e) => (e.UPDATE_PARAMS = "UPDATE_PARAMS", e.UPDATE_APP_DATA = "UPDATE_APP_DATA", e.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", e.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", e))(A || {}), W = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e.YIELD = "yield", e))(W || {});
297
+ const Ee = [
255
298
  "primary",
256
299
  "background",
257
300
  "paper",
@@ -261,183 +304,192 @@ const ue = [
261
304
  "alert",
262
305
  "info",
263
306
  "success"
264
- ], v = new b("cowSwapWidget");
265
- class $ {
266
- constructor(n, t = []) {
267
- m(this, "eventEmitter", new j());
268
- m(this, "listeners", []);
269
- m(this, "widgetListener");
270
- this.contentWindow = n, this.updateListeners(t), this.widgetListener = v.listenToMessageFromWindow(
307
+ ], m = new b("cowSwapWidget");
308
+ class J {
309
+ constructor(t, n = []) {
310
+ w(this, "eventEmitter", new z());
311
+ w(this, "listeners", []);
312
+ w(this, "widgetListener");
313
+ this.contentWindow = t, this.updateListeners(n), this.widgetListener = m.listenToMessageFromWindow(
271
314
  this.contentWindow,
272
- R.EMIT_COW_EVENT,
315
+ I.EMIT_COW_EVENT,
273
316
  (s) => this.eventEmitter.emit(s.event, s.payload)
274
317
  );
275
318
  }
319
+ // TODO: Add proper return type annotation
320
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
276
321
  stopListeningIframe() {
277
- v.stopListeningWindowListener(this.contentWindow, this.widgetListener);
322
+ m.stopListeningWindowListener(this.contentWindow, this.widgetListener);
278
323
  }
279
- updateListeners(n) {
280
- for (const t of this.listeners)
281
- this.eventEmitter.off(t);
282
- this.listeners = n || [];
283
- for (const t of this.listeners)
284
- this.eventEmitter.on(t);
324
+ updateListeners(t) {
325
+ for (const n of this.listeners)
326
+ this.eventEmitter.off(n);
327
+ this.listeners = t || [];
328
+ for (const n of this.listeners)
329
+ this.eventEmitter.on(n);
285
330
  }
286
331
  }
287
- class B {
288
- constructor(n, t) {
289
- m(this, "forwardSdkMessage");
290
- this.appWindow = n, this.iframeWidow = t, this.forwardSdkMessage = (s) => {
291
- q(s.data) && s.origin !== window.location.origin && (Y(s.data) ? this.appWindow.parent.postMessage(s.data, "*") : z(s.data) && this.iframeWidow.postMessage(s.data, "*"));
332
+ class K {
333
+ constructor(t, n) {
334
+ w(this, "forwardSdkMessage");
335
+ this.appWindow = t, this.iframeWidow = n, this.forwardSdkMessage = (s) => {
336
+ X(s.data) && s.origin !== window.location.origin && (Z(s.data) ? this.appWindow.parent.postMessage(s.data, "*") : ee(s.data) && this.iframeWidow.postMessage(s.data, "*"));
292
337
  }, this.startListening();
293
338
  }
339
+ // TODO: Add proper return type annotation
340
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
294
341
  startListening() {
295
342
  this.appWindow.addEventListener("message", this.forwardSdkMessage);
296
343
  }
344
+ // TODO: Add proper return type annotation
345
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
297
346
  stopListening() {
298
347
  this.appWindow.removeEventListener("message", this.forwardSdkMessage);
299
348
  }
300
349
  }
301
- function q(e) {
350
+ function X(e) {
302
351
  return typeof e == "object" && e !== null && "id" in e && typeof e.id == "string";
303
352
  }
304
- function Y(e) {
353
+ function Z(e) {
305
354
  return "method" in e && typeof e.method == "string" && "params" in e && "env" in e && typeof e.env == "object" && e.env !== null && "sdkVersion" in e.env;
306
355
  }
307
- function z(e) {
356
+ function ee(e) {
308
357
  return "success" in e && typeof e.success == "boolean" && "version" in e && typeof e.version == "string";
309
358
  }
310
- function J(e) {
359
+ function te(e) {
311
360
  return !!(e && typeof e == "object");
312
361
  }
313
- const A = "_";
314
- function K(e) {
315
- const n = typeof e.baseUrl == "string" ? e.baseUrl : "https://swap.cow.fi", t = N(e);
316
- return n + "/#" + t + "?" + V(e);
362
+ const y = "_";
363
+ function ne(e) {
364
+ const t = typeof e.baseUrl == "string" ? e.baseUrl : "https://swap.cow.fi", n = F(e);
365
+ return t + "/#" + n + "?" + U(e);
317
366
  }
318
- function N(e) {
319
- const { chainId: n = 1, sell: t, buy: s, tradeType: d = C.SWAP } = e, l = [(t == null ? void 0 : t.asset) || A, (s == null ? void 0 : s.asset) || A].map(encodeURIComponent).join("/");
320
- return `/${n}/widget/${d}/${l}`;
367
+ function F(e) {
368
+ const { chainId: t = 1, sell: n, buy: s, tradeType: p = W.SWAP } = e, l = [(n == null ? void 0 : n.asset) || y, (s == null ? void 0 : s.asset) || y].map(encodeURIComponent).join("/");
369
+ return `/${t}/widget/${p}/${l}`;
370
+ }
371
+ function U(e) {
372
+ const t = new URLSearchParams();
373
+ return oe(re(se(t, e), e), e);
321
374
  }
322
- function V(e) {
323
- const n = new URLSearchParams();
324
- return Z(X(n, e), e);
375
+ function se(e, t) {
376
+ const { sell: n, buy: s } = t;
377
+ return n != null && n.amount && e.append("sellAmount", n.amount), s != null && s.amount && e.append("buyAmount", s.amount), e;
325
378
  }
326
- function X(e, n) {
327
- const { sell: t, buy: s } = n;
328
- return t != null && t.amount && e.append("sellAmount", t.amount), s != null && s.amount && e.append("buyAmount", s.amount), e;
379
+ function re(e, t) {
380
+ const n = t.theme;
381
+ return n ? (te(n) ? (e.append("palette", encodeURIComponent(JSON.stringify(n))), e.append("theme", n.baseTheme)) : (e.append("palette", "null"), e.append("theme", n)), e) : (e.append("palette", "null"), e);
329
382
  }
330
- function Z(e, n) {
331
- const t = n.theme;
332
- return t ? (J(t) ? (e.append("palette", encodeURIComponent(JSON.stringify(t))), e.append("theme", t.baseTheme)) : (e.append("palette", "null"), e.append("theme", t)), e) : (e.append("palette", "null"), e);
383
+ function oe(e, t) {
384
+ return t.targetChainId && e.append("targetChainId", t.targetChainId.toString()), e;
333
385
  }
334
- const M = "640px", ee = "450px", te = 20;
335
- function fe(e, n) {
336
- const { params: t, provider: s, listeners: d } = n;
337
- let l = s, w = t;
338
- const u = ne(t);
386
+ const x = "640px", ie = "450px", ae = 20;
387
+ function _e(e, t) {
388
+ const { params: n, provider: s, listeners: p } = t;
389
+ let l = s, _ = n;
390
+ const u = ce(n);
339
391
  e.innerHTML = "", e.appendChild(u);
340
392
  const { contentWindow: c } = u;
341
393
  if (!c)
342
394
  throw console.error("Iframe does not contain a window", u), new Error("Iframe does not contain a window!");
343
395
  const r = [];
344
- r.push(se(c, t.appCode)), r.push(...oe(u, t.height, t.maxHeight)), r.push(re());
345
- const o = new $(window, d);
346
- let i = W(c, null, l);
347
- u.addEventListener("load", () => L(c, w, l));
348
- const E = new B(window, c);
396
+ r.push(ue(c, n.appCode)), r.push(...fe(u, n.height, n.maxHeight)), r.push(de());
397
+ const o = new J(window, p);
398
+ let i = D(c, null, l);
399
+ u.addEventListener("load", () => L(c, _, l));
400
+ const E = new K(window, c);
349
401
  return {
350
- updateParams: (f) => {
351
- w = f, L(c, w, l);
402
+ updateParams: (d) => {
403
+ _ = d, L(c, _, l);
352
404
  },
353
- updateListeners: (f) => o.updateListeners(f),
354
- updateProvider: (f) => {
355
- l = f, i = W(c, i, f);
405
+ updateListeners: (d) => o.updateListeners(d),
406
+ updateProvider: (d) => {
407
+ l = d, i = D(c, i, d);
356
408
  },
357
409
  destroy: () => {
358
- i.disconnect(), o.stopListeningIframe(), r.forEach((f) => window.removeEventListener("message", f)), E.stopListening(), e.removeChild(u);
410
+ i.disconnect(), o.stopListeningIframe(), r.forEach((d) => window.removeEventListener("message", d)), E.stopListening(), e.removeChild(u);
359
411
  }
360
412
  };
361
413
  }
362
- function W(e, n, t) {
363
- n && n.disconnect();
364
- const s = n || new G(e);
365
- return t && s.onConnect(t), s;
414
+ function D(e, t, n) {
415
+ t && t.disconnect();
416
+ const s = t || new B(e);
417
+ return n && s.onConnect(n), s;
366
418
  }
367
- function ne(e) {
368
- const { width: n = ee, height: t = M } = e, s = document.createElement("iframe");
369
- return s.src = K(e), s.width = n, s.height = t, s.style.border = "0", s.allow = "clipboard-read; clipboard-write", s;
419
+ function ce(e) {
420
+ const { width: t = ie, height: n = x } = e, s = document.createElement("iframe");
421
+ return s.src = ne(e), s.width = t, s.height = n, s.style.border = "0", s.allow = "clipboard-read; clipboard-write", s;
370
422
  }
371
- function L(e, n, t) {
372
- const s = !!t, d = N(n), l = V(n).toString(), { theme: w, ...u } = n;
373
- v.postMessageToWindow(e, y.UPDATE_PARAMS, {
423
+ function L(e, t, n) {
424
+ const s = !!n, p = F(t), l = U(t).toString(), { theme: _, ...u } = t;
425
+ m.postMessageToWindow(e, A.UPDATE_PARAMS, {
374
426
  urlParams: {
375
- pathname: d,
427
+ pathname: p,
376
428
  search: l
377
429
  },
378
430
  appParams: u,
379
431
  hasProvider: s
380
432
  });
381
433
  }
382
- function se(e, n) {
383
- return v.listenToMessageFromWindow(window, R.ACTIVATE, () => {
384
- v.postMessageToWindow(e, y.UPDATE_APP_DATA, {
385
- metaData: n ? { appCode: n } : void 0
434
+ function ue(e, t) {
435
+ return m.listenToMessageFromWindow(window, I.ACTIVATE, () => {
436
+ m.postMessageToWindow(e, A.UPDATE_APP_DATA, {
437
+ metaData: t ? { appCode: t } : void 0
386
438
  });
387
439
  });
388
440
  }
389
- function re() {
390
- return v.listenToMessageFromWindow(
441
+ function de() {
442
+ return m.listenToMessageFromWindow(
391
443
  window,
392
- R.INTERCEPT_WINDOW_OPEN,
393
- ({ href: e, rel: n, target: t }) => {
444
+ I.INTERCEPT_WINDOW_OPEN,
445
+ ({ href: e, rel: t, target: n }) => {
394
446
  const s = e.toString();
395
447
  if (!s.startsWith("http") && s.match(/^[a-zA-Z0-9]+:\/\//)) {
396
- window.open(s, t, n);
448
+ window.open(s, n, t);
397
449
  return;
398
450
  }
399
451
  }
400
452
  );
401
453
  }
402
- function oe(e, n = M, t) {
454
+ function fe(e, t = x, n) {
403
455
  return [
404
- v.listenToMessageFromWindow(window, R.UPDATE_HEIGHT, (s) => {
405
- const d = s.height ? s.height + te : void 0;
406
- e.style.height = d ? `${t ? Math.min(d, t) : d}px` : n;
456
+ m.listenToMessageFromWindow(window, I.UPDATE_HEIGHT, (s) => {
457
+ const p = s.height ? s.height + ae : void 0;
458
+ e.style.height = p ? `${n ? Math.min(p, n) : p}px` : t;
407
459
  }),
408
- v.listenToMessageFromWindow(window, R.SET_FULL_HEIGHT, ({ isUpToSmall: s }) => {
409
- e.style.height = s ? n : `${t || document.body.offsetHeight}px`;
460
+ m.listenToMessageFromWindow(window, I.SET_FULL_HEIGHT, ({ isUpToSmall: s }) => {
461
+ e.style.height = s ? t : `${n || document.body.offsetHeight}px`;
410
462
  })
411
463
  ];
412
464
  }
413
- const ie = Object.values(C);
414
- function pe(e, n, t) {
415
- if (S(e)) {
416
- const s = e[t];
417
- return D(s) ? s[n] : s;
418
- }
419
- if (D(e)) {
465
+ const pe = Object.values(W);
466
+ function we(e, t, n) {
467
+ if (N(e)) {
420
468
  const s = e[n];
421
- return S(s) ? s[t] : s;
469
+ return M(s) ? s[t] : s;
470
+ }
471
+ if (M(e)) {
472
+ const s = e[t];
473
+ return N(s) ? s[n] : s;
422
474
  }
423
475
  return e;
424
476
  }
425
- function S(e) {
426
- return typeof e != "object" ? !1 : Object.keys(e).every((n) => ie.includes(n));
477
+ function N(e) {
478
+ return typeof e != "object" ? !1 : Object.keys(e).every((t) => pe.includes(t));
427
479
  }
428
- const ae = /^\d+$/;
429
- function D(e) {
430
- return typeof e != "object" ? !1 : Object.keys(e).every((n) => typeof n == "number" || ae.test(n));
480
+ const he = /^\d+$/;
481
+ function M(e) {
482
+ return typeof e != "object" ? !1 : Object.keys(e).every((t) => typeof t == "number" || he.test(t));
431
483
  }
432
484
  export {
433
- C as TradeType,
434
- ue as WIDGET_PALETTE_COLORS,
435
- R as WidgetMethodsEmit,
436
- y as WidgetMethodsListen,
437
- fe as createCowSwapWidget,
438
- J as isCowSwapWidgetPalette,
439
- D as isPerNetworkConfig,
440
- S as isPerTradeTypeConfig,
441
- pe as resolveFlexibleConfig,
442
- v as widgetIframeTransport
485
+ W as TradeType,
486
+ Ee as WIDGET_PALETTE_COLORS,
487
+ I as WidgetMethodsEmit,
488
+ A as WidgetMethodsListen,
489
+ _e as createCowSwapWidget,
490
+ te as isCowSwapWidgetPalette,
491
+ M as isPerNetworkConfig,
492
+ N as isPerTradeTypeConfig,
493
+ we as resolveFlexibleConfig,
494
+ m as widgetIframeTransport
443
495
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-lib",
3
- "version": "0.18.0",
3
+ "version": "0.20.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,7 +21,7 @@
21
21
  "widget-lib"
22
22
  ],
23
23
  "dependencies": {
24
- "@cowprotocol/events": "^1.5.0",
25
- "@cowprotocol/iframe-transport": "^1.1.0"
24
+ "@cowprotocol/events": "^1.6.1",
25
+ "@cowprotocol/iframe-transport": "^1.1.1"
26
26
  }
27
27
  }
package/types.d.ts CHANGED
@@ -130,19 +130,6 @@ export interface CowSwapWidgetImages {
130
130
  */
131
131
  emptyOrders?: string | null;
132
132
  }
133
- export interface CowSwapWidgetBanners {
134
- /**
135
- * Banner text: "Use Safe web app..."
136
- *
137
- * Conditions for displaying the banner:
138
- * - Safe-like app is connected to CoW Swap via WalletConnect
139
- * - Selling native token via Swap
140
- * - Sell token needs approval
141
- *
142
- * If the flag is set to true, the banner will not be displayed
143
- */
144
- hideSafeWebAppBanner?: boolean;
145
- }
146
133
  export interface CowSwapWidgetContent {
147
134
  feeLabel?: string;
148
135
  feeTooltipMarkdown?: string;
@@ -169,6 +156,10 @@ export interface CowSwapWidgetParams {
169
156
  * Network ID.
170
157
  */
171
158
  chainId?: SupportedChainId;
159
+ /**
160
+ * An id of a network to bridge the output token.
161
+ */
162
+ targetChainId?: number;
172
163
  /**
173
164
  * The token lists urls to use in the widget
174
165
  */
@@ -266,10 +257,6 @@ export interface CowSwapWidgetParams {
266
257
  * Sounds configuration for the app.
267
258
  */
268
259
  sounds?: CowSwapWidgetSounds;
269
- /**
270
- * Flags to control the display of banners in the widget.
271
- */
272
- banners?: CowSwapWidgetBanners;
273
260
  /**
274
261
  * In case when widget does not support some tokens, you can provide a list of tokens to be used in the widget
275
262
  */