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