@getpara/wagmi-v2-integration 1.4.2 → 1.4.4-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,8 @@ export declare class ParaEIP1193Provider extends EventEmitter implements EIP1193
33
33
  private accountFromAddress;
34
34
  private setCurrentChain;
35
35
  closeModal: () => void;
36
+ private waitForLogin;
37
+ private waitForAccounts;
36
38
  request: EIP1193RequestFn<EIP1474Methods>;
37
39
  }
38
40
  export {};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{injected as O}from"wagmi/connectors";import{ProviderRpcError as p,webSocket as E,publicActions as y,http as S,formatTransaction as b}from"viem";import{EventEmitter as x}from"eventemitter3";import{extractRpcUrls as D}from"@wagmi/core";import{getViemChain as M,createParaViemClient as N,createParaAccount as R}from"@getpara/viem-v2-integration";import{decimalToHex as h,hexToDecimal as u}from"@getpara/react-sdk";import{ParaModal as A}from"@getpara/react-sdk";import{jsx as T}from"react/jsx-runtime";function P(n,o,e){let s=document.getElementById("para-modal"),t=s??document.createElement("div");t.id="para-modal",s||document.body.appendChild(t);let a=()=>{e(),o.onClose&&o.onClose(),r(!1)},r=async i=>{let d=T(A,{...o,onClose:a,para:n,isOpen:i});try{(await import("react-dom/client")).createRoot(t).render(d)}catch{(await import("react-dom")).render(d,t)}};r(!0)}var w="@CAPSULE/chainId",_=6e5,H={setItem:()=>{},getItem:()=>null},m=class extends x{constructor(e){super();this.getRpcUrlsFromViemChain=e=>D({chain:e,transports:this.transports});this.wagmiChainToAddEthereumChainParameters=e=>{let s=h(`${e.id}`);return[s,{chainId:s,chainName:e.name,nativeCurrency:e.nativeCurrency,rpcUrls:this.getRpcUrlsFromViemChain(e)}]};this.wagmiChainsToAddEthereumChainParameters=e=>Object.fromEntries(e.map(this.wagmiChainToAddEthereumChainParameters));this.accountFromAddress=e=>R(this.para,e);this.setCurrentChain=e=>{let s=this.chains[e];this.setChainId(e);let t=this.viemChains[e]||M(u(e)),a=this.getRpcUrlsFromViemChain(t),r;this.transports[t.id]?r=this.transports[t.id]:a[0].startsWith("ws")?r=E(s.rpcUrls[0]):(r=S(a[0]),this.chainTransportSubscribe=void 0);let i=r({chain:t});i.config.type==="ws"&&(this.chainTransportSubscribe=i.value.subscribe),this.walletClient=N(this.para,{chain:t,transport:r},{noAccount:!0}).extend(y),this.emit("chainChanged",this.currentHexChainId)};this.closeModal=()=>{this.isModalClosed=!0};this.request=async e=>{let{method:s,params:t}=e;switch(s){case"eth_accounts":return this.accounts;case"eth_chainId":return this.currentHexChainId;case"eth_requestAccounts":{if(await this.para.isFullyLoggedIn())return this.accounts;this.isModalClosed=!1;let a=()=>{this.isModalClosed=!0};this.disableModal||P(this.para,this.modalProps,a);let r=Date.now();for(;Date.now()-r<_;){if(await new Promise(i=>setTimeout(i,2e3)),await this.para.isFullyLoggedIn()){let i=this.accounts;return this.emit("accountsChanged",i),i}if(this.isModalClosed)throw new p(new Error("user closed modal"),{code:4001,shortMessage:"user closed modal"})}throw new p(new Error("timed out waiting for user to log in"),{code:4001,shortMessage:"timed out waiting for user to log in"})}case"eth_sendTransaction":{let a=t[0].from;return this.walletClient.sendTransaction({...b(t[0]),chain:void 0,account:this.accountFromAddress(a)})}case"eth_sign":case"personal_sign":return this.walletClient.signMessage({message:{raw:t[0]},account:this.accountFromAddress(t[1])});case"eth_signTransaction":{let a=t[0].from;return this.accountFromAddress(a).signTransaction(b(t[0]))}case"eth_signTypedData_v4":{let a=t[0],r=t[1];return typeof r=="string"&&(r=JSON.parse(r)),this.walletClient.signTypedData({...r,account:this.accountFromAddress(a)})}case"eth_subscribe":{if(!this.chainTransportSubscribe)throw new p(new Error("chain does not support subscriptions"),{code:4200,shortMessage:"chain does not support subscriptions"});return(await this.chainTransportSubscribe({params:t,onData:r=>{this.emit("message",{type:"eth_subscription",data:r})}})).subscriptionId}case"wallet_addEthereumChain":return this.chains[t[0].chainId]||(this.chains[t[0].chainId]=t[0]),null;case"wallet_getPermissions":return[];case"wallet_requestPermissions":return[];case"wallet_switchEthereumChain":{if(!this.chains[t[0].chainId]){let a=M(u(t[0].chainId)),[r,i]=this.wagmiChainToAddEthereumChainParameters(a);this.chains[r]=i,this.setCurrentChain(t[0].chainId)}return this.currentHexChainId!==t[0].chainId&&this.setCurrentChain(t[0].chainId),null}case"wallet_watchAsset":return!1;default:return this.walletClient.request({method:s,params:t})}};this.storage=e.storageOverride||typeof window>"u"?H:sessionStorage,this.isModalClosed=!0,this.para=e.para,this.modalProps={...e},this.disableModal=!!e.disableModal,this.viemChains=e.chains.reduce((a,r)=>(a[h(`${r.id}`)]=r,a),{}),this.chains=this.wagmiChainsToAddEthereumChainParameters(e.chains),this.transports=e.transports;let s=this.getStorageChainId()||e.chainId,t=this.chains[h(s)]?s:`${e.chains[0].id}`;this.setCurrentChain(h(t)),this.emit("connect",{chainId:this.currentHexChainId})}get accounts(){return this.para.getWalletsByType("EVM").map(e=>e.address)}getStorageChainId(){return this.storage.getItem(w)}setChainId(e){this.currentHexChainId=e,this.storage.setItem(w,u(e))}};import{createConnector as W}from"wagmi";var f="para",v="Para",F="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjE2IiBoZWlnaHQ9IjIwNCIgdmlld0JveD0iMCAwIDIxNiAyMDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik02MCAwSDE0NEMxODMuNzY0IDAgMjE2IDMyLjIzNTUgMjE2IDcyQzIxNiAxMTEuNzY1IDE4My43NjQgMTQ0IDE0NCAxNDRIOTZDODIuNzQ1MiAxNDQgNzIgMTU0Ljc0NSA3MiAxNjhWMjA0SDBWMTMySDM2QzQ5LjI1NDggMTMyIDYwIDEyMS4yNTUgNjAgMTA4TDYwIDBaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K",me=({para:n,chains:o,disableModal:e,storageOverride:s,options:t,iconOverride:a,nameOverride:r,idOverride:i,transports:d,...l})=>W(c=>{let C=[...c.chains],I=new m({para:n,chainId:`${C[0].id}`,chains:C,disableModal:e,storageOverride:s,transports:d||c.transports,...l}),g=O({target:{name:v,id:i??f,provider:I},...t})(c);return{...g,type:i??f,name:r??v,icon:a??F,disconnect:async()=>{I.closeModal(),await g.disconnect(),n.logout()}}});export{m as ParaEIP1193Provider,me as paraConnector};
