@cowprotocol/widget-react 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './lib/CowSwapWidget';
2
- export type * from '@cowprotocol/widget-lib';
2
+ export * from '@cowprotocol/widget-lib';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),i=require("react"),w="2.0",g="*",m=["connect","disconnect","close","chainChanged","accountsChanged"];class E{constructor(e){this.contentWindow=e,window.addEventListener("message",this.processEvent)}ethereumProvider=null;requests={};disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(s=>{this.processRequest(this.requests[s])}),this.requests={},m.forEach(s=>{e.on(s,n=>{this.postMessage({method:s,params:[n]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(n=>{this.postMessage({id:e.id,result:n})}).catch(n=>{this.postMessage({id:e.id,error:n})})}processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)};postMessage(e){this.contentWindow.postMessage({jsonrpc:w,...e},g)}}function y(){return typeof window>"u"||!window?"":`https://swap-dev-git-${window.location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const R={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:y()};var u=(t=>(t.SWAP="swap",t.LIMIT="limit",t.ADVANCED="advanced",t))(u||{});const a="_";function v(t){const e=R[t.env||"prod"],s=h(t),n=p(t);return e+"/#"+s+"?"+n}function h(t){const{chainId:e=1,sell:s,buy:n,tradeType:o=u.SWAP}=t,r=[s?.asset||a,n?.asset||a].map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${r}`}function p(t){const{sell:e,buy:s,theme:n}=t,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),s?.amount&&o.append("buyAmount",s.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const c="cowSwapWidget",f="640px",P="450px",W=20;function S(t,e={}){const{provider:s}=e,n=T(e);t.innerHTML="",t.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return C(o,e.appCode),M(n,e.height),s&&new E(o).onConnect(s),n.addEventListener("load",()=>{d(e,o)}),r=>d(r,o)}function T(t){const{width:e=P,height:s=f}=t,n=document.createElement("iframe");return n.src=v(t),n.width=e,n.height=s,n.style.border="0",n}function d(t,e){const s=h(t),n=p(t).toString();e.postMessage({key:c,method:"update",urlParams:{pathname:s,search:n},appParams:{...t,provider:void 0}},"*")}function C(t,e){window.addEventListener("message",s=>{s.data.key!==c||s.data.method!=="activate"||t.postMessage({key:c,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function M(t,e=f){window.addEventListener("message",s=>{s.data.key!==c||s.data.method!=="iframeHeight"||(t.style.height=s.data.height?`${s.data.height+W}px`:e)})}function b({params:t,provider:e}){const s=i.useRef(),n=i.useRef(null),o=i.useRef(null);return i.useEffect(()=>{n.current&&(e&&s.current!==e&&(o.current=null),o.current?o.current(t):o.current=S(n.current,t))},[e,t]),i.useEffect(()=>{s.current=e},[e]),l.jsx("div",{ref:n})}exports.CowSwapWidget=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),i=require("react"),m="2.0",E="*",W=["connect","disconnect","close","chainChanged","accountsChanged"];class y{constructor(e){this.contentWindow=e,window.addEventListener("message",this.processEvent)}ethereumProvider=null;requests={};disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(e){this.ethereumProvider=e,Object.keys(this.requests).forEach(s=>{this.processRequest(this.requests[s])}),this.requests={},W.forEach(s=>{e.on(s,n=>{this.postMessage({method:s,params:[n]})})})}processRequest(e){if(!this.ethereumProvider)return;(e.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(e)).then(n=>{this.postMessage({id:e.id,result:n})}).catch(n=>{this.postMessage({id:e.id,error:n})})}processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)};postMessage(e){this.contentWindow.postMessage({jsonrpc:m,...e},E)}}function R(){return typeof window>"u"||!window?"":`https://swap-dev-git-${window.location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const h={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:R()};var a=(t=>(t.SWAP="swap",t.LIMIT="limit",t.ADVANCED="advanced",t))(a||{});const d="_";function P(t){const e=h[t.env||"prod"],s=p(t),n=f(t);return e+"/#"+s+"?"+n}function p(t){const{chainId:e=1,sell:s,buy:n,tradeType:o=a.SWAP}=t,r=[s?.asset||d,n?.asset||d].map(encodeURIComponent).join("/");return`/${e}/widget/${o}/${r}`}function f(t){const{sell:e,buy:s,theme:n}=t,o=new URLSearchParams;return e?.amount&&o.append("sellAmount",e.amount),s?.amount&&o.append("buyAmount",s.amount),n&&o.append("theme",typeof n=="string"?n:n.baseTheme),o}const c="cowSwapWidget",w="640px",v="450px",S=20;function l(t,e={}){const{provider:s}=e,n=T(e);t.innerHTML="",t.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return C(o,e.appCode),A(n,e.height),s&&new y(o).onConnect(s),n.addEventListener("load",()=>{u(e,o)}),r=>u(r,o)}function T(t){const{width:e=v,height:s=w}=t,n=document.createElement("iframe");return n.src=P(t),n.width=e,n.height=s,n.style.border="0",n}function u(t,e){const s=p(t),n=f(t).toString();e.postMessage({key:c,method:"update",urlParams:{pathname:s,search:n},appParams:{...t,provider:void 0}},"*")}function C(t,e){window.addEventListener("message",s=>{s.data.key!==c||s.data.method!=="activate"||t.postMessage({key:c,method:"metaData",metaData:e?{appCode:e}:void 0},"*")})}function A(t,e=w){window.addEventListener("message",s=>{s.data.key!==c||s.data.method!=="iframeHeight"||(t.style.height=s.data.height?`${s.data.height+S}px`:e)})}function M({params:t,provider:e}){const s=i.useRef(),n=i.useRef(null),o=i.useRef(null);return i.useEffect(()=>{n.current&&(e&&s.current!==e&&(o.current=null),o.current?o.current(t):o.current=l(n.current,t))},[e,t]),i.useEffect(()=>{s.current=e},[e]),g.jsx("div",{ref:n})}exports.COWSWAP_URLS=h;exports.CowSwapWidget=M;exports.TradeType=a;exports.cowSwapWidget=l;
package/index.mjs CHANGED
@@ -143,5 +143,8 @@ function L({ params: t, provider: e }) {
143
143
  }, [e]), /* @__PURE__ */ w("div", { ref: n });
144
144
  }
145
145
  export {
146
- L as CowSwapWidget
146
+ P as COWSWAP_URLS,
147
+ L as CowSwapWidget,
148
+ h as TradeType,
149
+ A as cowSwapWidget
147
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-react",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
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",