From 4f4b7d56e1cf806d52f09875f95c0afa15a06985 Mon Sep 17 00:00:00 2001 From: Leandro Date: Mon, 16 Oct 2023 09:24:15 -0700 Subject: [PATCH 1/4] fix(wc): add back patch which fixes WC path issue (#3230) --- .../@walletconnect+universal-provider+2.10.2.patch | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 patches/@walletconnect+universal-provider+2.10.2.patch diff --git a/patches/@walletconnect+universal-provider+2.10.2.patch b/patches/@walletconnect+universal-provider+2.10.2.patch new file mode 100644 index 0000000000..c387a1fad7 --- /dev/null +++ b/patches/@walletconnect+universal-provider+2.10.2.patch @@ -0,0 +1,11 @@ +diff --git a/node_modules/@walletconnect/universal-provider/dist/index.cjs.js b/node_modules/@walletconnect/universal-provider/dist/index.cjs.js +index d4fc0f5..7384e91 100644 +--- a/node_modules/@walletconnect/universal-provider/dist/index.cjs.js ++++ b/node_modules/@walletconnect/universal-provider/dist/index.cjs.js +@@ -24,5 +24,5 @@ __p += '`),H&&(m+=`' + + function print() { __p += __j.call(arguments, '') } + `:`; + `)+m+`return __p +-}`;var b=_a(function(){return U(o,I+"return "+m).apply(i,f)});if(b.source=m,Ei(b))throw b;return b}function $d(n){return q(n).toLowerCase()}function Ud(n){return q(n).toUpperCase()}function qd(n,t,e){if(n=q(n),n&&(e||t===i))return ys(n);if(!n||!(t=pn(t)))return n;var r=On(n),s=On(t),o=Ss(r,s),f=Rs(r,s)+1;return at(r,o,f).join("")}function Wd(n,t,e){if(n=q(n),n&&(e||t===i))return n.slice(0,bs(n)+1);if(!n||!(t=pn(t)))return n;var r=On(n),s=Rs(r,On(t))+1;return at(r,0,s).join("")}function Fd(n,t,e){if(n=q(n),n&&(e||t===i))return n.replace(Er,"");if(!n||!(t=pn(t)))return n;var r=On(n),s=Ss(r,On(t));return at(r,s).join("")}function Md(n,t){var e=La,r=Da;if(z(t)){var s="separator"in t?t.separator:s;e="length"in t?O(t.length):e,r="omission"in t?pn(t.omission):r}n=q(n);var o=n.length;if(Dt(n)){var f=On(n);o=f.length}if(e>=o)return n;var c=e-Nt(r);if(c<1)return r;var l=f?at(f,0,c).join(""):n.slice(0,c);if(s===i)return l+r;if(f&&(c+=l.length-c),yi(s)){if(n.slice(c).search(s)){var v,_=l;for(s.global||(s=Br(s.source,q(Zi.exec(s))+"g")),s.lastIndex=0;v=s.exec(_);)var m=v.index;l=l.slice(0,m===i?c:m)}}else if(n.indexOf(pn(s),c)!=c){var P=l.lastIndexOf(s);P>-1&&(l=l.slice(0,P))}return l+r}function Bd(n){return n=q(n),n&&Va.test(n)?n.replace(zi,_f):n}var Gd=Mt(function(n,t,e){return n+(e?" ":"")+t.toUpperCase()}),Oi=mu("toUpperCase");function va(n,t,e){return n=q(n),t=e?i:t,t===i?lf(n)?Pf(n):ef(n):n.match(t)||[]}var _a=L(function(n,t){try{return hn(n,i,t)}catch(e){return Ei(e)?e:new S(e)}}),Kd=Yn(function(n,t){return wn(t,function(e){e=Wn(e),zn(n,e,Ii(n[e],n))}),n});function zd(n){var t=n==null?0:n.length,e=x();return n=t?G(n,function(r){if(typeof r[1]!="function")throw new Pn($);return[e(r[0]),r[1]]}):[],L(function(r){for(var s=-1;++sjn)return[];var e=$n,r=nn(n,$n);t=x(t),n-=$n;for(var s=Wr(r,t);++e0||t<0)?new N(e):(n<0?e=e.takeRight(-n):n&&(e=e.drop(n)),t!==i&&(t=O(t),e=t<0?e.dropRight(-t):e.take(t-n)),e)},N.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},N.prototype.toArray=function(){return this.take($n)},Un(N.prototype,function(n,t){var e=/^(?:filter|find|map|reject)|While$/.test(t),r=/^(?:head|last)$/.test(t),s=a[r?"take"+(t=="last"?"Right":""):t],o=r||/^find/.test(t);s&&(a.prototype[t]=function(){var f=this.__wrapped__,c=r?[1]:arguments,l=f instanceof N,v=c[0],_=l||R(f),m=function(D){var H=s.apply(a,tt([D],c));return r&&P?H[0]:H};_&&e&&typeof v=="function"&&v.length!=1&&(l=_=!1);var P=this.__chain__,I=!!this.__actions__.length,E=o&&!P,b=l&&!I;if(!o&&_){f=b?f:new N(this);var y=n.apply(f,c);return y.__actions__.push({func:er,args:[m],thisArg:i}),new An(y,P)}return E&&b?n.apply(this,c):(y=this.thru(m),E?r?y.value()[0]:y.value():y)})}),wn(["pop","push","shift","sort","splice","unshift"],function(n){var t=Re[n],e=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",r=/^(?:pop|shift)$/.test(n);a.prototype[n]=function(){var s=arguments;if(r&&!this.__chain__){var o=this.value();return t.apply(R(o)?o:[],s)}return this[e](function(f){return t.apply(R(f)?f:[],s)})}}),Un(N.prototype,function(n,t){var e=a[t];if(e){var r=e.name+"";W.call(qt,r)||(qt[r]=[]),qt[r].push({name:t,func:e})}}),qt[Xe(i,ht).name]=[{name:"wrapper",func:i}],N.prototype.clone=Bf,N.prototype.reverse=Gf,N.prototype.value=Kf,a.prototype.at=wl,a.prototype.chain=Pl,a.prototype.commit=Al,a.prototype.next=Cl,a.prototype.plant=xl,a.prototype.reverse=El,a.prototype.toJSON=a.prototype.valueOf=a.prototype.value=yl,a.prototype.first=a.prototype.head,te&&(a.prototype[te]=Il),a},Ht=Af();pt?((pt.exports=Ht)._=Ht,Tr._=Ht):k._=Ht}).call(ge)})(Ui,Ui.exports);var $g=Object.defineProperty,Ug=Object.defineProperties,qg=Object.getOwnPropertyDescriptors,Ea=Object.getOwnPropertySymbols,Wg=Object.prototype.hasOwnProperty,Fg=Object.prototype.propertyIsEnumerable,ya=(A,u,i)=>u in A?$g(A,u,{enumerable:!0,configurable:!0,writable:!0,value:i}):A[u]=i,cr=(A,u)=>{for(var i in u||(u={}))Wg.call(u,i)&&ya(A,i,u[i]);if(Ea)for(var i of Ea(u))Fg.call(u,i)&&ya(A,i,u[i]);return A},Mg=(A,u)=>Ug(A,qg(u));function ct(A,u,i){var d;const w=en.parseChainId(A);return((d=u.rpcMap)==null?void 0:d[w.reference])||`${Hg}?chainId=${w.namespace}:${w.reference}&projectId=${i}`}function It(A){return A.includes(":")?A.split(":")[1]:A}function Sa(A){return A.map(u=>`${u.split(":")[0]}:${u.split(":")[1]}`)}function Bg(A,u){const i=Object.keys(u.namespaces).filter(w=>w.includes(A));if(!i.length)return[];const d=[];return i.forEach(w=>{const T=u.namespaces[w].accounts;d.push(...T)}),d}function Gg(A={},u={}){const i=Ra(A),d=Ra(u);return Ui.exports.merge(i,d)}function Ra(A){var u,i,d,w;const T={};if(!en.isValidObject(A))return T;for(const[$,yn]of Object.entries(A)){const zt=en.isCaipNamespace($)?[$]:yn.chains,pr=yn.methods||[],xt=yn.events||[],Dn=yn.rpcMap||{},Fn=en.parseNamespaceKey($);T[Fn]=Mg(cr(cr({},T[Fn]),yn),{chains:en.mergeArrays(zt,(u=T[Fn])==null?void 0:u.chains),methods:en.mergeArrays(pr,(i=T[Fn])==null?void 0:i.methods),events:en.mergeArrays(xt,(d=T[Fn])==null?void 0:d.events),rpcMap:cr(cr({},Dn),(w=T[Fn])==null?void 0:w.rpcMap)})}return T}function Kg(A){return A.includes(":")?A.split(":")[2]:A}function zg(A){const u={};for(const[i,d]of Object.entries(A)){const w=d.methods||[],T=d.events||[],$=d.accounts||[],yn=en.isCaipNamespace(i)?[i]:d.chains?d.chains:Sa(d.accounts);u[i]={chains:yn,methods:w,events:T,accounts:$}}return u}function qi(A){return typeof A=="number"?A:A.includes("0x")?parseInt(A,16):A.includes(":")?Number(A.split(":")[1]):Number(A)}const Oa={},K=A=>Oa[A],Wi=(A,u)=>{Oa[A]=u};class Jg{constructor(u){this.name="polkadot",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getAccounts(){const u=this.namespace.accounts;return u?u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2])||[]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Yg{constructor(u){this.name="eip155",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(u){switch(u.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return await this.handleSwitchChain(u);case"eth_chainId":return parseInt(this.getDefaultChain())}return this.namespace.methods.includes(u.request.method)?await this.client.request(u):this.getHttpProvider().request(u.request)}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(parseInt(u),i),this.chainId=parseInt(u),this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}createHttpProvider(u,i){const d=i||ct(`${this.name}:${u}`,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ca.HttpConnection(d,K("disableProviderPing")))}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=parseInt(It(i));u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}getHttpProvider(){const u=this.chainId,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}async handleSwitchChain(u){var i,d;let w=u.request.params?(i=u.request.params[0])==null?void 0:i.chainId:"0x0";w=w.startsWith("0x")?w:`0x${w}`;const T=parseInt(w,16);if(this.isChainApproved(T))this.setDefaultChain(`${T}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:u.topic,request:{method:u.request.method,params:[{chainId:w}]},chainId:(d=this.namespace.chains)==null?void 0:d[0]}),this.setDefaultChain(`${T}`);else throw new Error(`Failed to switch to chain 'eip155:${T}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(u){return this.namespace.chains.includes(`${this.name}:${u}`)}}class Zg{constructor(u){this.name="solana",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Xg{constructor(u){this.name="cosmos",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Qg{constructor(u){this.name="cip34",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{const d=this.getCardanoRPCUrl(i),w=It(i);u[w]=this.createHttpProvider(w,d)}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}getCardanoRPCUrl(u){const i=this.namespace.rpcMap;if(i)return i[u]}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||this.getCardanoRPCUrl(u);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Vg{constructor(u){this.name="elrond",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class kg{constructor(u){this.name="multiversx",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class jg{constructor(u){this.name="near",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){if(this.chainId=u,!this.httpProviders[u]){const d=i||ct(`${this.name}:${u}`,this.namespace);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);this.setHttpProvider(u,d)}this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2])||[]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;u[i]=this.createHttpProvider(i,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace);return typeof d>"u"?void 0:new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}var nv=Object.defineProperty,tv=Object.defineProperties,ev=Object.getOwnPropertyDescriptors,ba=Object.getOwnPropertySymbols,rv=Object.prototype.hasOwnProperty,iv=Object.prototype.propertyIsEnumerable,Ta=(A,u,i)=>u in A?nv(A,u,{enumerable:!0,configurable:!0,writable:!0,value:i}):A[u]=i,hr=(A,u)=>{for(var i in u||(u={}))rv.call(u,i)&&Ta(A,i,u[i]);if(ba)for(var i of ba(u))iv.call(u,i)&&Ta(A,i,u[i]);return A},Fi=(A,u)=>tv(A,ev(u));class lr{constructor(u){this.events=new Tg.default,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.disableProviderPing=!1,this.providerOpts=u,this.logger=typeof u?.logger<"u"&&typeof u?.logger!="string"?u.logger:Aa.pino(Aa.getDefaultLoggerOptions({level:u?.logger||Ia})),this.disableProviderPing=u?.disableProviderPing||!1}static async init(u){const i=new lr(u);return await i.initialize(),i}async request(u,i){const[d,w]=this.validateChain(i);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(d).request({request:hr({},u),chainId:`${d}:${w}`,topic:this.session.topic})}sendAsync(u,i,d){this.request(u,d).then(w=>i(null,w)).catch(w=>i(w,void 0))}async enable(){if(!this.client)throw new Error("Sign Client not initialized");return this.session||await this.connect({namespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties}),await this.requestAccounts()}async disconnect(){var u;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(u=this.session)==null?void 0:u.topic,reason:en.getSdkError("USER_DISCONNECTED")}),await this.cleanup()}async connect(u){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(u),await this.cleanupPendingPairings(),!u.skipPairing)return await this.pair(u.pairingTopic)}on(u,i){this.events.on(u,i)}once(u,i){this.events.once(u,i)}removeListener(u,i){this.events.removeListener(u,i)}off(u,i){this.events.off(u,i)}get isWalletConnect(){return!0}async pair(u){this.shouldAbortPairingAttempt=!1;let i=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(i>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:d,approval:w}=await this.client.connect({pairingTopic:u,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});d&&(this.uri=d,this.events.emit("display_uri",d)),await w().then(T=>{this.session=T,this.namespaces||(this.namespaces=zg(T.namespaces),this.persist("namespaces",this.namespaces))}).catch(T=>{if(T.message!==Pa.PROPOSAL_EXPIRY_MESSAGE)throw T;i++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(u,i){try{if(!this.session)return;const[d,w]=this.validateChain(u);this.getProvider(d).setDefaultChain(w,i)}catch(d){if(!/Please call connect/.test(d.message))throw d}}async cleanupPendingPairings(u={}){this.logger.info("Cleaning up inactive pairings...");const i=this.client.pairing.getAll();if(en.isValidArray(i)){for(const d of i)u.deletePairings?this.client.core.expirer.set(d.topic,0):await this.client.core.relayer.subscriber.unsubscribe(d.topic);this.logger.info(`Inactive pairings cleared: ${i.length}`)}}abortPairingAttempt(){this.shouldAbortPairingAttempt=!0}async checkStorage(){if(this.namespaces=await this.getFromStore("namespaces"),this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.client.session.length){const u=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[u]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await bg.default.init({logger:this.providerOpts.logger||Ia,relayUrl:this.providerOpts.relayUrl||Lg,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,storage:this.providerOpts.storage,name:this.providerOpts.name}),this.logger.trace("SignClient Initialized")}createProviders(){if(!this.client)throw new Error("Sign Client not initialized");if(!this.session)throw new Error("Session not initialized. Please call connect() before enable()");const u=[...new Set(Object.keys(this.session.namespaces).map(i=>en.parseNamespaceKey(i)))];Wi("client",this.client),Wi("events",this.events),Wi("disableProviderPing",this.disableProviderPing),u.forEach(i=>{if(!this.session)return;const d=Bg(i,this.session),w=Sa(d),T=Gg(this.namespaces,this.optionalNamespaces),$=Fi(hr({},T[i]),{accounts:d,chains:w});switch(i){case"eip155":this.rpcProviders[i]=new Yg({namespace:$});break;case"solana":this.rpcProviders[i]=new Zg({namespace:$});break;case"cosmos":this.rpcProviders[i]=new Xg({namespace:$});break;case"polkadot":this.rpcProviders[i]=new Jg({namespace:$});break;case"cip34":this.rpcProviders[i]=new Qg({namespace:$});break;case"elrond":this.rpcProviders[i]=new Vg({namespace:$});break;case"multiversx":this.rpcProviders[i]=new kg({namespace:$});break;case"near":this.rpcProviders[i]=new jg({namespace:$});break}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",u=>{this.events.emit("session_ping",u)}),this.client.on("session_event",u=>{const{params:i}=u,{event:d}=i;if(d.name==="accountsChanged"){const w=d.data;w&&en.isValidArray(w)&&this.events.emit("accountsChanged",w.map(Kg))}else if(d.name==="chainChanged"){const w=i.chainId,T=i.event.data,$=en.parseNamespaceKey(w),yn=qi(w)!==qi(T)?`${$}:${qi(T)}`:w;this.onChainChanged(yn)}else this.events.emit(d.name,d.data);this.events.emit("session_event",u)}),this.client.on("session_update",({topic:u,params:i})=>{var d;const{namespaces:w}=i,T=(d=this.client)==null?void 0:d.session.get(u);this.session=Fi(hr({},T),{namespaces:w}),this.onSessionUpdate(),this.events.emit("session_update",{topic:u,params:i})}),this.client.on("session_delete",async u=>{await this.cleanup(),this.events.emit("session_delete",u),this.events.emit("disconnect",Fi(hr({},en.getSdkError("USER_DISCONNECTED")),{data:u.topic}))}),this.on(kn.DEFAULT_CHAIN_CHANGED,u=>{this.onChainChanged(u,!0)})}getProvider(u){if(!this.rpcProviders[u])throw new Error(`Provider not found: ${u}`);return this.rpcProviders[u]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(u=>{var i;this.getProvider(u).updateNamespace((i=this.session)==null?void 0:i.namespaces[u])})}setNamespaces(u){const{namespaces:i,optionalNamespaces:d,sessionProperties:w}=u;i&&Object.keys(i).length&&(this.namespaces=i),d&&Object.keys(d).length&&(this.optionalNamespaces=d),this.sessionProperties=w,this.persist("namespaces",i),this.persist("optionalNamespaces",d)}validateChain(u){const[i,d]=u?.split(":")||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[i,d];if(i&&!Object.keys(this.namespaces||{}).map($=>en.parseNamespaceKey($)).includes(i))throw new Error(`Namespace '${i}' is not configured. Please call connect() first with namespace config.`);if(i&&d)return[i,d];const w=en.parseNamespaceKey(Object.keys(this.namespaces)[0]),T=this.rpcProviders[w].getDefaultChain();return[w,T]}async requestAccounts(){const[u]=this.validateChain();return await this.getProvider(u).requestAccounts()}onChainChanged(u,i=!1){var d;if(!this.namespaces)return;const[w,T]=this.validateChain(u);i||this.getProvider(w).setDefaultChain(T),((d=this.namespaces[w])!=null?d:this.namespaces[`${w}:${T}`]).defaultChain=T,this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",T)}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,this.persist("namespaces",void 0),this.persist("optionalNamespaces",void 0),this.persist("sessionProperties",void 0),await this.cleanupPendingPairings({deletePairings:!0})}persist(u,i){this.client.core.storage.setItem(`${xa}/${u}`,i)}async getFromStore(u){return await this.client.core.storage.getItem(`${xa}/${u}`)}}const sv=lr;exports.UniversalProvider=sv,exports.default=lr; ++}`;var b=_a(function(){return U(o,I+"return "+m).apply(i,f)});if(b.source=m,Ei(b))throw b;return b}function $d(n){return q(n).toLowerCase()}function Ud(n){return q(n).toUpperCase()}function qd(n,t,e){if(n=q(n),n&&(e||t===i))return ys(n);if(!n||!(t=pn(t)))return n;var r=On(n),s=On(t),o=Ss(r,s),f=Rs(r,s)+1;return at(r,o,f).join("")}function Wd(n,t,e){if(n=q(n),n&&(e||t===i))return n.slice(0,bs(n)+1);if(!n||!(t=pn(t)))return n;var r=On(n),s=Rs(r,On(t))+1;return at(r,0,s).join("")}function Fd(n,t,e){if(n=q(n),n&&(e||t===i))return n.replace(Er,"");if(!n||!(t=pn(t)))return n;var r=On(n),s=Ss(r,On(t));return at(r,s).join("")}function Md(n,t){var e=La,r=Da;if(z(t)){var s="separator"in t?t.separator:s;e="length"in t?O(t.length):e,r="omission"in t?pn(t.omission):r}n=q(n);var o=n.length;if(Dt(n)){var f=On(n);o=f.length}if(e>=o)return n;var c=e-Nt(r);if(c<1)return r;var l=f?at(f,0,c).join(""):n.slice(0,c);if(s===i)return l+r;if(f&&(c+=l.length-c),yi(s)){if(n.slice(c).search(s)){var v,_=l;for(s.global||(s=Br(s.source,q(Zi.exec(s))+"g")),s.lastIndex=0;v=s.exec(_);)var m=v.index;l=l.slice(0,m===i?c:m)}}else if(n.indexOf(pn(s),c)!=c){var P=l.lastIndexOf(s);P>-1&&(l=l.slice(0,P))}return l+r}function Bd(n){return n=q(n),n&&Va.test(n)?n.replace(zi,_f):n}var Gd=Mt(function(n,t,e){return n+(e?" ":"")+t.toUpperCase()}),Oi=mu("toUpperCase");function va(n,t,e){return n=q(n),t=e?i:t,t===i?lf(n)?Pf(n):ef(n):n.match(t)||[]}var _a=L(function(n,t){try{return hn(n,i,t)}catch(e){return Ei(e)?e:new S(e)}}),Kd=Yn(function(n,t){return wn(t,function(e){e=Wn(e),zn(n,e,Ii(n[e],n))}),n});function zd(n){var t=n==null?0:n.length,e=x();return n=t?G(n,function(r){if(typeof r[1]!="function")throw new Pn($);return[e(r[0]),r[1]]}):[],L(function(r){for(var s=-1;++sjn)return[];var e=$n,r=nn(n,$n);t=x(t),n-=$n;for(var s=Wr(r,t);++e0||t<0)?new N(e):(n<0?e=e.takeRight(-n):n&&(e=e.drop(n)),t!==i&&(t=O(t),e=t<0?e.dropRight(-t):e.take(t-n)),e)},N.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},N.prototype.toArray=function(){return this.take($n)},Un(N.prototype,function(n,t){var e=/^(?:filter|find|map|reject)|While$/.test(t),r=/^(?:head|last)$/.test(t),s=a[r?"take"+(t=="last"?"Right":""):t],o=r||/^find/.test(t);s&&(a.prototype[t]=function(){var f=this.__wrapped__,c=r?[1]:arguments,l=f instanceof N,v=c[0],_=l||R(f),m=function(D){var H=s.apply(a,tt([D],c));return r&&P?H[0]:H};_&&e&&typeof v=="function"&&v.length!=1&&(l=_=!1);var P=this.__chain__,I=!!this.__actions__.length,E=o&&!P,b=l&&!I;if(!o&&_){f=b?f:new N(this);var y=n.apply(f,c);return y.__actions__.push({func:er,args:[m],thisArg:i}),new An(y,P)}return E&&b?n.apply(this,c):(y=this.thru(m),E?r?y.value()[0]:y.value():y)})}),wn(["pop","push","shift","sort","splice","unshift"],function(n){var t=Re[n],e=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",r=/^(?:pop|shift)$/.test(n);a.prototype[n]=function(){var s=arguments;if(r&&!this.__chain__){var o=this.value();return t.apply(R(o)?o:[],s)}return this[e](function(f){return t.apply(R(f)?f:[],s)})}}),Un(N.prototype,function(n,t){var e=a[t];if(e){var r=e.name+"";W.call(qt,r)||(qt[r]=[]),qt[r].push({name:t,func:e})}}),qt[Xe(i,ht).name]=[{name:"wrapper",func:i}],N.prototype.clone=Bf,N.prototype.reverse=Gf,N.prototype.value=Kf,a.prototype.at=wl,a.prototype.chain=Pl,a.prototype.commit=Al,a.prototype.next=Cl,a.prototype.plant=xl,a.prototype.reverse=El,a.prototype.toJSON=a.prototype.valueOf=a.prototype.value=yl,a.prototype.first=a.prototype.head,te&&(a.prototype[te]=Il),a},Ht=Af();pt?((pt.exports=Ht)._=Ht,Tr._=Ht):k._=Ht}).call(ge)})(Ui,Ui.exports);var $g=Object.defineProperty,Ug=Object.defineProperties,qg=Object.getOwnPropertyDescriptors,Ea=Object.getOwnPropertySymbols,Wg=Object.prototype.hasOwnProperty,Fg=Object.prototype.propertyIsEnumerable,ya=(A,u,i)=>u in A?$g(A,u,{enumerable:!0,configurable:!0,writable:!0,value:i}):A[u]=i,cr=(A,u)=>{for(var i in u||(u={}))Wg.call(u,i)&&ya(A,i,u[i]);if(Ea)for(var i of Ea(u))Fg.call(u,i)&&ya(A,i,u[i]);return A},Mg=(A,u)=>Ug(A,qg(u));function ct(A,u,i){var d;const w=en.parseChainId(A);return((d=u.rpcMap)==null?void 0:d[w.reference])||`${Hg}?chainId=${w.namespace}:${w.reference}&projectId=${i}`}function It(A){return A.includes(":")?A.split(":")[1]:A}function Sa(A){return A.map(u=>`${u.split(":")[0]}:${u.split(":")[1]}`)}function Bg(A,u){const i=Object.keys(u.namespaces).filter(w=>w.includes(A));if(!i.length)return[];const d=[];return i.forEach(w=>{const T=u.namespaces[w].accounts;d.push(...T)}),d}function Gg(A={},u={}){const i=Ra(A),d=Ra(u);return Ui.exports.merge(i,d)}function Ra(A){var u,i,d,w;const T={};if(!en.isValidObject(A))return T;for(const[$,yn]of Object.entries(A)){const zt=en.isCaipNamespace($)?[$]:yn.chains,pr=yn.methods||[],xt=yn.events||[],Dn=yn.rpcMap||{},Fn=en.parseNamespaceKey($);T[Fn]=Mg(cr(cr({},T[Fn]),yn),{chains:en.mergeArrays(zt,(u=T[Fn])==null?void 0:u.chains),methods:en.mergeArrays(pr,(i=T[Fn])==null?void 0:i.methods),events:en.mergeArrays(xt,(d=T[Fn])==null?void 0:d.events),rpcMap:cr(cr({},Dn),(w=T[Fn])==null?void 0:w.rpcMap)})}return T}function Kg(A){return A.includes(":")?A.split(":")[2]:A}function zg(A){const u={};for(const[i,d]of Object.entries(A)){const w=d.methods||[],T=d.events||[],$=d.accounts||[],yn=en.isCaipNamespace(i)?[i]:d.chains?d.chains:Sa(d.accounts);u[i]={chains:yn,methods:w,events:T,accounts:$}}return u}function qi(A){return typeof A=="number"?A:A.includes("0x")?parseInt(A,16):A.includes(":")?Number(A.split(":")[1]):Number(A)}const Oa={},K=A=>Oa[A],Wi=(A,u)=>{Oa[A]=u};class Jg{constructor(u){this.name="polkadot",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getAccounts(){const u=this.namespace.accounts;return u?u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2])||[]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Yg{constructor(u){this.name="eip155",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(u){switch(u.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return await this.handleSwitchChain(u);case"eth_chainId":return parseInt(this.getDefaultChain())}return this.namespace.methods.includes(u.request.method)?await this.client.request(u):this.getHttpProvider().request(u.request)}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(parseInt(u),i),this.chainId=parseInt(u),this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}createHttpProvider(u,i){const d=i||ct(`${this.name}:${u}`,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ca.HttpConnection(d,K("disableProviderPing")))}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=parseInt(It(i));u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}getHttpProvider(){const u=this.chainId,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}async handleSwitchChain(u){var i,d;let w=u.request.params?(i=u.request.params[0])==null?void 0:i.chainId:"0x0";w=w.startsWith("0x")?w:`0x${w}`;const T=parseInt(w,16);if(this.isChainApproved(T))this.setDefaultChain(`${T}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:u.topic,request:{method:u.request.method,params:[{chainId:w}]},chainId:(d=this.namespace.chains)==null?void 0:d[0]}),this.setDefaultChain(`${T}`);else throw new Error(`Failed to switch to chain 'eip155:${T}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(u){return this.namespace.chains.includes(`${this.name}:${u}`)}}class Zg{constructor(u){this.name="solana",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Xg{constructor(u){this.name="cosmos",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Qg{constructor(u){this.name="cip34",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{const d=this.getCardanoRPCUrl(i),w=It(i);u[w]=this.createHttpProvider(w,d)}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}getCardanoRPCUrl(u){const i=this.namespace.rpcMap;if(i)return i[u]}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||this.getCardanoRPCUrl(u);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class Vg{constructor(u){this.name="elrond",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class kg{constructor(u){this.name="multiversx",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){this.httpProviders[u]||this.setHttpProvider(u,i),this.chainId=u,this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${u}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}getAccounts(){const u=this.namespace.accounts;return u?[...new Set(u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2]))]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;const w=It(i);u[w]=this.createHttpProvider(w,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace,this.client.core.projectId);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);return new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}class jg{constructor(u){this.name="near",this.namespace=u.namespace,this.events=K("events"),this.client=K("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(u){this.namespace=Object.assign(this.namespace,u)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const u=this.namespace.chains[0];if(!u)throw new Error("ChainId not found");return u.split(":")[1]}request(u){return this.namespace.methods.includes(u.request.method)?this.client.request(u):this.getHttpProvider().request(u.request)}setDefaultChain(u,i){if(this.chainId=u,!this.httpProviders[u]){const d=i||ct(`${this.name}:${u}`,this.namespace);if(!d)throw new Error(`No RPC url provided for chainId: ${u}`);this.setHttpProvider(u,d)}this.events.emit(kn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const u=this.namespace.accounts;return u?u.filter(i=>i.split(":")[1]===this.chainId.toString()).map(i=>i.split(":")[2])||[]:[]}createHttpProviders(){const u={};return this.namespace.chains.forEach(i=>{var d;u[i]=this.createHttpProvider(i,(d=this.namespace.rpcMap)==null?void 0:d[i])}),u}getHttpProvider(){const u=`${this.name}:${this.chainId}`,i=this.httpProviders[u];if(typeof i>"u")throw new Error(`JSON-RPC provider for ${u} not found`);return i}setHttpProvider(u,i){const d=this.createHttpProvider(u,i);d&&(this.httpProviders[u]=d)}createHttpProvider(u,i){const d=i||ct(u,this.namespace);return typeof d>"u"?void 0:new ft.JsonRpcProvider(new Ct.default(d,K("disableProviderPing")))}}var nv=Object.defineProperty,tv=Object.defineProperties,ev=Object.getOwnPropertyDescriptors,ba=Object.getOwnPropertySymbols,rv=Object.prototype.hasOwnProperty,iv=Object.prototype.propertyIsEnumerable,Ta=(A,u,i)=>u in A?nv(A,u,{enumerable:!0,configurable:!0,writable:!0,value:i}):A[u]=i,hr=(A,u)=>{for(var i in u||(u={}))rv.call(u,i)&&Ta(A,i,u[i]);if(ba)for(var i of ba(u))iv.call(u,i)&&Ta(A,i,u[i]);return A},Fi=(A,u)=>tv(A,ev(u));class lr{constructor(u){this.events=new Tg.default,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.disableProviderPing=!1,this.providerOpts=u,this.logger=typeof u?.logger<"u"&&typeof u?.logger!="string"?u.logger:Aa.pino(Aa.getDefaultLoggerOptions({level:u?.logger||Ia})),this.disableProviderPing=u?.disableProviderPing||!1}static async init(u){const i=new lr(u);return await i.initialize(),i}async request(u,i){const[d,w]=this.validateChain(i);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(d).request({request:hr({},u),chainId:`${d}:${w}`,topic:this.session.topic})}sendAsync(u,i,d){this.request(u,d).then(w=>i(null,w)).catch(w=>i(w,void 0))}async enable(){if(!this.client)throw new Error("Sign Client not initialized");return this.session||await this.connect({namespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties}),await this.requestAccounts()}async disconnect(){var u;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(u=this.session)==null?void 0:u.topic,reason:en.getSdkError("USER_DISCONNECTED")}),await this.cleanup()}async connect(u){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(u),await this.cleanupPendingPairings(),!u.skipPairing)return await this.pair(u.pairingTopic)}on(u,i){this.events.on(u,i)}once(u,i){this.events.once(u,i)}removeListener(u,i){this.events.removeListener(u,i)}off(u,i){this.events.off(u,i)}get isWalletConnect(){return!0}async pair(u){this.shouldAbortPairingAttempt=!1;let i=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(i>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:d,approval:w}=await this.client.connect({pairingTopic:u,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});d&&(this.uri=d,this.events.emit("display_uri",d)),await w().then(T=>{this.session=T,this.namespaces||(this.namespaces=zg(T.namespaces),this.persist("namespaces",this.namespaces))}).catch(T=>{if(T.message!==Pa.PROPOSAL_EXPIRY_MESSAGE)throw T;i++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(u,i){try{if(!this.session)return;const[d,w]=this.validateChain(u);this.getProvider(d).setDefaultChain(w,i)}catch(d){if(!/Please call connect/.test(d.message))throw d}}async cleanupPendingPairings(u={}){this.logger.info("Cleaning up inactive pairings...");const i=this.client.pairing.getAll();if(en.isValidArray(i)){for(const d of i)u.deletePairings?this.client.core.expirer.set(d.topic,0):await this.client.core.relayer.subscriber.unsubscribe(d.topic);this.logger.info(`Inactive pairings cleared: ${i.length}`)}}abortPairingAttempt(){this.shouldAbortPairingAttempt=!0}async checkStorage(){if(this.namespaces=await this.getFromStore("namespaces"),this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.client.session.length){const u=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[u]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await (bg.default.init || bg.default.default.init)({logger:this.providerOpts.logger||Ia,relayUrl:this.providerOpts.relayUrl||Lg,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,storage:this.providerOpts.storage,name:this.providerOpts.name}),this.logger.trace("SignClient Initialized")}createProviders(){if(!this.client)throw new Error("Sign Client not initialized");if(!this.session)throw new Error("Session not initialized. Please call connect() before enable()");const u=[...new Set(Object.keys(this.session.namespaces).map(i=>en.parseNamespaceKey(i)))];Wi("client",this.client),Wi("events",this.events),Wi("disableProviderPing",this.disableProviderPing),u.forEach(i=>{if(!this.session)return;const d=Bg(i,this.session),w=Sa(d),T=Gg(this.namespaces,this.optionalNamespaces),$=Fi(hr({},T[i]),{accounts:d,chains:w});switch(i){case"eip155":this.rpcProviders[i]=new Yg({namespace:$});break;case"solana":this.rpcProviders[i]=new Zg({namespace:$});break;case"cosmos":this.rpcProviders[i]=new Xg({namespace:$});break;case"polkadot":this.rpcProviders[i]=new Jg({namespace:$});break;case"cip34":this.rpcProviders[i]=new Qg({namespace:$});break;case"elrond":this.rpcProviders[i]=new Vg({namespace:$});break;case"multiversx":this.rpcProviders[i]=new kg({namespace:$});break;case"near":this.rpcProviders[i]=new jg({namespace:$});break}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",u=>{this.events.emit("session_ping",u)}),this.client.on("session_event",u=>{const{params:i}=u,{event:d}=i;if(d.name==="accountsChanged"){const w=d.data;w&&en.isValidArray(w)&&this.events.emit("accountsChanged",w.map(Kg))}else if(d.name==="chainChanged"){const w=i.chainId,T=i.event.data,$=en.parseNamespaceKey(w),yn=qi(w)!==qi(T)?`${$}:${qi(T)}`:w;this.onChainChanged(yn)}else this.events.emit(d.name,d.data);this.events.emit("session_event",u)}),this.client.on("session_update",({topic:u,params:i})=>{var d;const{namespaces:w}=i,T=(d=this.client)==null?void 0:d.session.get(u);this.session=Fi(hr({},T),{namespaces:w}),this.onSessionUpdate(),this.events.emit("session_update",{topic:u,params:i})}),this.client.on("session_delete",async u=>{await this.cleanup(),this.events.emit("session_delete",u),this.events.emit("disconnect",Fi(hr({},en.getSdkError("USER_DISCONNECTED")),{data:u.topic}))}),this.on(kn.DEFAULT_CHAIN_CHANGED,u=>{this.onChainChanged(u,!0)})}getProvider(u){if(!this.rpcProviders[u])throw new Error(`Provider not found: ${u}`);return this.rpcProviders[u]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(u=>{var i;this.getProvider(u).updateNamespace((i=this.session)==null?void 0:i.namespaces[u])})}setNamespaces(u){const{namespaces:i,optionalNamespaces:d,sessionProperties:w}=u;i&&Object.keys(i).length&&(this.namespaces=i),d&&Object.keys(d).length&&(this.optionalNamespaces=d),this.sessionProperties=w,this.persist("namespaces",i),this.persist("optionalNamespaces",d)}validateChain(u){const[i,d]=u?.split(":")||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[i,d];if(i&&!Object.keys(this.namespaces||{}).map($=>en.parseNamespaceKey($)).includes(i))throw new Error(`Namespace '${i}' is not configured. Please call connect() first with namespace config.`);if(i&&d)return[i,d];const w=en.parseNamespaceKey(Object.keys(this.namespaces)[0]),T=this.rpcProviders[w].getDefaultChain();return[w,T]}async requestAccounts(){const[u]=this.validateChain();return await this.getProvider(u).requestAccounts()}onChainChanged(u,i=!1){var d;if(!this.namespaces)return;const[w,T]=this.validateChain(u);i||this.getProvider(w).setDefaultChain(T),((d=this.namespaces[w])!=null?d:this.namespaces[`${w}:${T}`]).defaultChain=T,this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",T)}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,this.persist("namespaces",void 0),this.persist("optionalNamespaces",void 0),this.persist("sessionProperties",void 0),await this.cleanupPendingPairings({deletePairings:!0})}persist(u,i){this.client.core.storage.setItem(`${xa}/${u}`,i)}async getFromStore(u){return await this.client.core.storage.getItem(`${xa}/${u}`)}}const sv=lr;exports.UniversalProvider=sv,exports.default=lr; + //# sourceMappingURL=index.cjs.js.map From aad09c6b71c1c0a8dabb1f3ea85292bed332dbc7 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Tue, 17 Oct 2023 14:56:52 +0600 Subject: [PATCH 2/4] fix(swap): don't crash app when token decimals eq 0 (#3228) --- apps/cowswap-frontend/src/modules/swap/pure/warnings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/cowswap-frontend/src/modules/swap/pure/warnings.tsx b/apps/cowswap-frontend/src/modules/swap/pure/warnings.tsx index f7720bd985..3682af3634 100644 --- a/apps/cowswap-frontend/src/modules/swap/pure/warnings.tsx +++ b/apps/cowswap-frontend/src/modules/swap/pure/warnings.tsx @@ -101,7 +101,7 @@ export const SwapWarningsTop = React.memo(function (props: SwapWarningsTopProps) priceImpact={priceImpact} buyingFiatAmount={buyingFiatAmount} tradeUrlParams={tradeUrlParams} - sellAmount={trade?.inputAmount.toFixed(trade?.inputAmount?.currency?.decimals || 18)} + sellAmount={trade?.inputAmount.toExact()} /> ) From 409e60e9443be7ba0bc99da80e14b812eb51fafe Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Tue, 17 Oct 2023 15:50:12 +0600 Subject: [PATCH 3/4] chore(main): release 1.48.1 (#3233) --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00f68e4d57..050d5cef09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.48.1](https://github.com/cowprotocol/cowswap/compare/v1.48.0...v1.48.1) (2023-10-17) + + +### Bug Fixes + +* **swap:** don't crash app when token decimals eq 0 ([#3228](https://github.com/cowprotocol/cowswap/issues/3228)) ([aad09c6](https://github.com/cowprotocol/cowswap/commit/aad09c6b71c1c0a8dabb1f3ea85292bed332dbc7)) +* **wc:** add back patch which fixes WC path issue ([#3230](https://github.com/cowprotocol/cowswap/issues/3230)) ([4f4b7d5](https://github.com/cowprotocol/cowswap/commit/4f4b7d56e1cf806d52f09875f95c0afa15a06985)) + ## [1.48.0](https://github.com/cowprotocol/cowswap/compare/v1.47.1...v1.48.0) (2023-10-16) diff --git a/package.json b/package.json index e54fc05eda..46e253e01c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cowswap", - "version": "1.48.0", + "version": "1.48.1", "description": "CoW Swap", "main": "index.js", "author": "", From 9c1f2f1b13597a4af5600c1c915bd59ecf14f578 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Tue, 17 Oct 2023 18:42:58 +0600 Subject: [PATCH 4/4] fix(swap): don't reset swap form on recipient ens input (#3234) --- .../src/modules/trade/updaters/RecipientAddressUpdater.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/cowswap-frontend/src/modules/trade/updaters/RecipientAddressUpdater.tsx b/apps/cowswap-frontend/src/modules/trade/updaters/RecipientAddressUpdater.tsx index 7e46c45981..d84bf88bac 100644 --- a/apps/cowswap-frontend/src/modules/trade/updaters/RecipientAddressUpdater.tsx +++ b/apps/cowswap-frontend/src/modules/trade/updaters/RecipientAddressUpdater.tsx @@ -10,9 +10,9 @@ export function RecipientAddressUpdater() { useEffect(() => { if (state?.recipientAddress !== recipientAddress) { - updateState?.({ recipientAddress }) + updateState?.({ ...state, recipientAddress }) } - }, [recipientAddress, state?.recipientAddress, updateState]) + }, [recipientAddress, state, updateState]) return null }