New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cowprotocol/widget-lib

Package Overview
Dependencies
Maintainers
5
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cowprotocol/widget-lib - npm Package Compare versions

Comparing version

to
0.14.0

2

index.iife.js

@@ -1,1 +0,1 @@

var cowSwapWidget=function(s){"use strict";var ne=Object.defineProperty;var ie=(s,r,u)=>r in s?ne(s,r,{enumerable:!0,configurable:!0,writable:!0,value:u}):s[r]=u;var d=(s,r,u)=>(ie(s,typeof r!="symbol"?r+"":r,u),u);class r{constructor(){d(this,"subscriptions",{})}on(t){const{event:n,handler:i}=t;this.subscriptions[n]||(this.subscriptions[n]=[]),this.subscriptions[n].push(i)}off(t){const{event:n,handler:i}=t;this.subscriptions[n]&&(this.subscriptions[n]=this.subscriptions[n].filter(o=>o!==i))}emit(t,n){this.subscriptions[t]&&this.subscriptions[t].forEach(i=>i(n))}}const u="cowSwapWidget";function T(e,t,n){const o={key:u,method:t,...typeof n=="object"?n:{}};e.postMessage(o,"*")}function E(e,t,n){const i=o=>{!y(o.data)||o.data.key!==u||o.data.method!==t||n(o.data)};return e.addEventListener("message",i),i}function y(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function W(e,t,n){e.removeEventListener("message",n)}function C(e,t){e.removeEventListener("message",t)}var a=(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))(a||{}),w=(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))(w||{}),m=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(m||{});const N=["primary","background","paper","text","danger","warning","alert","info","success"];class U{constructor(t,n=[]){d(this,"eventEmitter",new r);d(this,"listeners",[]);d(this,"widgetListener");this.contentWindow=t,this.updateListeners(n),this.widgetListener=E(this.contentWindow,a.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){C(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)}}const V=["connect","disconnect","close","chainChanged","accountsChanged"];class F{constructor(t){d(this,"ethereumProvider",null);d(this,"requestWaitingForConnection",{});d(this,"processRpcCallFromWindow",({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)});this.iframeWidow=t}disconnect(){this.ethereumProvider=null,W(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(t){this.ethereumProvider?this.disconnect():E(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=t,this.processPendingRequests(),V.forEach(n=>{t.on(n,i=>this.onProviderEvent(n,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(t=>{this.processRpcRequest(this.requestWaitingForConnection[t])}),this.requestWaitingForConnection={}}processRpcRequest(t){const{id:n,jsonrpc:i,method:o}=t;if(!this.ethereumProvider||!n)return;(o==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...t,id:n})).then(p=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,result:p}})).catch(p=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,error:p}}))}onProviderEvent(t,n){T(this.iframeWidow,w.PROVIDER_ON_EVENT,{event:t,params:n})}forwardRpcResponseToIframe(t){T(this.iframeWidow,w.PROVIDER_RPC_RESPONSE,t)}}class H{constructor(t,n){d(this,"forwardSdkMessage");this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=i=>{M(i.data)&&i.origin!==window.location.origin&&(k(i.data)?this.appWindow.parent.postMessage(i.data,"*"):G(i.data)&&this.iframeWidow.postMessage(i.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function M(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function k(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 G(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function I(e){return!!(e&&typeof e=="object")}const v="_";function Q(e){const t=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",n=A(e);return t+"/#"+n+"?"+S(e)}function A(e){const{chainId:t=1,sell:n,buy:i,tradeType:o=m.SWAP}=e,c=[(n==null?void 0:n.asset)||v,(i==null?void 0:i.asset)||v].map(encodeURIComponent).join("/");return`/${t}/widget/${o}/${c}`}function S(e){const t=new URLSearchParams;return $(j(t,e),e)}function j(e,t){const{sell:n,buy:i}=t;return n!=null&&n.amount&&e.append("sellAmount",n.amount),i!=null&&i.amount&&e.append("buyAmount",i.amount),e}function $(e,t){const n=t.theme;return n?(I(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)}const L="640px",B="450px",q=20;function K(e,t){const{params:n,provider:i,listeners:o}=t;let c=i,p=n;const h=Y(n);e.innerHTML="",e.appendChild(h);const{contentWindow:l}=h;if(!l)throw console.error("Iframe does not contain a window",h),new Error("Iframe does not contain a window!");const P=[];P.push(z(l,n.appCode)),P.push(...X(h,n.height)),P.push(J());const b=new U(window,o);let g=O(l,null,c);h.addEventListener("load",()=>D(l,p,c));const te=new H(window,l);return{updateParams:f=>{p=f,D(l,p,c)},updateListeners:f=>b.updateListeners(f),updateProvider:f=>{c=f,g=O(l,g,f)},destroy:()=>{g.disconnect(),b.stopListeningIframe(),P.forEach(f=>window.removeEventListener("message",f)),te.stopListening(),e.removeChild(h)}}}function O(e,t,n){t&&t.disconnect();const i=t||new F(e);return n&&i.onConnect(n),i}function Y(e){const{width:t=B,height:n=L}=e,i=document.createElement("iframe");return i.src=Q(e),i.width=t,i.height=n,i.style.border="0",i.allow="clipboard-read; clipboard-write",i}function D(e,t,n){const i=!!n,o=A(t),c=S(t).toString(),{theme:p,...h}=t;T(e,w.UPDATE_PARAMS,{urlParams:{pathname:o,search:c},appParams:h,hasProvider:i})}function z(e,t){return E(window,a.ACTIVATE,()=>{T(e,w.UPDATE_APP_DATA,{metaData:t?{appCode:t}:void 0})})}function J(){return E(window,a.INTERCEPT_WINDOW_OPEN,({href:e,rel:t,target:n})=>{const i=e.toString();if(!i.startsWith("http")&&i.match(/^[a-zA-Z0-9]+:\/\//)){window.open(i,n,t);return}})}function X(e,t=L){return[E(window,a.UPDATE_HEIGHT,n=>{e.style.height=n.height?`${n.height+q}px`:t}),E(window,a.SET_FULL_HEIGHT,({isUpToSmall:n})=>{e.style.height=n?t:`${document.body.offsetHeight}px`})]}const Z=Object.values(m);function x(e,t,n){if(_(e)){const i=e[n];return R(i)?i[t]:i}if(R(e)){const i=e[t];return _(i)?i[n]:i}return e}function _(e){return typeof e!="object"?!1:Object.keys(e).every(t=>Z.includes(t))}const ee=/^\d+$/;function R(e){return typeof e!="object"?!1:Object.keys(e).every(t=>typeof t=="number"||ee.test(t))}return s.TradeType=m,s.WIDGET_PALETTE_COLORS=N,s.WidgetMethodsEmit=a,s.WidgetMethodsListen=w,s.createCowSwapWidget=K,s.isCowSwapWidgetPalette=I,s.isPerNetworkConfig=R,s.isPerTradeTypeConfig=_,s.listenToMessageFromWindow=E,s.postMessageToWindow=T,s.resolveFlexibleConfig=x,s.stopListeningToMessageFromWindow=W,s.stopListeningWindowListener=C,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s}({});
var cowSwapWidget=function(s){"use strict";var ne=Object.defineProperty;var ie=(s,r,u)=>r in s?ne(s,r,{enumerable:!0,configurable:!0,writable:!0,value:u}):s[r]=u;var d=(s,r,u)=>(ie(s,typeof r!="symbol"?r+"":r,u),u);class r{constructor(){d(this,"subscriptions",{})}on(t){const{event:n,handler:i}=t;return this.subscriptions[n]||(this.subscriptions[n]=[]),this.subscriptions[n].push(i),t}off(t){const{event:n,handler:i}=t;return this.subscriptions[n]&&(this.subscriptions[n]=this.subscriptions[n].filter(o=>o!==i)),t}emit(t,n){this.subscriptions[t]&&this.subscriptions[t].forEach(i=>i(n))}}const u="cowSwapWidget";function T(e,t,n){const o={key:u,method:t,...typeof n=="object"?n:{}};e.postMessage(o,"*")}function E(e,t,n){const i=o=>{!y(o.data)||o.data.key!==u||o.data.method!==t||n(o.data)};return e.addEventListener("message",i),i}function y(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function W(e,t,n){e.removeEventListener("message",n)}function C(e,t){e.removeEventListener("message",t)}var a=(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))(a||{}),w=(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))(w||{}),m=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(m||{});const N=["primary","background","paper","text","danger","warning","alert","info","success"];class U{constructor(t,n=[]){d(this,"eventEmitter",new r);d(this,"listeners",[]);d(this,"widgetListener");this.contentWindow=t,this.updateListeners(n),this.widgetListener=E(this.contentWindow,a.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){C(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)}}const V=["connect","disconnect","close","chainChanged","accountsChanged"];class F{constructor(t){d(this,"ethereumProvider",null);d(this,"requestWaitingForConnection",{});d(this,"processRpcCallFromWindow",({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)});this.iframeWidow=t}disconnect(){this.ethereumProvider=null,W(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(t){this.ethereumProvider?this.disconnect():E(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=t,this.processPendingRequests(),V.forEach(n=>{t.on(n,i=>this.onProviderEvent(n,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(t=>{this.processRpcRequest(this.requestWaitingForConnection[t])}),this.requestWaitingForConnection={}}processRpcRequest(t){const{id:n,jsonrpc:i,method:o}=t;if(!this.ethereumProvider||!n)return;(o==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...t,id:n})).then(p=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,result:p}})).catch(p=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,error:p}}))}onProviderEvent(t,n){T(this.iframeWidow,w.PROVIDER_ON_EVENT,{event:t,params:n})}forwardRpcResponseToIframe(t){T(this.iframeWidow,w.PROVIDER_RPC_RESPONSE,t)}}class H{constructor(t,n){d(this,"forwardSdkMessage");this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=i=>{M(i.data)&&i.origin!==window.location.origin&&(k(i.data)?this.appWindow.parent.postMessage(i.data,"*"):G(i.data)&&this.iframeWidow.postMessage(i.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function M(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function k(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 G(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function I(e){return!!(e&&typeof e=="object")}const v="_";function Q(e){const t=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",n=A(e);return t+"/#"+n+"?"+S(e)}function A(e){const{chainId:t=1,sell:n,buy:i,tradeType:o=m.SWAP}=e,c=[(n==null?void 0:n.asset)||v,(i==null?void 0:i.asset)||v].map(encodeURIComponent).join("/");return`/${t}/widget/${o}/${c}`}function S(e){const t=new URLSearchParams;return $(j(t,e),e)}function j(e,t){const{sell:n,buy:i}=t;return n!=null&&n.amount&&e.append("sellAmount",n.amount),i!=null&&i.amount&&e.append("buyAmount",i.amount),e}function $(e,t){const n=t.theme;return n?(I(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)}const L="640px",B="450px",q=20;function K(e,t){const{params:n,provider:i,listeners:o}=t;let c=i,p=n;const h=Y(n);e.innerHTML="",e.appendChild(h);const{contentWindow:l}=h;if(!l)throw console.error("Iframe does not contain a window",h),new Error("Iframe does not contain a window!");const P=[];P.push(z(l,n.appCode)),P.push(...X(h,n.height)),P.push(J());const b=new U(window,o);let g=O(l,null,c);h.addEventListener("load",()=>D(l,p,c));const te=new H(window,l);return{updateParams:f=>{p=f,D(l,p,c)},updateListeners:f=>b.updateListeners(f),updateProvider:f=>{c=f,g=O(l,g,f)},destroy:()=>{g.disconnect(),b.stopListeningIframe(),P.forEach(f=>window.removeEventListener("message",f)),te.stopListening(),e.removeChild(h)}}}function O(e,t,n){t&&t.disconnect();const i=t||new F(e);return n&&i.onConnect(n),i}function Y(e){const{width:t=B,height:n=L}=e,i=document.createElement("iframe");return i.src=Q(e),i.width=t,i.height=n,i.style.border="0",i.allow="clipboard-read; clipboard-write",i}function D(e,t,n){const i=!!n,o=A(t),c=S(t).toString(),{theme:p,...h}=t;T(e,w.UPDATE_PARAMS,{urlParams:{pathname:o,search:c},appParams:h,hasProvider:i})}function z(e,t){return E(window,a.ACTIVATE,()=>{T(e,w.UPDATE_APP_DATA,{metaData:t?{appCode:t}:void 0})})}function J(){return E(window,a.INTERCEPT_WINDOW_OPEN,({href:e,rel:t,target:n})=>{const i=e.toString();if(!i.startsWith("http")&&i.match(/^[a-zA-Z0-9]+:\/\//)){window.open(i,n,t);return}})}function X(e,t=L){return[E(window,a.UPDATE_HEIGHT,n=>{e.style.height=n.height?`${n.height+q}px`:t}),E(window,a.SET_FULL_HEIGHT,({isUpToSmall:n})=>{e.style.height=n?t:`${document.body.offsetHeight}px`})]}const Z=Object.values(m);function x(e,t,n){if(_(e)){const i=e[n];return R(i)?i[t]:i}if(R(e)){const i=e[t];return _(i)?i[n]:i}return e}function _(e){return typeof e!="object"?!1:Object.keys(e).every(t=>Z.includes(t))}const ee=/^\d+$/;function R(e){return typeof e!="object"?!1:Object.keys(e).every(t=>typeof t=="number"||ee.test(t))}return s.TradeType=m,s.WIDGET_PALETTE_COLORS=N,s.WidgetMethodsEmit=a,s.WidgetMethodsListen=w,s.createCowSwapWidget=K,s.isCowSwapWidgetPalette=I,s.isPerNetworkConfig=R,s.isPerTradeTypeConfig=_,s.listenToMessageFromWindow=E,s.postMessageToWindow=T,s.resolveFlexibleConfig=x,s.stopListeningToMessageFromWindow=W,s.stopListeningWindowListener=C,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s}({});

@@ -1,1 +0,1 @@

"use strict";var b=Object.defineProperty;var y=(e,t,n)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var r=(e,t,n)=>(y(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class N{constructor(){r(this,"subscriptions",{})}on(t){const{event:n,handler:i}=t;this.subscriptions[n]||(this.subscriptions[n]=[]),this.subscriptions[n].push(i)}off(t){const{event:n,handler:i}=t;this.subscriptions[n]&&(this.subscriptions[n]=this.subscriptions[n].filter(s=>s!==i))}emit(t,n){this.subscriptions[t]&&this.subscriptions[t].forEach(i=>i(n))}}const W="cowSwapWidget";function E(e,t,n){const s={key:W,method:t,...typeof n=="object"?n:{}};e.postMessage(s,"*")}function h(e,t,n){const i=s=>{!U(s.data)||s.data.key!==W||s.data.method!==t||n(s.data)};return e.addEventListener("message",i),i}function U(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function I(e,t,n){e.removeEventListener("message",n)}function v(e,t){e.removeEventListener("message",t)}var a=(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))(a||{}),f=(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))(f||{}),w=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(w||{});const V=["primary","background","paper","text","danger","warning","alert","info","success"];class F{constructor(t,n=[]){r(this,"eventEmitter",new N);r(this,"listeners",[]);r(this,"widgetListener");this.contentWindow=t,this.updateListeners(n),this.widgetListener=h(this.contentWindow,a.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){v(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)}}const H=["connect","disconnect","close","chainChanged","accountsChanged"];class M{constructor(t){r(this,"ethereumProvider",null);r(this,"requestWaitingForConnection",{});r(this,"processRpcCallFromWindow",({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)});this.iframeWidow=t}disconnect(){this.ethereumProvider=null,I(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(t){this.ethereumProvider?this.disconnect():h(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=t,this.processPendingRequests(),H.forEach(n=>{t.on(n,i=>this.onProviderEvent(n,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(t=>{this.processRpcRequest(this.requestWaitingForConnection[t])}),this.requestWaitingForConnection={}}processRpcRequest(t){const{id:n,jsonrpc:i,method:s}=t;if(!this.ethereumProvider||!n)return;(s==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...t,id:n})).then(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,result:c}})).catch(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,error:c}}))}onProviderEvent(t,n){E(this.iframeWidow,f.PROVIDER_ON_EVENT,{event:t,params:n})}forwardRpcResponseToIframe(t){E(this.iframeWidow,f.PROVIDER_RPC_RESPONSE,t)}}class k{constructor(t,n){r(this,"forwardSdkMessage");this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=i=>{G(i.data)&&i.origin!==window.location.origin&&(x(i.data)?this.appWindow.parent.postMessage(i.data,"*"):Q(i.data)&&this.iframeWidow.postMessage(i.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function G(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function x(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 Q(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function A(e){return!!(e&&typeof e=="object")}const R="_";function j(e){const t=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",n=S(e);return t+"/#"+n+"?"+L(e)}function S(e){const{chainId:t=1,sell:n,buy:i,tradeType:s=w.SWAP}=e,o=[(n==null?void 0:n.asset)||R,(i==null?void 0:i.asset)||R].map(encodeURIComponent).join("/");return`/${t}/widget/${s}/${o}`}function L(e){const t=new URLSearchParams;return B($(t,e),e)}function $(e,t){const{sell:n,buy:i}=t;return n!=null&&n.amount&&e.append("sellAmount",n.amount),i!=null&&i.amount&&e.append("buyAmount",i.amount),e}function B(e,t){const n=t.theme;return n?(A(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)}const O="640px",q="450px",K=20;function Y(e,t){const{params:n,provider:i,listeners:s}=t;let o=i,c=n;const d=z(n);e.innerHTML="",e.appendChild(d);const{contentWindow:u}=d;if(!u)throw console.error("Iframe does not contain a window",d),new Error("Iframe does not contain a window!");const l=[];l.push(J(u,n.appCode)),l.push(...Z(d,n.height)),l.push(X());const _=new F(window,s);let T=g(u,null,o);d.addEventListener("load",()=>C(u,c,o));const D=new k(window,u);return{updateParams:p=>{c=p,C(u,c,o)},updateListeners:p=>_.updateListeners(p),updateProvider:p=>{o=p,T=g(u,T,p)},destroy:()=>{T.disconnect(),_.stopListeningIframe(),l.forEach(p=>window.removeEventListener("message",p)),D.stopListening(),e.removeChild(d)}}}function g(e,t,n){t&&t.disconnect();const i=t||new M(e);return n&&i.onConnect(n),i}function z(e){const{width:t=q,height:n=O}=e,i=document.createElement("iframe");return i.src=j(e),i.width=t,i.height=n,i.style.border="0",i.allow="clipboard-read; clipboard-write",i}function C(e,t,n){const i=!!n,s=S(t),o=L(t).toString(),{theme:c,...d}=t;E(e,f.UPDATE_PARAMS,{urlParams:{pathname:s,search:o},appParams:d,hasProvider:i})}function J(e,t){return h(window,a.ACTIVATE,()=>{E(e,f.UPDATE_APP_DATA,{metaData:t?{appCode:t}:void 0})})}function X(){return h(window,a.INTERCEPT_WINDOW_OPEN,({href:e,rel:t,target:n})=>{const i=e.toString();if(!i.startsWith("http")&&i.match(/^[a-zA-Z0-9]+:\/\//)){window.open(i,n,t);return}})}function Z(e,t=O){return[h(window,a.UPDATE_HEIGHT,n=>{e.style.height=n.height?`${n.height+K}px`:t}),h(window,a.SET_FULL_HEIGHT,({isUpToSmall:n})=>{e.style.height=n?t:`${document.body.offsetHeight}px`})]}const ee=Object.values(w);function te(e,t,n){if(m(e)){const i=e[n];return P(i)?i[t]:i}if(P(e)){const i=e[t];return m(i)?i[n]:i}return e}function m(e){return typeof e!="object"?!1:Object.keys(e).every(t=>ee.includes(t))}const ne=/^\d+$/;function P(e){return typeof e!="object"?!1:Object.keys(e).every(t=>typeof t=="number"||ne.test(t))}exports.TradeType=w;exports.WIDGET_PALETTE_COLORS=V;exports.WidgetMethodsEmit=a;exports.WidgetMethodsListen=f;exports.createCowSwapWidget=Y;exports.isCowSwapWidgetPalette=A;exports.isPerNetworkConfig=P;exports.isPerTradeTypeConfig=m;exports.listenToMessageFromWindow=h;exports.postMessageToWindow=E;exports.resolveFlexibleConfig=te;exports.stopListeningToMessageFromWindow=I;exports.stopListeningWindowListener=v;
"use strict";var b=Object.defineProperty;var y=(e,t,n)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var r=(e,t,n)=>(y(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class N{constructor(){r(this,"subscriptions",{})}on(t){const{event:n,handler:i}=t;return this.subscriptions[n]||(this.subscriptions[n]=[]),this.subscriptions[n].push(i),t}off(t){const{event:n,handler:i}=t;return this.subscriptions[n]&&(this.subscriptions[n]=this.subscriptions[n].filter(s=>s!==i)),t}emit(t,n){this.subscriptions[t]&&this.subscriptions[t].forEach(i=>i(n))}}const W="cowSwapWidget";function E(e,t,n){const s={key:W,method:t,...typeof n=="object"?n:{}};e.postMessage(s,"*")}function h(e,t,n){const i=s=>{!U(s.data)||s.data.key!==W||s.data.method!==t||n(s.data)};return e.addEventListener("message",i),i}function U(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function I(e,t,n){e.removeEventListener("message",n)}function v(e,t){e.removeEventListener("message",t)}var a=(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))(a||{}),f=(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))(f||{}),w=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(w||{});const V=["primary","background","paper","text","danger","warning","alert","info","success"];class F{constructor(t,n=[]){r(this,"eventEmitter",new N);r(this,"listeners",[]);r(this,"widgetListener");this.contentWindow=t,this.updateListeners(n),this.widgetListener=h(this.contentWindow,a.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){v(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)}}const H=["connect","disconnect","close","chainChanged","accountsChanged"];class M{constructor(t){r(this,"ethereumProvider",null);r(this,"requestWaitingForConnection",{});r(this,"processRpcCallFromWindow",({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)});this.iframeWidow=t}disconnect(){this.ethereumProvider=null,I(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(t){this.ethereumProvider?this.disconnect():h(window,a.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=t,this.processPendingRequests(),H.forEach(n=>{t.on(n,i=>this.onProviderEvent(n,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(t=>{this.processRpcRequest(this.requestWaitingForConnection[t])}),this.requestWaitingForConnection={}}processRpcRequest(t){const{id:n,jsonrpc:i,method:s}=t;if(!this.ethereumProvider||!n)return;(s==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...t,id:n})).then(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,result:c}})).catch(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:n,error:c}}))}onProviderEvent(t,n){E(this.iframeWidow,f.PROVIDER_ON_EVENT,{event:t,params:n})}forwardRpcResponseToIframe(t){E(this.iframeWidow,f.PROVIDER_RPC_RESPONSE,t)}}class k{constructor(t,n){r(this,"forwardSdkMessage");this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=i=>{G(i.data)&&i.origin!==window.location.origin&&(x(i.data)?this.appWindow.parent.postMessage(i.data,"*"):Q(i.data)&&this.iframeWidow.postMessage(i.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function G(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function x(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 Q(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function A(e){return!!(e&&typeof e=="object")}const R="_";function j(e){const t=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",n=S(e);return t+"/#"+n+"?"+L(e)}function S(e){const{chainId:t=1,sell:n,buy:i,tradeType:s=w.SWAP}=e,o=[(n==null?void 0:n.asset)||R,(i==null?void 0:i.asset)||R].map(encodeURIComponent).join("/");return`/${t}/widget/${s}/${o}`}function L(e){const t=new URLSearchParams;return B($(t,e),e)}function $(e,t){const{sell:n,buy:i}=t;return n!=null&&n.amount&&e.append("sellAmount",n.amount),i!=null&&i.amount&&e.append("buyAmount",i.amount),e}function B(e,t){const n=t.theme;return n?(A(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)}const O="640px",q="450px",K=20;function Y(e,t){const{params:n,provider:i,listeners:s}=t;let o=i,c=n;const d=z(n);e.innerHTML="",e.appendChild(d);const{contentWindow:u}=d;if(!u)throw console.error("Iframe does not contain a window",d),new Error("Iframe does not contain a window!");const l=[];l.push(J(u,n.appCode)),l.push(...Z(d,n.height)),l.push(X());const _=new F(window,s);let T=g(u,null,o);d.addEventListener("load",()=>C(u,c,o));const D=new k(window,u);return{updateParams:p=>{c=p,C(u,c,o)},updateListeners:p=>_.updateListeners(p),updateProvider:p=>{o=p,T=g(u,T,p)},destroy:()=>{T.disconnect(),_.stopListeningIframe(),l.forEach(p=>window.removeEventListener("message",p)),D.stopListening(),e.removeChild(d)}}}function g(e,t,n){t&&t.disconnect();const i=t||new M(e);return n&&i.onConnect(n),i}function z(e){const{width:t=q,height:n=O}=e,i=document.createElement("iframe");return i.src=j(e),i.width=t,i.height=n,i.style.border="0",i.allow="clipboard-read; clipboard-write",i}function C(e,t,n){const i=!!n,s=S(t),o=L(t).toString(),{theme:c,...d}=t;E(e,f.UPDATE_PARAMS,{urlParams:{pathname:s,search:o},appParams:d,hasProvider:i})}function J(e,t){return h(window,a.ACTIVATE,()=>{E(e,f.UPDATE_APP_DATA,{metaData:t?{appCode:t}:void 0})})}function X(){return h(window,a.INTERCEPT_WINDOW_OPEN,({href:e,rel:t,target:n})=>{const i=e.toString();if(!i.startsWith("http")&&i.match(/^[a-zA-Z0-9]+:\/\//)){window.open(i,n,t);return}})}function Z(e,t=O){return[h(window,a.UPDATE_HEIGHT,n=>{e.style.height=n.height?`${n.height+K}px`:t}),h(window,a.SET_FULL_HEIGHT,({isUpToSmall:n})=>{e.style.height=n?t:`${document.body.offsetHeight}px`})]}const ee=Object.values(w);function te(e,t,n){if(m(e)){const i=e[n];return P(i)?i[t]:i}if(P(e)){const i=e[t];return m(i)?i[n]:i}return e}function m(e){return typeof e!="object"?!1:Object.keys(e).every(t=>ee.includes(t))}const ne=/^\d+$/;function P(e){return typeof e!="object"?!1:Object.keys(e).every(t=>typeof t=="number"||ne.test(t))}exports.TradeType=w;exports.WIDGET_PALETTE_COLORS=V;exports.WidgetMethodsEmit=a;exports.WidgetMethodsListen=f;exports.createCowSwapWidget=Y;exports.isCowSwapWidgetPalette=A;exports.isPerNetworkConfig=P;exports.isPerTradeTypeConfig=m;exports.listenToMessageFromWindow=h;exports.postMessageToWindow=E;exports.resolveFlexibleConfig=te;exports.stopListeningToMessageFromWindow=I;exports.stopListeningWindowListener=v;
{
"name": "@cowprotocol/widget-lib",
"version": "0.13.2",
"version": "0.14.0",
"type": "commonjs",

@@ -5,0 +5,0 @@ "description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your website.",

@@ -205,2 +205,10 @@ import { CowEventListeners, CowEventPayloadMap, CowEvents } from '../../events/src/index.ts';

/**
* Disables showing the progress bar after a SWAP order is placed.
* The SWAP progress bar offers a transparent view into CoW Protocol's unique solution finding mechanism.
* If you wish to not show it, set `disableProgressBar` to `true`.
*
* Defaults to false.
*/
disableProgressBar?: boolean;
/**
* Disables showing the toast messages.

@@ -207,0 +215,0 @@ * Some UI might want to disable it and subscribe to WidgetMethodsEmit.ON_TOAST_MESSAGE event to handle the toast messages itself.

Sorry, the diff of this file is not supported yet