@berachain/wagmi 0.4.2-beta.3 → 0.4.2-beta.4
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/dist/{BeraWagmi-D_9r9lFE.d.cts → BeraWagmi-DPriTsqn.d.cts} +1 -1
- package/dist/{BeraWagmi-BYoBR8sq.d.ts → BeraWagmi-PCCV3r-u.d.ts} +1 -1
- package/dist/chunk-FMEKPQER.cjs +1 -0
- package/dist/chunk-FPJ6HXP4.mjs +1 -0
- package/dist/chunk-HU7OL27P.mjs +1 -0
- package/dist/chunk-OLYL3V2D.cjs +1 -0
- package/dist/context/index.cjs +1 -1
- package/dist/context/index.d.cts +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/context/lightweight/index.cjs +1 -0
- package/dist/context/lightweight/index.d.cts +27 -0
- package/dist/context/lightweight/index.d.ts +27 -0
- package/dist/context/lightweight/index.mjs +1 -0
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.mjs +1 -1
- package/package.json +1 -1
- package/src/context/BeraWagmi.tsx +18 -140
- package/src/context/BeraWagmiLightWeight.tsx +36 -167
- package/src/context/WagmiProviderLightWeight.tsx +39 -14
- package/src/context/useThirdweb.tsx +21 -158
- package/src/context/useThirdwebLightWeight.tsx +26 -23
- package/dist/chunk-KNUNU6MD.cjs +0 -1
- package/dist/chunk-KXR247FP.mjs +0 -1
- package/dist/chunk-LEALKQIH.cjs +0 -1
- package/dist/chunk-XFXKXV5F.mjs +0 -1
- package/dist/context/thirdweb/index.cjs +0 -1
- package/dist/context/thirdweb/index.d.cts +0 -47
- package/dist/context/thirdweb/index.d.ts +0 -47
- package/dist/context/thirdweb/index.mjs +0 -1
- /package/src/context/{thirdweb → lightweight}/index.ts +0 -0
|
@@ -120,4 +120,4 @@ interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
|
120
120
|
publicJsonRpcUrl?: string;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
export { type BeraWagmiApi as B,
|
|
123
|
+
export { type BeraWagmiApi as B, type ConnectEvent as C, type IBeraWagmiProviderProps as I, ChainId as a, useBeraWagmi as u };
|
|
@@ -120,4 +120,4 @@ interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
|
120
120
|
publicJsonRpcUrl?: string;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
export { type BeraWagmiApi as B,
|
|
123
|
+
export { type BeraWagmiApi as B, type ConnectEvent as C, type IBeraWagmiProviderProps as I, ChainId as a, useBeraWagmi as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkOLYL3V2Dcjs = require('./chunk-OLYL3V2D.cjs');var _react = require('react');var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');var _jsxruntime = require('react/jsx-runtime');function h({config:n,theme:o,chains:d=[],chain:l,onConnect:r,onConnectError:a,publicJsonRpcUrl:c}){let e=_chunkOLYL3V2Dcjs.d.call(void 0, {config:n,chain:l,onConnect:r,onConnectError:a,publicJsonRpcUrl:c}),{connect:s}=_react3.useConnectModal.call(void 0, );return{...e,async openConnectModal(){try{let t=await s({...e.connectOptions,wallets:n.wallets,theme:o==="auto"?void 0:o,size:"compact",chains:[e.thirdwebChain,...d.filter(i=>i.id!==e.thirdwebChain.id).map(i=>_thirdweb.defineChain.call(void 0, {id:i.id}))]});_optionalChain([r, 'optionalCall', _ => _({type:"connect_modal"})]),await e.syncConnectedWallet(t)}catch(t){throw _optionalChain([a, 'optionalCall', _2 => _2(t)]),t}},DebugConnectButton(){return _jsxruntime.jsx.call(void 0, _react3.ConnectButton,{...e.connectOptions,connectModal:{size:"compact"},onConnect:t=>e.syncConnectedWallet(t)})}}}function x(){let n=_react.useContext.call(void 0, _chunkOLYL3V2Dcjs.a);if(!n)throw new Error("BeraWagmiContext not found");return n}function U({children:n,config:o,flags:d,theme:l,onSmartAccountRejection:r,chains:a=[],defaultChain:c,thirdweb:e,publicJsonRpcUrl:s,onConnect:t,onConnectError:i}){let p=h({config:o,theme:l,chains:a,chain:c,publicJsonRpcUrl:s,onConnect:t,onConnectError:i});return _jsxruntime.jsx.call(void 0, _chunkOLYL3V2Dcjs.c,{config:o,flags:d,onSmartAccountRejection:r,defaultChain:c,thirdweb:e,thirdwebResult:p,openConnectModal:async()=>{await p.openConnectModal()},DebugConnectButton:p.DebugConnectButton,children:n})}exports.a = x; exports.b = U;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext as O}from"react";var I=O(void 0);import{createContext as S}from"react";import{jsx as j}from"react/jsx-runtime";var _=S(void 0);function T({children:o,address:e,defaultChainId:c}){return j(_.Provider,{value:{address:e,defaultChainId:c},children:o})}import{useMemo as y}from"react";import q from"swr/immutable";import{normalize as F}from"viem/ens";import{useAccount as G,useDisconnect as H,useEnsAvatar as J,useEnsName as K,usePublicClient as Q,useWalletClient as V}from"wagmi";import{jsx as x}from"react/jsx-runtime";function we({children:o,config:e,flags:{disableEip5792:c,disable5792Upgrade:g,accountOverride:d}={},onSmartAccountRejection:C,defaultChain:l,thirdweb:a,thirdwebResult:{wallet:s,connect:w,connectionId:m,disconnect:A,connectorName:b,isEmbeddedWallet:f,profiles:u,preAuthenticate:p,isConnecting:W},openConnectModal:v,DebugConnectButton:i}){let{address:n,chainId:t}=G(),{disconnect:U}=H(),R=Q(),r=y(()=>{if(!(!n||!s))return d??n},[d,n,s]),{data:h}=K({config:e.wagmi,chainId:l.id,address:r}),{data:B}=q(r?["BeraWagmiProvider_code",r,t]:null,([k,N,ae])=>R?.getCode({address:N}),{refreshInterval:6e4}),[D,L]=y(()=>B?B.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[B]),{data:P}=V(),M=y(()=>{try{return h?F(h):void 0}catch{}},[h]),z=J({name:M});return x(I.Provider,{value:{preAuthenticate:p,flags:{disableEip5792:!!c,disable5792Upgrade:!!g},walletClient:P,onSmartAccountRejection:()=>{C?.()},isEmbeddedWalletsEnabled:a.embeddedWallets??!0,isConnecting:W,isConnected:!!r&&!!P,DebugConnectButton:i??(()=>null),account:s&&t&&r?{connectionId:m,chainId:t,connectorName:b,isEmbeddedWallet:f,profiles:u,wallet:{address:r,ensName:h?.replace(".bera",".\u{1F43B}\u26D3\uFE0F")??null,ensAvatar:z.data??null,has7702Authorization:L,isContract:D}}:void 0,connect:w,openConnectModal:v??(()=>{throw new Error("openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context instead.")}),disconnect:()=>{U(),A()},defaultChainId:l.id},children:x(T,{address:r,defaultChainId:l.id,children:o})})}import{useMemo as E}from"react";import{defineChain as X}from"thirdweb";import{useActiveAccount as Y,useActiveWallet as Z,useAutoConnect as $,useProfiles as ee,useConnect as te,useDisconnect as ne,useWalletInfo as oe}from"thirdweb/react";import{preAuthenticate as ie}from"thirdweb/wallets/in-app";import{useConnect as re}from"wagmi";function Ie({config:o,chain:e,onConnect:c,onConnectError:g,publicJsonRpcUrl:d=e.rpcUrls.default.http[0]}){let{connectors:C,connect:l}=re(),a=Z(),s=Y(),{disconnect:w}=ne(),{data:m}=oe(a?.id),{connect:A}=te(),{data:b}=ee({client:o.client}),f=E(()=>X({id:e.id,blockExplorers:e.blockExplorers,blockTime:e.blockTime,ensTlds:e.ensTlds,testnet:e.testnet,contracts:e.contracts,nativeCurrency:e.nativeCurrency,name:e.name,rpcUrls:{default:{http:[d]}}}),[d,e]),u={client:o.client,chain:f,wallets:o.wallets};async function p(i){let n=C.find(t=>t.id==="in-app-wallet");if(n){let t={withCapabilities:!0,wallet:i};l({connector:n,chainId:e.id,...t})}else console.error("no tw connector found")}let{isLoading:W}=$({...u,onConnect:p}),v=E(()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[a?.id,s?.address]);return{connect(i){if(!o.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return A(async()=>{let n=o.wallets.find(t=>t.id==="inApp");if(!n)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return n.connect({...u,...i}).then(async()=>(c?.({type:"connect",data:i}),await p(n),n)).catch(t=>{throw g?.(t),t})})},disconnect(){a&&w(a)},isConnecting:W,connectionId:v,connectorName:m?.name??null,isEmbeddedWallet:m?.id==="inApp",wallet:s,profiles:b,preAuthenticate(i){return ie({...i,client:o.client})},syncConnectedWallet:p,connectOptions:u,thirdwebChain:f}}export{I as a,_ as b,we as c,Ie as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as u,c as m,d as g}from"./chunk-FPJ6HXP4.mjs";import{useContext as w}from"react";import{defineChain as f}from"thirdweb";import{ConnectButton as C,useConnectModal as b}from"thirdweb/react";import{jsx as y}from"react/jsx-runtime";function h({config:n,theme:o,chains:d=[],chain:l,onConnect:r,onConnectError:a,publicJsonRpcUrl:c}){let e=g({config:n,chain:l,onConnect:r,onConnectError:a,publicJsonRpcUrl:c}),{connect:s}=b();return{...e,async openConnectModal(){try{let t=await s({...e.connectOptions,wallets:n.wallets,theme:o==="auto"?void 0:o,size:"compact",chains:[e.thirdwebChain,...d.filter(i=>i.id!==e.thirdwebChain.id).map(i=>f({id:i.id}))]});r?.({type:"connect_modal"}),await e.syncConnectedWallet(t)}catch(t){throw a?.(t),t}},DebugConnectButton(){return y(C,{...e.connectOptions,connectModal:{size:"compact"},onConnect:t=>e.syncConnectedWallet(t)})}}}import{jsx as A}from"react/jsx-runtime";function x(){let n=w(u);if(!n)throw new Error("BeraWagmiContext not found");return n}function U({children:n,config:o,flags:d,theme:l,onSmartAccountRejection:r,chains:a=[],defaultChain:c,thirdweb:e,publicJsonRpcUrl:s,onConnect:t,onConnectError:i}){let p=h({config:o,theme:l,chains:a,chain:c,publicJsonRpcUrl:s,onConnect:t,onConnectError:i});return A(m,{config:o,flags:d,onSmartAccountRejection:r,defaultChain:c,thirdweb:e,thirdwebResult:p,openConnectModal:async()=>{await p.openConnectModal()},DebugConnectButton:p.DebugConnectButton,children:n})}export{x as a,U as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var I=_react.createContext.call(void 0, void 0);var _jsxruntime = require('react/jsx-runtime');var _=_react.createContext.call(void 0, void 0);function T({children:o,address:e,defaultChainId:c}){return _jsxruntime.jsx.call(void 0, _.Provider,{value:{address:e,defaultChainId:c},children:o})}var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _ens = require('viem/ens');var _wagmi = require('wagmi');function we({children:o,config:e,flags:{disableEip5792:c,disable5792Upgrade:g,accountOverride:d}={},onSmartAccountRejection:C,defaultChain:l,thirdweb:a,thirdwebResult:{wallet:s,connect:w,connectionId:m,disconnect:A,connectorName:b,isEmbeddedWallet:f,profiles:u,preAuthenticate:p,isConnecting:W},openConnectModal:v,DebugConnectButton:i}){let{address:n,chainId:t}=_wagmi.useAccount.call(void 0, ),{disconnect:U}=_wagmi.useDisconnect.call(void 0, ),R=_wagmi.usePublicClient.call(void 0, ),r=_react.useMemo.call(void 0, ()=>{if(!(!n||!s))return _nullishCoalesce(d, () => (n))},[d,n,s]),{data:h}=_wagmi.useEnsName.call(void 0, {config:e.wagmi,chainId:l.id,address:r}),{data:B}=_immutable2.default.call(void 0, r?["BeraWagmiProvider_code",r,t]:null,([k,N,ae])=>_optionalChain([R, 'optionalAccess', _2 => _2.getCode, 'call', _3 => _3({address:N})]),{refreshInterval:6e4}),[D,L]=_react.useMemo.call(void 0, ()=>B?B.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[B]),{data:P}=_wagmi.useWalletClient.call(void 0, ),M=_react.useMemo.call(void 0, ()=>{try{return h?_ens.normalize.call(void 0, h):void 0}catch (e2){}},[h]),z=_wagmi.useEnsAvatar.call(void 0, {name:M});return _jsxruntime.jsx.call(void 0, I.Provider,{value:{preAuthenticate:p,flags:{disableEip5792:!!c,disable5792Upgrade:!!g},walletClient:P,onSmartAccountRejection:()=>{_optionalChain([C, 'optionalCall', _4 => _4()])},isEmbeddedWalletsEnabled:_nullishCoalesce(a.embeddedWallets, () => (!0)),isConnecting:W,isConnected:!!r&&!!P,DebugConnectButton:_nullishCoalesce(i, () => ((()=>null))),account:s&&t&&r?{connectionId:m,chainId:t,connectorName:b,isEmbeddedWallet:f,profiles:u,wallet:{address:r,ensName:_nullishCoalesce(_optionalChain([h, 'optionalAccess', _5 => _5.replace, 'call', _6 => _6(".bera",".\u{1F43B}\u26D3\uFE0F")]), () => (null)),ensAvatar:_nullishCoalesce(z.data, () => (null)),has7702Authorization:L,isContract:D}}:void 0,connect:w,openConnectModal:_nullishCoalesce(v, () => ((()=>{throw new Error("openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context instead.")}))),disconnect:()=>{U(),A()},defaultChainId:l.id},children:_jsxruntime.jsx.call(void 0, T,{address:r,defaultChainId:l.id,children:o})})}var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');var _inapp = require('thirdweb/wallets/in-app');function Ie({config:o,chain:e,onConnect:c,onConnectError:g,publicJsonRpcUrl:d=e.rpcUrls.default.http[0]}){let{connectors:C,connect:l}=_wagmi.useConnect.call(void 0, ),a=_react3.useActiveWallet.call(void 0, ),s=_react3.useActiveAccount.call(void 0, ),{disconnect:w}=_react3.useDisconnect.call(void 0, ),{data:m}=_react3.useWalletInfo.call(void 0, _optionalChain([a, 'optionalAccess', _7 => _7.id])),{connect:A}=_react3.useConnect.call(void 0, ),{data:b}=_react3.useProfiles.call(void 0, {client:o.client}),f=_react.useMemo.call(void 0, ()=>_thirdweb.defineChain.call(void 0, {id:e.id,blockExplorers:e.blockExplorers,blockTime:e.blockTime,ensTlds:e.ensTlds,testnet:e.testnet,contracts:e.contracts,nativeCurrency:e.nativeCurrency,name:e.name,rpcUrls:{default:{http:[d]}}}),[d,e]),u={client:o.client,chain:f,wallets:o.wallets};async function p(i){let n=C.find(t=>t.id==="in-app-wallet");if(n){let t={withCapabilities:!0,wallet:i};l({connector:n,chainId:e.id,...t})}else console.error("no tw connector found")}let{isLoading:W}=_react3.useAutoConnect.call(void 0, {...u,onConnect:p}),v=_react.useMemo.call(void 0, ()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[_optionalChain([a, 'optionalAccess', _8 => _8.id]),_optionalChain([s, 'optionalAccess', _9 => _9.address])]);return{connect(i){if(!o.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return A(async()=>{let n=o.wallets.find(t=>t.id==="inApp");if(!n)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return n.connect({...u,...i}).then(async()=>(_optionalChain([c, 'optionalCall', _10 => _10({type:"connect",data:i})]),await p(n),n)).catch(t=>{throw _optionalChain([g, 'optionalCall', _11 => _11(t)]),t})})},disconnect(){a&&w(a)},isConnecting:W,connectionId:v,connectorName:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _12 => _12.name]), () => (null)),isEmbeddedWallet:_optionalChain([m, 'optionalAccess', _13 => _13.id])==="inApp",wallet:s,profiles:b,preAuthenticate(i){return _inapp.preAuthenticate.call(void 0, {...i,client:o.client})},syncConnectedWallet:p,connectOptions:u,thirdwebChain:f}}exports.a = I; exports.b = _; exports.c = we; exports.d = Ie;
|
package/dist/context/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var _chunkFMEKPQERcjs = require('../chunk-FMEKPQER.cjs');var _chunkPVMPBWIGcjs = require('../chunk-PVMPBWIG.cjs');require('../chunk-OLYL3V2D.cjs');var _react = require('react');var _reactquery = require('@tanstack/react-query');var _react3 = require('thirdweb/react');var _wagmi = require('wagmi');var _jsxruntime = require('react/jsx-runtime');var u=new _reactquery.QueryClient;function B({transports:t,defaultChain:e,chains:i,thirdweb:o,...f}){let n=_react.useMemo.call(void 0, ()=>_chunkPVMPBWIGcjs.a.call(void 0, {thirdweb:o,transports:t,defaultChain:e,chains:i}),[e,o,t,i]);return _jsxruntime.jsx.call(void 0, _react3.ThirdwebProvider,{children:_jsxruntime.jsx.call(void 0, _wagmi.WagmiProvider,{config:n.wagmi,reconnectOnMount:!1,children:_jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider,{client:u,children:_jsxruntime.jsx.call(void 0, _chunkFMEKPQERcjs.b,{...f,thirdweb:o,chains:i,defaultChain:e,config:n})})})})}exports.WagmiProvider = B;
|
package/dist/context/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { Transport, Chain } from 'viem';
|
|
3
|
-
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-
|
|
3
|
+
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-DPriTsqn.cjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'thirdweb/wallets';
|
|
6
6
|
import 'wagmi';
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { Transport, Chain } from 'viem';
|
|
3
|
-
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-
|
|
3
|
+
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-PCCV3r-u.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'thirdweb/wallets';
|
|
6
6
|
import 'wagmi';
|
package/dist/context/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{b as a}from"../chunk-HU7OL27P.mjs";import{a as m}from"../chunk-MZZ62TKM.mjs";import"../chunk-FPJ6HXP4.mjs";import{useMemo as p}from"react";import{QueryClient as d,QueryClientProvider as g}from"@tanstack/react-query";import{ThirdwebProvider as P}from"thirdweb/react";import{WagmiProvider as s}from"wagmi";import{jsx as r}from"react/jsx-runtime";var u=new d;function B({transports:t,defaultChain:e,chains:i,thirdweb:o,...f}){let n=p(()=>m({thirdweb:o,transports:t,defaultChain:e,chains:i}),[e,o,t,i]);return r(P,{children:r(s,{config:n.wagmi,reconnectOnMount:!1,children:r(g,{client:u,children:r(a,{...f,thirdweb:o,chains:i,defaultChain:e,config:n})})})})}export{B as WagmiProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var _chunkPVMPBWIGcjs = require('../../chunk-PVMPBWIG.cjs');var _chunkOLYL3V2Dcjs = require('../../chunk-OLYL3V2D.cjs');var _react = require('react');var _reactquery = require('@tanstack/react-query');var _react3 = require('thirdweb/react');var _wagmi = require('wagmi');var _jsxruntime = require('react/jsx-runtime');var C=new _reactquery.QueryClient;function A({transports:t,defaultChain:r,chains:n,thirdweb:i,children:s,onConnect:c,onConnectError:g,publicJsonRpcUrl:p,...f}){let o=_react.useMemo.call(void 0, ()=>_chunkPVMPBWIGcjs.a.call(void 0, {thirdweb:i,transports:t,defaultChain:r,chains:n}),[r,i,t,n]),h=_chunkOLYL3V2Dcjs.d.call(void 0, {config:o,chain:r,publicJsonRpcUrl:p,onConnect:c,onConnectError:g});return _jsxruntime.jsx.call(void 0, _react3.ThirdwebProvider,{children:_jsxruntime.jsx.call(void 0, _wagmi.WagmiProvider,{config:o.wagmi,reconnectOnMount:!1,children:_jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider,{client:C,children:_jsxruntime.jsx.call(void 0, _chunkOLYL3V2Dcjs.c,{...f,thirdweb:i,defaultChain:r,config:o,thirdwebResult:h,children:s})})})})}exports.WagmiProvider = A;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { Transport, Chain, Address } from 'viem';
|
|
4
|
+
import { ThirdwebConfig } from '../../config/index.cjs';
|
|
5
|
+
import { C as ConnectEvent } from '../../BeraWagmi-DPriTsqn.cjs';
|
|
6
|
+
import 'thirdweb';
|
|
7
|
+
import 'thirdweb/wallets';
|
|
8
|
+
import 'wagmi';
|
|
9
|
+
|
|
10
|
+
type WagmiProviderLightWeightProps = PropsWithChildren<{
|
|
11
|
+
transports?: Record<number, Transport>;
|
|
12
|
+
defaultChain: Chain;
|
|
13
|
+
chains?: Chain[];
|
|
14
|
+
thirdweb: ThirdwebConfig;
|
|
15
|
+
flags?: {
|
|
16
|
+
disableEip5792?: boolean;
|
|
17
|
+
disable5792Upgrade?: boolean;
|
|
18
|
+
accountOverride?: Address;
|
|
19
|
+
};
|
|
20
|
+
onSmartAccountRejection?: () => void;
|
|
21
|
+
onConnect?: (event: ConnectEvent) => void;
|
|
22
|
+
onConnectError?: (error: Error) => void;
|
|
23
|
+
publicJsonRpcUrl?: string;
|
|
24
|
+
}>;
|
|
25
|
+
declare function WagmiProvider({ transports, defaultChain, chains, thirdweb, children, onConnect, onConnectError, publicJsonRpcUrl, ...baseProps }: WagmiProviderLightWeightProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { WagmiProvider };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { Transport, Chain, Address } from 'viem';
|
|
4
|
+
import { ThirdwebConfig } from '../../config/index.js';
|
|
5
|
+
import { C as ConnectEvent } from '../../BeraWagmi-PCCV3r-u.js';
|
|
6
|
+
import 'thirdweb';
|
|
7
|
+
import 'thirdweb/wallets';
|
|
8
|
+
import 'wagmi';
|
|
9
|
+
|
|
10
|
+
type WagmiProviderLightWeightProps = PropsWithChildren<{
|
|
11
|
+
transports?: Record<number, Transport>;
|
|
12
|
+
defaultChain: Chain;
|
|
13
|
+
chains?: Chain[];
|
|
14
|
+
thirdweb: ThirdwebConfig;
|
|
15
|
+
flags?: {
|
|
16
|
+
disableEip5792?: boolean;
|
|
17
|
+
disable5792Upgrade?: boolean;
|
|
18
|
+
accountOverride?: Address;
|
|
19
|
+
};
|
|
20
|
+
onSmartAccountRejection?: () => void;
|
|
21
|
+
onConnect?: (event: ConnectEvent) => void;
|
|
22
|
+
onConnectError?: (error: Error) => void;
|
|
23
|
+
publicJsonRpcUrl?: string;
|
|
24
|
+
}>;
|
|
25
|
+
declare function WagmiProvider({ transports, defaultChain, chains, thirdweb, children, onConnect, onConnectError, publicJsonRpcUrl, ...baseProps }: WagmiProviderLightWeightProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { WagmiProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{a as m}from"../../chunk-MZZ62TKM.mjs";import{c as a,d}from"../../chunk-FPJ6HXP4.mjs";import{useMemo as v}from"react";import{QueryClient as l,QueryClientProvider as u}from"@tanstack/react-query";import{ThirdwebProvider as P}from"thirdweb/react";import{WagmiProvider as b}from"wagmi";import{jsx as e}from"react/jsx-runtime";var C=new l;function A({transports:t,defaultChain:r,chains:n,thirdweb:i,children:s,onConnect:c,onConnectError:g,publicJsonRpcUrl:p,...f}){let o=v(()=>m({thirdweb:i,transports:t,defaultChain:r,chains:n}),[r,i,t,n]),h=d({config:o,chain:r,publicJsonRpcUrl:p,onConnect:c,onConnectError:g});return e(P,{children:e(b,{config:o.wagmi,reconnectOnMount:!1,children:e(u,{client:C,children:e(a,{...f,thirdweb:i,defaultChain:r,config:o,thirdwebResult:h,children:s})})})})}export{A as WagmiProvider};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkFMEKPQERcjs = require('../chunk-FMEKPQER.cjs');var _chunkOLYL3V2Dcjs = require('../chunk-OLYL3V2D.cjs');var _wagmi = require('wagmi');var _react = require('react');function a(){let t=_react.useContext.call(void 0, _chunkOLYL3V2Dcjs.b);if(!t)throw new Error("LightweightAccountContext not found");let{address:e,defaultChainId:r}=t;return{isConnected:!!e,address:e,defaultChainId:r}}function u(){let{account:t,isConnected:e}=_chunkFMEKPQERcjs.a.call(void 0, );return{...t,isConnected:e}}function p({chainId:t}){let{flags:e,account:r}=_chunkFMEKPQERcjs.a.call(void 0, ),{data:i}=_wagmi.useCapabilities.call(void 0, {account:_optionalChain([r, 'optionalAccess', _ => _.wallet, 'optionalAccess', _2 => _2.address]),scopeKey:_optionalChain([r, 'optionalAccess', _3 => _3.connectionId]),query:{retry:3},chainId:t});return{supportsAtomic:_react.useMemo.call(void 0, ()=>e.disableEip5792||!i?!1:_optionalChain([i, 'optionalAccess', _4 => _4.atomic, 'optionalAccess', _5 => _5.status])==="supported"||!e.disable5792Upgrade&&_optionalChain([i, 'optionalAccess', _6 => _6.atomic, 'optionalAccess', _7 => _7.status])==="ready",[i,e.disableEip5792,e.disable5792Upgrade,t]),capabilities:i}}function w(t){let{defaultChainId:e}=a(),{chainId:r,...i}=_nullishCoalesce(t, () => ({}));return _wagmi.usePublicClient.call(void 0, {chainId:_nullishCoalesce(r, () => (e)),...i})}exports.useBeraAccount = u; exports.useBeraWagmi = _chunkFMEKPQERcjs.a; exports.useBeraWallet = a; exports.useBlockNumber = _wagmi.useBlockNumber; exports.useCapabilities = p; exports.useChains = _wagmi.useChains; exports.useConfig = _wagmi.useConfig; exports.useEnsAvatar = _wagmi.useEnsAvatar; exports.useEnsName = _wagmi.useEnsName; exports.usePublicClient = w; exports.useSwitchChain = _wagmi.useSwitchChain; exports.useTransactionReceipt = _wagmi.useTransactionReceipt;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UsePublicClientParameters, UsePublicClientReturnType } from 'wagmi';
|
|
2
2
|
export { useBlockNumber, useChains, useConfig, useEnsAvatar, useEnsName, useSwitchChain, useTransactionReceipt } from 'wagmi';
|
|
3
|
-
import { B as BeraWagmiApi,
|
|
4
|
-
export { u as useBeraWagmi } from '../BeraWagmi-
|
|
3
|
+
import { B as BeraWagmiApi, a as ChainId } from '../BeraWagmi-DPriTsqn.cjs';
|
|
4
|
+
export { u as useBeraWagmi } from '../BeraWagmi-DPriTsqn.cjs';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'thirdweb/wallets';
|
|
7
7
|
import 'viem';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UsePublicClientParameters, UsePublicClientReturnType } from 'wagmi';
|
|
2
2
|
export { useBlockNumber, useChains, useConfig, useEnsAvatar, useEnsName, useSwitchChain, useTransactionReceipt } from 'wagmi';
|
|
3
|
-
import { B as BeraWagmiApi,
|
|
4
|
-
export { u as useBeraWagmi } from '../BeraWagmi-
|
|
3
|
+
import { B as BeraWagmiApi, a as ChainId } from '../BeraWagmi-PCCV3r-u.js';
|
|
4
|
+
export { u as useBeraWagmi } from '../BeraWagmi-PCCV3r-u.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'thirdweb/wallets';
|
|
7
7
|
import 'viem';
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a as o}from"../chunk-HU7OL27P.mjs";import{b as s}from"../chunk-FPJ6HXP4.mjs";import{usePublicClient as m}from"wagmi";import{useContext as n}from"react";function a(){let t=n(s);if(!t)throw new Error("LightweightAccountContext not found");let{address:e,defaultChainId:r}=t;return{isConnected:!!e,address:e,defaultChainId:r}}import{useBlockNumber as E,useChains as N,useConfig as R,useEnsAvatar as T,useEnsName as L,useSwitchChain as k,useTransactionReceipt as q}from"wagmi";function u(){let{account:t,isConnected:e}=o();return{...t,isConnected:e}}import{useMemo as c}from"react";import{useCapabilities as l}from"wagmi";function p({chainId:t}){let{flags:e,account:r}=o(),{data:i}=l({account:r?.wallet?.address,scopeKey:r?.connectionId,query:{retry:3},chainId:t});return{supportsAtomic:c(()=>e.disableEip5792||!i?!1:i?.atomic?.status==="supported"||!e.disable5792Upgrade&&i?.atomic?.status==="ready",[i,e.disableEip5792,e.disable5792Upgrade,t]),capabilities:i}}function w(t){let{defaultChainId:e}=a(),{chainId:r,...i}=t??{};return m({chainId:r??e,...i})}export{u as useBeraAccount,o as useBeraWagmi,a as useBeraWallet,E as useBlockNumber,p as useCapabilities,N as useChains,R as useConfig,T as useEnsAvatar,L as useEnsName,w as usePublicClient,k as useSwitchChain,q as useTransactionReceipt};
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type PropsWithChildren, useContext
|
|
2
|
-
import useSWRImmutable from "swr/immutable";
|
|
1
|
+
import { type PropsWithChildren, useContext } from "react";
|
|
3
2
|
import type {
|
|
4
3
|
MultiStepAuthArgsType,
|
|
5
4
|
Profile,
|
|
@@ -7,20 +6,13 @@ import type {
|
|
|
7
6
|
Wallet,
|
|
8
7
|
} from "thirdweb/wallets";
|
|
9
8
|
import type { Address, Chain } from "viem";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
type UseWalletClientReturnType,
|
|
13
|
-
useAccount,
|
|
14
|
-
useDisconnect,
|
|
15
|
-
usePublicClient,
|
|
16
|
-
useWalletClient,
|
|
17
|
-
} from "wagmi";
|
|
9
|
+
import type { UseWalletClientReturnType } from "wagmi";
|
|
18
10
|
|
|
19
11
|
import type { getConfig, ThirdwebConfig } from "../config";
|
|
20
|
-
import {
|
|
12
|
+
import { BeraWagmiProviderBase } from "./BeraWagmiLightWeight";
|
|
21
13
|
import { BeraWagmiContext } from "./beraWagmiContext";
|
|
22
|
-
import { LightweightAccountProvider } from "./LightweightAccountProvider";
|
|
23
14
|
import { useThirdweb } from "./useThirdweb";
|
|
15
|
+
|
|
24
16
|
export function useBeraWagmi() {
|
|
25
17
|
const context = useContext(BeraWagmiContext);
|
|
26
18
|
if (!context) {
|
|
@@ -151,7 +143,7 @@ export interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
|
151
143
|
export function BeraWagmiProvider({
|
|
152
144
|
children,
|
|
153
145
|
config,
|
|
154
|
-
flags
|
|
146
|
+
flags,
|
|
155
147
|
theme,
|
|
156
148
|
onSmartAccountRejection,
|
|
157
149
|
chains = [],
|
|
@@ -161,19 +153,7 @@ export function BeraWagmiProvider({
|
|
|
161
153
|
onConnect,
|
|
162
154
|
onConnectError,
|
|
163
155
|
}: IBeraWagmiProviderProps) {
|
|
164
|
-
const {
|
|
165
|
-
wallet,
|
|
166
|
-
openConnectModal,
|
|
167
|
-
connect,
|
|
168
|
-
DebugConnectButton,
|
|
169
|
-
connectionId,
|
|
170
|
-
disconnect: disconnectProvider,
|
|
171
|
-
connectorName,
|
|
172
|
-
isEmbeddedWallet,
|
|
173
|
-
profiles,
|
|
174
|
-
preAuthenticate,
|
|
175
|
-
isConnecting,
|
|
176
|
-
} = useThirdweb({
|
|
156
|
+
const thirdwebResult = useThirdweb({
|
|
177
157
|
config,
|
|
178
158
|
theme,
|
|
179
159
|
chains,
|
|
@@ -183,122 +163,20 @@ export function BeraWagmiProvider({
|
|
|
183
163
|
onConnectError,
|
|
184
164
|
});
|
|
185
165
|
|
|
186
|
-
const { address: connectedAddress, chainId } = useAccount(); // wagmi
|
|
187
|
-
|
|
188
|
-
const { disconnect: disconnectWagmi } = useDisconnect();
|
|
189
|
-
const publicClient = usePublicClient();
|
|
190
|
-
|
|
191
|
-
const address = useMemo<Address | undefined>(() => {
|
|
192
|
-
// no address anyway if no connected address
|
|
193
|
-
if (!connectedAddress || !wallet) return undefined;
|
|
194
|
-
|
|
195
|
-
return accountOverride ?? connectedAddress;
|
|
196
|
-
}, [accountOverride, connectedAddress, wallet]);
|
|
197
|
-
|
|
198
|
-
const { data: ens } = useEnsName({
|
|
199
|
-
config: config.wagmi,
|
|
200
|
-
chainId: defaultChain.id,
|
|
201
|
-
address,
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const { data: code } = useSWRImmutable(
|
|
205
|
-
address ? (["BeraWagmiProvider_code", address, chainId] as const) : null,
|
|
206
|
-
([_, walletAddress, _chainId]) => {
|
|
207
|
-
return publicClient?.getCode({
|
|
208
|
-
address: walletAddress,
|
|
209
|
-
});
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
refreshInterval: 60_000,
|
|
213
|
-
},
|
|
214
|
-
);
|
|
215
|
-
const [isContract, has7702Authorization] = useMemo(() => {
|
|
216
|
-
if (!code)
|
|
217
|
-
// if no code, it's not a contract or has 7702 authorization
|
|
218
|
-
return [false, false];
|
|
219
|
-
|
|
220
|
-
const has7702Authorization = code.startsWith("0xef01");
|
|
221
|
-
|
|
222
|
-
if (has7702Authorization) {
|
|
223
|
-
// if has 7702 authorization, it's not a contract
|
|
224
|
-
return [false, true];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// if doesn't have 7702 authorization but has code, it's a contract
|
|
228
|
-
return [true, false];
|
|
229
|
-
}, [code]);
|
|
230
|
-
|
|
231
|
-
const { data: walletClient } = useWalletClient();
|
|
232
|
-
|
|
233
|
-
const normalizedEns = useMemo(() => {
|
|
234
|
-
try {
|
|
235
|
-
// some characters might throw an error when normalizing
|
|
236
|
-
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
237
|
-
return ens ? normalize(ens) : undefined;
|
|
238
|
-
} catch {
|
|
239
|
-
// not catching the error here, just returning undefined
|
|
240
|
-
// @see https://berachain-dapps.sentry.io/issues/6949741717/?alert_rule_id=16379160&alert_type=issue¬ification_uuid=b01366a6-78b0-4348-a3c1-5f76ced1d539&project=4509842561630209
|
|
241
|
-
}
|
|
242
|
-
}, [ens]);
|
|
243
|
-
|
|
244
|
-
const avatar = useEnsAvatar({
|
|
245
|
-
name: normalizedEns,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
166
|
return (
|
|
249
|
-
<
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
onSmartAccountRejection?.();
|
|
259
|
-
},
|
|
260
|
-
isEmbeddedWalletsEnabled: thirdweb.embeddedWallets ?? true,
|
|
261
|
-
isConnecting,
|
|
262
|
-
isConnected:
|
|
263
|
-
!!address &&
|
|
264
|
-
// this seems obvious but might fix some re-render issues.
|
|
265
|
-
!!walletClient,
|
|
266
|
-
DebugConnectButton,
|
|
267
|
-
account:
|
|
268
|
-
wallet && chainId && address
|
|
269
|
-
? {
|
|
270
|
-
connectionId,
|
|
271
|
-
chainId,
|
|
272
|
-
connectorName,
|
|
273
|
-
isEmbeddedWallet,
|
|
274
|
-
profiles,
|
|
275
|
-
wallet: {
|
|
276
|
-
address,
|
|
277
|
-
ensName: ens?.replace(".bera", ".🐻⛓️") ?? null,
|
|
278
|
-
ensAvatar: avatar.data ?? null,
|
|
279
|
-
has7702Authorization,
|
|
280
|
-
isContract,
|
|
281
|
-
},
|
|
282
|
-
}
|
|
283
|
-
: undefined,
|
|
284
|
-
connect,
|
|
285
|
-
openConnectModal: async () => {
|
|
286
|
-
await openConnectModal();
|
|
287
|
-
},
|
|
288
|
-
disconnect: () => {
|
|
289
|
-
disconnectWagmi();
|
|
290
|
-
disconnectProvider();
|
|
291
|
-
},
|
|
292
|
-
// chains,
|
|
293
|
-
defaultChainId: defaultChain.id,
|
|
167
|
+
<BeraWagmiProviderBase
|
|
168
|
+
config={config}
|
|
169
|
+
flags={flags}
|
|
170
|
+
onSmartAccountRejection={onSmartAccountRejection}
|
|
171
|
+
defaultChain={defaultChain}
|
|
172
|
+
thirdweb={thirdweb}
|
|
173
|
+
thirdwebResult={thirdwebResult}
|
|
174
|
+
openConnectModal={async () => {
|
|
175
|
+
await thirdwebResult.openConnectModal();
|
|
294
176
|
}}
|
|
177
|
+
DebugConnectButton={thirdwebResult.DebugConnectButton}
|
|
295
178
|
>
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
defaultChainId={defaultChain.id}
|
|
299
|
-
>
|
|
300
|
-
{children}
|
|
301
|
-
</LightweightAccountProvider>
|
|
302
|
-
</BeraWagmiContext.Provider>
|
|
179
|
+
{children}
|
|
180
|
+
</BeraWagmiProviderBase>
|
|
303
181
|
);
|
|
304
182
|
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { type PropsWithChildren,
|
|
1
|
+
import { type PropsWithChildren, useMemo } from "react";
|
|
2
2
|
import useSWRImmutable from "swr/immutable";
|
|
3
|
-
import type {
|
|
4
|
-
MultiStepAuthArgsType,
|
|
5
|
-
Profile,
|
|
6
|
-
SingleStepAuthArgsType,
|
|
7
|
-
Wallet,
|
|
8
|
-
} from "thirdweb/wallets";
|
|
9
3
|
import type { Address, Chain } from "viem";
|
|
10
4
|
import { normalize } from "viem/ens";
|
|
11
5
|
import {
|
|
12
|
-
type UseWalletClientReturnType,
|
|
13
6
|
useAccount,
|
|
14
7
|
useDisconnect,
|
|
15
8
|
useEnsAvatar,
|
|
@@ -19,151 +12,40 @@ import {
|
|
|
19
12
|
} from "wagmi";
|
|
20
13
|
|
|
21
14
|
import type { getConfig, ThirdwebConfig } from "../config";
|
|
15
|
+
import type { BeraWagmiApi } from "./BeraWagmi";
|
|
22
16
|
import { BeraWagmiContext } from "./beraWagmiContext";
|
|
23
17
|
import { LightweightAccountProvider } from "./LightweightAccountProvider";
|
|
24
|
-
import {
|
|
18
|
+
import type { UseThirdwebBaseResult } from "./useThirdwebLightWeight";
|
|
25
19
|
|
|
26
|
-
export
|
|
27
|
-
const context = useContext(BeraWagmiContext);
|
|
28
|
-
if (!context) {
|
|
29
|
-
throw new Error("BeraWagmiContext not found");
|
|
30
|
-
}
|
|
31
|
-
return context;
|
|
32
|
-
}
|
|
33
|
-
export interface BeraWagmiApi {
|
|
34
|
-
/**
|
|
35
|
-
* @deprecated used for prototyping only.
|
|
36
|
-
*/
|
|
37
|
-
DebugConnectButton(): React.ReactNode;
|
|
38
|
-
/**
|
|
39
|
-
* Account connected to berachain dapp. It might include some additional data once embedded wallets are enabled.
|
|
40
|
-
*/
|
|
41
|
-
account:
|
|
42
|
-
| {
|
|
43
|
-
/**
|
|
44
|
-
* Chain ID to which the wallet provider is currently connected to.
|
|
45
|
-
*/
|
|
46
|
-
chainId: number;
|
|
47
|
-
/**
|
|
48
|
-
* Whether the wallet is an embedded wallet.
|
|
49
|
-
*/
|
|
50
|
-
isEmbeddedWallet: boolean;
|
|
51
|
-
connectorName: string | null;
|
|
52
|
-
connectionId: string;
|
|
53
|
-
profiles: Profile[] | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Wallet to display.
|
|
56
|
-
*
|
|
57
|
-
* This might be manually overridden by the accountOverride prop, thus not being the same as the connected wallet.
|
|
58
|
-
*/
|
|
59
|
-
wallet:
|
|
60
|
-
| {
|
|
61
|
-
address: Address;
|
|
62
|
-
/**
|
|
63
|
-
* ENS name of the wallet.
|
|
64
|
-
*/
|
|
65
|
-
ensName: string | null;
|
|
66
|
-
/**
|
|
67
|
-
* ENS avatar of the wallet.
|
|
68
|
-
*/
|
|
69
|
-
ensAvatar: string | null;
|
|
70
|
-
/**
|
|
71
|
-
* Whether the wallet has 7702 authorization.
|
|
72
|
-
*/
|
|
73
|
-
has7702Authorization: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Whether the wallet is a contract.
|
|
76
|
-
*/
|
|
77
|
-
isContract: boolean;
|
|
78
|
-
}
|
|
79
|
-
| undefined;
|
|
80
|
-
}
|
|
81
|
-
| undefined;
|
|
82
|
-
isEmbeddedWalletsEnabled: boolean;
|
|
83
|
-
isConnected: boolean;
|
|
84
|
-
isConnecting: boolean;
|
|
85
|
-
flags: {
|
|
86
|
-
disableEip5792: boolean;
|
|
87
|
-
disable5792Upgrade: boolean;
|
|
88
|
-
};
|
|
89
|
-
walletClient: UseWalletClientReturnType["data"];
|
|
90
|
-
openConnectModal(): Promise<void> | void;
|
|
91
|
-
/**
|
|
92
|
-
* Connects a wallet using a specific strategy.
|
|
93
|
-
* For email/phone use MultiStepAuthArgsType (requires preAuthenticate first).
|
|
94
|
-
*/
|
|
95
|
-
connect(
|
|
96
|
-
args: SingleStepAuthArgsType | MultiStepAuthArgsType,
|
|
97
|
-
): Promise<Wallet | null> | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* Sends an OTP to the user's email or phone number.
|
|
100
|
-
* Call this before connect() when using email or phone strategy.
|
|
101
|
-
*/
|
|
102
|
-
preAuthenticate(
|
|
103
|
-
args:
|
|
104
|
-
| { strategy: "email"; email: string }
|
|
105
|
-
| { strategy: "phone"; phoneNumber: string },
|
|
106
|
-
): Promise<void>;
|
|
107
|
-
disconnect(): void;
|
|
108
|
-
/**
|
|
109
|
-
* A callback that is called when a smart account upgrade is rejected.
|
|
110
|
-
*
|
|
111
|
-
* This is used to disable EIP-5792 temporarily.
|
|
112
|
-
*/
|
|
113
|
-
onSmartAccountRejection(): void;
|
|
114
|
-
|
|
115
|
-
defaultChainId: ChainId;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export enum ChainId {
|
|
119
|
-
MAINNET = 80094,
|
|
120
|
-
BEPOLIA = 80069,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export type ConnectEvent =
|
|
124
|
-
| { type: "connect"; data: SingleStepAuthArgsType | MultiStepAuthArgsType }
|
|
125
|
-
| { type: "connect_modal" };
|
|
126
|
-
|
|
127
|
-
export interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
20
|
+
export interface IBeraWagmiProviderBaseProps extends PropsWithChildren {
|
|
128
21
|
config: ReturnType<typeof getConfig>;
|
|
129
|
-
theme?: "dark" | "light" | "auto";
|
|
130
22
|
flags?: {
|
|
131
23
|
disableEip5792?: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Whether to disable the 5792 upgrade for users that haven't upgraded yet.
|
|
134
|
-
*
|
|
135
|
-
* `atomic.status === "ready"`
|
|
136
|
-
*/
|
|
137
24
|
disable5792Upgrade?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* A value that mocks the connected wallet address, while transactions are still sent from the connected wallet.
|
|
140
|
-
* It can be used for advanced use cases like sending permissionless transactions (like incentive claims).
|
|
141
|
-
*/
|
|
142
25
|
accountOverride?: Address;
|
|
143
26
|
};
|
|
144
27
|
onSmartAccountRejection?: () => void;
|
|
145
|
-
onConnect?: (event: ConnectEvent) => void;
|
|
146
|
-
onConnectError?: (error: Error) => void;
|
|
147
|
-
chains?: Chain[];
|
|
148
28
|
defaultChain: Chain;
|
|
149
29
|
thirdweb: ThirdwebConfig;
|
|
150
|
-
|
|
30
|
+
/** The thirdweb hook result — lightweight or full. */
|
|
31
|
+
thirdwebResult: UseThirdwebBaseResult;
|
|
32
|
+
/** Provided by the full variant; lightweight stubs these. */
|
|
33
|
+
openConnectModal?: BeraWagmiApi["openConnectModal"];
|
|
34
|
+
DebugConnectButton?: BeraWagmiApi["DebugConnectButton"];
|
|
151
35
|
}
|
|
152
36
|
|
|
153
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Base provider that wires up the BeraWagmiContext.
|
|
39
|
+
* Both the lightweight and full WagmiProviders render this.
|
|
40
|
+
*/
|
|
41
|
+
export function BeraWagmiProviderBase({
|
|
154
42
|
children,
|
|
155
43
|
config,
|
|
156
44
|
flags: { disableEip5792, disable5792Upgrade, accountOverride } = {},
|
|
157
|
-
theme,
|
|
158
45
|
onSmartAccountRejection,
|
|
159
|
-
chains = [],
|
|
160
46
|
defaultChain,
|
|
161
47
|
thirdweb,
|
|
162
|
-
|
|
163
|
-
onConnect,
|
|
164
|
-
onConnectError,
|
|
165
|
-
}: IBeraWagmiProviderProps) {
|
|
166
|
-
const {
|
|
48
|
+
thirdwebResult: {
|
|
167
49
|
wallet,
|
|
168
50
|
connect,
|
|
169
51
|
connectionId,
|
|
@@ -173,25 +55,17 @@ export function BeraWagmiProvider({
|
|
|
173
55
|
profiles,
|
|
174
56
|
preAuthenticate,
|
|
175
57
|
isConnecting,
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
publicJsonRpcUrl,
|
|
182
|
-
onConnect,
|
|
183
|
-
onConnectError,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const { address: connectedAddress, chainId } = useAccount(); // wagmi
|
|
58
|
+
},
|
|
59
|
+
openConnectModal,
|
|
60
|
+
DebugConnectButton,
|
|
61
|
+
}: IBeraWagmiProviderBaseProps) {
|
|
62
|
+
const { address: connectedAddress, chainId } = useAccount();
|
|
187
63
|
|
|
188
64
|
const { disconnect: disconnectWagmi } = useDisconnect();
|
|
189
65
|
const publicClient = usePublicClient();
|
|
190
66
|
|
|
191
67
|
const address = useMemo<Address | undefined>(() => {
|
|
192
|
-
// no address anyway if no connected address
|
|
193
68
|
if (!connectedAddress || !wallet) return undefined;
|
|
194
|
-
|
|
195
69
|
return accountOverride ?? connectedAddress;
|
|
196
70
|
}, [accountOverride, connectedAddress, wallet]);
|
|
197
71
|
|
|
@@ -213,18 +87,14 @@ export function BeraWagmiProvider({
|
|
|
213
87
|
},
|
|
214
88
|
);
|
|
215
89
|
const [isContract, has7702Authorization] = useMemo(() => {
|
|
216
|
-
if (!code)
|
|
217
|
-
// if no code, it's not a contract or has 7702 authorization
|
|
218
|
-
return [false, false];
|
|
90
|
+
if (!code) return [false, false];
|
|
219
91
|
|
|
220
92
|
const has7702Authorization = code.startsWith("0xef01");
|
|
221
93
|
|
|
222
94
|
if (has7702Authorization) {
|
|
223
|
-
// if has 7702 authorization, it's not a contract
|
|
224
95
|
return [false, true];
|
|
225
96
|
}
|
|
226
97
|
|
|
227
|
-
// if doesn't have 7702 authorization but has code, it's a contract
|
|
228
98
|
return [true, false];
|
|
229
99
|
}, [code]);
|
|
230
100
|
|
|
@@ -232,11 +102,10 @@ export function BeraWagmiProvider({
|
|
|
232
102
|
|
|
233
103
|
const normalizedEns = useMemo(() => {
|
|
234
104
|
try {
|
|
235
|
-
// some characters might throw an error when normalizing
|
|
236
|
-
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
237
105
|
return ens ? normalize(ens) : undefined;
|
|
238
106
|
} catch {
|
|
239
|
-
//
|
|
107
|
+
// some characters might throw an error when normalizing
|
|
108
|
+
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
240
109
|
// @see https://berachain-dapps.sentry.io/issues/6949741717/?alert_rule_id=16379160&alert_type=issue¬ification_uuid=b01366a6-78b0-4348-a3c1-5f76ced1d539&project=4509842561630209
|
|
241
110
|
}
|
|
242
111
|
}, [ens]);
|
|
@@ -259,13 +128,12 @@ export function BeraWagmiProvider({
|
|
|
259
128
|
},
|
|
260
129
|
isEmbeddedWalletsEnabled: thirdweb.embeddedWallets ?? true,
|
|
261
130
|
isConnecting,
|
|
262
|
-
isConnected:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
},
|
|
131
|
+
isConnected: !!address && !!walletClient,
|
|
132
|
+
DebugConnectButton:
|
|
133
|
+
DebugConnectButton ??
|
|
134
|
+
(() => {
|
|
135
|
+
return null;
|
|
136
|
+
}),
|
|
269
137
|
account:
|
|
270
138
|
wallet && chainId && address
|
|
271
139
|
? {
|
|
@@ -284,16 +152,17 @@ export function BeraWagmiProvider({
|
|
|
284
152
|
}
|
|
285
153
|
: undefined,
|
|
286
154
|
connect,
|
|
287
|
-
openConnectModal
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
155
|
+
openConnectModal:
|
|
156
|
+
openConnectModal ??
|
|
157
|
+
(() => {
|
|
158
|
+
throw new Error(
|
|
159
|
+
"openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context instead.",
|
|
160
|
+
);
|
|
161
|
+
}),
|
|
292
162
|
disconnect: () => {
|
|
293
163
|
disconnectWagmi();
|
|
294
164
|
disconnectProvider();
|
|
295
165
|
},
|
|
296
|
-
// chains,
|
|
297
166
|
defaultChainId: defaultChain.id,
|
|
298
167
|
}}
|
|
299
168
|
>
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
3
4
|
import { useMemo } from "react";
|
|
4
5
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
6
|
import { ThirdwebProvider } from "thirdweb/react";
|
|
6
|
-
import type { Chain, Transport } from "viem";
|
|
7
|
+
import type { Address, Chain, Transport } from "viem";
|
|
7
8
|
import { WagmiProvider as WagmiProviderBase } from "wagmi";
|
|
8
9
|
|
|
10
|
+
import type { ThirdwebConfig } from "../config";
|
|
9
11
|
import { getConfig } from "../config/defaultWagmiConfig";
|
|
10
|
-
import {
|
|
12
|
+
import type { ConnectEvent } from "./BeraWagmi";
|
|
13
|
+
import { BeraWagmiProviderBase } from "./BeraWagmiLightWeight";
|
|
14
|
+
import { useThirdwebLightWeight } from "./useThirdwebLightWeight";
|
|
11
15
|
|
|
12
|
-
type
|
|
13
|
-
IBeraWagmiProviderProps,
|
|
14
|
-
"config" | "defaultChain"
|
|
15
|
-
> & {
|
|
16
|
+
type WagmiProviderLightWeightProps = PropsWithChildren<{
|
|
16
17
|
transports?: Record<number, Transport>;
|
|
17
18
|
defaultChain: Chain;
|
|
18
|
-
|
|
19
|
+
chains?: Chain[];
|
|
20
|
+
thirdweb: ThirdwebConfig;
|
|
21
|
+
flags?: {
|
|
22
|
+
disableEip5792?: boolean;
|
|
23
|
+
disable5792Upgrade?: boolean;
|
|
24
|
+
accountOverride?: Address;
|
|
25
|
+
};
|
|
26
|
+
onSmartAccountRejection?: () => void;
|
|
27
|
+
onConnect?: (event: ConnectEvent) => void;
|
|
28
|
+
onConnectError?: (error: Error) => void;
|
|
29
|
+
publicJsonRpcUrl?: string;
|
|
30
|
+
}>;
|
|
19
31
|
|
|
20
32
|
const queryClient = new QueryClient();
|
|
21
33
|
|
|
@@ -24,9 +36,12 @@ export function WagmiProvider({
|
|
|
24
36
|
defaultChain,
|
|
25
37
|
chains,
|
|
26
38
|
thirdweb,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
children,
|
|
40
|
+
onConnect,
|
|
41
|
+
onConnectError,
|
|
42
|
+
publicJsonRpcUrl,
|
|
43
|
+
...baseProps
|
|
44
|
+
}: WagmiProviderLightWeightProps) {
|
|
30
45
|
const config = useMemo(() => {
|
|
31
46
|
return getConfig({
|
|
32
47
|
thirdweb,
|
|
@@ -36,6 +51,14 @@ export function WagmiProvider({
|
|
|
36
51
|
});
|
|
37
52
|
}, [defaultChain, thirdweb, transports, chains]);
|
|
38
53
|
|
|
54
|
+
const thirdwebResult = useThirdwebLightWeight({
|
|
55
|
+
config,
|
|
56
|
+
chain: defaultChain,
|
|
57
|
+
publicJsonRpcUrl,
|
|
58
|
+
onConnect,
|
|
59
|
+
onConnectError,
|
|
60
|
+
});
|
|
61
|
+
|
|
39
62
|
return (
|
|
40
63
|
<ThirdwebProvider>
|
|
41
64
|
<WagmiProviderBase
|
|
@@ -44,13 +67,15 @@ export function WagmiProvider({
|
|
|
44
67
|
reconnectOnMount={false}
|
|
45
68
|
>
|
|
46
69
|
<QueryClientProvider client={queryClient}>
|
|
47
|
-
<
|
|
48
|
-
{...
|
|
70
|
+
<BeraWagmiProviderBase
|
|
71
|
+
{...baseProps}
|
|
49
72
|
thirdweb={thirdweb}
|
|
50
|
-
chains={chains}
|
|
51
73
|
defaultChain={defaultChain}
|
|
52
74
|
config={config}
|
|
53
|
-
|
|
75
|
+
thirdwebResult={thirdwebResult}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</BeraWagmiProviderBase>
|
|
54
79
|
</QueryClientProvider>
|
|
55
80
|
</WagmiProviderBase>
|
|
56
81
|
</ThirdwebProvider>
|
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
|
|
3
1
|
import { defineChain } from "thirdweb";
|
|
4
2
|
import {
|
|
5
3
|
ConnectButton,
|
|
6
|
-
useActiveAccount,
|
|
7
|
-
useActiveWallet,
|
|
8
|
-
useAutoConnect,
|
|
9
|
-
useProfiles,
|
|
10
|
-
useConnect as useTwConnect,
|
|
11
4
|
useConnectModal as useTwConnectModal,
|
|
12
|
-
useDisconnect as useTwDisconnect,
|
|
13
|
-
useWalletInfo,
|
|
14
5
|
} from "thirdweb/react";
|
|
15
|
-
import type {
|
|
16
|
-
Account,
|
|
17
|
-
AutoConnectProps,
|
|
18
|
-
Profile,
|
|
19
|
-
Wallet,
|
|
20
|
-
} from "thirdweb/wallets";
|
|
21
|
-
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
22
6
|
import type { Chain } from "viem";
|
|
23
|
-
import { useConnect } from "wagmi";
|
|
24
7
|
|
|
25
|
-
import type { getConfig
|
|
8
|
+
import type { getConfig } from "../config";
|
|
26
9
|
import type { BeraWagmiApi, ConnectEvent } from "./BeraWagmi";
|
|
10
|
+
import {
|
|
11
|
+
type UseThirdwebBaseResult,
|
|
12
|
+
useThirdwebLightWeight,
|
|
13
|
+
} from "./useThirdwebLightWeight";
|
|
27
14
|
|
|
28
15
|
export function useThirdweb({
|
|
29
16
|
config,
|
|
@@ -32,7 +19,7 @@ export function useThirdweb({
|
|
|
32
19
|
chain,
|
|
33
20
|
onConnect,
|
|
34
21
|
onConnectError,
|
|
35
|
-
publicJsonRpcUrl
|
|
22
|
+
publicJsonRpcUrl,
|
|
36
23
|
}: {
|
|
37
24
|
onConnect?: (event: ConnectEvent) => void;
|
|
38
25
|
onConnectError?: (error: Error) => void;
|
|
@@ -41,142 +28,32 @@ export function useThirdweb({
|
|
|
41
28
|
chains?: Chain[];
|
|
42
29
|
publicJsonRpcUrl?: string;
|
|
43
30
|
chain: Chain;
|
|
44
|
-
}):
|
|
45
|
-
BeraWagmiApi,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
> & {
|
|
53
|
-
connectionId: string;
|
|
54
|
-
connectorName: string | null;
|
|
55
|
-
isEmbeddedWallet: boolean;
|
|
56
|
-
wallet: Account | undefined;
|
|
57
|
-
profiles: Profile[] | undefined;
|
|
58
|
-
} {
|
|
59
|
-
const { connectors, connect: wagmiConnect } = useConnect();
|
|
60
|
-
|
|
61
|
-
const activeWallet = useActiveWallet();
|
|
62
|
-
const activeAccount = useActiveAccount(); // thirdweb
|
|
63
|
-
const { disconnect: disconnectThirdweb } = useTwDisconnect();
|
|
64
|
-
const { data: walletInfo } = useWalletInfo(activeWallet?.id);
|
|
65
|
-
const { connect: twConnect } = useTwConnect();
|
|
66
|
-
|
|
67
|
-
const { data: profiles } = useProfiles({ client: config.client });
|
|
68
|
-
|
|
69
|
-
const thirdwebChain = useMemo(
|
|
70
|
-
() =>
|
|
71
|
-
defineChain({
|
|
72
|
-
id: chain.id,
|
|
73
|
-
blockExplorers: chain.blockExplorers,
|
|
74
|
-
blockTime: chain.blockTime,
|
|
75
|
-
ensTlds: chain.ensTlds,
|
|
76
|
-
testnet: chain.testnet,
|
|
77
|
-
contracts: chain.contracts,
|
|
78
|
-
nativeCurrency: chain.nativeCurrency,
|
|
79
|
-
name: chain.name,
|
|
80
|
-
rpcUrls: {
|
|
81
|
-
default: {
|
|
82
|
-
http: [publicJsonRpcUrl],
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
[publicJsonRpcUrl, chain],
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const connectOptions = {
|
|
90
|
-
client: config.client,
|
|
91
|
-
chain: thirdwebChain,
|
|
92
|
-
wallets: config.wallets,
|
|
93
|
-
} as const satisfies AutoConnectProps;
|
|
94
|
-
|
|
95
|
-
async function syncConnectedWallet(wallet: Wallet) {
|
|
96
|
-
// console.debug("syncConnectedWallet", wallet);
|
|
97
|
-
// now "connect" the wagmi connector
|
|
98
|
-
const twConnector = connectors.find((c) => c.id === "in-app-wallet");
|
|
99
|
-
|
|
100
|
-
if (twConnector) {
|
|
101
|
-
const options: ConnectionOptions = {
|
|
102
|
-
withCapabilities: true,
|
|
103
|
-
wallet,
|
|
104
|
-
} as const;
|
|
105
|
-
|
|
106
|
-
wagmiConnect({
|
|
107
|
-
connector: twConnector,
|
|
108
|
-
chainId: chain.id,
|
|
109
|
-
...options,
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
// captureException is not available here since we don't have shared-ui
|
|
113
|
-
// however this happens only if wagmi is misconfigured
|
|
114
|
-
console.error("no tw connector found");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const { isLoading: isAutoConnecting } = useAutoConnect({
|
|
119
|
-
...connectOptions,
|
|
120
|
-
onConnect: syncConnectedWallet,
|
|
31
|
+
}): UseThirdwebBaseResult &
|
|
32
|
+
Pick<BeraWagmiApi, "openConnectModal" | "DebugConnectButton"> {
|
|
33
|
+
const base = useThirdwebLightWeight({
|
|
34
|
+
config,
|
|
35
|
+
chain,
|
|
36
|
+
onConnect,
|
|
37
|
+
onConnectError,
|
|
38
|
+
publicJsonRpcUrl,
|
|
121
39
|
});
|
|
122
40
|
|
|
123
|
-
const connectionId = useMemo(() => {
|
|
124
|
-
// this might not be available in some environments
|
|
125
|
-
if ("randomUUID" in crypto) {
|
|
126
|
-
return crypto.randomUUID();
|
|
127
|
-
}
|
|
128
|
-
return Math.random().toString(36).substring(2, 15);
|
|
129
|
-
}, [activeWallet?.id, activeAccount?.address]);
|
|
130
|
-
|
|
131
41
|
const { connect: twConnectModal } = useTwConnectModal();
|
|
132
42
|
|
|
133
43
|
return {
|
|
134
|
-
|
|
135
|
-
if (!config.hasEmbeddedWallets) {
|
|
136
|
-
console.error(
|
|
137
|
-
"useBeraWagmi.connect: this function is not available if embedded wallets are disabled",
|
|
138
|
-
);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
return twConnect(async () => {
|
|
142
|
-
// this must be called inside twConnect or it won't work for social login wallets
|
|
143
|
-
const wallet = config.wallets.find(
|
|
144
|
-
(w) => w.id === "inApp",
|
|
145
|
-
) as InAppWallet;
|
|
146
|
-
|
|
147
|
-
if (!wallet) {
|
|
148
|
-
console.error("useBeraWagmi.connect: no inApp wallet found");
|
|
149
|
-
throw new Error("no inApp wallet found");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return wallet
|
|
153
|
-
.connect({
|
|
154
|
-
...connectOptions,
|
|
155
|
-
...args,
|
|
156
|
-
})
|
|
157
|
-
.then(async () => {
|
|
158
|
-
onConnect?.({ type: "connect", data: args });
|
|
159
|
-
await syncConnectedWallet(wallet);
|
|
160
|
-
return wallet;
|
|
161
|
-
})
|
|
162
|
-
.catch((e) => {
|
|
163
|
-
onConnectError?.(e);
|
|
164
|
-
throw e;
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
},
|
|
44
|
+
...base,
|
|
168
45
|
async openConnectModal() {
|
|
169
46
|
try {
|
|
170
47
|
const wallet = await twConnectModal({
|
|
171
|
-
...connectOptions,
|
|
48
|
+
...base.connectOptions,
|
|
172
49
|
wallets: config.wallets,
|
|
173
50
|
theme: theme === "auto" ? undefined : theme,
|
|
174
51
|
size: "compact",
|
|
175
52
|
chains: [
|
|
176
|
-
thirdwebChain,
|
|
53
|
+
base.thirdwebChain,
|
|
177
54
|
...chains
|
|
178
55
|
// avoid duplicates
|
|
179
|
-
.filter((c) => c.id !== thirdwebChain.id)
|
|
56
|
+
.filter((c) => c.id !== base.thirdwebChain.id)
|
|
180
57
|
.map((c) =>
|
|
181
58
|
defineChain({
|
|
182
59
|
id: c.id,
|
|
@@ -186,34 +63,20 @@ export function useThirdweb({
|
|
|
186
63
|
}); // opens the connect modal
|
|
187
64
|
|
|
188
65
|
onConnect?.({ type: "connect_modal" });
|
|
189
|
-
await syncConnectedWallet(wallet);
|
|
66
|
+
await base.syncConnectedWallet(wallet);
|
|
190
67
|
} catch (e) {
|
|
191
68
|
onConnectError?.(e as Error);
|
|
192
69
|
throw e;
|
|
193
70
|
}
|
|
194
71
|
},
|
|
195
|
-
disconnect() {
|
|
196
|
-
if (activeWallet) {
|
|
197
|
-
disconnectThirdweb(activeWallet);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
isConnecting: isAutoConnecting,
|
|
201
|
-
connectionId,
|
|
202
|
-
connectorName: walletInfo?.name ?? null,
|
|
203
|
-
isEmbeddedWallet: walletInfo?.id === "inApp",
|
|
204
|
-
wallet: activeAccount,
|
|
205
|
-
profiles,
|
|
206
|
-
preAuthenticate(args) {
|
|
207
|
-
return preAuthenticate({ ...args, client: config.client });
|
|
208
|
-
},
|
|
209
72
|
DebugConnectButton() {
|
|
210
73
|
return (
|
|
211
74
|
<ConnectButton
|
|
212
|
-
{...connectOptions}
|
|
75
|
+
{...base.connectOptions}
|
|
213
76
|
connectModal={{
|
|
214
77
|
size: "compact",
|
|
215
78
|
}}
|
|
216
|
-
onConnect={(wallet) => syncConnectedWallet(wallet)}
|
|
79
|
+
onConnect={(wallet) => base.syncConnectedWallet(wallet)}
|
|
217
80
|
/>
|
|
218
81
|
);
|
|
219
82
|
},
|
|
@@ -21,37 +21,39 @@ import type { Chain } from "viem";
|
|
|
21
21
|
import { useConnect } from "wagmi";
|
|
22
22
|
|
|
23
23
|
import type { getConfig, InAppWallet } from "../config";
|
|
24
|
-
import type { BeraWagmiApi, ConnectEvent } from "./
|
|
24
|
+
import type { BeraWagmiApi, ConnectEvent } from "./BeraWagmi";
|
|
25
25
|
|
|
26
|
-
export
|
|
27
|
-
config,
|
|
28
|
-
chain,
|
|
29
|
-
onConnect,
|
|
30
|
-
onConnectError,
|
|
31
|
-
publicJsonRpcUrl = chain.rpcUrls.default.http[0],
|
|
32
|
-
}: {
|
|
26
|
+
export interface UseThirdwebBaseArgs {
|
|
33
27
|
onConnect?: (event: ConnectEvent) => void;
|
|
34
28
|
onConnectError?: (error: Error) => void;
|
|
35
29
|
config: ReturnType<typeof getConfig>;
|
|
36
|
-
theme: "light" | "dark" | "auto" | undefined;
|
|
37
|
-
chains?: Chain[];
|
|
38
30
|
publicJsonRpcUrl?: string;
|
|
39
31
|
chain: Chain;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
| "preAuthenticate"
|
|
48
|
-
> & {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UseThirdwebBaseResult {
|
|
35
|
+
connect: BeraWagmiApi["connect"];
|
|
36
|
+
disconnect: BeraWagmiApi["disconnect"];
|
|
37
|
+
isConnecting: BeraWagmiApi["isConnecting"];
|
|
38
|
+
preAuthenticate: BeraWagmiApi["preAuthenticate"];
|
|
49
39
|
connectionId: string;
|
|
50
40
|
connectorName: string | null;
|
|
51
41
|
isEmbeddedWallet: boolean;
|
|
52
42
|
wallet: Account | undefined;
|
|
53
43
|
profiles: Profile[] | undefined;
|
|
54
|
-
|
|
44
|
+
/** Exposed so the full variant can call it after opening the modal. */
|
|
45
|
+
syncConnectedWallet: (wallet: Wallet) => Promise<void>;
|
|
46
|
+
connectOptions: AutoConnectProps;
|
|
47
|
+
thirdwebChain: ReturnType<typeof defineChain>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function useThirdwebLightWeight({
|
|
51
|
+
config,
|
|
52
|
+
chain,
|
|
53
|
+
onConnect,
|
|
54
|
+
onConnectError,
|
|
55
|
+
publicJsonRpcUrl = chain.rpcUrls.default.http[0],
|
|
56
|
+
}: UseThirdwebBaseArgs): UseThirdwebBaseResult {
|
|
55
57
|
const { connectors, connect: wagmiConnect } = useConnect();
|
|
56
58
|
|
|
57
59
|
const activeWallet = useActiveWallet();
|
|
@@ -89,8 +91,6 @@ export function useThirdwebLightWeight({
|
|
|
89
91
|
} as const satisfies AutoConnectProps;
|
|
90
92
|
|
|
91
93
|
async function syncConnectedWallet(wallet: Wallet) {
|
|
92
|
-
// console.debug("syncConnectedWallet", wallet);
|
|
93
|
-
// now "connect" the wagmi connector
|
|
94
94
|
const twConnector = connectors.find((c) => c.id === "in-app-wallet");
|
|
95
95
|
|
|
96
96
|
if (twConnector) {
|
|
@@ -172,6 +172,9 @@ export function useThirdwebLightWeight({
|
|
|
172
172
|
profiles,
|
|
173
173
|
preAuthenticate(args) {
|
|
174
174
|
return preAuthenticate({ ...args, client: config.client });
|
|
175
|
-
}
|
|
175
|
+
},
|
|
176
|
+
syncConnectedWallet,
|
|
177
|
+
connectOptions,
|
|
178
|
+
thirdwebChain,
|
|
176
179
|
};
|
|
177
180
|
}
|
package/dist/chunk-KNUNU6MD.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkLEALKQIHcjs = require('./chunk-LEALKQIH.cjs');var _wagmi = require('wagmi');var _react = require('react');function M(){let e=_react.useContext.call(void 0, _chunkLEALKQIHcjs.a);if(!e)throw new Error("LightweightAccountContext not found");let{address:n,defaultChainId:r}=e;return{isConnected:!!n,address:n,defaultChainId:r}}var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _ens = require('viem/ens');var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');var _inapp = require('thirdweb/wallets/in-app');var _jsxruntime = require('react/jsx-runtime');function L({config:e,theme:n,chains:r=[],chain:t,onConnect:c,onConnectError:g,publicJsonRpcUrl:h=t.rpcUrls.default.http[0]}){let{connectors:y,connect:l}=_wagmi.useConnect.call(void 0, ),d=_react3.useActiveWallet.call(void 0, ),b=_react3.useActiveAccount.call(void 0, ),{disconnect:W}=_react3.useDisconnect.call(void 0, ),{data:A}=_react3.useWalletInfo.call(void 0, _optionalChain([d, 'optionalAccess', _2 => _2.id])),{connect:m}=_react3.useConnect.call(void 0, ),{data:v}=_react3.useProfiles.call(void 0, {client:e.client}),f=_react.useMemo.call(void 0, ()=>_thirdweb.defineChain.call(void 0, {id:t.id,blockExplorers:t.blockExplorers,blockTime:t.blockTime,ensTlds:t.ensTlds,testnet:t.testnet,contracts:t.contracts,nativeCurrency:t.nativeCurrency,name:t.name,rpcUrls:{default:{http:[h]}}}),[h,t]),u={client:e.client,chain:f,wallets:e.wallets};async function p(o){let i=y.find(a=>a.id==="in-app-wallet");if(i){let a={withCapabilities:!0,wallet:o};l({connector:i,chainId:t.id,...a})}else console.error("no tw connector found")}let{isLoading:P}=_react3.useAutoConnect.call(void 0, {...u,onConnect:p}),E=_react.useMemo.call(void 0, ()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[_optionalChain([d, 'optionalAccess', _3 => _3.id]),_optionalChain([b, 'optionalAccess', _4 => _4.address])]),{connect:B}=_react3.useConnectModal.call(void 0, );return{connect(o){if(!e.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return m(async()=>{let i=e.wallets.find(a=>a.id==="inApp");if(!i)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return i.connect({...u,...o}).then(async()=>(_optionalChain([c, 'optionalCall', _5 => _5({type:"connect",data:o})]),await p(i),i)).catch(a=>{throw _optionalChain([g, 'optionalCall', _6 => _6(a)]),a})})},async openConnectModal(){try{let o=await B({...u,wallets:e.wallets,theme:n==="auto"?void 0:n,size:"compact",chains:[f,...r.filter(i=>i.id!==f.id).map(i=>_thirdweb.defineChain.call(void 0, {id:i.id}))]});_optionalChain([c, 'optionalCall', _7 => _7({type:"connect_modal"})]),await p(o)}catch(o){throw _optionalChain([g, 'optionalCall', _8 => _8(o)]),o}},disconnect(){d&&W(d)},isConnecting:P,connectionId:E,connectorName:_nullishCoalesce(_optionalChain([A, 'optionalAccess', _9 => _9.name]), () => (null)),isEmbeddedWallet:_optionalChain([A, 'optionalAccess', _10 => _10.id])==="inApp",wallet:b,profiles:v,preAuthenticate(o){return _inapp.preAuthenticate.call(void 0, {...o,client:e.client})},DebugConnectButton(){return _jsxruntime.jsx.call(void 0, _react3.ConnectButton,{...u,connectModal:{size:"compact"},onConnect:o=>p(o)})}}}function C(){let e=_react.useContext.call(void 0, _chunkLEALKQIHcjs.c);if(!e)throw new Error("BeraWagmiContext not found");return e}function Oe({children:e,config:n,flags:{disableEip5792:r,disable5792Upgrade:t,accountOverride:c}={},theme:g,onSmartAccountRejection:h,chains:y=[],defaultChain:l,thirdweb:d,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}){let{wallet:m,openConnectModal:v,connect:f,DebugConnectButton:u,connectionId:p,disconnect:P,connectorName:E,isEmbeddedWallet:B,profiles:o,preAuthenticate:i,isConnecting:a}=L({config:n,theme:g,chains:y,chain:l,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}),{address:x,chainId:I}=_wagmi.useAccount.call(void 0, ),{disconnect:q}=_wagmi.useDisconnect.call(void 0, ),J=_wagmi.usePublicClient.call(void 0, ),s=_react.useMemo.call(void 0, ()=>{if(!(!x||!m))return _nullishCoalesce(c, () => (x))},[c,x,m]),{data:w}=_wagmi.useEnsName.call(void 0, {config:n.wagmi,chainId:l.id,address:s}),{data:T}=_immutable2.default.call(void 0, s?["BeraWagmiProvider_code",s,I]:null,([Q,V,ye])=>_optionalChain([J, 'optionalAccess', _11 => _11.getCode, 'call', _12 => _12({address:V})]),{refreshInterval:6e4}),[K,F]=_react.useMemo.call(void 0, ()=>T?T.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[T]),{data:S}=_wagmi.useWalletClient.call(void 0, ),G=_react.useMemo.call(void 0, ()=>{try{return w?_ens.normalize.call(void 0, w):void 0}catch (e2){}},[w]),H=_wagmi.useEnsAvatar.call(void 0, {name:G});return _jsxruntime.jsx.call(void 0, _chunkLEALKQIHcjs.c.Provider,{value:{preAuthenticate:i,flags:{disableEip5792:!!r,disable5792Upgrade:!!t},walletClient:S,onSmartAccountRejection:()=>{_optionalChain([h, 'optionalCall', _13 => _13()])},isEmbeddedWalletsEnabled:_nullishCoalesce(d.embeddedWallets, () => (!0)),isConnecting:a,isConnected:!!s&&!!S,DebugConnectButton:u,account:m&&I&&s?{connectionId:p,chainId:I,connectorName:E,isEmbeddedWallet:B,profiles:o,wallet:{address:s,ensName:_nullishCoalesce(_optionalChain([w, 'optionalAccess', _14 => _14.replace, 'call', _15 => _15(".bera",".\u{1F43B}\u26D3\uFE0F")]), () => (null)),ensAvatar:_nullishCoalesce(H.data, () => (null)),has7702Authorization:F,isContract:K}}:void 0,connect:f,openConnectModal:async()=>{await v()},disconnect:()=>{q(),P()},defaultChainId:l.id},children:_jsxruntime.jsx.call(void 0, _chunkLEALKQIHcjs.b,{address:s,defaultChainId:l.id,children:e})})}function ge(){let{account:e,isConnected:n}=C();return{...e,isConnected:n}}function Ae({chainId:e}){let{flags:n,account:r}=C(),{data:t}=_wagmi.useCapabilities.call(void 0, {account:_optionalChain([r, 'optionalAccess', _16 => _16.wallet, 'optionalAccess', _17 => _17.address]),scopeKey:_optionalChain([r, 'optionalAccess', _18 => _18.connectionId]),query:{retry:3},chainId:e});return{supportsAtomic:_react.useMemo.call(void 0, ()=>n.disableEip5792||!t?!1:_optionalChain([t, 'optionalAccess', _19 => _19.atomic, 'optionalAccess', _20 => _20.status])==="supported"||!n.disable5792Upgrade&&_optionalChain([t, 'optionalAccess', _21 => _21.atomic, 'optionalAccess', _22 => _22.status])==="ready",[t,n.disableEip5792,n.disable5792Upgrade,e]),capabilities:t}}function Ye(e){let{defaultChainId:n}=M(),{chainId:r,...t}=_nullishCoalesce(e, () => ({}));return _wagmi.usePublicClient.call(void 0, {chainId:_nullishCoalesce(r, () => (n)),...t})}exports.a = M; exports.b = ge; exports.c = Ae; exports.d = Ye; exports.e = _wagmi.useBlockNumber; exports.f = _wagmi.useChains; exports.g = _wagmi.useConfig; exports.h = _wagmi.useEnsAvatar; exports.i = _wagmi.useEnsName; exports.j = _wagmi.useSwitchChain; exports.k = _wagmi.useTransactionReceipt; exports.l = C; exports.m = Oe;
|
package/dist/chunk-KXR247FP.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createContext as r}from"react";import{jsx as n}from"react/jsx-runtime";var d=r(void 0);function p({children:e,address:t,defaultChainId:i}){return n(d.Provider,{value:{address:t,defaultChainId:i},children:e})}import{createContext as o}from"react";var s=o(void 0);export{d as a,p as b,s as c};
|
package/dist/chunk-LEALKQIH.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var d=_react.createContext.call(void 0, void 0);function p({children:e,address:t,defaultChainId:i}){return _jsxruntime.jsx.call(void 0, d.Provider,{value:{address:t,defaultChainId:i},children:e})}var s=_react.createContext.call(void 0, void 0);exports.a = d; exports.b = p; exports.c = s;
|
package/dist/chunk-XFXKXV5F.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as R,b as D,c as U}from"./chunk-KXR247FP.mjs";import{usePublicClient as we}from"wagmi";import{useContext as X}from"react";function M(){let e=X(R);if(!e)throw new Error("LightweightAccountContext not found");let{address:n,defaultChainId:r}=e;return{isConnected:!!n,address:n,defaultChainId:r}}import{useBlockNumber as et,useChains as tt,useConfig as nt,useEnsAvatar as O,useEnsName as j,useSwitchChain as ot,useTransactionReceipt as it}from"wagmi";import{useContext as le,useMemo as N}from"react";import de from"swr/immutable";import{normalize as ue}from"viem/ens";import{useAccount as pe,useDisconnect as me,usePublicClient as fe,useWalletClient as Ce}from"wagmi";import{useMemo as k}from"react";import{defineChain as z}from"thirdweb";import{ConnectButton as Y,useActiveAccount as Z,useActiveWallet as $,useAutoConnect as ee,useProfiles as te,useConnect as ne,useConnectModal as oe,useDisconnect as ie,useWalletInfo as re}from"thirdweb/react";import{preAuthenticate as ae}from"thirdweb/wallets/in-app";import{useConnect as se}from"wagmi";import{jsx as ce}from"react/jsx-runtime";function L({config:e,theme:n,chains:r=[],chain:t,onConnect:c,onConnectError:g,publicJsonRpcUrl:h=t.rpcUrls.default.http[0]}){let{connectors:y,connect:l}=se(),d=$(),b=Z(),{disconnect:W}=ie(),{data:A}=re(d?.id),{connect:m}=ne(),{data:v}=te({client:e.client}),f=k(()=>z({id:t.id,blockExplorers:t.blockExplorers,blockTime:t.blockTime,ensTlds:t.ensTlds,testnet:t.testnet,contracts:t.contracts,nativeCurrency:t.nativeCurrency,name:t.name,rpcUrls:{default:{http:[h]}}}),[h,t]),u={client:e.client,chain:f,wallets:e.wallets};async function p(o){let i=y.find(a=>a.id==="in-app-wallet");if(i){let a={withCapabilities:!0,wallet:o};l({connector:i,chainId:t.id,...a})}else console.error("no tw connector found")}let{isLoading:P}=ee({...u,onConnect:p}),E=k(()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[d?.id,b?.address]),{connect:B}=oe();return{connect(o){if(!e.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return m(async()=>{let i=e.wallets.find(a=>a.id==="inApp");if(!i)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return i.connect({...u,...o}).then(async()=>(c?.({type:"connect",data:o}),await p(i),i)).catch(a=>{throw g?.(a),a})})},async openConnectModal(){try{let o=await B({...u,wallets:e.wallets,theme:n==="auto"?void 0:n,size:"compact",chains:[f,...r.filter(i=>i.id!==f.id).map(i=>z({id:i.id}))]});c?.({type:"connect_modal"}),await p(o)}catch(o){throw g?.(o),o}},disconnect(){d&&W(d)},isConnecting:P,connectionId:E,connectorName:A?.name??null,isEmbeddedWallet:A?.id==="inApp",wallet:b,profiles:v,preAuthenticate(o){return ae({...o,client:e.client})},DebugConnectButton(){return ce(Y,{...u,connectModal:{size:"compact"},onConnect:o=>p(o)})}}}import{jsx as _}from"react/jsx-runtime";function C(){let e=le(U);if(!e)throw new Error("BeraWagmiContext not found");return e}function Oe({children:e,config:n,flags:{disableEip5792:r,disable5792Upgrade:t,accountOverride:c}={},theme:g,onSmartAccountRejection:h,chains:y=[],defaultChain:l,thirdweb:d,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}){let{wallet:m,openConnectModal:v,connect:f,DebugConnectButton:u,connectionId:p,disconnect:P,connectorName:E,isEmbeddedWallet:B,profiles:o,preAuthenticate:i,isConnecting:a}=L({config:n,theme:g,chains:y,chain:l,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}),{address:x,chainId:I}=pe(),{disconnect:q}=me(),J=fe(),s=N(()=>{if(!(!x||!m))return c??x},[c,x,m]),{data:w}=j({config:n.wagmi,chainId:l.id,address:s}),{data:T}=de(s?["BeraWagmiProvider_code",s,I]:null,([Q,V,ye])=>J?.getCode({address:V}),{refreshInterval:6e4}),[K,F]=N(()=>T?T.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[T]),{data:S}=Ce(),G=N(()=>{try{return w?ue(w):void 0}catch{}},[w]),H=O({name:G});return _(U.Provider,{value:{preAuthenticate:i,flags:{disableEip5792:!!r,disable5792Upgrade:!!t},walletClient:S,onSmartAccountRejection:()=>{h?.()},isEmbeddedWalletsEnabled:d.embeddedWallets??!0,isConnecting:a,isConnected:!!s&&!!S,DebugConnectButton:u,account:m&&I&&s?{connectionId:p,chainId:I,connectorName:E,isEmbeddedWallet:B,profiles:o,wallet:{address:s,ensName:w?.replace(".bera",".\u{1F43B}\u26D3\uFE0F")??null,ensAvatar:H.data??null,has7702Authorization:F,isContract:K}}:void 0,connect:f,openConnectModal:async()=>{await v()},disconnect:()=>{q(),P()},defaultChainId:l.id},children:_(D,{address:s,defaultChainId:l.id,children:e})})}function ge(){let{account:e,isConnected:n}=C();return{...e,isConnected:n}}import{useMemo as he}from"react";import{useCapabilities as be}from"wagmi";function Ae({chainId:e}){let{flags:n,account:r}=C(),{data:t}=be({account:r?.wallet?.address,scopeKey:r?.connectionId,query:{retry:3},chainId:e});return{supportsAtomic:he(()=>n.disableEip5792||!t?!1:t?.atomic?.status==="supported"||!n.disable5792Upgrade&&t?.atomic?.status==="ready",[t,n.disableEip5792,n.disable5792Upgrade,e]),capabilities:t}}function Ye(e){let{defaultChainId:n}=M(),{chainId:r,...t}=e??{};return we({chainId:r??n,...t})}export{M as a,ge as b,Ae as c,Ye as d,et as e,tt as f,nt as g,O as h,j as i,ot as j,it as k,C as l,Oe as m};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";var _chunkPVMPBWIGcjs = require('../../chunk-PVMPBWIG.cjs');var _chunkLEALKQIHcjs = require('../../chunk-LEALKQIH.cjs');var _react = require('react');var _reactquery = require('@tanstack/react-query');var _react3 = require('thirdweb/react');var _wagmi = require('wagmi');var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _ens = require('viem/ens');var _thirdweb = require('thirdweb');var _inapp = require('thirdweb/wallets/in-app');function R({config:t,chain:e,onConnect:i,onConnectError:a,publicJsonRpcUrl:s=e.rpcUrls.default.http[0]}){let{connectors:d,connect:b}=_wagmi.useConnect.call(void 0, ),u=_react3.useActiveWallet.call(void 0, ),c=_react3.useActiveAccount.call(void 0, ),{disconnect:v}=_react3.useDisconnect.call(void 0, ),{data:m}=_react3.useWalletInfo.call(void 0, _optionalChain([u, 'optionalAccess', _2 => _2.id])),{connect:A}=_react3.useConnect.call(void 0, ),{data:w}=_react3.useProfiles.call(void 0, {client:t.client}),p=_react.useMemo.call(void 0, ()=>_thirdweb.defineChain.call(void 0, {id:e.id,blockExplorers:e.blockExplorers,blockTime:e.blockTime,ensTlds:e.ensTlds,testnet:e.testnet,contracts:e.contracts,nativeCurrency:e.nativeCurrency,name:e.name,rpcUrls:{default:{http:[s]}}}),[s,e]),f={client:t.client,chain:p,wallets:t.wallets};async function g(r){let o=d.find(n=>n.id==="in-app-wallet");if(o){let n={withCapabilities:!0,wallet:r};b({connector:o,chainId:e.id,...n})}else console.error("no tw connector found")}let{isLoading:W}=_react3.useAutoConnect.call(void 0, {...f,onConnect:g}),y=_react.useMemo.call(void 0, ()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[_optionalChain([u, 'optionalAccess', _3 => _3.id]),_optionalChain([c, 'optionalAccess', _4 => _4.address])]);return{connect(r){if(!t.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return A(async()=>{let o=t.wallets.find(n=>n.id==="inApp");if(!o)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return o.connect({...f,...r}).then(async()=>(_optionalChain([i, 'optionalCall', _5 => _5({type:"connect",data:r})]),await g(o),o)).catch(n=>{throw _optionalChain([a, 'optionalCall', _6 => _6(n)]),n})})},disconnect(){u&&v(u)},isConnecting:W,connectionId:y,connectorName:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _7 => _7.name]), () => (null)),isEmbeddedWallet:_optionalChain([m, 'optionalAccess', _8 => _8.id])==="inApp",wallet:c,profiles:w,preAuthenticate(r){return _inapp.preAuthenticate.call(void 0, {...r,client:t.client})}}}var _jsxruntime = require('react/jsx-runtime');function D({children:t,config:e,flags:{disableEip5792:i,disable5792Upgrade:a,accountOverride:s}={},theme:d,onSmartAccountRejection:b,chains:u=[],defaultChain:c,thirdweb:v,publicJsonRpcUrl:m,onConnect:A,onConnectError:w}){let{wallet:p,connect:f,connectionId:g,disconnect:W,connectorName:y,isEmbeddedWallet:r,profiles:o,preAuthenticate:n,isConnecting:k}=R({config:e,theme:d,chains:u,chain:c,publicJsonRpcUrl:m,onConnect:A,onConnectError:w}),{address:P,chainId:E}=_wagmi.useAccount.call(void 0, ),{disconnect:L}=_wagmi.useDisconnect.call(void 0, ),z=_wagmi.usePublicClient.call(void 0, ),l=_react.useMemo.call(void 0, ()=>{if(!(!P||!p))return _nullishCoalesce(s, () => (P))},[s,P,p]),{data:h}=_wagmi.useEnsName.call(void 0, {config:e.wagmi,chainId:c.id,address:l}),{data:T}=_immutable2.default.call(void 0, l?["BeraWagmiProvider_code",l,E]:null,([q,J,ge])=>_optionalChain([z, 'optionalAccess', _9 => _9.getCode, 'call', _10 => _10({address:J})]),{refreshInterval:6e4}),[O,_]=_react.useMemo.call(void 0, ()=>T?T.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[T]),{data:I}=_wagmi.useWalletClient.call(void 0, ),Q=_react.useMemo.call(void 0, ()=>{try{return h?_ens.normalize.call(void 0, h):void 0}catch (e2){}},[h]),j=_wagmi.useEnsAvatar.call(void 0, {name:Q});return _jsxruntime.jsx.call(void 0, _chunkLEALKQIHcjs.c.Provider,{value:{preAuthenticate:n,flags:{disableEip5792:!!i,disable5792Upgrade:!!a},walletClient:I,onSmartAccountRejection:()=>{_optionalChain([b, 'optionalCall', _11 => _11()])},isEmbeddedWalletsEnabled:_nullishCoalesce(v.embeddedWallets, () => (!0)),isConnecting:k,isConnected:!!l&&!!I,DebugConnectButton(){return null},account:p&&E&&l?{connectionId:g,chainId:E,connectorName:y,isEmbeddedWallet:r,profiles:o,wallet:{address:l,ensName:_nullishCoalesce(_optionalChain([h, 'optionalAccess', _12 => _12.replace, 'call', _13 => _13(".bera",".\u{1F43B}\u26D3\uFE0F")]), () => (null)),ensAvatar:_nullishCoalesce(j.data, () => (null)),has7702Authorization:_,isContract:O}}:void 0,connect:f,openConnectModal(){throw new Error("openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context/full instead.")},disconnect:()=>{L(),W()},defaultChainId:c.id},children:_jsxruntime.jsx.call(void 0, _chunkLEALKQIHcjs.b,{address:l,defaultChainId:c.id,children:t})})}var fe=new _reactquery.QueryClient;function ze({transports:t,defaultChain:e,chains:i,thirdweb:a,...s}){let d=_react.useMemo.call(void 0, ()=>_chunkPVMPBWIGcjs.a.call(void 0, {thirdweb:a,transports:t,defaultChain:e,chains:i}),[e,a,t,i]);return _jsxruntime.jsx.call(void 0, _react3.ThirdwebProvider,{children:_jsxruntime.jsx.call(void 0, _wagmi.WagmiProvider,{config:d.wagmi,reconnectOnMount:!1,children:_jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider,{client:fe,children:_jsxruntime.jsx.call(void 0, D,{...s,thirdweb:a,chains:i,defaultChain:e,config:d})})})})}exports.WagmiProvider = ze;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { Address, Chain, Transport } from 'viem';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import { SingleStepAuthArgsType, MultiStepAuthArgsType } from 'thirdweb/wallets';
|
|
5
|
-
import { getConfig, ThirdwebConfig } from '../../config/index.cjs';
|
|
6
|
-
import 'thirdweb';
|
|
7
|
-
import 'wagmi';
|
|
8
|
-
|
|
9
|
-
type ConnectEvent = {
|
|
10
|
-
type: "connect";
|
|
11
|
-
data: SingleStepAuthArgsType | MultiStepAuthArgsType;
|
|
12
|
-
} | {
|
|
13
|
-
type: "connect_modal";
|
|
14
|
-
};
|
|
15
|
-
interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
16
|
-
config: ReturnType<typeof getConfig>;
|
|
17
|
-
theme?: "dark" | "light" | "auto";
|
|
18
|
-
flags?: {
|
|
19
|
-
disableEip5792?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Whether to disable the 5792 upgrade for users that haven't upgraded yet.
|
|
22
|
-
*
|
|
23
|
-
* `atomic.status === "ready"`
|
|
24
|
-
*/
|
|
25
|
-
disable5792Upgrade?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* A value that mocks the connected wallet address, while transactions are still sent from the connected wallet.
|
|
28
|
-
* It can be used for advanced use cases like sending permissionless transactions (like incentive claims).
|
|
29
|
-
*/
|
|
30
|
-
accountOverride?: Address;
|
|
31
|
-
};
|
|
32
|
-
onSmartAccountRejection?: () => void;
|
|
33
|
-
onConnect?: (event: ConnectEvent) => void;
|
|
34
|
-
onConnectError?: (error: Error) => void;
|
|
35
|
-
chains?: Chain[];
|
|
36
|
-
defaultChain: Chain;
|
|
37
|
-
thirdweb: ThirdwebConfig;
|
|
38
|
-
publicJsonRpcUrl?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type WagmiProviderProps = Omit<IBeraWagmiProviderProps, "config" | "defaultChain"> & {
|
|
42
|
-
transports?: Record<number, Transport>;
|
|
43
|
-
defaultChain: Chain;
|
|
44
|
-
};
|
|
45
|
-
declare function WagmiProvider({ transports, defaultChain, chains, thirdweb, ...beraWagmiProps }: WagmiProviderProps): react_jsx_runtime.JSX.Element;
|
|
46
|
-
|
|
47
|
-
export { WagmiProvider };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { Address, Chain, Transport } from 'viem';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import { SingleStepAuthArgsType, MultiStepAuthArgsType } from 'thirdweb/wallets';
|
|
5
|
-
import { getConfig, ThirdwebConfig } from '../../config/index.js';
|
|
6
|
-
import 'thirdweb';
|
|
7
|
-
import 'wagmi';
|
|
8
|
-
|
|
9
|
-
type ConnectEvent = {
|
|
10
|
-
type: "connect";
|
|
11
|
-
data: SingleStepAuthArgsType | MultiStepAuthArgsType;
|
|
12
|
-
} | {
|
|
13
|
-
type: "connect_modal";
|
|
14
|
-
};
|
|
15
|
-
interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
16
|
-
config: ReturnType<typeof getConfig>;
|
|
17
|
-
theme?: "dark" | "light" | "auto";
|
|
18
|
-
flags?: {
|
|
19
|
-
disableEip5792?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Whether to disable the 5792 upgrade for users that haven't upgraded yet.
|
|
22
|
-
*
|
|
23
|
-
* `atomic.status === "ready"`
|
|
24
|
-
*/
|
|
25
|
-
disable5792Upgrade?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* A value that mocks the connected wallet address, while transactions are still sent from the connected wallet.
|
|
28
|
-
* It can be used for advanced use cases like sending permissionless transactions (like incentive claims).
|
|
29
|
-
*/
|
|
30
|
-
accountOverride?: Address;
|
|
31
|
-
};
|
|
32
|
-
onSmartAccountRejection?: () => void;
|
|
33
|
-
onConnect?: (event: ConnectEvent) => void;
|
|
34
|
-
onConnectError?: (error: Error) => void;
|
|
35
|
-
chains?: Chain[];
|
|
36
|
-
defaultChain: Chain;
|
|
37
|
-
thirdweb: ThirdwebConfig;
|
|
38
|
-
publicJsonRpcUrl?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type WagmiProviderProps = Omit<IBeraWagmiProviderProps, "config" | "defaultChain"> & {
|
|
42
|
-
transports?: Record<number, Transport>;
|
|
43
|
-
defaultChain: Chain;
|
|
44
|
-
};
|
|
45
|
-
declare function WagmiProvider({ transports, defaultChain, chains, thirdweb, ...beraWagmiProps }: WagmiProviderProps): react_jsx_runtime.JSX.Element;
|
|
46
|
-
|
|
47
|
-
export { WagmiProvider };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{a as x}from"../../chunk-MZZ62TKM.mjs";import{b as S,c as M}from"../../chunk-KXR247FP.mjs";import{useMemo as le}from"react";import{QueryClient as de,QueryClientProvider as ue}from"@tanstack/react-query";import{ThirdwebProvider as pe}from"thirdweb/react";import{WagmiProvider as me}from"wagmi";import{useContext as ye,useMemo as B}from"react";import te from"swr/immutable";import{normalize as ne}from"viem/ens";import{useAccount as oe,useDisconnect as re,useEnsAvatar as ie,useEnsName as ae,usePublicClient as se,useWalletClient as ce}from"wagmi";import{useMemo as U}from"react";import{defineChain as F}from"thirdweb";import{useActiveAccount as G,useActiveWallet as H,useAutoConnect as K,useProfiles as V,useConnect as X,useDisconnect as Y,useWalletInfo as Z}from"thirdweb/react";import{preAuthenticate as $}from"thirdweb/wallets/in-app";import{useConnect as ee}from"wagmi";function R({config:t,chain:e,onConnect:i,onConnectError:a,publicJsonRpcUrl:s=e.rpcUrls.default.http[0]}){let{connectors:d,connect:b}=ee(),u=H(),c=G(),{disconnect:v}=Y(),{data:m}=Z(u?.id),{connect:A}=X(),{data:w}=V({client:t.client}),p=U(()=>F({id:e.id,blockExplorers:e.blockExplorers,blockTime:e.blockTime,ensTlds:e.ensTlds,testnet:e.testnet,contracts:e.contracts,nativeCurrency:e.nativeCurrency,name:e.name,rpcUrls:{default:{http:[s]}}}),[s,e]),f={client:t.client,chain:p,wallets:t.wallets};async function g(r){let o=d.find(n=>n.id==="in-app-wallet");if(o){let n={withCapabilities:!0,wallet:r};b({connector:o,chainId:e.id,...n})}else console.error("no tw connector found")}let{isLoading:W}=K({...f,onConnect:g}),y=U(()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[u?.id,c?.address]);return{connect(r){if(!t.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return A(async()=>{let o=t.wallets.find(n=>n.id==="inApp");if(!o)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return o.connect({...f,...r}).then(async()=>(i?.({type:"connect",data:r}),await g(o),o)).catch(n=>{throw a?.(n),n})})},disconnect(){u&&v(u)},isConnecting:W,connectionId:y,connectorName:m?.name??null,isEmbeddedWallet:m?.id==="inApp",wallet:c,profiles:w,preAuthenticate(r){return $({...r,client:t.client})}}}import{jsx as N}from"react/jsx-runtime";function D({children:t,config:e,flags:{disableEip5792:i,disable5792Upgrade:a,accountOverride:s}={},theme:d,onSmartAccountRejection:b,chains:u=[],defaultChain:c,thirdweb:v,publicJsonRpcUrl:m,onConnect:A,onConnectError:w}){let{wallet:p,connect:f,connectionId:g,disconnect:W,connectorName:y,isEmbeddedWallet:r,profiles:o,preAuthenticate:n,isConnecting:k}=R({config:e,theme:d,chains:u,chain:c,publicJsonRpcUrl:m,onConnect:A,onConnectError:w}),{address:P,chainId:E}=oe(),{disconnect:L}=re(),z=se(),l=B(()=>{if(!(!P||!p))return s??P},[s,P,p]),{data:h}=ae({config:e.wagmi,chainId:c.id,address:l}),{data:T}=te(l?["BeraWagmiProvider_code",l,E]:null,([q,J,ge])=>z?.getCode({address:J}),{refreshInterval:6e4}),[O,_]=B(()=>T?T.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[T]),{data:I}=ce(),Q=B(()=>{try{return h?ne(h):void 0}catch{}},[h]),j=ie({name:Q});return N(M.Provider,{value:{preAuthenticate:n,flags:{disableEip5792:!!i,disable5792Upgrade:!!a},walletClient:I,onSmartAccountRejection:()=>{b?.()},isEmbeddedWalletsEnabled:v.embeddedWallets??!0,isConnecting:k,isConnected:!!l&&!!I,DebugConnectButton(){return null},account:p&&E&&l?{connectionId:g,chainId:E,connectorName:y,isEmbeddedWallet:r,profiles:o,wallet:{address:l,ensName:h?.replace(".bera",".\u{1F43B}\u26D3\uFE0F")??null,ensAvatar:j.data??null,has7702Authorization:_,isContract:O}}:void 0,connect:f,openConnectModal(){throw new Error("openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context/full instead.")},disconnect:()=>{L(),W()},defaultChainId:c.id},children:N(S,{address:l,defaultChainId:c.id,children:t})})}import{jsx as C}from"react/jsx-runtime";var fe=new de;function ze({transports:t,defaultChain:e,chains:i,thirdweb:a,...s}){let d=le(()=>x({thirdweb:a,transports:t,defaultChain:e,chains:i}),[e,a,t,i]);return C(pe,{children:C(me,{config:d.wagmi,reconnectOnMount:!1,children:C(ue,{client:fe,children:C(D,{...s,thirdweb:a,chains:i,defaultChain:e,config:d})})})})}export{ze as WagmiProvider};
|
|
File without changes
|