2
+ import{injected as F}from"wagmi/connectors";import{ProviderRpcError as d,webSocket as E,publicActions as y,http as S,formatTransaction as w}from"viem";import{EventEmitter as x}from"eventemitter3";import{extractRpcUrls as D}from"@wagmi/core";import{getViemChain as b,createParaViemClient as N,createParaAccount as R}from"@getpara/viem-v2-integration";import{decimalToHex as l,hexToDecimal as p}from"@getpara/react-sdk";import{ParaModal as T}from"@getpara/react-sdk";import{jsx as A}from"react/jsx-runtime";function P(n,o,e){let s=document.getElementById("para-modal"),t=s??document.createElement("div");t.id="para-modal",s||document.body.appendChild(t);let r=()=>{e(),o.onClose&&o.onClose(),a(!1)},a=async i=>{let h=A(T,{...o,onClose:r,para:n,isOpen:i});try{(await import("react-dom/client")).createRoot(t).render(h)}catch{(await import("react-dom")).render(h,t)}};a(!0)}var M="@CAPSULE/chainId",_=6e5,H={setItem:()=>{},getItem:()=>null},m=class extends x{constructor(e){super();this.getRpcUrlsFromViemChain=e=>D({chain:e,transports:this.transports});this.wagmiChainToAddEthereumChainParameters=e=>{let s=l(`${e.id}`);return[s,{chainId:s,chainName:e.name,nativeCurrency:e.nativeCurrency,rpcUrls:this.getRpcUrlsFromViemChain(e)}]};this.wagmiChainsToAddEthereumChainParameters=e=>Object.fromEntries(e.map(this.wagmiChainToAddEthereumChainParameters));this.accountFromAddress=e=>R(this.para,e);this.setCurrentChain=e=>{let s=this.chains[e];this.setChainId(e);let t=this.viemChains[e]||b(p(e)),r=this.getRpcUrlsFromViemChain(t),a;this.transports[t.id]?a=this.transports[t.id]:r[0].startsWith("ws")?a=E(s.rpcUrls[0]):(a=S(r[0]),this.chainTransportSubscribe=void 0);let i=a({chain:t});i.config.type==="ws"&&(this.chainTransportSubscribe=i.value.subscribe),this.walletClient=N(this.para,{chain:t,transport:a},{noAccount:!0}).extend(y),this.emit("chainChanged",this.currentHexChainId)};this.closeModal=()=>{this.isModalClosed=!0};this.request=async e=>{let{method:s,params:t}=e;switch(s){case"eth_accounts":return this.accounts;case"eth_chainId":return this.currentHexChainId;case"eth_requestAccounts":{if(await this.para.isFullyLoggedIn()){let r=this.accounts;if(r&&r.length>0)return r}this.disableModal||(this.isModalClosed=!1,P(this.para,this.modalProps,()=>{this.isModalClosed=!0})),await this.waitForLogin();try{let r=await this.waitForAccounts();return this.emit("accountsChanged",r),r}catch{throw new d(new Error("accounts not available after login"),{code:4001,shortMessage:"accounts not available after login"})}}case"eth_sendTransaction":{let r=t[0].from;return this.walletClient.sendTransaction({...w(t[0]),chain:void 0,account:this.accountFromAddress(r)})}case"eth_sign":case"personal_sign":return this.walletClient.signMessage({message:{raw:t[0]},account:this.accountFromAddress(t[1])});case"eth_signTransaction":{let r=t[0].from;return this.accountFromAddress(r).signTransaction(w(t[0]))}case"eth_signTypedData_v4":{let r=t[0],a=t[1];return typeof a=="string"&&(a=JSON.parse(a)),this.walletClient.signTypedData({...a,account:this.accountFromAddress(r)})}case"eth_subscribe":{if(!this.chainTransportSubscribe)throw new d(new Error("chain does not support subscriptions"),{code:4200,shortMessage:"chain does not support subscriptions"});return(await this.chainTransportSubscribe({params:t,onData:a=>{this.emit("message",{type:"eth_subscription",data:a})}})).subscriptionId}case"wallet_addEthereumChain":return this.chains[t[0].chainId]||(this.chains[t[0].chainId]=t[0]),null;case"wallet_getPermissions":return[];case"wallet_requestPermissions":return[];case"wallet_switchEthereumChain":{if(!this.chains[t[0].chainId]){let r=b(p(t[0].chainId)),[a,i]=this.wagmiChainToAddEthereumChainParameters(r);this.chains[a]=i,this.setCurrentChain(t[0].chainId)}return this.currentHexChainId!==t[0].chainId&&this.setCurrentChain(t[0].chainId),null}case"wallet_watchAsset":return!1;default:return this.walletClient.request({method:s,params:t})}};this.storage=e.storageOverride||typeof window>"u"?H:sessionStorage,this.isModalClosed=!0,this.para=e.para,this.modalProps={...e},this.disableModal=!!e.disableModal,this.viemChains=e.chains.reduce((r,a)=>(r[l(`${a.id}`)]=a,r),{}),this.chains=this.wagmiChainsToAddEthereumChainParameters(e.chains),this.transports=e.transports;let s=this.getStorageChainId()||e.chainId,t=this.chains[l(s)]?s:`${e.chains[0].id}`;this.setCurrentChain(l(t)),this.emit("connect",{chainId:this.currentHexChainId})}get accounts(){return this.para.getWalletsByType("EVM").map(e=>e.address)}getStorageChainId(){return this.storage.getItem(M)}setChainId(e){this.currentHexChainId=e,this.storage.setItem(M,p(e))}async waitForLogin(e=_){let s=Date.now();for(;Date.now()-s<e;){if(await this.para.isFullyLoggedIn())return!0;if(!this.disableModal&&this.isModalClosed)throw new d(new Error("user closed modal"),{code:4001,shortMessage:"user closed modal"});await new Promise(t=>setTimeout(t,2e3))}throw new d(new Error("timed out waiting for user to log in"),{code:4900,shortMessage:"timed out waiting for user to log in"})}async waitForAccounts(e=5e3){let s=Date.now();for(;Date.now()-s<e;){let t=this.accounts;if(t&&t.length>0)return t;await new Promise(r=>setTimeout(r,500))}throw new d(new Error("timed out waiting for accounts to load"),{code:4900,shortMessage:"timed out waiting for accounts to load"})}};import{createConnector as O}from"wagmi";var f="para",v="Para",W="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjE2IiBoZWlnaHQ9IjIwNCIgdmlld0JveD0iMCAwIDIxNiAyMDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik02MCAwSDE0NEMxODMuNzY0IDAgMjE2IDMyLjIzNTUgMjE2IDcyQzIxNiAxMTEuNzY1IDE4My43NjQgMTQ0IDE0NCAxNDRIOTZDODIuNzQ1MiAxNDQgNzIgMTU0Ljc0NSA3MiAxNjhWMjA0SDBWMTMySDM2QzQ5LjI1NDggMTMyIDYwIDEyMS4yNTUgNjAgMTA4TDYwIDBaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K",le=({para:n,chains:o,disableModal:e,storageOverride:s,options:t,iconOverride:r,nameOverride:a,idOverride:i,transports:h,...u})=>O(c=>{let g=[...c.chains],C=new m({para:n,chainId:`${g[0].id}`,chains:g,disableModal:e,storageOverride:s,transports:h||c.transports,...u}),I=F({target:{name:v,id:i??f,provider:C},...t})(c);return{...I,type:i??f,name:a??v,icon:r??W,disconnect:async()=>{C.closeModal(),await I.disconnect(),n.logout()}}});export{m as ParaEIP1193Provider,le as paraConnector};
package/dist/index.js.br CHANGED
Binary file
package/dist/index.js.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/wagmi-v2-integration",
3
- "version": "1.4.2",
3
+ "version": "1.4.4-dev.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "sideEffects": false,
8
8
  "dependencies": {
9
- "@getpara/react-sdk": "1.4.2",
10
- "@getpara/viem-v2-integration": "1.4.2"
9
+ "@getpara/react-sdk": "1.4.3",
10
+ "@getpara/viem-v2-integration": "1.4.3"
11
11
  },
12
12
  "scripts": {
13
13
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
@@ -28,5 +28,5 @@
28
28
  "dist",
29
29
  "package.json"
30
30
  ],
31
- "gitHead": "8404d1f8461109347360fe21be6057f826d31cec"
31
+ "gitHead": "e6e791d4e4f9afd94f2093d6045d686b85e5a682"
32
32
  }