@cowprotocol/widget-lib 0.8.0 → 0.9.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.d.ts CHANGED
@@ -2,3 +2,4 @@ export { createCowSwapWidget } from './cowSwapWidget';
2
2
  export type { CowSwapWidgetHandler } from './cowSwapWidget';
3
3
  export * from './types';
4
4
  export * from './messages';
5
+ export * from './themeUtils';
package/index.iife.js CHANGED
@@ -1 +1 @@
1
- var cowSwapWidget=function(o){"use strict";const l="cowSwapWidget";function p(e,n,t){const s={key:l,method:n,...typeof t=="object"?t:{}};e.postMessage(s,"*")}function f(e,n,t){const i=s=>{!C(s.data)||s.data.key!==l||s.data.method!==n||t(s.data)};return e.addEventListener("message",i),i}function C(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function R(e,n,t){e.removeEventListener("message",t)}function E(e,n){e.removeEventListener("message",n)}var d=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e))(d||{}),u=(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))(u||{}),w=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(w||{});const S=["connect","disconnect","close","chainChanged","accountsChanged"];class D{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)}}disconnect(){this.ethereumProvider=null,R(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():f(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),S.forEach(t=>{n.on(t,i=>this.onProviderEvent(t,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:t,jsonrpc:i,method:s}=n;if(!this.ethereumProvider||!t)return;(s==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:t,result:r}})).catch(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:t,error:r}}))}onProviderEvent(n,t){p(this.iframeWidow,u.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){p(this.iframeWidow,u.PROVIDER_RPC_RESPONSE,n)}}const T="_";function L(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=g(e),i=_(e);return n+"/#"+t+"?"+i}function g(e){const{chainId:n=1,sell:t,buy:i,tradeType:s=w.SWAP}=e,a=[(t==null?void 0:t.asset)||T,(i==null?void 0:i.asset)||T].map(encodeURIComponent).join("/");return`/${n}/widget/${s}/${a}`}function _(e){const{sell:n,buy:t,theme:i}=e,s=new URLSearchParams;return n!=null&&n.amount&&s.append("sellAmount",n.amount),t!=null&&t.amount&&s.append("buyAmount",t.amount),i&&s.append("theme",typeof i=="string"?i:i.baseTheme),s}class O{constructor(){this.subscriptions={}}on(n){const{event:t,handler:i}=n;this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(i)}off(n){const{event:t,handler:i}=n;this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(s=>s!==i))}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(i=>i(t))}}class y{constructor(n,t=[]){this.contentWindow=n,this.eventEmitter=new O,this.listeners=[],this.updateListeners(t),this.widgetListener=f(this.contentWindow,d.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){E(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 V{constructor(n,t){this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=i=>{M(i.data)&&(U(i.data)?this.appWindow.parent.postMessage(i.data,"*"):b(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 U(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 b(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}const A="640px",F="450px",N=20;function H(e,n){const{params:t,provider:i,listeners:s}=n;let a=i;const r=q(t);e.innerHTML="",e.appendChild(r);const{contentWindow:h}=r;if(!h)throw console.error("Iframe does not contain a window",r),new Error("Iframe does not contain a window!");const m=[];m.push(k(h,t.appCode)),m.push(G(r,t.height));const I=new y(window,s);let P=v(h,null,a);r.addEventListener("load",()=>W(h,t,a));const Q=new V(window,h);return{updateParams:c=>W(h,c,a),updateListeners:c=>I.updateListeners(c),updateProvider:c=>{a=c,P=v(h,P,c)},destroy:()=>{P.disconnect(),I.stopListeningIframe(),m.forEach(c=>window.removeEventListener("message",c)),Q.stopListening(),e.removeChild(r)}}}function v(e,n,t){n&&n.disconnect();const i=n||new D(e);return t&&i.onConnect(t),i}function q(e){const{width:n=F,height:t=A}=e,i=document.createElement("iframe");return i.src=L(e),i.width=n,i.height=t,i.style.border="0",i}function W(e,n,t){const i=!!t,s=g(n),a=_(n).toString();p(e,u.UPDATE_PARAMS,{urlParams:{pathname:s,search:a},appParams:{...n},hasProvider:i})}function k(e,n){const t=f(window,d.ACTIVATE,()=>{E(window,t),p(e,u.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return t}function G(e,n=A){return f(window,d.UPDATE_HEIGHT,t=>{e.style.height=t.height?`${t.height+N}px`:n})}return o.TradeType=w,o.WidgetMethodsEmit=d,o.WidgetMethodsListen=u,o.createCowSwapWidget=H,o.listenToMessageFromWindow=f,o.postMessageToWindow=p,o.stopListeningToMessageFromWindow=R,o.stopListeningWindowListener=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
1
+ var cowSwapWidget=function(o){"use strict";const T="cowSwapWidget";function f(e,n,t){const s={key:T,method:n,...typeof t=="object"?t:{}};e.postMessage(s,"*")}function E(e,n,t){const i=s=>{!D(s.data)||s.data.key!==T||s.data.method!==n||t(s.data)};return e.addEventListener("message",i),i}function D(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function R(e,n,t){e.removeEventListener("message",t)}function m(e,n){e.removeEventListener("message",n)}var h=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e))(h||{}),p=(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))(p||{}),w=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(w||{});const L=["primary","background","paper","text","danger","warning","alert","info","success"],O=["connect","disconnect","close","chainChanged","accountsChanged"];class V{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)}}disconnect(){this.ethereumProvider=null,R(window,h.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():E(window,h.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),O.forEach(t=>{n.on(t,i=>this.onProviderEvent(t,i))})}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(n=>{this.processRpcRequest(this.requestWaitingForConnection[n])}),this.requestWaitingForConnection={}}processRpcRequest(n){const{id:t,jsonrpc:i,method:s}=n;if(!this.ethereumProvider||!t)return;(s==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(a=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:t,result:a}})).catch(a=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:i,id:t,error:a}}))}onProviderEvent(n,t){f(this.iframeWidow,p.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){f(this.iframeWidow,p.PROVIDER_RPC_RESPONSE,n)}}function g(e){return!!(e&&typeof e=="object")}const _="_";function y(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=A(e);return n+"/#"+t+"?"+W(e)}function A(e){const{chainId:n=1,sell:t,buy:i,tradeType:s=w.SWAP}=e,r=[(t==null?void 0:t.asset)||_,(i==null?void 0:i.asset)||_].map(encodeURIComponent).join("/");return`/${n}/widget/${s}/${r}`}function W(e){const n=new URLSearchParams;return U(M(n,e),e)}function M(e,n){const{sell:t,buy:i}=n;return t!=null&&t.amount&&e.append("sellAmount",t.amount),i!=null&&i.amount&&e.append("buyAmount",i.amount),e}function U(e,n){const t=n.theme;return t&&(g(t)?(e.append("palette",encodeURIComponent(JSON.stringify(t))),e.append("theme",t.baseTheme)):e.append("theme",t)),e}class b{constructor(){this.subscriptions={}}on(n){const{event:t,handler:i}=n;this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(i)}off(n){const{event:t,handler:i}=n;this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(s=>s!==i))}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(i=>i(t))}}class F{constructor(n,t=[]){this.contentWindow=n,this.eventEmitter=new b,this.listeners=[],this.updateListeners(t),this.widgetListener=E(this.contentWindow,h.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload))}stopListeningIframe(){m(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 N{constructor(n,t){this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=i=>{H(i.data)&&(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 H(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"}const v="640px",Q="450px",q=20;function B(e,n){const{params:t,provider:i,listeners:s}=n;let r=i,a=t;const c=$(t);e.innerHTML="",e.appendChild(c);const{contentWindow:u}=c;if(!u)throw console.error("Iframe does not contain a window",c),new Error("Iframe does not contain a window!");const l=[];l.push(K(u,t.appCode)),l.push(Y(c,t.height));const S=new F(window,s);let P=C(u,null,r);c.addEventListener("load",()=>I(u,a,r));const j=new N(window,u);return{updateParams:d=>{a=d,I(u,a,r)},updateListeners:d=>S.updateListeners(d),updateProvider:d=>{r=d,P=C(u,P,d)},destroy:()=>{P.disconnect(),S.stopListeningIframe(),l.forEach(d=>window.removeEventListener("message",d)),j.stopListening(),e.removeChild(c)}}}function C(e,n,t){n&&n.disconnect();const i=n||new V(e);return t&&i.onConnect(t),i}function $(e){const{width:n=Q,height:t=v}=e,i=document.createElement("iframe");return i.src=y(e),i.width=n,i.height=t,i.style.border="0",i}function I(e,n,t){const i=!!t,s=A(n),r=W(n).toString(),{theme:a,...c}=n;f(e,p.UPDATE_PARAMS,{urlParams:{pathname:s,search:r},appParams:c,hasProvider:i})}function K(e,n){const t=E(window,h.ACTIVATE,()=>{m(window,t),f(e,p.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return t}function Y(e,n=v){return E(window,h.UPDATE_HEIGHT,t=>{e.style.height=t.height?`${t.height+q}px`:n})}return o.TradeType=w,o.WIDGET_PALETTE_COLORS=L,o.WidgetMethodsEmit=h,o.WidgetMethodsListen=p,o.createCowSwapWidget=B,o.isCowSwapWidgetPalette=g,o.listenToMessageFromWindow=E,o.postMessageToWindow=f,o.stopListeningToMessageFromWindow=R,o.stopListeningWindowListener=m,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="cowSwapWidget";function u(e,n,t){const i={key:g,method:n,...typeof t=="object"?t:{}};e.postMessage(i,"*")}function p(e,n,t){const s=i=>{!C(i.data)||i.data.key!==g||i.data.method!==n||t(i.data)};return e.addEventListener("message",s),s}function C(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function _(e,n,t){e.removeEventListener("message",t)}function m(e,n){e.removeEventListener("message",n)}var d=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e))(d||{}),h=(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))(h||{}),w=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(w||{});const S=["connect","disconnect","close","chainChanged","accountsChanged"];class D{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)}}disconnect(){this.ethereumProvider=null,_(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():p(window,d.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),S.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:i}=n;if(!this.ethereumProvider||!t)return;(i==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(o=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:o}})).catch(o=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:o}}))}onProviderEvent(n,t){u(this.iframeWidow,h.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){u(this.iframeWidow,h.PROVIDER_RPC_RESPONSE,n)}}const l="_";function L(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=A(e),s=v(e);return n+"/#"+t+"?"+s}function A(e){const{chainId:n=1,sell:t,buy:s,tradeType:i=w.SWAP}=e,r=[(t==null?void 0:t.asset)||l,(s==null?void 0:s.asset)||l].map(encodeURIComponent).join("/");return`/${n}/widget/${i}/${r}`}function v(e){const{sell:n,buy:t,theme:s}=e,i=new URLSearchParams;return n!=null&&n.amount&&i.append("sellAmount",n.amount),t!=null&&t.amount&&i.append("buyAmount",t.amount),s&&i.append("theme",typeof s=="string"?s:s.baseTheme),i}class O{constructor(){this.subscriptions={}}on(n){const{event:t,handler:s}=n;this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(s)}off(n){const{event:t,handler:s}=n;this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(i=>i!==s))}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(t))}}class y{constructor(n,t=[]){this.contentWindow=n,this.eventEmitter=new O,this.listeners=[],this.updateListeners(t),this.widgetListener=p(this.contentWindow,d.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){m(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 V{constructor(n,t){this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=s=>{M(s.data)&&(U(s.data)?this.appWindow.parent.postMessage(s.data,"*"):b(s.data)&&this.iframeWidow.postMessage(s.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 U(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 b(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}const W="640px",F="450px",N=20;function H(e,n){const{params:t,provider:s,listeners:i}=n;let r=s;const o=q(t);e.innerHTML="",e.appendChild(o);const{contentWindow:c}=o;if(!c)throw console.error("Iframe does not contain a window",o),new Error("Iframe does not contain a window!");const f=[];f.push(k(c,t.appCode)),f.push(G(o,t.height));const P=new y(window,i);let E=R(c,null,r);o.addEventListener("load",()=>T(c,t,r));const I=new V(window,c);return{updateParams:a=>T(c,a,r),updateListeners:a=>P.updateListeners(a),updateProvider:a=>{r=a,E=R(c,E,a)},destroy:()=>{E.disconnect(),P.stopListeningIframe(),f.forEach(a=>window.removeEventListener("message",a)),I.stopListening(),e.removeChild(o)}}}function R(e,n,t){n&&n.disconnect();const s=n||new D(e);return t&&s.onConnect(t),s}function q(e){const{width:n=F,height:t=W}=e,s=document.createElement("iframe");return s.src=L(e),s.width=n,s.height=t,s.style.border="0",s}function T(e,n,t){const s=!!t,i=A(n),r=v(n).toString();u(e,h.UPDATE_PARAMS,{urlParams:{pathname:i,search:r},appParams:{...n},hasProvider:s})}function k(e,n){const t=p(window,d.ACTIVATE,()=>{m(window,t),u(e,h.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return t}function G(e,n=W){return p(window,d.UPDATE_HEIGHT,t=>{e.style.height=t.height?`${t.height+N}px`:n})}exports.TradeType=w;exports.WidgetMethodsEmit=d;exports.WidgetMethodsListen=h;exports.createCowSwapWidget=H;exports.listenToMessageFromWindow=p;exports.postMessageToWindow=u;exports.stopListeningToMessageFromWindow=_;exports.stopListeningWindowListener=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _="cowSwapWidget";function u(e,n,t){const i={key:_,method:n,...typeof t=="object"?t:{}};e.postMessage(i,"*")}function f(e,n,t){const s=i=>{!D(i.data)||i.data.key!==_||i.data.method!==n||t(i.data)};return e.addEventListener("message",s),s}function D(e){return typeof e=="object"&&e!==null&&"key"in e&&"method"in e&&typeof e.key=="string"&&typeof e.method=="string"}function A(e,n,t){e.removeEventListener("message",t)}function w(e,n){e.removeEventListener("message",n)}var h=(e=>(e.ACTIVATE="ACTIVATE",e.UPDATE_HEIGHT="UPDATE_HEIGHT",e.EMIT_COW_EVENT="EMIT_COW_EVENT",e.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",e))(h||{}),p=(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))(p||{}),l=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e))(l||{});const L=["primary","background","paper","text","danger","warning","alert","info","success"],O=["connect","disconnect","close","chainChanged","accountsChanged"];class V{constructor(n){this.iframeWidow=n,this.ethereumProvider=null,this.requestWaitingForConnection={},this.processRpcCallFromWindow=({rpcRequest:t})=>{if(!this.ethereumProvider){t.id&&(this.requestWaitingForConnection[t.id]=t);return}this.processRpcRequest(t)}}disconnect(){this.ethereumProvider=null,A(window,h.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow)}onConnect(n){this.ethereumProvider?this.disconnect():f(window,h.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=n,this.processPendingRequests(),O.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:i}=n;if(!this.ethereumProvider||!t)return;(i==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request({...n,id:t})).then(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:r}})).catch(r=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:r}}))}onProviderEvent(n,t){u(this.iframeWidow,p.PROVIDER_ON_EVENT,{event:n,params:t})}forwardRpcResponseToIframe(n){u(this.iframeWidow,p.PROVIDER_RPC_RESPONSE,n)}}function W(e){return!!(e&&typeof e=="object")}const T="_";function y(e){const n=typeof e.baseUrl=="string"?e.baseUrl:"https://swap.cow.fi",t=v(e);return n+"/#"+t+"?"+C(e)}function v(e){const{chainId:n=1,sell:t,buy:s,tradeType:i=l.SWAP}=e,o=[(t==null?void 0:t.asset)||T,(s==null?void 0:s.asset)||T].map(encodeURIComponent).join("/");return`/${n}/widget/${i}/${o}`}function C(e){const n=new URLSearchParams;return U(M(n,e),e)}function M(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 U(e,n){const t=n.theme;return t&&(W(t)?(e.append("palette",encodeURIComponent(JSON.stringify(t))),e.append("theme",t.baseTheme)):e.append("theme",t)),e}class b{constructor(){this.subscriptions={}}on(n){const{event:t,handler:s}=n;this.subscriptions[t]||(this.subscriptions[t]=[]),this.subscriptions[t].push(s)}off(n){const{event:t,handler:s}=n;this.subscriptions[t]&&(this.subscriptions[t]=this.subscriptions[t].filter(i=>i!==s))}emit(n,t){this.subscriptions[n]&&this.subscriptions[n].forEach(s=>s(t))}}class F{constructor(n,t=[]){this.contentWindow=n,this.eventEmitter=new b,this.listeners=[],this.updateListeners(t),this.widgetListener=f(this.contentWindow,h.EMIT_COW_EVENT,s=>this.eventEmitter.emit(s.event,s.payload))}stopListeningIframe(){w(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 N{constructor(n,t){this.appWindow=n,this.iframeWidow=t,this.forwardSdkMessage=s=>{H(s.data)&&(k(s.data)?this.appWindow.parent.postMessage(s.data,"*"):G(s.data)&&this.iframeWidow.postMessage(s.data,"*"))},this.startListening()}startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function H(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"}const I="640px",Q="450px",q=20;function x(e,n){const{params:t,provider:s,listeners:i}=n;let o=s,r=t;const a=B(t);e.innerHTML="",e.appendChild(a);const{contentWindow:d}=a;if(!d)throw console.error("Iframe does not contain a window",a),new Error("Iframe does not contain a window!");const E=[];E.push($(d,t.appCode)),E.push(K(a,t.height));const P=new F(window,i);let m=R(d,null,o);a.addEventListener("load",()=>g(d,r,o));const S=new N(window,d);return{updateParams:c=>{r=c,g(d,r,o)},updateListeners:c=>P.updateListeners(c),updateProvider:c=>{o=c,m=R(d,m,c)},destroy:()=>{m.disconnect(),P.stopListeningIframe(),E.forEach(c=>window.removeEventListener("message",c)),S.stopListening(),e.removeChild(a)}}}function R(e,n,t){n&&n.disconnect();const s=n||new V(e);return t&&s.onConnect(t),s}function B(e){const{width:n=Q,height:t=I}=e,s=document.createElement("iframe");return s.src=y(e),s.width=n,s.height=t,s.style.border="0",s}function g(e,n,t){const s=!!t,i=v(n),o=C(n).toString(),{theme:r,...a}=n;u(e,p.UPDATE_PARAMS,{urlParams:{pathname:i,search:o},appParams:a,hasProvider:s})}function $(e,n){const t=f(window,h.ACTIVATE,()=>{w(window,t),u(e,p.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0})});return t}function K(e,n=I){return f(window,h.UPDATE_HEIGHT,t=>{e.style.height=t.height?`${t.height+q}px`:n})}exports.TradeType=l;exports.WIDGET_PALETTE_COLORS=L;exports.WidgetMethodsEmit=h;exports.WidgetMethodsListen=p;exports.createCowSwapWidget=x;exports.isCowSwapWidgetPalette=W;exports.listenToMessageFromWindow=f;exports.postMessageToWindow=u;exports.stopListeningToMessageFromWindow=A;exports.stopListeningWindowListener=w;
package/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- const l = "cowSwapWidget";
1
+ const T = "cowSwapWidget";
2
2
  function u(e, n, t) {
3
3
  const i = {
4
- key: l,
4
+ key: T,
5
5
  method: n,
6
6
  ...typeof t == "object" ? t : {}
7
7
  };
@@ -11,24 +11,34 @@ function u(e, n, t) {
11
11
  // TODO: Change to CoW specific origin in production. https://github.com/cowprotocol/cowswap/issues/3828
12
12
  );
13
13
  }
14
- function p(e, n, t) {
14
+ function f(e, n, t) {
15
15
  const s = (i) => {
16
- !C(i.data) || i.data.key !== l || i.data.method !== n || t(i.data);
16
+ !W(i.data) || i.data.key !== T || i.data.method !== n || t(i.data);
17
17
  };
18
18
  return e.addEventListener("message", s), s;
19
19
  }
20
- function C(e) {
20
+ function W(e) {
21
21
  return typeof e == "object" && e !== null && "key" in e && "method" in e && typeof e.key == "string" && typeof e.method == "string";
22
22
  }
23
- function W(e, n, t) {
23
+ function S(e, n, t) {
24
24
  e.removeEventListener("message", t);
25
25
  }
26
- function T(e, n) {
26
+ function _(e, n) {
27
27
  e.removeEventListener("message", n);
28
28
  }
29
- var d = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.UPDATE_HEIGHT = "UPDATE_HEIGHT", e.EMIT_COW_EVENT = "EMIT_COW_EVENT", e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e))(d || {}), h = /* @__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))(h || {}), _ = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e))(_ || {});
30
- const S = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
31
- class D {
29
+ var h = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.UPDATE_HEIGHT = "UPDATE_HEIGHT", e.EMIT_COW_EVENT = "EMIT_COW_EVENT", e.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", e))(h || {}), p = /* @__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))(p || {}), g = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e))(g || {});
30
+ const $ = [
31
+ "primary",
32
+ "background",
33
+ "paper",
34
+ "text",
35
+ "danger",
36
+ "warning",
37
+ "alert",
38
+ "info",
39
+ "success"
40
+ ], D = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
41
+ class O {
32
42
  /**
33
43
  * Creates an instance of IframeRpcProviderBridge.
34
44
  * @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
@@ -47,14 +57,14 @@ class D {
47
57
  * Disconnects the JSON-RPC bridge from the Ethereum provider.
48
58
  */
49
59
  disconnect() {
50
- this.ethereumProvider = null, W(window, d.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
60
+ this.ethereumProvider = null, S(window, h.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
51
61
  }
52
62
  /**
53
63
  * Handles the 'connect' event and sets up event listeners for Ethereum provider events.
54
64
  * @param newProvider - The Ethereum provider to connect.
55
65
  */
56
66
  onConnect(n) {
57
- this.ethereumProvider ? this.disconnect() : p(window, d.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), this.ethereumProvider = n, this.processPendingRequests(), S.forEach((t) => {
67
+ this.ethereumProvider ? this.disconnect() : f(window, h.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), this.ethereumProvider = n, this.processPendingRequests(), D.forEach((t) => {
58
68
  n.on(t, (s) => this.onProviderEvent(t, s));
59
69
  });
60
70
  }
@@ -72,17 +82,17 @@ class D {
72
82
  if (!this.ethereumProvider || !t)
73
83
  return;
74
84
  (i === "enable" ? this.ethereumProvider.enable() : this.ethereumProvider.request({ ...n, id: t })).then(
75
- (o) => this.forwardRpcResponseToIframe({
76
- rpcResponse: { jsonrpc: s, id: t, result: o }
85
+ (r) => this.forwardRpcResponseToIframe({
86
+ rpcResponse: { jsonrpc: s, id: t, result: r }
77
87
  })
78
88
  ).catch(
79
- (o) => this.forwardRpcResponseToIframe({
80
- rpcResponse: { jsonrpc: s, id: t, error: o }
89
+ (r) => this.forwardRpcResponseToIframe({
90
+ rpcResponse: { jsonrpc: s, id: t, error: r }
81
91
  })
82
92
  );
83
93
  }
84
94
  onProviderEvent(n, t) {
85
- u(this.iframeWidow, h.PROVIDER_ON_EVENT, {
95
+ u(this.iframeWidow, p.PROVIDER_ON_EVENT, {
86
96
  event: n,
87
97
  params: t
88
98
  });
@@ -91,23 +101,34 @@ class D {
91
101
  * Forward a JSON-RPC message to the content window.
92
102
  */
93
103
  forwardRpcResponseToIframe(n) {
94
- u(this.iframeWidow, h.PROVIDER_RPC_RESPONSE, n);
104
+ u(this.iframeWidow, p.PROVIDER_RPC_RESPONSE, n);
95
105
  }
96
106
  }
97
- const w = "_";
98
- function O(e) {
99
- const n = typeof e.baseUrl == "string" ? e.baseUrl : "https://swap.cow.fi", t = g(e), s = A(e);
100
- return n + "/#" + t + "?" + s;
107
+ function L(e) {
108
+ return !!(e && typeof e == "object");
101
109
  }
102
- function g(e) {
103
- const { chainId: n = 1, sell: t, buy: s, tradeType: i = _.SWAP } = e, r = [(t == null ? void 0 : t.asset) || w, (s == null ? void 0 : s.asset) || w].map(encodeURIComponent).join("/");
104
- return `/${n}/widget/${i}/${r}`;
110
+ const P = "_";
111
+ function V(e) {
112
+ const n = typeof e.baseUrl == "string" ? e.baseUrl : "https://swap.cow.fi", t = A(e);
113
+ return n + "/#" + t + "?" + v(e);
105
114
  }
106
115
  function A(e) {
107
- const { sell: n, buy: t, theme: s } = e, i = new URLSearchParams();
108
- return n != null && n.amount && i.append("sellAmount", n.amount), t != null && t.amount && i.append("buyAmount", t.amount), s && i.append("theme", typeof s == "string" ? s : s.baseTheme), i;
116
+ const { chainId: n = 1, sell: t, buy: s, tradeType: i = g.SWAP } = e, o = [(t == null ? void 0 : t.asset) || P, (s == null ? void 0 : s.asset) || P].map(encodeURIComponent).join("/");
117
+ return `/${n}/widget/${i}/${o}`;
109
118
  }
110
- class L {
119
+ function v(e) {
120
+ const n = new URLSearchParams();
121
+ return y(U(n, e), e);
122
+ }
123
+ function U(e, n) {
124
+ const { sell: t, buy: s } = n;
125
+ return t != null && t.amount && e.append("sellAmount", t.amount), s != null && s.amount && e.append("buyAmount", s.amount), e;
126
+ }
127
+ function y(e, n) {
128
+ const t = n.theme;
129
+ return t && (L(t) ? (e.append("palette", encodeURIComponent(JSON.stringify(t))), e.append("theme", t.baseTheme)) : e.append("theme", t)), e;
130
+ }
131
+ class b {
111
132
  constructor() {
112
133
  this.subscriptions = {};
113
134
  }
@@ -123,16 +144,16 @@ class L {
123
144
  this.subscriptions[n] && this.subscriptions[n].forEach((s) => s(t));
124
145
  }
125
146
  }
126
- class V {
147
+ class N {
127
148
  constructor(n, t = []) {
128
- this.contentWindow = n, this.eventEmitter = new L(), this.listeners = [], this.updateListeners(t), this.widgetListener = p(
149
+ this.contentWindow = n, this.eventEmitter = new b(), this.listeners = [], this.updateListeners(t), this.widgetListener = f(
129
150
  this.contentWindow,
130
- d.EMIT_COW_EVENT,
151
+ h.EMIT_COW_EVENT,
131
152
  (s) => this.eventEmitter.emit(s.event, s.payload)
132
153
  );
133
154
  }
134
155
  stopListeningIframe() {
135
- T(this.contentWindow, this.widgetListener);
156
+ _(this.contentWindow, this.widgetListener);
136
157
  }
137
158
  updateListeners(n) {
138
159
  for (const t of this.listeners)
@@ -142,10 +163,10 @@ class V {
142
163
  this.eventEmitter.on(t);
143
164
  }
144
165
  }
145
- class y {
166
+ class M {
146
167
  constructor(n, t) {
147
168
  this.appWindow = n, this.iframeWidow = t, this.forwardSdkMessage = (s) => {
148
- U(s.data) && (M(s.data) ? this.appWindow.parent.postMessage(s.data, "*") : N(s.data) && this.iframeWidow.postMessage(s.data, "*"));
169
+ F(s.data) && (H(s.data) ? this.appWindow.parent.postMessage(s.data, "*") : k(s.data) && this.iframeWidow.postMessage(s.data, "*"));
149
170
  }, this.startListening();
150
171
  }
151
172
  startListening() {
@@ -155,83 +176,85 @@ class y {
155
176
  this.appWindow.removeEventListener("message", this.forwardSdkMessage);
156
177
  }
157
178
  }
158
- function U(e) {
179
+ function F(e) {
159
180
  return typeof e == "object" && e !== null && "id" in e && typeof e.id == "string";
160
181
  }
161
- function M(e) {
182
+ function H(e) {
162
183
  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;
163
184
  }
164
- function N(e) {
185
+ function k(e) {
165
186
  return "success" in e && typeof e.success == "boolean" && "version" in e && typeof e.version == "string";
166
187
  }
167
- const v = "640px", b = "450px", F = 20;
168
- function G(e, n) {
188
+ const I = "640px", G = "450px", Q = 20;
189
+ function K(e, n) {
169
190
  const { params: t, provider: s, listeners: i } = n;
170
- let r = s;
171
- const o = H(t);
172
- e.innerHTML = "", e.appendChild(o);
173
- const { contentWindow: c } = o;
174
- if (!c)
175
- throw console.error("Iframe does not contain a window", o), new Error("Iframe does not contain a window!");
176
- const f = [];
177
- f.push(q(c, t.appCode)), f.push(k(o, t.height));
178
- const m = new V(window, i);
179
- let E = P(c, null, r);
180
- o.addEventListener("load", () => R(c, t, r));
181
- const I = new y(window, c);
191
+ let o = s, r = t;
192
+ const a = x(t);
193
+ e.innerHTML = "", e.appendChild(a);
194
+ const { contentWindow: d } = a;
195
+ if (!d)
196
+ throw console.error("Iframe does not contain a window", a), new Error("Iframe does not contain a window!");
197
+ const E = [];
198
+ E.push(q(d, t.appCode)), E.push(B(a, t.height));
199
+ const w = new N(window, i);
200
+ let m = l(d, null, o);
201
+ a.addEventListener("load", () => R(d, r, o));
202
+ const C = new M(window, d);
182
203
  return {
183
- updateParams: (a) => R(c, a, r),
184
- updateListeners: (a) => m.updateListeners(a),
185
- updateProvider: (a) => {
186
- r = a, E = P(c, E, a);
204
+ updateParams: (c) => {
205
+ r = c, R(d, r, o);
206
+ },
207
+ updateListeners: (c) => w.updateListeners(c),
208
+ updateProvider: (c) => {
209
+ o = c, m = l(d, m, c);
187
210
  },
188
211
  destroy: () => {
189
- E.disconnect(), m.stopListeningIframe(), f.forEach((a) => window.removeEventListener("message", a)), I.stopListening(), e.removeChild(o);
212
+ m.disconnect(), w.stopListeningIframe(), E.forEach((c) => window.removeEventListener("message", c)), C.stopListening(), e.removeChild(a);
190
213
  }
191
214
  };
192
215
  }
193
- function P(e, n, t) {
216
+ function l(e, n, t) {
194
217
  n && n.disconnect();
195
- const s = n || new D(e);
218
+ const s = n || new O(e);
196
219
  return t && s.onConnect(t), s;
197
220
  }
198
- function H(e) {
199
- const { width: n = b, height: t = v } = e, s = document.createElement("iframe");
200
- return s.src = O(e), s.width = n, s.height = t, s.style.border = "0", s;
221
+ function x(e) {
222
+ const { width: n = G, height: t = I } = e, s = document.createElement("iframe");
223
+ return s.src = V(e), s.width = n, s.height = t, s.style.border = "0", s;
201
224
  }
202
225
  function R(e, n, t) {
203
- const s = !!t, i = g(n), r = A(n).toString();
204
- u(e, h.UPDATE_PARAMS, {
226
+ const s = !!t, i = A(n), o = v(n).toString(), { theme: r, ...a } = n;
227
+ u(e, p.UPDATE_PARAMS, {
205
228
  urlParams: {
206
229
  pathname: i,
207
- search: r
208
- },
209
- appParams: {
210
- ...n
230
+ search: o
211
231
  },
232
+ appParams: a,
212
233
  hasProvider: s
213
234
  });
214
235
  }
215
236
  function q(e, n) {
216
- const t = p(window, d.ACTIVATE, () => {
217
- T(window, t), u(e, h.UPDATE_APP_DATA, {
237
+ const t = f(window, h.ACTIVATE, () => {
238
+ _(window, t), u(e, p.UPDATE_APP_DATA, {
218
239
  metaData: n ? { appCode: n } : void 0
219
240
  });
220
241
  });
221
242
  return t;
222
243
  }
223
- function k(e, n = v) {
224
- return p(window, d.UPDATE_HEIGHT, (t) => {
225
- e.style.height = t.height ? `${t.height + F}px` : n;
244
+ function B(e, n = I) {
245
+ return f(window, h.UPDATE_HEIGHT, (t) => {
246
+ e.style.height = t.height ? `${t.height + Q}px` : n;
226
247
  });
227
248
  }
228
249
  export {
229
- _ as TradeType,
230
- d as WidgetMethodsEmit,
231
- h as WidgetMethodsListen,
232
- G as createCowSwapWidget,
233
- p as listenToMessageFromWindow,
250
+ g as TradeType,
251
+ $ as WIDGET_PALETTE_COLORS,
252
+ h as WidgetMethodsEmit,
253
+ p as WidgetMethodsListen,
254
+ K as createCowSwapWidget,
255
+ L as isCowSwapWidgetPalette,
256
+ f as listenToMessageFromWindow,
234
257
  u as postMessageToWindow,
235
- W as stopListeningToMessageFromWindow,
236
- T as stopListeningWindowListener
258
+ S as stopListeningToMessageFromWindow,
259
+ _ as stopListeningWindowListener
237
260
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-lib",
3
- "version": "0.8.0",
3
+ "version": "0.9.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,6 +21,6 @@
21
21
  "widget-lib"
22
22
  ],
23
23
  "dependencies": {
24
- "@cowprotocol/events": "^1.1.0"
24
+ "@cowprotocol/events": "^1.2.0"
25
25
  }
26
26
  }
@@ -0,0 +1,2 @@
1
+ import { CowSwapTheme, CowSwapWidgetPalette } from './types';
2
+ export declare function isCowSwapWidgetPalette(palette: CowSwapTheme | CowSwapWidgetPalette | undefined): palette is CowSwapWidgetPalette;
package/types.d.ts CHANGED
@@ -93,18 +93,14 @@ export type TokenInfo = {
93
93
  symbol: string;
94
94
  logoURI?: string;
95
95
  };
96
- export interface CowSwapWidgetPalette {
96
+ export declare const WIDGET_PALETTE_COLORS: readonly ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"];
97
+ export type CowSwapWidgetPaletteColors = (typeof WIDGET_PALETTE_COLORS)[number];
98
+ export type CowSwapWidgetPaletteParams = {
99
+ [K in CowSwapWidgetPaletteColors]: string;
100
+ };
101
+ export type CowSwapWidgetPalette = {
97
102
  baseTheme: CowSwapTheme;
98
- primary: string;
99
- background: string;
100
- paper: string;
101
- text: string;
102
- danger: string;
103
- warning: string;
104
- alert: string;
105
- info: string;
106
- success: string;
107
- }
103
+ } & CowSwapWidgetPaletteParams;
108
104
  export interface CowSwapWidgetSounds {
109
105
  /**
110
106
  * The sound to play when the order is executed. Defaults to world wide famous CoW Swap moooooooooo!
@@ -254,12 +250,13 @@ export interface WidgetMethodsListenPayloadMap {
254
250
  }
255
251
  export type WidgetMethodsEmitPayloads = WidgetMethodsEmitPayloadMap[WidgetMethodsEmit];
256
252
  export type WidgetMethodsListenPayloads = WidgetMethodsListenPayloadMap[WidgetMethodsListen];
253
+ export type CowSwapWidgetAppParams = Omit<CowSwapWidgetParams, 'theme'>;
257
254
  export interface UpdateParamsPayload {
258
255
  urlParams: {
259
256
  pathname: string;
260
257
  search: string;
261
258
  };
262
- appParams: CowSwapWidgetParams;
259
+ appParams: CowSwapWidgetAppParams;
263
260
  hasProvider: boolean;
264
261
  }
265
262
  export interface UpdateAppDataPayload {
package/urlUtils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { CowSwapWidgetParams } from './types';
2
2
  export declare function buildWidgetUrl(params: Partial<CowSwapWidgetParams>): string;
3
3
  export declare function buildWidgetPath(params: Partial<CowSwapWidgetParams>): string;
4
- export declare function buildTradeAmountsQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams;
4
+ export declare function buildWidgetUrlQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams;