@cowprotocol/widget-lib 4.4.0 → 4.4.2

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.
@@ -1,8 +1,12 @@
1
1
  export declare class IframeSafeSdkBridge {
2
2
  private appWindow;
3
- private iframeWidow;
3
+ private iframeWindow;
4
+ private iframeOrigin;
5
+ private parentOrigin;
4
6
  forwardSdkMessage: (event: MessageEvent<unknown>) => void;
5
- constructor(appWindow: Window, iframeWidow: Window);
7
+ constructor(appWindow: Window, iframeWindow: Window, iframeOrigin: string, parentOrigin: string | null);
6
8
  private startListening;
7
9
  stopListening(): void;
10
+ private forwardRequest;
11
+ private forwardResponse;
8
12
  }
@@ -11,6 +11,12 @@ export declare const DEFAULT_WIDGET_PARAMS: {
11
11
  * - allow-forms: trade inputs and similar controls.
12
12
  * - allow-popups + allow-popups-to-escape-sandbox: wallet connect / WalletConnect windows.
13
13
  */
14
+ /**
15
+ * Iframe sandbox allowlist for hosts that opt out of opening widget popups.
16
+ * Omitting allow-popups makes `disableWindowOpen` browser-enforced instead of
17
+ * only disabling the parent-window relay.
18
+ */
19
+ export declare const WIDGET_IFRAME_SANDBOX_WITHOUT_POPUPS = "allow-scripts allow-same-origin allow-forms";
14
20
  export declare const WIDGET_IFRAME_SANDBOX = "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox";
15
21
  /** Limits referrer leakage when the widget is embedded on third-party origins. */
16
22
  export declare const WIDGET_IFRAME_REFERRER_POLICY = "strict-origin-when-cross-origin";
@@ -1,5 +1,5 @@
1
1
  import { SupportedChainId } from '@cowprotocol/cow-sdk';
2
2
  import { FlexibleConfig, PerNetworkConfig, PerTradeTypeConfig, TradeType } from './types';
3
- export declare function resolveFlexibleConfig<T>(config: FlexibleConfig<T>, chainId: SupportedChainId, tradeType: TradeType): T | undefined;
4
3
  export declare function isPerTradeTypeConfig<T>(config: FlexibleConfig<T>): config is PerTradeTypeConfig<T>;
4
+ export declare function resolveFlexibleConfig<T>(config: FlexibleConfig<T>, chainId: SupportedChainId, tradeType: TradeType): T | undefined;
5
5
  export declare function isPerNetworkConfig<T>(config: FlexibleConfig<T>): config is PerNetworkConfig<T>;
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@cowprotocol/iframe-transport"),oe=require("@cowprotocol/events"),re=new Set(["wc:","metamask:","imtokenv2:","trustassetapp:","okex:","ledgerlive:","rainbow:","argent:","exodus:","zerion:","okxwallet:","uniswap:","robinhood-wallet:","krakenwallet:","bitpay:","oneinch:","safe:","backpack:","tangem:","mathwallet:","keplrwallet:","coin98:","tpoutside:","bncus:","bnc:"]),ie=new Set(["http:","https:"]);function se(e){try{const t=new URL(e).protocol;return ie.has(t)||re.has(t)}catch{return!1}}function ae(e,t){if(t){e.removeAttribute("style");for(const n of Object.keys(t)){const o=n,r=t[o];if(r==null||typeof r!="string"&&typeof r!="number")continue;const i=`${r}`;e.style[o]=i}}}const K="cowswap-widget-iframe",le="cowswap-widget",de={appCode:""},Y="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",Q="strict-origin-when-cross-origin",z="clipboard-read; clipboard-write";var w=(e=>(e.ACTIVATE="ACTIVATE",e.READY="READY",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.PROCESS_HOOK="PROCESS_HOOK",e))(w||{}),T=(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.HOOK_RESULT="HOOK_RESULT",e))(T||{}),_=(e=>(e.ON_BEFORE_APPROVAL="ON_BEFORE_APPROVAL",e.ON_BEFORE_TRADE="ON_BEFORE_TRADE",e.ON_BEFORE_WRAP_UNWRAP="ON_BEFORE_WRAP_UNWRAP",e.ON_BEFORE_ORDER_CANCEL="ON_BEFORE_ORDER_CANCEL",e.ON_BEFORE_ORDERS_CANCEL="ON_BEFORE_ORDERS_CANCEL",e))(_||{}),L=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(L||{});const ce=["primary","background","paper","text","danger","warning","alert","info","success"],p=new j.IframeTransport("cowSwapWidget");class ue{constructor(t,n,o,r=[]){this.contentWindow=t,this.updateListeners(r),this.widgetListener=p.listenToMessageFromWindow(this.contentWindow,o,w.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload),n)}eventEmitter=new oe.SimpleCowEventEmitter;listeners=[];widgetListener;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 pe{constructor(t,n){this.appWindow=t,this.iframeWidow=n,this.forwardSdkMessage=o=>{fe(o.data)&&(typeof window<"u"&&o.origin===window.location.origin||(Ee(o.data)?this.appWindow.parent.postMessage(o.data,"*"):we(o.data)&&this.iframeWidow.postMessage(o.data,"*")))},this.startListening()}forwardSdkMessage;startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}}function fe(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function Ee(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 we(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function he(e="Default",t="#1c5dbf",...n){console.debug(`%c [COW][${e}]`,`font-weight: bold; color: ${t}`,...n)}function _e(...e){process.env.NODE_ENV!=="test"&&he("Widget","#47aba8",...e)}function D(e){return!!(e&&typeof e=="object")}const X="https://swap.cow.fi",x="_",ge="CoW Swap widget: invalid baseUrl.",J=!1;function Re(e){return e==="localhost"||e==="127.0.0.1"||e==="::1"||e.endsWith(".localhost")}function v(e,t){const n=`${ge} ${e}`;if(t)throw new Error(n);return console.error("[CoW Widget]",n),X}function Z(e,t=J){const n=typeof e=="string"?e.trim():"";if(!n)return X;let o;try{o=new URL(n)}catch{return v(`Not a valid URL: ${JSON.stringify(n)}`,t)}if(o.username||o.password)return v("Userinfo (username/password) in URL is not allowed.",t);const r=o.protocol==="https:",i=o.protocol==="http:"&&Re(o.hostname);if(!r&&!i)return v(`Use https, or http only on localhost / 127.0.0.1 / ::1 / *.localhost (got ${o.protocol}//${o.hostname}).`,t);const f=o.pathname==="/"||o.pathname===""?"":o.pathname.replace(/\/+$/,"");return`${o.origin}${f}`}function me(e){const t=Z(e.baseUrl),n=q(e);return t+"/#"+n+"?"+ee(e)}function q(e){const{chainId:t=1,sell:n,buy:o,tradeType:r=L.SWAP}=e,i=[n?.asset||x,o?.asset||x].map(encodeURIComponent).join("/");return`/${t}/widget/${r}/${i}`}function ee(e){const t=new URLSearchParams;return Ae(ye(Te(Se(Oe(t,e),e),e),e),e)}function Oe(e,t){const{sell:n,buy:o}=t;return n?.amount&&e.append("sellAmount",n.amount),o?.amount&&e.append("buyAmount",o.amount),e}function Se(e,t){const n=t.theme;return n?(D(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 Te(e,t){return t.targetChainId&&e.append("targetChainId",t.targetChainId.toString()),e}function ye(e,t){return t.locale&&e.append("lng",t.locale),e}function Ae(e,t){return Le(t.hooks)?e.append("hooksEnabled","true"):e.delete("hooksEnabled"),e}function Le(e){return!!e&&Object.values(e).some(Boolean)}const Ce=3e4,h="cow-widget-loading-error",B=`data-${h}`;function Ie(e,t,n,o,r){const i=t.src;let f=!1,E=null;function c(){r?.(),t.style.display="none",Pe();const l=document.createElement("div"),s=document.createElement("button"),d=document.createElement("p");s.innerText="Reload",s.addEventListener("click",()=>{e.removeChild(l),o(!0),t.src="about:blank",t.style.display="",setTimeout(()=>{t.src=i,n()},100)}),d.innerText="Couldn't load the page. Please, try again later",l.classList.add(h),l.appendChild(d),l.appendChild(s),e.appendChild(l)}return t.addEventListener("error",l=>{f||(console.error("Could not load iframe",l),c())}),E=window.setTimeout(()=>{f||c()},Ce),{onWidgetReady(){E&&clearTimeout(E);const l=document.getElementsByClassName(h)[0];l&&e.removeChild(l)},cancelWidgetLoading(){f=!0}}}let m=null;function Pe(){if(!(typeof document>"u")){if(ve()){m||(m=new CSSStyleSheet,m.replaceSync(k)),document.adoptedStyleSheets.includes(m)||(document.adoptedStyleSheets=[...document.adoptedStyleSheets,m]);return}if(!document.head.querySelector(`style[${B}]`)){const e=document.createElement("style");e.setAttribute(B,""),e.textContent=k,document.head.appendChild(e)}}}function ve(){return typeof document<"u"&&"adoptedStyleSheets"in Document.prototype&&typeof CSSStyleSheet=="function"&&typeof CSSStyleSheet.prototype.replaceSync=="function"}const k=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("@cowprotocol/iframe-transport"),se=require("@cowprotocol/events"),ae=new Set(["wc:","metamask:","imtokenv2:","trustassetapp:","okex:","ledgerlive:","rainbow:","argent:","exodus:","zerion:","okxwallet:","uniswap:","robinhood-wallet:","krakenwallet:","bitpay:","oneinch:","safe:","backpack:","tangem:","mathwallet:","keplrwallet:","coin98:","tpoutside:","bncus:","bnc:"]),de=new Set(["http:","https:"]);function le(e){try{const t=new URL(e).protocol;return de.has(t)||ae.has(t)}catch{return!1}}function ce(e,t){if(t){e.removeAttribute("style");for(const n of Object.keys(t)){const o=n,r=t[o];if(r==null||typeof r!="string"&&typeof r!="number")continue;const i=`${r}`;e.style[o]=i}}}const Y="cowswap-widget-iframe",ue="cowswap-widget",pe={appCode:""},Q="allow-scripts allow-same-origin allow-forms",z=`${Q} allow-popups allow-popups-to-escape-sandbox`,X="strict-origin-when-cross-origin",J="clipboard-read; clipboard-write";var I=(e=>(e.SWAP="swap",e.LIMIT="limit",e.ADVANCED="advanced",e.YIELD="yield",e))(I||{}),g=(e=>(e.ON_BEFORE_APPROVAL="ON_BEFORE_APPROVAL",e.ON_BEFORE_TRADE="ON_BEFORE_TRADE",e.ON_BEFORE_WRAP_UNWRAP="ON_BEFORE_WRAP_UNWRAP",e.ON_BEFORE_ORDER_CANCEL="ON_BEFORE_ORDER_CANCEL",e.ON_BEFORE_ORDERS_CANCEL="ON_BEFORE_ORDERS_CANCEL",e))(g||{}),w=(e=>(e.ACTIVATE="ACTIVATE",e.READY="READY",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.PROCESS_HOOK="PROCESS_HOOK",e))(w||{}),T=(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.HOOK_RESULT="HOOK_RESULT",e))(T||{});const fe=["primary","background","paper","text","danger","warning","alert","info","success"],p=new v.IframeTransport("cowSwapWidget");class Ee{constructor(t,n,o,r=[]){this.contentWindow=t,this.updateListeners(r),this.widgetListener=p.listenToMessageFromWindow(this.contentWindow,o,w.EMIT_COW_EVENT,i=>this.eventEmitter.emit(i.event,i.payload),n)}eventEmitter=new se.SimpleCowEventEmitter;listeners=[];widgetListener;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 we{constructor(t,n,o,r){this.appWindow=t,this.iframeWindow=n,this.iframeOrigin=o,this.parentOrigin=r,this.forwardSdkMessage=i=>{he(i.data)&&(ge(i.data)?this.forwardRequest(i,i.data):_e(i.data)&&this.forwardResponse(i,i.data))},this.startListening()}forwardSdkMessage;startListening(){this.appWindow.addEventListener("message",this.forwardSdkMessage)}stopListening(){this.appWindow.removeEventListener("message",this.forwardSdkMessage)}forwardRequest(t,n){!this.parentOrigin||this.appWindow.parent===this.appWindow||t.source!==this.iframeWindow||t.origin!==this.iframeOrigin||this.appWindow.parent.postMessage(n,this.parentOrigin)}forwardResponse(t,n){this.appWindow.parent!==this.appWindow&&(t.source!==this.appWindow.parent||t.origin!==this.parentOrigin||this.iframeWindow.postMessage(n,this.iframeOrigin))}}function he(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function ge(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 _e(e){return"success"in e&&typeof e.success=="boolean"&&"version"in e&&typeof e.version=="string"}function Oe(...e){process.env.NODE_ENV!=="test"&&Re("Widget","#47aba8",...e)}function Re(e="Default",t="#1c5dbf",...n){console.debug(`%c [COW][${e}]`,`font-weight: bold; color: ${t}`,...n)}function D(e){return!!(e&&typeof e=="object")}const Z="https://swap.cow.fi",k="_",me="CoW Swap widget: invalid baseUrl.",q=!1;function ee(e){const{chainId:t=1,sell:n,buy:o,tradeType:r=I.SWAP}=e,i=[n?.asset||k,o?.asset||k].map(encodeURIComponent).join("/");return`/${t}/widget/${r}/${i}`}function te(e){const t=oe(e.baseUrl),n=ee(e);return t+"/#"+n+"?"+ne(e)}function ne(e){const t=new URLSearchParams;return Se(Te(ye(Ae(Ie(t,e),e),e),e),e)}function oe(e,t=q){const n=typeof e=="string"?e.trim():"";if(!n)return Z;let o;try{o=new URL(n)}catch{return W(`Not a valid URL: ${JSON.stringify(n)}`,t)}if(o.username||o.password)return W("Userinfo (username/password) in URL is not allowed.",t);const r=o.protocol==="https:",i=o.protocol==="http:"&&Ce(o.hostname);if(!r&&!i)return W(`Use https, or http only on localhost / 127.0.0.1 / ::1 / *.localhost (got ${o.protocol}//${o.hostname}).`,t);const f=o.pathname==="/"||o.pathname===""?"":o.pathname.replace(/\/+$/,"");return`${o.origin}${f}`}function Se(e,t){return Le(t.hooks)?e.append("hooksEnabled","true"):e.delete("hooksEnabled"),e}function Te(e,t){return t.locale&&e.append("lng",t.locale),e}function ye(e,t){return t.targetChainId&&e.append("targetChainId",t.targetChainId.toString()),e}function Ae(e,t){const n=t.theme;return n?(D(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){const{sell:n,buy:o}=t;return n?.amount&&e.append("sellAmount",n.amount),o?.amount&&e.append("buyAmount",o.amount),e}function W(e,t){const n=`${me} ${e}`;if(t)throw new Error(n);return console.error("[CoW Widget]",n),Z}function Le(e){return!!e&&Object.values(e).some(Boolean)}function Ce(e){return e==="localhost"||e==="127.0.0.1"||e==="::1"||e.endsWith(".localhost")}const Pe=3e4,h="cow-widget-loading-error",M=`data-${h}`;function We(e,t,n,o,r){const i=t.src;let f=!1,E=null;function d(){r?.(),t.style.display="none",be();const c=document.createElement("div"),s=document.createElement("button"),l=document.createElement("p");s.innerText="Reload",s.addEventListener("click",()=>{e.removeChild(c),o(!0),t.src="about:blank",t.style.display="",setTimeout(()=>{t.src=i,n()},100)}),l.innerText="Couldn't load the page. Please, try again later",c.classList.add(h),c.appendChild(l),c.appendChild(s),e.appendChild(c)}return t.addEventListener("error",c=>{f||(console.error("Could not load iframe",c),d())}),E=window.setTimeout(()=>{f||d()},Pe),{onWidgetReady(){E&&clearTimeout(E);const c=document.getElementsByClassName(h)[0];c&&e.removeChild(c)},cancelWidgetLoading(){f=!0}}}let R=null;function be(){if(!(typeof document>"u")){if(ve()){R||(R=new CSSStyleSheet,R.replaceSync(V)),document.adoptedStyleSheets.includes(R)||(document.adoptedStyleSheets=[...document.adoptedStyleSheets,R]);return}if(!document.head.querySelector(`style[${M}]`)){const e=document.createElement("style");e.setAttribute(M,""),e.textContent=V,document.head.appendChild(e)}}}function ve(){return typeof document<"u"&&"adoptedStyleSheets"in Document.prototype&&typeof CSSStyleSheet=="function"&&typeof CSSStyleSheet.prototype.replaceSync=="function"}const V=`
2
2
  .${h} {
3
3
  display: flex;
4
4
  flex-direction: column;
@@ -41,4 +41,4 @@
41
41
  .${h} button:not(:disabled):hover {
42
42
  background: #d32f2f;
43
43
  color: #fff5f5;
44
- }`,We={iframe:null,updateParams:()=>{},updateListeners:()=>{},updateProvider:()=>{},destroy:()=>{}};function De(e,t){const{params:n,provider:o,listeners:r,onReady:i,enableSafeSdkBridge:f=!0}=t;let E=o,c=M(n),l="";if(typeof window>"u")return We;const s=be(c),d=Ne(s);_e("Resolved trusted iframe origin",{iframeOrigin:d});const y=[];e.innerHTML="",e.appendChild(s),$(e,c);let a=null,C=()=>{},I=()=>{},b=()=>{},P=null,A=null,N=null,U=[],R=null;function H(){if(a=s.contentWindow,!a)throw console.error("Iframe does not contain a window",s),new Error("Iframe does not contain a window!");y.push(He(a,d,()=>{i?.(),te()})),y.push(Ue(a,d,c.appCode)),U=ke(e,s,d,ne=>{l=ne});let u=null;C=()=>{a&&(u&&window.removeEventListener("message",u),!c.disableWindowOpen&&(u=Fe(d,a),y.push(u)))},I=()=>{a&&(R&&window.removeEventListener("message",R),R=$e(a,d,c.hooks))},C(),I(),P=new ue(window,d,a,r),A=V(a,d,null,E),s.addEventListener("load",()=>{a&&G(a,d,c,E)}),N=f?new pe(window,a):null;const g=Ie(e,s,H,F,t.onLoadingError);b=g.cancelWidgetLoading;const te=g.onWidgetReady}function F(u=!1){A?.disconnect(),P?.stopListeningIframe(),U.forEach(g=>window.removeEventListener("message",g)),y.forEach(g=>window.removeEventListener("message",g)),R&&window.removeEventListener("message",R),N?.stopListening(),!u&&s&&s.parentNode===e&&e.removeChild(s),b?.()}return H(),{iframe:s,updateParams:u=>{a&&(c=M(u),$(e,c,l),G(a,d,c,E),C(),I())},updateListeners:u=>P?.updateListeners(u),updateProvider:u=>{a&&(E=u,A=V(a,d,A,u))},destroy:F}}function M(e){const t={...de,...e};if(typeof t.appCode!="string"||t.appCode.trim().length===0)throw new Error("Required param `appCode` is missing");return t}function V(e,t,n,o){n&&n.disconnect();const r=n||new j.IframeRpcProviderBridge(e,t);return o&&r.onConnect(o),r}function be(e){const t=document.createElement("iframe");return t.id=K,t.src=me(e),t.setAttribute("sandbox",Y),t.referrerPolicy=Q,t.allow=z,t.style.width="100%",t.style.height="100%",t.style.border="0",t.style.display="block",t}function $(e,t,n){ae(e,t.rootStyle),[{name:"params.width",value:t.width,replacementName:"rootStyle.width",replacementValue:t.rootStyle?.width,applyDeprecated:()=>t.width?e.style.width=t.width:void 0},{name:"params.height",value:t.height,replacementName:"rootStyle.height",replacementValue:t.rootStyle?.height,applyDeprecated:()=>t.height?e.style.height=t.height:void 0},{name:"params.maxHeight",value:t.maxHeight,replacementName:"rootStyle.maxHeight",replacementValue:t.rootStyle?.maxHeight,applyDeprecated:()=>t.maxHeight?e.style.maxHeight=`${t.maxHeight}px`:void 0},{name:"params.theme.boxShadow",value:D(t.theme)?t.theme.boxShadow:void 0,replacementName:"cardStyle.boxShadow",replacementValue:t.cardStyle?.boxShadow,applyDeprecated:()=>{}}].filter(r=>!!r.value).forEach(r=>{r.replacementValue?console.warn(`Both ${r.name} and ${r.replacementName} have been set. ${r.name} will be ignored.`):(console.warn(`${r.name} is deprecated. Use ${r.replacementName} instead.`),r.applyDeprecated())}),n&&e.style.setProperty(W,n)}function Ne(e){return new URL(e.src).origin}function G(e,t,n,o){const r=!!o,i=q(n),f=ee(n).toString(),{theme:E,hooks:c,rootStyle:l,...s}=n;p.postMessageToWindow(e,T.UPDATE_PARAMS,{urlParams:{pathname:i,search:f},appParams:s,hasProvider:r},t)}function Ue(e,t,n){return p.listenToMessageFromWindow(window,e,w.ACTIVATE,()=>{p.postMessageToWindow(e,T.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0},t)},t)}function He(e,t,n){let o=!1;return p.listenToMessageFromWindow(window,e,w.READY,()=>{o||(o=!0,n())},t)}function Fe(e,t){return p.listenToMessageFromWindow(window,t,w.INTERCEPT_WINDOW_OPEN,({href:n,rel:o,target:r})=>{const i=xe(n.toString(),e);i&&se(i)&&window.open(i,r,o)},e)}function xe(e,t){const n=e.trim();if(!n)return null;try{return new URL(n,t).toString()}catch{return null}}const W="--dynamicHeight",Be=0;function ke(e,t,n,o){return t.contentWindow?[p.listenToMessageFromWindow(window,t.contentWindow,w.UPDATE_HEIGHT,r=>{const i=`${(r?.height??0)+Be}px`;e.style.setProperty(W,i),o(i)},n),p.listenToMessageFromWindow(window,t.contentWindow,w.SET_FULL_HEIGHT,()=>{e.style.setProperty(W,"100dvh"),o("100dvh")},n)]:[]}const Me={[_.ON_BEFORE_APPROVAL]:(e,t)=>t?.onBeforeApproval?t.onBeforeApproval(e):!0,[_.ON_BEFORE_TRADE]:(e,t)=>t?.onBeforeTrade?t.onBeforeTrade(e):!0,[_.ON_BEFORE_WRAP_UNWRAP]:(e,t)=>t?.onBeforeWrapOrUnwrap?t.onBeforeWrapOrUnwrap(e):!0,[_.ON_BEFORE_ORDER_CANCEL]:(e,t)=>t?.onBeforeOrderCancel?t.onBeforeOrderCancel(e):!0,[_.ON_BEFORE_ORDERS_CANCEL]:(e,t)=>t?.onBeforeOrdersCancel?t.onBeforeOrdersCancel(e):!0};function Ve(e,t){return Me[e.event](e.payload,t)}function $e(e,t,n){return p.listenToMessageFromWindow(window,e,w.PROCESS_HOOK,async o=>{let r=!1;try{r=await Ve(o,n)}catch{}p.postMessageToWindow(e,T.HOOK_RESULT,{id:o.id,result:r},t)},t)}const Ge=Object.values(L);function je(e,t,n){if(O(e)){const o=e[n];return S(o)?o[t]:o}if(S(e)){const o=e[t];return O(o)?o[n]:o}return e}function O(e){return typeof e!="object"?!1:Object.keys(e).every(t=>Ge.includes(t))}const Ke=/^\d+$/;function S(e){return typeof e!="object"?!1:Object.keys(e).every(t=>Ke.test(t))}function Ye(e){return O(e)?Object.values(e).flatMap(t=>S(t)?Object.values(t):[t]):S(e)?Object.values(e).flatMap(t=>O(t)?Object.values(t):[t]):[e]}exports.SHOULD_THROW_IF_INVALID_URL=J;exports.TradeType=L;exports.WIDGET_CONTAINER_ID=le;exports.WIDGET_IFRAME_ALLOW=z;exports.WIDGET_IFRAME_ID=K;exports.WIDGET_IFRAME_REFERRER_POLICY=Q;exports.WIDGET_IFRAME_SANDBOX=Y;exports.WIDGET_PALETTE_COLORS=ce;exports.WidgetHookEvents=_;exports.WidgetMethodsEmit=w;exports.WidgetMethodsListen=T;exports.createCowSwapWidget=De;exports.isCowSwapWidgetPalette=D;exports.isPerNetworkConfig=S;exports.isPerTradeTypeConfig=O;exports.resolveFlexibleConfig=je;exports.resolveFlexibleConfigValues=Ye;exports.sanitizeWidgetBaseUrl=Z;exports.widgetIframeTransport=p;
44
+ }`,De={iframe:null,updateParams:()=>{},updateListeners:()=>{},updateProvider:()=>{},destroy:()=>{}};function Ne(e,t){const{params:n,provider:o,listeners:r,onReady:i,enableSafeSdkBridge:f=!0}=t;let E=o,d=G(n),c="";if(typeof window>"u")return De;const s=Ue(d),l=He(s);Oe("Resolved trusted iframe origin",{iframeOrigin:l});const y=[];e.innerHTML="",e.appendChild(s),$(e,d);let a=null,L=()=>{},C=()=>{},U=()=>{},P=null,A=null,x=null,H=[],O=null;function F(){if(a=s.contentWindow,!a)throw console.error("Iframe does not contain a window",s),new Error("Iframe does not contain a window!");y.push(Be(a,l,()=>{i?.(),re()})),y.push($e(a,l,d.appCode)),H=je(e,s,l,ie=>{c=ie});let u=null;L=()=>{a&&(u&&window.removeEventListener("message",u),!d.disableWindowOpen&&(u=Fe(l,a),y.push(u)))},C=()=>{a&&(O&&window.removeEventListener("message",O),O=Qe(a,l,d.hooks))},L(),C(),P=new Ee(window,l,a,r),A=K(a,l,null,E),s.addEventListener("load",()=>{a&&j(a,l,d,E)}),x=xe(f,window,a,l);const _=We(e,s,F,B,t.onLoadingError);U=_.cancelWidgetLoading;const re=_.onWidgetReady}function B(u=!1){A?.disconnect(),P?.stopListeningIframe(),H.forEach(_=>window.removeEventListener("message",_)),y.forEach(_=>window.removeEventListener("message",_)),O&&window.removeEventListener("message",O),x?.stopListening(),!u&&s&&s.parentNode===e&&e.removeChild(s),U?.()}return F(),{iframe:s,updateParams:u=>{a&&(d=G(u),$(e,d,c),Me(s,d)?ke(s,d):j(a,l,d,E),L(),C())},updateListeners:u=>P?.updateListeners(u),updateProvider:u=>{a&&(E=u,A=K(a,l,A,u))},destroy:B}}function $(e,t,n){ce(e,t.rootStyle),[{name:"params.width",value:t.width,replacementName:"rootStyle.width",replacementValue:t.rootStyle?.width,applyDeprecated:()=>t.width?e.style.width=t.width:void 0},{name:"params.height",value:t.height,replacementName:"rootStyle.height",replacementValue:t.rootStyle?.height,applyDeprecated:()=>t.height?e.style.height=t.height:void 0},{name:"params.maxHeight",value:t.maxHeight,replacementName:"rootStyle.maxHeight",replacementValue:t.rootStyle?.maxHeight,applyDeprecated:()=>t.maxHeight?e.style.maxHeight=`${t.maxHeight}px`:void 0},{name:"params.theme.boxShadow",value:D(t.theme)?t.theme.boxShadow:void 0,replacementName:"cardStyle.boxShadow",replacementValue:t.cardStyle?.boxShadow,applyDeprecated:()=>{}}].filter(r=>!!r.value).forEach(r=>{r.replacementValue?console.warn(`Both ${r.name} and ${r.replacementName} have been set. ${r.name} will be ignored.`):(console.warn(`${r.name} is deprecated. Use ${r.replacementName} instead.`),r.applyDeprecated())}),n&&e.style.setProperty(b,n)}function Ue(e){const t=document.createElement("iframe");return t.id=Y,t.src=te(e),t.setAttribute("sandbox",N(e)),t.referrerPolicy=X,t.allow=J,t.style.width="100%",t.style.height="100%",t.style.border="0",t.style.display="block",t}function xe(e,t,n,o){return e?new we(t,n,o,v.getParentOrigin()||null):null}function He(e){return new URL(e.src).origin}function N(e){return e.disableWindowOpen?Q:z}function Fe(e,t){return p.listenToMessageFromWindow(window,t,w.INTERCEPT_WINDOW_OPEN,({href:n,rel:o,target:r})=>{const i=Ve(n.toString(),e);i&&le(i)&&window.open(i,r,o)},e)}function Be(e,t,n){let o=!1;return p.listenToMessageFromWindow(window,e,w.READY,()=>{o||(o=!0,n())},t)}function ke(e,t){const n=N(t),o=te(t);e.addEventListener("load",()=>{e.src=o},{once:!0}),e.setAttribute("sandbox",n),e.src="about:blank"}function Me(e,t){const n=N(t);return e.getAttribute("sandbox")!==n}function G(e){const t={...pe,...e};if(typeof t.appCode!="string"||t.appCode.trim().length===0)throw new Error("Required param `appCode` is missing");if(t.disableWindowOpen&&t.standaloneMode!==!1)throw new Error("`disableWindowOpen: true` requires `standaloneMode: false`");return t}function Ve(e,t){const n=e.trim();if(!n)return null;try{return new URL(n,t).toString()}catch{return null}}function $e(e,t,n){return p.listenToMessageFromWindow(window,e,w.ACTIVATE,()=>{p.postMessageToWindow(e,T.UPDATE_APP_DATA,{metaData:n?{appCode:n}:void 0},t)},t)}function j(e,t,n,o){const r=!!o,i=ee(n),f=ne(n).toString(),{theme:E,hooks:d,rootStyle:c,...s}=n;p.postMessageToWindow(e,T.UPDATE_PARAMS,{urlParams:{pathname:i,search:f},appParams:s,hasProvider:r},t)}function K(e,t,n,o){n&&n.disconnect();const r=n||new v.IframeRpcProviderBridge(e,t);return o&&r.onConnect(o),r}const b="--dynamicHeight",Ge=0;function je(e,t,n,o){return t.contentWindow?[p.listenToMessageFromWindow(window,t.contentWindow,w.UPDATE_HEIGHT,r=>{const i=`${(r?.height??0)+Ge}px`;e.style.setProperty(b,i),o(i)},n),p.listenToMessageFromWindow(window,t.contentWindow,w.SET_FULL_HEIGHT,()=>{e.style.setProperty(b,"100dvh"),o("100dvh")},n)]:[]}const Ke={[g.ON_BEFORE_APPROVAL]:(e,t)=>t?.onBeforeApproval?t.onBeforeApproval(e):!0,[g.ON_BEFORE_TRADE]:(e,t)=>t?.onBeforeTrade?t.onBeforeTrade(e):!0,[g.ON_BEFORE_WRAP_UNWRAP]:(e,t)=>t?.onBeforeWrapOrUnwrap?t.onBeforeWrapOrUnwrap(e):!0,[g.ON_BEFORE_ORDER_CANCEL]:(e,t)=>t?.onBeforeOrderCancel?t.onBeforeOrderCancel(e):!0,[g.ON_BEFORE_ORDERS_CANCEL]:(e,t)=>t?.onBeforeOrdersCancel?t.onBeforeOrdersCancel(e):!0};function Ye(e,t){return Ke[e.event](e.payload,t)}function Qe(e,t,n){return p.listenToMessageFromWindow(window,e,w.PROCESS_HOOK,async o=>{let r=!1;try{r=await Ye(o,n)}catch{}p.postMessageToWindow(e,T.HOOK_RESULT,{id:o.id,result:r},t)},t)}const ze=Object.values(I);function m(e){return typeof e!="object"?!1:Object.keys(e).every(t=>ze.includes(t))}function Xe(e,t,n){if(m(e)){const o=e[n];return S(o)?o[t]:o}if(S(e)){const o=e[t];return m(o)?o[n]:o}return e}const Je=/^\d+$/;function S(e){return typeof e!="object"?!1:Object.keys(e).every(t=>Je.test(t))}function Ze(e){return m(e)?Object.values(e).flatMap(t=>S(t)?Object.values(t):[t]):S(e)?Object.values(e).flatMap(t=>m(t)?Object.values(t):[t]):[e]}exports.SHOULD_THROW_IF_INVALID_URL=q;exports.TradeType=I;exports.WIDGET_CONTAINER_ID=ue;exports.WIDGET_IFRAME_ALLOW=J;exports.WIDGET_IFRAME_ID=Y;exports.WIDGET_IFRAME_REFERRER_POLICY=X;exports.WIDGET_IFRAME_SANDBOX=z;exports.WIDGET_PALETTE_COLORS=fe;exports.WidgetHookEvents=g;exports.WidgetMethodsEmit=w;exports.WidgetMethodsListen=T;exports.createCowSwapWidget=Ne;exports.isCowSwapWidgetPalette=D;exports.isPerNetworkConfig=S;exports.isPerTradeTypeConfig=m;exports.resolveFlexibleConfig=Xe;exports.resolveFlexibleConfigValues=Ze;exports.sanitizeWidgetBaseUrl=oe;exports.widgetIframeTransport=p;
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { IframeTransport as X, IframeRpcProviderBridge as J } from "@cowprotocol/iframe-transport";
2
- import { SimpleCowEventEmitter as Z } from "@cowprotocol/events";
3
- const q = /* @__PURE__ */ new Set([
1
+ import { IframeTransport as q, IframeRpcProviderBridge as ee, getParentOrigin as te } from "@cowprotocol/iframe-transport";
2
+ import { SimpleCowEventEmitter as ne } from "@cowprotocol/events";
3
+ const oe = /* @__PURE__ */ new Set([
4
4
  "wc:",
5
5
  // default Wallet-connect protocol
6
6
  "metamask:",
@@ -27,16 +27,16 @@ const q = /* @__PURE__ */ new Set([
27
27
  "tpoutside:",
28
28
  "bncus:",
29
29
  "bnc:"
30
- ]), ee = /* @__PURE__ */ new Set(["http:", "https:"]);
31
- function te(e) {
30
+ ]), re = /* @__PURE__ */ new Set(["http:", "https:"]);
31
+ function ie(e) {
32
32
  try {
33
33
  const t = new URL(e).protocol;
34
- return ee.has(t) || q.has(t);
34
+ return re.has(t) || oe.has(t);
35
35
  } catch {
36
36
  return !1;
37
37
  }
38
38
  }
39
- function ne(e, t) {
39
+ function se(e, t) {
40
40
  if (t) {
41
41
  e.removeAttribute("style");
42
42
  for (const n of Object.keys(t)) {
@@ -48,16 +48,16 @@ function ne(e, t) {
48
48
  }
49
49
  }
50
50
  }
51
- const oe = "cowswap-widget-iframe", Ke = "cowswap-widget", re = {
51
+ const ae = "cowswap-widget-iframe", Ze = "cowswap-widget", de = {
52
52
  appCode: ""
53
- }, ie = "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", se = "strict-origin-when-cross-origin", ae = "clipboard-read; clipboard-write";
54
- var h = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.READY = "READY", 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.PROCESS_HOOK = "PROCESS_HOOK", e))(h || {}), 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.HOOK_RESULT = "HOOK_RESULT", e))(A || {}), g = /* @__PURE__ */ ((e) => (e.ON_BEFORE_APPROVAL = "ON_BEFORE_APPROVAL", e.ON_BEFORE_TRADE = "ON_BEFORE_TRADE", e.ON_BEFORE_WRAP_UNWRAP = "ON_BEFORE_WRAP_UNWRAP", e.ON_BEFORE_ORDER_CANCEL = "ON_BEFORE_ORDER_CANCEL", e.ON_BEFORE_ORDERS_CANCEL = "ON_BEFORE_ORDERS_CANCEL", e))(g || {}), b = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e.YIELD = "yield", e))(b || {});
55
- const Ye = ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"], p = new X("cowSwapWidget");
56
- class le {
53
+ }, j = "allow-scripts allow-same-origin allow-forms", le = `${j} allow-popups allow-popups-to-escape-sandbox`, ce = "strict-origin-when-cross-origin", ue = "clipboard-read; clipboard-write";
54
+ var W = /* @__PURE__ */ ((e) => (e.SWAP = "swap", e.LIMIT = "limit", e.ADVANCED = "advanced", e.YIELD = "yield", e))(W || {}), m = /* @__PURE__ */ ((e) => (e.ON_BEFORE_APPROVAL = "ON_BEFORE_APPROVAL", e.ON_BEFORE_TRADE = "ON_BEFORE_TRADE", e.ON_BEFORE_WRAP_UNWRAP = "ON_BEFORE_WRAP_UNWRAP", e.ON_BEFORE_ORDER_CANCEL = "ON_BEFORE_ORDER_CANCEL", e.ON_BEFORE_ORDERS_CANCEL = "ON_BEFORE_ORDERS_CANCEL", e))(m || {}), h = /* @__PURE__ */ ((e) => (e.ACTIVATE = "ACTIVATE", e.READY = "READY", 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.PROCESS_HOOK = "PROCESS_HOOK", e))(h || {}), 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.HOOK_RESULT = "HOOK_RESULT", e))(A || {});
55
+ const qe = ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"], p = new q("cowSwapWidget");
56
+ class pe {
57
57
  constructor(t, n, o, r = []) {
58
58
  this.contentWindow = t, this.updateListeners(r), this.widgetListener = p.listenToMessageFromWindow(this.contentWindow, o, h.EMIT_COW_EVENT, (i) => this.eventEmitter.emit(i.event, i.payload), n);
59
59
  }
60
- eventEmitter = new Z();
60
+ eventEmitter = new ne();
61
61
  listeners = [];
62
62
  widgetListener;
63
63
  stopListeningIframe() {
@@ -71,10 +71,10 @@ class le {
71
71
  this.eventEmitter.on(n);
72
72
  }
73
73
  }
74
- class de {
75
- constructor(t, n) {
76
- this.appWindow = t, this.iframeWidow = n, this.forwardSdkMessage = (o) => {
77
- ce(o.data) && (typeof window < "u" && o.origin === window.location.origin || (ue(o.data) ? this.appWindow.parent.postMessage(o.data, "*") : pe(o.data) && this.iframeWidow.postMessage(o.data, "*")));
74
+ class fe {
75
+ constructor(t, n, o, r) {
76
+ this.appWindow = t, this.iframeWindow = n, this.iframeOrigin = o, this.parentOrigin = r, this.forwardSdkMessage = (i) => {
77
+ Ee(i.data) && (we(i.data) ? this.forwardRequest(i, i.data) : he(i.data) && this.forwardResponse(i, i.data));
78
78
  }, this.startListening();
79
79
  }
80
80
  forwardSdkMessage;
@@ -84,138 +84,144 @@ class de {
84
84
  stopListening() {
85
85
  this.appWindow.removeEventListener("message", this.forwardSdkMessage);
86
86
  }
87
+ forwardRequest(t, n) {
88
+ !this.parentOrigin || this.appWindow.parent === this.appWindow || t.source !== this.iframeWindow || t.origin !== this.iframeOrigin || this.appWindow.parent.postMessage(n, this.parentOrigin);
89
+ }
90
+ forwardResponse(t, n) {
91
+ this.appWindow.parent !== this.appWindow && (t.source !== this.appWindow.parent || t.origin !== this.parentOrigin || this.iframeWindow.postMessage(n, this.iframeOrigin));
92
+ }
87
93
  }
88
- function ce(e) {
94
+ function Ee(e) {
89
95
  return typeof e == "object" && e !== null && "id" in e && typeof e.id == "string";
90
96
  }
91
- function ue(e) {
97
+ function we(e) {
92
98
  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;
93
99
  }
94
- function pe(e) {
100
+ function he(e) {
95
101
  return "success" in e && typeof e.success == "boolean" && "version" in e && typeof e.version == "string";
96
102
  }
97
- function fe(e = "Default", t = "#1c5dbf", ...n) {
98
- console.debug(`%c [COW][${e}]`, `font-weight: bold; color: ${t}`, ...n);
103
+ function ge(...e) {
104
+ process.env.NODE_ENV !== "test" && me("Widget", "#47aba8", ...e);
99
105
  }
100
- function Ee(...e) {
101
- process.env.NODE_ENV !== "test" && fe("Widget", "#47aba8", ...e);
106
+ function me(e = "Default", t = "#1c5dbf", ...n) {
107
+ console.debug(`%c [COW][${e}]`, `font-weight: bold; color: ${t}`, ...n);
102
108
  }
103
- function G(e) {
109
+ function K(e) {
104
110
  return !!(e && typeof e == "object");
105
111
  }
106
- const j = "https://swap.cow.fi", x = "_", we = "CoW Swap widget: invalid baseUrl.", he = !1;
107
- function me(e) {
108
- return e === "localhost" || e === "127.0.0.1" || e === "::1" || e.endsWith(".localhost");
112
+ const Y = "https://swap.cow.fi", B = "_", _e = "CoW Swap widget: invalid baseUrl.", Oe = !1;
113
+ function Q(e) {
114
+ const {
115
+ chainId: t = 1,
116
+ sell: n,
117
+ buy: o,
118
+ tradeType: r = W.SWAP
119
+ } = e, i = [n?.asset || B, o?.asset || B].map(encodeURIComponent).join("/");
120
+ return `/${t}/widget/${r}/${i}`;
109
121
  }
110
- function v(e, t) {
111
- const n = `${we} ${e}`;
112
- if (t)
113
- throw new Error(n);
114
- return console.error("[CoW Widget]", n), j;
122
+ function z(e) {
123
+ const t = Re(e.baseUrl), n = Q(e);
124
+ return t + "/#" + n + "?" + X(e);
115
125
  }
116
- function ge(e, t = he) {
126
+ function X(e) {
127
+ const t = new URLSearchParams();
128
+ return Se(Te(ye(Ae(Le(t, e), e), e), e), e);
129
+ }
130
+ function Re(e, t = Oe) {
117
131
  const n = typeof e == "string" ? e.trim() : "";
118
132
  if (!n)
119
- return j;
133
+ return Y;
120
134
  let o;
121
135
  try {
122
136
  o = new URL(n);
123
137
  } catch {
124
- return v(`Not a valid URL: ${JSON.stringify(n)}`, t);
138
+ return b(`Not a valid URL: ${JSON.stringify(n)}`, t);
125
139
  }
126
140
  if (o.username || o.password)
127
- return v("Userinfo (username/password) in URL is not allowed.", t);
128
- const r = o.protocol === "https:", i = o.protocol === "http:" && me(o.hostname);
141
+ return b("Userinfo (username/password) in URL is not allowed.", t);
142
+ const r = o.protocol === "https:", i = o.protocol === "http:" && Ce(o.hostname);
129
143
  if (!r && !i)
130
- return v(`Use https, or http only on localhost / 127.0.0.1 / ::1 / *.localhost (got ${o.protocol}//${o.hostname}).`, t);
144
+ return b(`Use https, or http only on localhost / 127.0.0.1 / ::1 / *.localhost (got ${o.protocol}//${o.hostname}).`, t);
131
145
  const f = o.pathname === "/" || o.pathname === "" ? "" : o.pathname.replace(/\/+$/, "");
132
146
  return `${o.origin}${f}`;
133
147
  }
134
- function _e(e) {
135
- const t = ge(e.baseUrl), n = K(e);
136
- return t + "/#" + n + "?" + Y(e);
148
+ function Se(e, t) {
149
+ return Pe(t.hooks) ? e.append("hooksEnabled", "true") : e.delete("hooksEnabled"), e;
137
150
  }
138
- function K(e) {
139
- const {
140
- chainId: t = 1,
141
- sell: n,
142
- buy: o,
143
- tradeType: r = b.SWAP
144
- } = e, i = [n?.asset || x, o?.asset || x].map(encodeURIComponent).join("/");
145
- return `/${t}/widget/${r}/${i}`;
151
+ function Te(e, t) {
152
+ return t.locale && e.append("lng", t.locale), e;
146
153
  }
147
- function Y(e) {
148
- const t = new URLSearchParams();
149
- return Te(ye(Se(Oe(Re(t, e), e), e), e), e);
154
+ function ye(e, t) {
155
+ return t.targetChainId && e.append("targetChainId", t.targetChainId.toString()), e;
156
+ }
157
+ function Ae(e, t) {
158
+ const n = t.theme;
159
+ return n ? (K(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);
150
160
  }
151
- function Re(e, t) {
161
+ function Le(e, t) {
152
162
  const {
153
163
  sell: n,
154
164
  buy: o
155
165
  } = t;
156
166
  return n?.amount && e.append("sellAmount", n.amount), o?.amount && e.append("buyAmount", o.amount), e;
157
167
  }
158
- function Oe(e, t) {
159
- const n = t.theme;
160
- return n ? (G(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);
161
- }
162
- function Se(e, t) {
163
- return t.targetChainId && e.append("targetChainId", t.targetChainId.toString()), e;
164
- }
165
- function ye(e, t) {
166
- return t.locale && e.append("lng", t.locale), e;
167
- }
168
- function Te(e, t) {
169
- return Ae(t.hooks) ? e.append("hooksEnabled", "true") : e.delete("hooksEnabled"), e;
168
+ function b(e, t) {
169
+ const n = `${_e} ${e}`;
170
+ if (t)
171
+ throw new Error(n);
172
+ return console.error("[CoW Widget]", n), Y;
170
173
  }
171
- function Ae(e) {
174
+ function Pe(e) {
172
175
  return !!e && Object.values(e).some(Boolean);
173
176
  }
174
- const Le = 3e4, w = "cow-widget-loading-error", B = `data-${w}`;
175
- function Ce(e, t, n, o, r) {
177
+ function Ce(e) {
178
+ return e === "localhost" || e === "127.0.0.1" || e === "::1" || e.endsWith(".localhost");
179
+ }
180
+ const be = 3e4, w = "cow-widget-loading-error", k = `data-${w}`;
181
+ function Ie(e, t, n, o, r) {
176
182
  const i = t.src;
177
183
  let f = !1, E = null;
178
- function c() {
179
- r?.(), t.style.display = "none", Pe();
180
- const l = document.createElement("div"), s = document.createElement("button"), d = document.createElement("p");
184
+ function d() {
185
+ r?.(), t.style.display = "none", We();
186
+ const c = document.createElement("div"), s = document.createElement("button"), l = document.createElement("p");
181
187
  s.innerText = "Reload", s.addEventListener("click", () => {
182
- e.removeChild(l), o(!0), t.src = "about:blank", t.style.display = "", setTimeout(() => {
188
+ e.removeChild(c), o(!0), t.src = "about:blank", t.style.display = "", setTimeout(() => {
183
189
  t.src = i, n();
184
190
  }, 100);
185
- }), d.innerText = "Couldn't load the page. Please, try again later", l.classList.add(w), l.appendChild(d), l.appendChild(s), e.appendChild(l);
191
+ }), l.innerText = "Couldn't load the page. Please, try again later", c.classList.add(w), c.appendChild(l), c.appendChild(s), e.appendChild(c);
186
192
  }
187
- return t.addEventListener("error", (l) => {
188
- f || (console.error("Could not load iframe", l), c());
193
+ return t.addEventListener("error", (c) => {
194
+ f || (console.error("Could not load iframe", c), d());
189
195
  }), E = window.setTimeout(() => {
190
- f || c();
191
- }, Le), {
196
+ f || d();
197
+ }, be), {
192
198
  onWidgetReady() {
193
199
  E && clearTimeout(E);
194
- const l = document.getElementsByClassName(w)[0];
195
- l && e.removeChild(l);
200
+ const c = document.getElementsByClassName(w)[0];
201
+ c && e.removeChild(c);
196
202
  },
197
203
  cancelWidgetLoading() {
198
204
  f = !0;
199
205
  }
200
206
  };
201
207
  }
202
- let R = null;
203
- function Pe() {
208
+ let O = null;
209
+ function We() {
204
210
  if (!(typeof document > "u")) {
205
211
  if (ve()) {
206
- R || (R = new CSSStyleSheet(), R.replaceSync(k)), document.adoptedStyleSheets.includes(R) || (document.adoptedStyleSheets = [...document.adoptedStyleSheets, R]);
212
+ O || (O = new CSSStyleSheet(), O.replaceSync(F)), document.adoptedStyleSheets.includes(O) || (document.adoptedStyleSheets = [...document.adoptedStyleSheets, O]);
207
213
  return;
208
214
  }
209
- if (!document.head.querySelector(`style[${B}]`)) {
215
+ if (!document.head.querySelector(`style[${k}]`)) {
210
216
  const e = document.createElement("style");
211
- e.setAttribute(B, ""), e.textContent = k, document.head.appendChild(e);
217
+ e.setAttribute(k, ""), e.textContent = F, document.head.appendChild(e);
212
218
  }
213
219
  }
214
220
  }
215
221
  function ve() {
216
222
  return typeof document < "u" && "adoptedStyleSheets" in Document.prototype && typeof CSSStyleSheet == "function" && typeof CSSStyleSheet.prototype.replaceSync == "function";
217
223
  }
218
- const k = `
224
+ const F = `
219
225
  .${w} {
220
226
  display: flex;
221
227
  flex-direction: column;
@@ -258,7 +264,7 @@ const k = `
258
264
  .${w} button:not(:disabled):hover {
259
265
  background: #d32f2f;
260
266
  color: #fff5f5;
261
- }`, Ie = {
267
+ }`, De = {
262
268
  iframe: null,
263
269
  updateParams: () => {
264
270
  },
@@ -269,7 +275,7 @@ const k = `
269
275
  destroy: () => {
270
276
  }
271
277
  };
272
- function Qe(e, t) {
278
+ function et(e, t) {
273
279
  const {
274
280
  params: n,
275
281
  provider: o,
@@ -277,73 +283,55 @@ function Qe(e, t) {
277
283
  onReady: i,
278
284
  enableSafeSdkBridge: f = !0
279
285
  } = t;
280
- let E = o, c = F(n), l = "";
281
- if (typeof window > "u") return Ie;
282
- const s = be(c), d = De(s);
283
- Ee("Resolved trusted iframe origin", {
284
- iframeOrigin: d
286
+ let E = o, d = V(n), c = "";
287
+ if (typeof window > "u") return De;
288
+ const s = Ne(d), l = xe(s);
289
+ ge("Resolved trusted iframe origin", {
290
+ iframeOrigin: l
285
291
  });
286
- const O = [];
287
- e.innerHTML = "", e.appendChild(s), M(e, c);
292
+ const R = [];
293
+ e.innerHTML = "", e.appendChild(s), M(e, d);
288
294
  let a = null, L = () => {
289
- }, C = () => {
295
+ }, P = () => {
290
296
  }, D = () => {
291
- }, P = null, S = null, N = null, W = [], _ = null;
292
- function U() {
297
+ }, C = null, S = null, N = null, U = [], _ = null;
298
+ function x() {
293
299
  if (a = s.contentWindow, !a)
294
300
  throw console.error("Iframe does not contain a window", s), new Error("Iframe does not contain a window!");
295
- O.push(We(a, d, () => {
296
- i?.(), Q();
297
- })), O.push(Ne(a, d, c.appCode)), W = Be(e, s, d, (z) => {
298
- l = z;
301
+ R.push(Be(a, l, () => {
302
+ i?.(), J();
303
+ })), R.push(Ve(a, l, d.appCode)), U = Ge(e, s, l, (Z) => {
304
+ c = Z;
299
305
  });
300
306
  let u = null;
301
307
  L = () => {
302
- a && (u && window.removeEventListener("message", u), !c.disableWindowOpen && (u = Ue(d, a), O.push(u)));
303
- }, C = () => {
304
- a && (_ && window.removeEventListener("message", _), _ = Ve(a, d, c.hooks));
305
- }, L(), C(), P = new le(window, d, a, r), S = V(a, d, null, E), s.addEventListener("load", () => {
306
- a && $(a, d, c, E);
307
- }), N = f ? new de(window, a) : null;
308
- const m = Ce(e, s, U, H, t.onLoadingError);
309
- D = m.cancelWidgetLoading;
310
- const Q = m.onWidgetReady;
308
+ a && (u && window.removeEventListener("message", u), !d.disableWindowOpen && (u = He(l, a), R.push(u)));
309
+ }, P = () => {
310
+ a && (_ && window.removeEventListener("message", _), _ = Ye(a, l, d.hooks));
311
+ }, L(), P(), C = new pe(window, l, a, r), S = G(a, l, null, E), s.addEventListener("load", () => {
312
+ a && $(a, l, d, E);
313
+ }), N = Ue(f, window, a, l);
314
+ const g = Ie(e, s, x, H, t.onLoadingError);
315
+ D = g.cancelWidgetLoading;
316
+ const J = g.onWidgetReady;
311
317
  }
312
318
  function H(u = !1) {
313
- S?.disconnect(), P?.stopListeningIframe(), W.forEach((m) => window.removeEventListener("message", m)), O.forEach((m) => window.removeEventListener("message", m)), _ && window.removeEventListener("message", _), N?.stopListening(), !u && s && s.parentNode === e && e.removeChild(s), D?.();
319
+ S?.disconnect(), C?.stopListeningIframe(), U.forEach((g) => window.removeEventListener("message", g)), R.forEach((g) => window.removeEventListener("message", g)), _ && window.removeEventListener("message", _), N?.stopListening(), !u && s && s.parentNode === e && e.removeChild(s), D?.();
314
320
  }
315
- return U(), {
321
+ return x(), {
316
322
  iframe: s,
317
323
  updateParams: (u) => {
318
- a && (c = F(u), M(e, c, l), $(a, d, c, E), L(), C());
324
+ a && (d = V(u), M(e, d, c), Fe(s, d) ? ke(s, d) : $(a, l, d, E), L(), P());
319
325
  },
320
- updateListeners: (u) => P?.updateListeners(u),
326
+ updateListeners: (u) => C?.updateListeners(u),
321
327
  updateProvider: (u) => {
322
- a && (E = u, S = V(a, d, S, u));
328
+ a && (E = u, S = G(a, l, S, u));
323
329
  },
324
330
  destroy: H
325
331
  };
326
332
  }
327
- function F(e) {
328
- const t = {
329
- ...re,
330
- ...e
331
- };
332
- if (typeof t.appCode != "string" || t.appCode.trim().length === 0)
333
- throw new Error("Required param `appCode` is missing");
334
- return t;
335
- }
336
- function V(e, t, n, o) {
337
- n && n.disconnect();
338
- const r = n || new J(e, t);
339
- return o && r.onConnect(o), r;
340
- }
341
- function be(e) {
342
- const t = document.createElement("iframe");
343
- return t.id = oe, t.src = _e(e), t.setAttribute("sandbox", ie), t.referrerPolicy = se, t.allow = ae, t.style.width = "100%", t.style.height = "100%", t.style.border = "0", t.style.display = "block", t;
344
- }
345
333
  function M(e, t, n) {
346
- ne(e, t.rootStyle), [{
334
+ se(e, t.rootStyle), [{
347
335
  name: "params.width",
348
336
  value: t.width,
349
337
  replacementName: "rootStyle.width",
@@ -363,7 +351,7 @@ function M(e, t, n) {
363
351
  applyDeprecated: () => t.maxHeight ? e.style.maxHeight = `${t.maxHeight}px` : void 0
364
352
  }, {
365
353
  name: "params.theme.boxShadow",
366
- value: G(t.theme) ? t.theme.boxShadow : void 0,
354
+ value: K(t.theme) ? t.theme.boxShadow : void 0,
367
355
  replacementName: "cardStyle.boxShadow",
368
356
  replacementValue: t.cardStyle?.boxShadow,
369
357
  applyDeprecated: () => {
@@ -372,51 +360,59 @@ function M(e, t, n) {
372
360
  r.replacementValue ? console.warn(`Both ${r.name} and ${r.replacementName} have been set. ${r.name} will be ignored.`) : (console.warn(`${r.name} is deprecated. Use ${r.replacementName} instead.`), r.applyDeprecated());
373
361
  }), n && e.style.setProperty(I, n);
374
362
  }
375
- function De(e) {
376
- return new URL(e.src).origin;
363
+ function Ne(e) {
364
+ const t = document.createElement("iframe");
365
+ return t.id = ae, t.src = z(e), t.setAttribute("sandbox", v(e)), t.referrerPolicy = ce, t.allow = ue, t.style.width = "100%", t.style.height = "100%", t.style.border = "0", t.style.display = "block", t;
377
366
  }
378
- function $(e, t, n, o) {
379
- const r = !!o, i = K(n), f = Y(n).toString(), {
380
- theme: E,
381
- hooks: c,
382
- rootStyle: l,
383
- ...s
384
- } = n;
385
- p.postMessageToWindow(e, A.UPDATE_PARAMS, {
386
- urlParams: {
387
- pathname: i,
388
- search: f
389
- },
390
- appParams: s,
391
- hasProvider: r
392
- }, t);
367
+ function Ue(e, t, n, o) {
368
+ return e ? new fe(t, n, o, te() || null) : null;
393
369
  }
394
- function Ne(e, t, n) {
395
- return p.listenToMessageFromWindow(window, e, h.ACTIVATE, () => {
396
- p.postMessageToWindow(e, A.UPDATE_APP_DATA, {
397
- metaData: n ? {
398
- appCode: n
399
- } : void 0
400
- }, t);
401
- }, t);
370
+ function xe(e) {
371
+ return new URL(e.src).origin;
402
372
  }
403
- function We(e, t, n) {
404
- let o = !1;
405
- return p.listenToMessageFromWindow(window, e, h.READY, () => {
406
- o || (o = !0, n());
407
- }, t);
373
+ function v(e) {
374
+ return e.disableWindowOpen ? j : le;
408
375
  }
409
- function Ue(e, t) {
376
+ function He(e, t) {
410
377
  return p.listenToMessageFromWindow(window, t, h.INTERCEPT_WINDOW_OPEN, ({
411
378
  href: n,
412
379
  rel: o,
413
380
  target: r
414
381
  }) => {
415
- const i = He(n.toString(), e);
416
- i && te(i) && window.open(i, r, o);
382
+ const i = Me(n.toString(), e);
383
+ i && ie(i) && window.open(i, r, o);
417
384
  }, e);
418
385
  }
419
- function He(e, t) {
386
+ function Be(e, t, n) {
387
+ let o = !1;
388
+ return p.listenToMessageFromWindow(window, e, h.READY, () => {
389
+ o || (o = !0, n());
390
+ }, t);
391
+ }
392
+ function ke(e, t) {
393
+ const n = v(t), o = z(t);
394
+ e.addEventListener("load", () => {
395
+ e.src = o;
396
+ }, {
397
+ once: !0
398
+ }), e.setAttribute("sandbox", n), e.src = "about:blank";
399
+ }
400
+ function Fe(e, t) {
401
+ const n = v(t);
402
+ return e.getAttribute("sandbox") !== n;
403
+ }
404
+ function V(e) {
405
+ const t = {
406
+ ...de,
407
+ ...e
408
+ };
409
+ if (typeof t.appCode != "string" || t.appCode.trim().length === 0)
410
+ throw new Error("Required param `appCode` is missing");
411
+ if (t.disableWindowOpen && t.standaloneMode !== !1)
412
+ throw new Error("`disableWindowOpen: true` requires `standaloneMode: false`");
413
+ return t;
414
+ }
415
+ function Me(e, t) {
420
416
  const n = e.trim();
421
417
  if (!n)
422
418
  return null;
@@ -426,30 +422,60 @@ function He(e, t) {
426
422
  return null;
427
423
  }
428
424
  }
429
- const I = "--dynamicHeight", xe = 0;
430
- function Be(e, t, n, o) {
425
+ function Ve(e, t, n) {
426
+ return p.listenToMessageFromWindow(window, e, h.ACTIVATE, () => {
427
+ p.postMessageToWindow(e, A.UPDATE_APP_DATA, {
428
+ metaData: n ? {
429
+ appCode: n
430
+ } : void 0
431
+ }, t);
432
+ }, t);
433
+ }
434
+ function $(e, t, n, o) {
435
+ const r = !!o, i = Q(n), f = X(n).toString(), {
436
+ theme: E,
437
+ hooks: d,
438
+ rootStyle: c,
439
+ ...s
440
+ } = n;
441
+ p.postMessageToWindow(e, A.UPDATE_PARAMS, {
442
+ urlParams: {
443
+ pathname: i,
444
+ search: f
445
+ },
446
+ appParams: s,
447
+ hasProvider: r
448
+ }, t);
449
+ }
450
+ function G(e, t, n, o) {
451
+ n && n.disconnect();
452
+ const r = n || new ee(e, t);
453
+ return o && r.onConnect(o), r;
454
+ }
455
+ const I = "--dynamicHeight", $e = 0;
456
+ function Ge(e, t, n, o) {
431
457
  return t.contentWindow ? [p.listenToMessageFromWindow(window, t.contentWindow, h.UPDATE_HEIGHT, (r) => {
432
- const i = `${(r?.height ?? 0) + xe}px`;
458
+ const i = `${(r?.height ?? 0) + $e}px`;
433
459
  e.style.setProperty(I, i), o(i);
434
460
  }, n), p.listenToMessageFromWindow(window, t.contentWindow, h.SET_FULL_HEIGHT, () => {
435
461
  e.style.setProperty(I, "100dvh"), o("100dvh");
436
462
  }, n)] : [];
437
463
  }
438
- const ke = {
439
- [g.ON_BEFORE_APPROVAL]: (e, t) => t?.onBeforeApproval ? t.onBeforeApproval(e) : !0,
440
- [g.ON_BEFORE_TRADE]: (e, t) => t?.onBeforeTrade ? t.onBeforeTrade(e) : !0,
441
- [g.ON_BEFORE_WRAP_UNWRAP]: (e, t) => t?.onBeforeWrapOrUnwrap ? t.onBeforeWrapOrUnwrap(e) : !0,
442
- [g.ON_BEFORE_ORDER_CANCEL]: (e, t) => t?.onBeforeOrderCancel ? t.onBeforeOrderCancel(e) : !0,
443
- [g.ON_BEFORE_ORDERS_CANCEL]: (e, t) => t?.onBeforeOrdersCancel ? t.onBeforeOrdersCancel(e) : !0
464
+ const je = {
465
+ [m.ON_BEFORE_APPROVAL]: (e, t) => t?.onBeforeApproval ? t.onBeforeApproval(e) : !0,
466
+ [m.ON_BEFORE_TRADE]: (e, t) => t?.onBeforeTrade ? t.onBeforeTrade(e) : !0,
467
+ [m.ON_BEFORE_WRAP_UNWRAP]: (e, t) => t?.onBeforeWrapOrUnwrap ? t.onBeforeWrapOrUnwrap(e) : !0,
468
+ [m.ON_BEFORE_ORDER_CANCEL]: (e, t) => t?.onBeforeOrderCancel ? t.onBeforeOrderCancel(e) : !0,
469
+ [m.ON_BEFORE_ORDERS_CANCEL]: (e, t) => t?.onBeforeOrdersCancel ? t.onBeforeOrdersCancel(e) : !0
444
470
  };
445
- function Fe(e, t) {
446
- return ke[e.event](e.payload, t);
471
+ function Ke(e, t) {
472
+ return je[e.event](e.payload, t);
447
473
  }
448
- function Ve(e, t, n) {
474
+ function Ye(e, t, n) {
449
475
  return p.listenToMessageFromWindow(window, e, h.PROCESS_HOOK, async (o) => {
450
476
  let r = !1;
451
477
  try {
452
- r = await Fe(o, n);
478
+ r = await Ke(o, n);
453
479
  } catch {
454
480
  }
455
481
  p.postMessageToWindow(e, A.HOOK_RESULT, {
@@ -458,46 +484,46 @@ function Ve(e, t, n) {
458
484
  }, t);
459
485
  }, t);
460
486
  }
461
- const Me = Object.values(b);
462
- function ze(e, t, n) {
463
- if (y(e)) {
487
+ const Qe = Object.values(W);
488
+ function T(e) {
489
+ return typeof e != "object" ? !1 : Object.keys(e).every((t) => Qe.includes(t));
490
+ }
491
+ function tt(e, t, n) {
492
+ if (T(e)) {
464
493
  const o = e[n];
465
- return T(o) ? o[t] : o;
494
+ return y(o) ? o[t] : o;
466
495
  }
467
- if (T(e)) {
496
+ if (y(e)) {
468
497
  const o = e[t];
469
- return y(o) ? o[n] : o;
498
+ return T(o) ? o[n] : o;
470
499
  }
471
500
  return e;
472
501
  }
502
+ const ze = /^\d+$/;
473
503
  function y(e) {
474
- return typeof e != "object" ? !1 : Object.keys(e).every((t) => Me.includes(t));
475
- }
476
- const $e = /^\d+$/;
477
- function T(e) {
478
- return typeof e != "object" ? !1 : Object.keys(e).every((t) => $e.test(t));
504
+ return typeof e != "object" ? !1 : Object.keys(e).every((t) => ze.test(t));
479
505
  }
480
- function Xe(e) {
481
- return y(e) ? Object.values(e).flatMap((t) => T(t) ? Object.values(t) : [t]) : T(e) ? Object.values(e).flatMap((t) => y(t) ? Object.values(t) : [t]) : [e];
506
+ function nt(e) {
507
+ return T(e) ? Object.values(e).flatMap((t) => y(t) ? Object.values(t) : [t]) : y(e) ? Object.values(e).flatMap((t) => T(t) ? Object.values(t) : [t]) : [e];
482
508
  }
483
509
  export {
484
- he as SHOULD_THROW_IF_INVALID_URL,
485
- b as TradeType,
486
- Ke as WIDGET_CONTAINER_ID,
487
- ae as WIDGET_IFRAME_ALLOW,
488
- oe as WIDGET_IFRAME_ID,
489
- se as WIDGET_IFRAME_REFERRER_POLICY,
490
- ie as WIDGET_IFRAME_SANDBOX,
491
- Ye as WIDGET_PALETTE_COLORS,
492
- g as WidgetHookEvents,
510
+ Oe as SHOULD_THROW_IF_INVALID_URL,
511
+ W as TradeType,
512
+ Ze as WIDGET_CONTAINER_ID,
513
+ ue as WIDGET_IFRAME_ALLOW,
514
+ ae as WIDGET_IFRAME_ID,
515
+ ce as WIDGET_IFRAME_REFERRER_POLICY,
516
+ le as WIDGET_IFRAME_SANDBOX,
517
+ qe as WIDGET_PALETTE_COLORS,
518
+ m as WidgetHookEvents,
493
519
  h as WidgetMethodsEmit,
494
520
  A as WidgetMethodsListen,
495
- Qe as createCowSwapWidget,
496
- G as isCowSwapWidgetPalette,
497
- T as isPerNetworkConfig,
498
- y as isPerTradeTypeConfig,
499
- ze as resolveFlexibleConfig,
500
- Xe as resolveFlexibleConfigValues,
501
- ge as sanitizeWidgetBaseUrl,
521
+ et as createCowSwapWidget,
522
+ K as isCowSwapWidgetPalette,
523
+ y as isPerNetworkConfig,
524
+ T as isPerTradeTypeConfig,
525
+ tt as resolveFlexibleConfig,
526
+ nt as resolveFlexibleConfigValues,
527
+ Re as sanitizeWidgetBaseUrl,
502
528
  p as widgetIframeTransport
503
529
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-lib",
3
- "version": "4.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your website.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@cowprotocol/cow-sdk": "9.2.2",
19
- "@cowprotocol/events": "^4.7.1",
19
+ "@cowprotocol/events": "^4.8.0",
20
20
  "@cowprotocol/iframe-transport": "^2.3.2"
21
21
  },
22
22
  "devDependencies": {
package/types.d.ts CHANGED
@@ -3,9 +3,69 @@ import { CowWidgetEventListeners, CowWidgetEventPayloadMap, CowWidgetEvents, OnT
3
3
  import type * as CSS from 'csstype';
4
4
  export type { SupportedChainId } from '@cowprotocol/cow-sdk';
5
5
  export type { OnTradeParamsPayload } from '@cowprotocol/events';
6
- export type PerTradeTypeConfig<T> = Partial<Record<TradeType, T>>;
7
- export type PerNetworkConfig<T> = Partial<Record<SupportedChainId, T>>;
6
+ export type CowSwapTheme = 'dark' | 'light';
7
+ export interface CowSwapWidgetProps {
8
+ params: CowSwapWidgetParams;
9
+ provider?: EthereumProvider;
10
+ listeners?: CowWidgetEventListeners;
11
+ onReady?(): void;
12
+ onLoadingError?(): void;
13
+ enableSafeSdkBridge?: boolean;
14
+ }
15
+ export interface EthereumProvider {
16
+ /**
17
+ * Subscribes to Ethereum-related events.
18
+ * @param event - The event to subscribe to.
19
+ * @param args - Arguments for the event.
20
+ */
21
+ on(event: string, args: unknown): void;
22
+ /**
23
+ * Sends a JSON-RPC request to the Ethereum provider and returns the response.
24
+ * @param params - JSON-RPC request parameters.
25
+ * @returns A promise that resolves with the response.
26
+ */
27
+ request<T>(params: JsonRpcRequest): Promise<T>;
28
+ }
8
29
  export type FlexibleConfig<T> = T | PerNetworkConfig<T> | PerTradeTypeConfig<T> | PerTradeTypeConfig<PerNetworkConfig<T>> | PerNetworkConfig<PerTradeTypeConfig<T>>;
30
+ export type ForcedOrderDeadline = FlexibleConfig<number>;
31
+ export interface JsonRpcRequest {
32
+ id: number;
33
+ method: string;
34
+ params: unknown[];
35
+ }
36
+ export interface OnApprovalPayload {
37
+ chainId: SupportedChainId;
38
+ sellToken: TokenInfo;
39
+ sellAmount: string;
40
+ walletAddress: string;
41
+ spenderAddress: string;
42
+ }
43
+ /**
44
+ * The partner fee
45
+ */
46
+ export interface PartnerFee {
47
+ /**
48
+ * The fee in basis points (BPS). One basis point is equivalent to 0.01% (1/100th of a percent)
49
+ */
50
+ bps: FlexibleConfig<number>;
51
+ /**
52
+ * The Ethereum address of the partner to receive the fee.
53
+ */
54
+ recipient: FlexibleConfig<string>;
55
+ }
56
+ export type PerNetworkConfig<T> = Partial<Record<SupportedChainId, T>>;
57
+ export type PerTradeTypeConfig<T> = Partial<Record<TradeType, T>>;
58
+ /**
59
+ * ERC-20 token information
60
+ */
61
+ export type TokenInfo = {
62
+ chainId: number;
63
+ address: string;
64
+ name: string;
65
+ decimals: number;
66
+ symbol: string;
67
+ logoURI?: string;
68
+ };
9
69
  /**
10
70
  * A single forbidden sell→buy token combination for the widget.
11
71
  *
@@ -39,6 +99,24 @@ export type TokenPairConstraint = {
39
99
  chainId: SupportedChainId;
40
100
  };
41
101
  };
102
+ export type WidgetHookResult = Promise<boolean> | boolean;
103
+ export declare enum TradeType {
104
+ SWAP = "swap",
105
+ LIMIT = "limit",
106
+ /**
107
+ * Currently it means only TWAP orders.
108
+ * But in the future it can be extended to support other order types.
109
+ */
110
+ ADVANCED = "advanced",
111
+ YIELD = "yield"
112
+ }
113
+ export declare enum WidgetHookEvents {
114
+ ON_BEFORE_APPROVAL = "ON_BEFORE_APPROVAL",
115
+ ON_BEFORE_TRADE = "ON_BEFORE_TRADE",
116
+ ON_BEFORE_WRAP_UNWRAP = "ON_BEFORE_WRAP_UNWRAP",
117
+ ON_BEFORE_ORDER_CANCEL = "ON_BEFORE_ORDER_CANCEL",
118
+ ON_BEFORE_ORDERS_CANCEL = "ON_BEFORE_ORDERS_CANCEL"
119
+ }
42
120
  export declare enum WidgetMethodsEmit {
43
121
  ACTIVATE = "ACTIVATE",
44
122
  READY = "READY",
@@ -56,49 +134,6 @@ export declare enum WidgetMethodsListen {
56
134
  PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT",
57
135
  HOOK_RESULT = "HOOK_RESULT"
58
136
  }
59
- export declare enum WidgetHookEvents {
60
- ON_BEFORE_APPROVAL = "ON_BEFORE_APPROVAL",
61
- ON_BEFORE_TRADE = "ON_BEFORE_TRADE",
62
- ON_BEFORE_WRAP_UNWRAP = "ON_BEFORE_WRAP_UNWRAP",
63
- ON_BEFORE_ORDER_CANCEL = "ON_BEFORE_ORDER_CANCEL",
64
- ON_BEFORE_ORDERS_CANCEL = "ON_BEFORE_ORDERS_CANCEL"
65
- }
66
- export type WidgetHookResult = Promise<boolean> | boolean;
67
- export interface OnApprovalPayload {
68
- chainId: SupportedChainId;
69
- sellToken: TokenInfo;
70
- sellAmount: string;
71
- walletAddress: string;
72
- spenderAddress: string;
73
- }
74
- export interface CowSwapWidgetProps {
75
- params: CowSwapWidgetParams;
76
- provider?: EthereumProvider;
77
- listeners?: CowWidgetEventListeners;
78
- onReady?(): void;
79
- onLoadingError?(): void;
80
- enableSafeSdkBridge?: boolean;
81
- }
82
- export interface JsonRpcRequest {
83
- id: number;
84
- method: string;
85
- params: unknown[];
86
- }
87
- export interface EthereumProvider {
88
- /**
89
- * Subscribes to Ethereum-related events.
90
- * @param event - The event to subscribe to.
91
- * @param args - Arguments for the event.
92
- */
93
- on(event: string, args: unknown): void;
94
- /**
95
- * Sends a JSON-RPC request to the Ethereum provider and returns the response.
96
- * @param params - JSON-RPC request parameters.
97
- * @returns A promise that resolves with the response.
98
- */
99
- request<T>(params: JsonRpcRequest): Promise<T>;
100
- }
101
- export type CowSwapTheme = 'dark' | 'light';
102
137
  /**
103
138
  *Trade asset parameters, for example:
104
139
  * { asset: 'WBTC', amount: 12 }
@@ -114,46 +149,23 @@ interface TradeAsset {
114
149
  */
115
150
  amount?: string;
116
151
  }
117
- export type ForcedOrderDeadline = FlexibleConfig<number>;
118
- export declare enum TradeType {
119
- SWAP = "swap",
120
- LIMIT = "limit",
121
- /**
122
- * Currently it means only TWAP orders.
123
- * But in the future it can be extended to support other order types.
124
- */
125
- ADVANCED = "advanced",
126
- YIELD = "yield"
152
+ export declare const WIDGET_PALETTE_COLORS: readonly ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"];
153
+ export interface BaseJsonRpcResponseMessage {
154
+ id: number;
155
+ jsonrpc: '2.0';
127
156
  }
128
- /**
129
- * The partner fee
130
- */
131
- export interface PartnerFee {
132
- /**
133
- * The fee in basis points (BPS). One basis point is equivalent to 0.01% (1/100th of a percent)
134
- */
135
- bps: FlexibleConfig<number>;
157
+ export type CowSwapWidgetAppParams = Omit<CowSwapWidgetParams, 'theme' | 'hooks' | 'rootStyle'>;
158
+ export interface CowSwapWidgetContent {
159
+ feeLabel?: string;
160
+ feeTooltipMarkdown?: string;
161
+ }
162
+ export interface CowSwapWidgetImages {
136
163
  /**
137
- * The Ethereum address of the partner to receive the fee.
164
+ * The image to display when the orders table is empty (no orders yet). It defaults to "Yoga CoW" image.
165
+ * Alternatively, you can use a URL to a custom image file, or set to null to disable the image.
138
166
  */
139
- recipient: FlexibleConfig<string>;
167
+ emptyOrders?: string | null;
140
168
  }
141
- /**
142
- * ERC-20 token information
143
- */
144
- export type TokenInfo = {
145
- chainId: number;
146
- address: string;
147
- name: string;
148
- decimals: number;
149
- symbol: string;
150
- logoURI?: string;
151
- };
152
- export declare const WIDGET_PALETTE_COLORS: readonly ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"];
153
- export type CowSwapWidgetPaletteColors = (typeof WIDGET_PALETTE_COLORS)[number];
154
- export type CowSwapWidgetPaletteParams = {
155
- [K in CowSwapWidgetPaletteColors]: string;
156
- };
157
169
  export type CowSwapWidgetPalette = {
158
170
  baseTheme: CowSwapTheme;
159
171
  /**
@@ -164,43 +176,10 @@ export type CowSwapWidgetPalette = {
164
176
  */
165
177
  boxShadow?: string;
166
178
  } & CowSwapWidgetPaletteParams;
167
- export interface CowSwapWidgetSounds {
168
- /**
169
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap moooooooooo!
170
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
171
- */
172
- postOrder?: string | null;
173
- /**
174
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap happy moooooooooo!
175
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
176
- */
177
- orderExecuted?: string | null;
178
- /**
179
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap unhappy moooooooooo!
180
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
181
- */
182
- orderError?: string | null;
183
- }
184
- export interface CowSwapWidgetImages {
185
- /**
186
- * The image to display when the orders table is empty (no orders yet). It defaults to "Yoga CoW" image.
187
- * Alternatively, you can use a URL to a custom image file, or set to null to disable the image.
188
- */
189
- emptyOrders?: string | null;
190
- }
191
- export interface CowSwapWidgetContent {
192
- feeLabel?: string;
193
- feeTooltipMarkdown?: string;
194
- }
195
- export interface SlippageConfig {
196
- /** Minimum slippage in basis points (e.g., 10 = 0.1%) */
197
- min?: number;
198
- /** Maximum slippage in basis points (e.g., 5000 = 50%) - 5000 is max value for dApp */
199
- max?: number;
200
- /** Default slippage value in basis points (e.g., 50 = 0.5%) - min <= defaultValue <= max */
201
- defaultValue?: number;
202
- }
203
- export type FlexibleSlippageConfig = FlexibleConfig<SlippageConfig>;
179
+ export type CowSwapWidgetPaletteColors = (typeof WIDGET_PALETTE_COLORS)[number];
180
+ export type CowSwapWidgetPaletteParams = {
181
+ [K in CowSwapWidgetPaletteColors]: string;
182
+ };
204
183
  export interface CowSwapWidgetParams {
205
184
  /**
206
185
  * The unique identifier of the widget consumer.
@@ -394,7 +373,9 @@ export interface CowSwapWidgetParams {
394
373
  */
395
374
  disableToastMessages?: boolean;
396
375
  /**
397
- * When `true`, the host page will not use `window.open` to open links requested by the widget.
376
+ * When `true`, the host page will not use `window.open` to open links requested by the widget,
377
+ * and the widget iframe sandbox will not allow direct popups.
378
+ * Requires `standaloneMode: false`.
398
379
  * Defaults to `false`.
399
380
  */
400
381
  disableWindowOpen?: boolean;
@@ -467,27 +448,69 @@ export interface CowSwapWidgetParams {
467
448
  onBeforeOrdersCancel(payload: EnrichedOrder[]): WidgetHookResult;
468
449
  }>;
469
450
  }
470
- export interface WidgetMethodsEmitPayloadMap {
471
- [WidgetMethodsEmit.ACTIVATE]: void;
472
- [WidgetMethodsEmit.READY]: void;
473
- [WidgetMethodsEmit.EMIT_COW_EVENT]: EmitCowEventPayload<CowWidgetEvents>;
474
- [WidgetMethodsEmit.UPDATE_HEIGHT]: UpdateWidgetHeightPayload;
475
- [WidgetMethodsEmit.SET_FULL_HEIGHT]: void;
476
- [WidgetMethodsEmit.PROVIDER_RPC_REQUEST]: ProviderRpcRequestPayload;
477
- [WidgetMethodsEmit.INTERCEPT_WINDOW_OPEN]: WindowOpenPayload;
478
- [WidgetMethodsEmit.PROCESS_HOOK]: WidgetHookPayload<WidgetHookEvents>;
451
+ export interface CowSwapWidgetSounds {
452
+ /**
453
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap moooooooooo!
454
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
455
+ */
456
+ postOrder?: string | null;
457
+ /**
458
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap happy moooooooooo!
459
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
460
+ */
461
+ orderExecuted?: string | null;
462
+ /**
463
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap unhappy moooooooooo!
464
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
465
+ */
466
+ orderError?: string | null;
479
467
  }
480
- export interface WidgetMethodsListenPayloadMap {
481
- [WidgetMethodsListen.UPDATE_APP_DATA]: UpdateAppDataPayload;
482
- [WidgetMethodsListen.UPDATE_PARAMS]: UpdateParamsPayload;
483
- [WidgetMethodsListen.PROVIDER_RPC_RESPONSE]: ProviderRpcResponsePayload;
484
- [WidgetMethodsListen.PROVIDER_ON_EVENT]: ProviderOnEventPayload;
485
- [WidgetMethodsListen.HOOK_RESULT]: WidgetHookResultPayload;
468
+ export interface EmitCowEventPayload<T extends CowWidgetEvents> {
469
+ event: T;
470
+ payload: CowWidgetEventPayloadMap[T];
471
+ }
472
+ export type FlexibleSlippageConfig = FlexibleConfig<SlippageConfig>;
473
+ export interface JsonRpcError<TData = unknown> {
474
+ code: number;
475
+ message: string;
476
+ data?: TData;
477
+ }
478
+ export interface JsonRpcErrorResponseMessage<TErrorData = unknown> extends BaseJsonRpcResponseMessage {
479
+ error: JsonRpcError<TErrorData>;
480
+ }
481
+ export interface JsonRpcRequestMessage {
482
+ jsonrpc: '2.0';
483
+ id?: number;
484
+ method: string;
485
+ params: unknown[];
486
+ }
487
+ export type JsonRpcResponse = JsonRpcRequestMessage | JsonRpcErrorResponseMessage | JsonRpcSucessfulResponseMessage;
488
+ export interface JsonRpcSucessfulResponseMessage<TResult = unknown> extends BaseJsonRpcResponseMessage {
489
+ result: TResult;
490
+ }
491
+ export interface ProviderOnEventPayload {
492
+ event: string;
493
+ params: unknown;
494
+ }
495
+ export interface ProviderRpcRequestPayload {
496
+ rpcRequest: JsonRpcRequestMessage;
497
+ }
498
+ export type ProviderRpcResponsePayload = {
499
+ rpcResponse: JsonRpcResponse;
500
+ };
501
+ export interface SlippageConfig {
502
+ /** Minimum slippage in basis points (e.g., 10 = 0.1%) */
503
+ min?: number;
504
+ /** Maximum slippage in basis points (e.g., 5000 = 50%) - 5000 is max value for dApp */
505
+ max?: number;
506
+ /** Default slippage value in basis points (e.g., 50 = 0.5%) - min <= defaultValue <= max */
507
+ defaultValue?: number;
508
+ }
509
+ export interface UpdateAppDataPayload {
510
+ metaData?: {
511
+ appCode: string;
512
+ };
486
513
  }
487
- export type WidgetEventsPayloadMap = WidgetMethodsEmitPayloadMap & WidgetMethodsListenPayloadMap;
488
- export type WidgetMethodsEmitPayloads = WidgetMethodsEmitPayloadMap[WidgetMethodsEmit];
489
- export type WidgetMethodsListenPayloads = WidgetMethodsListenPayloadMap[WidgetMethodsListen];
490
- export type CowSwapWidgetAppParams = Omit<CowSwapWidgetParams, 'theme' | 'hooks' | 'rootStyle'>;
491
514
  export interface UpdateParamsPayload {
492
515
  urlParams: {
493
516
  pathname: string;
@@ -496,24 +519,16 @@ export interface UpdateParamsPayload {
496
519
  appParams: CowSwapWidgetAppParams;
497
520
  hasProvider: boolean;
498
521
  }
499
- export interface UpdateAppDataPayload {
500
- metaData?: {
501
- appCode: string;
502
- };
503
- }
504
522
  export interface UpdateWidgetHeightPayload {
505
523
  height?: number;
506
524
  }
525
+ export type WidgetEventsPayloadMap = WidgetMethodsEmitPayloadMap & WidgetMethodsListenPayloadMap;
507
526
  export type WidgetHookId = string;
508
527
  export interface WidgetHookPayload<T extends WidgetHookEvents> {
509
528
  id: WidgetHookId;
510
529
  event: T;
511
530
  payload: WidgetHookPayloadMap[T];
512
531
  }
513
- export interface WidgetHookResultPayload {
514
- id: WidgetHookId;
515
- result: boolean;
516
- }
517
532
  export interface WidgetHookPayloadMap {
518
533
  [WidgetHookEvents.ON_BEFORE_APPROVAL]: OnApprovalPayload;
519
534
  [WidgetHookEvents.ON_BEFORE_TRADE]: OnTradeParamsPayload;
@@ -521,50 +536,37 @@ export interface WidgetHookPayloadMap {
521
536
  [WidgetHookEvents.ON_BEFORE_ORDER_CANCEL]: EnrichedOrder;
522
537
  [WidgetHookEvents.ON_BEFORE_ORDERS_CANCEL]: EnrichedOrder[];
523
538
  }
524
- export interface EmitCowEventPayload<T extends CowWidgetEvents> {
525
- event: T;
526
- payload: CowWidgetEventPayloadMap[T];
539
+ export interface WidgetHookResultPayload {
540
+ id: WidgetHookId;
541
+ result: boolean;
527
542
  }
543
+ export type WidgetMethodHandler<T extends WidgetMethodsEmit> = (payload: WidgetMethodsEmitPayloadMap[T]) => void;
528
544
  export type WidgetMethodsEmitListener<T extends WidgetMethodsEmit> = T extends WidgetMethodsEmit ? {
529
545
  event: T;
530
546
  handler: WidgetMethodHandler<T>;
531
547
  } : never;
532
- export type WidgetMethodHandler<T extends WidgetMethodsEmit> = (payload: WidgetMethodsEmitPayloadMap[T]) => void;
533
- export interface ProviderRpcRequestPayload {
534
- rpcRequest: JsonRpcRequestMessage;
548
+ export interface WidgetMethodsEmitPayloadMap {
549
+ [WidgetMethodsEmit.ACTIVATE]: void;
550
+ [WidgetMethodsEmit.READY]: void;
551
+ [WidgetMethodsEmit.EMIT_COW_EVENT]: EmitCowEventPayload<CowWidgetEvents>;
552
+ [WidgetMethodsEmit.UPDATE_HEIGHT]: UpdateWidgetHeightPayload;
553
+ [WidgetMethodsEmit.SET_FULL_HEIGHT]: void;
554
+ [WidgetMethodsEmit.PROVIDER_RPC_REQUEST]: ProviderRpcRequestPayload;
555
+ [WidgetMethodsEmit.INTERCEPT_WINDOW_OPEN]: WindowOpenPayload;
556
+ [WidgetMethodsEmit.PROCESS_HOOK]: WidgetHookPayload<WidgetHookEvents>;
535
557
  }
558
+ export type WidgetMethodsEmitPayloads = WidgetMethodsEmitPayloadMap[WidgetMethodsEmit];
559
+ export interface WidgetMethodsListenPayloadMap {
560
+ [WidgetMethodsListen.UPDATE_APP_DATA]: UpdateAppDataPayload;
561
+ [WidgetMethodsListen.UPDATE_PARAMS]: UpdateParamsPayload;
562
+ [WidgetMethodsListen.PROVIDER_RPC_RESPONSE]: ProviderRpcResponsePayload;
563
+ [WidgetMethodsListen.PROVIDER_ON_EVENT]: ProviderOnEventPayload;
564
+ [WidgetMethodsListen.HOOK_RESULT]: WidgetHookResultPayload;
565
+ }
566
+ export type WidgetMethodsListenPayloads = WidgetMethodsListenPayloadMap[WidgetMethodsListen];
567
+ export type WindowListener = (event: MessageEvent<unknown>) => void;
536
568
  export interface WindowOpenPayload {
537
569
  href: string | URL;
538
570
  target: string;
539
571
  rel: string;
540
572
  }
541
- export interface JsonRpcRequestMessage {
542
- jsonrpc: '2.0';
543
- id?: number;
544
- method: string;
545
- params: unknown[];
546
- }
547
- export interface BaseJsonRpcResponseMessage {
548
- id: number;
549
- jsonrpc: '2.0';
550
- }
551
- export interface JsonRpcSucessfulResponseMessage<TResult = unknown> extends BaseJsonRpcResponseMessage {
552
- result: TResult;
553
- }
554
- export interface JsonRpcError<TData = unknown> {
555
- code: number;
556
- message: string;
557
- data?: TData;
558
- }
559
- export interface JsonRpcErrorResponseMessage<TErrorData = unknown> extends BaseJsonRpcResponseMessage {
560
- error: JsonRpcError<TErrorData>;
561
- }
562
- export type ProviderRpcResponsePayload = {
563
- rpcResponse: JsonRpcResponse;
564
- };
565
- export type JsonRpcResponse = JsonRpcRequestMessage | JsonRpcErrorResponseMessage | JsonRpcSucessfulResponseMessage;
566
- export interface ProviderOnEventPayload {
567
- event: string;
568
- params: unknown;
569
- }
570
- export type WindowListener = (event: MessageEvent<unknown>) => void;
package/urlUtils.d.ts CHANGED
@@ -4,6 +4,9 @@ import { CowSwapWidgetParams } from './types';
4
4
  * When `false`, invalid values are reported with `console.error` and the iframe falls back to the production host.
5
5
  */
6
6
  export declare const SHOULD_THROW_IF_INVALID_URL = false;
7
+ export declare function buildWidgetPath(params: Partial<CowSwapWidgetParams>): string;
8
+ export declare function buildWidgetUrl(params: Partial<CowSwapWidgetParams>): string;
9
+ export declare function buildWidgetUrlQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams;
7
10
  /**
8
11
  * Normalizes `baseUrl` for the widget iframe `src` and rejects unsafe values.
9
12
  * - Omits or blank `baseUrl` → production default (https://swap.cow.fi).
@@ -13,6 +16,3 @@ export declare const SHOULD_THROW_IF_INVALID_URL = false;
13
16
  * @throws {Error} When validation fails and `throwIfInvalid` is true (see {@link SHOULD_THROW_IF_INVALID_URL}).
14
17
  */
15
18
  export declare function sanitizeWidgetBaseUrl(baseUrl: string | undefined, throwIfInvalid?: boolean): string;
16
- export declare function buildWidgetUrl(params: Partial<CowSwapWidgetParams>): string;
17
- export declare function buildWidgetPath(params: Partial<CowSwapWidgetParams>): string;
18
- export declare function buildWidgetUrlQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams;