@berachain/wagmi 0.4.0 → 0.4.2

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.
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
- import { Profile, SingleStepAuthArgsType, Wallet } from 'thirdweb/wallets';
2
+ import { SingleStepAuthArgsType, MultiStepAuthArgsType, Profile, Wallet } from 'thirdweb/wallets';
3
3
  import { Address, Chain } from 'viem';
4
4
  import { UseWalletClientReturnType } from 'wagmi';
5
5
  import { getConfig, ThirdwebConfig } from './config/index.js';
@@ -61,8 +61,20 @@ interface BeraWagmiApi {
61
61
  openConnectModal(): Promise<void> | void;
62
62
  /**
63
63
  * Connects a wallet using a specific strategy.
64
+ * For email/phone use MultiStepAuthArgsType (requires preAuthenticate first).
64
65
  */
65
- connect(args: SingleStepAuthArgsType): Promise<Wallet | null> | undefined;
66
+ connect(args: SingleStepAuthArgsType | MultiStepAuthArgsType): Promise<Wallet | null> | undefined;
67
+ /**
68
+ * Sends an OTP to the user's email or phone number.
69
+ * Call this before connect() when using email or phone strategy.
70
+ */
71
+ preAuthenticate(args: {
72
+ strategy: "email";
73
+ email: string;
74
+ } | {
75
+ strategy: "phone";
76
+ phoneNumber: string;
77
+ }): Promise<void>;
66
78
  disconnect(): void;
67
79
  /**
68
80
  * A callback that is called when a smart account upgrade is rejected.
@@ -76,6 +88,12 @@ declare enum ChainId {
76
88
  MAINNET = 80094,
77
89
  BEPOLIA = 80069
78
90
  }
91
+ type ConnectEvent = {
92
+ type: "connect";
93
+ data: SingleStepAuthArgsType | MultiStepAuthArgsType;
94
+ } | {
95
+ type: "connect_modal";
96
+ };
79
97
  interface IBeraWagmiProviderProps extends PropsWithChildren {
80
98
  config: ReturnType<typeof getConfig>;
81
99
  theme?: "dark" | "light" | "auto";
@@ -94,12 +112,8 @@ interface IBeraWagmiProviderProps extends PropsWithChildren {
94
112
  accountOverride?: Address;
95
113
  };
96
114
  onSmartAccountRejection?: () => void;
97
- /**
98
- * Event triggered when a wallet is connected manually.
99
- *
100
- * This is not triggered when a wallet connect automatically after a refresh.
101
- */
102
- onConnectedWallet?: () => void;
115
+ onConnect?: (event: ConnectEvent) => void;
116
+ onConnectError?: (error: Error) => void;
103
117
  chains?: Chain[];
104
118
  defaultChain: Chain;
105
119
  thirdweb: ThirdwebConfig;
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
- import { Profile, SingleStepAuthArgsType, Wallet } from 'thirdweb/wallets';
2
+ import { SingleStepAuthArgsType, MultiStepAuthArgsType, Profile, Wallet } from 'thirdweb/wallets';
3
3
  import { Address, Chain } from 'viem';
4
4
  import { UseWalletClientReturnType } from 'wagmi';
5
5
  import { getConfig, ThirdwebConfig } from './config/index.cjs';
@@ -61,8 +61,20 @@ interface BeraWagmiApi {
61
61
  openConnectModal(): Promise<void> | void;
62
62
  /**
63
63
  * Connects a wallet using a specific strategy.
64
+ * For email/phone use MultiStepAuthArgsType (requires preAuthenticate first).
64
65
  */
65
- connect(args: SingleStepAuthArgsType): Promise<Wallet | null> | undefined;
66
+ connect(args: SingleStepAuthArgsType | MultiStepAuthArgsType): Promise<Wallet | null> | undefined;
67
+ /**
68
+ * Sends an OTP to the user's email or phone number.
69
+ * Call this before connect() when using email or phone strategy.
70
+ */
71
+ preAuthenticate(args: {
72
+ strategy: "email";
73
+ email: string;
74
+ } | {
75
+ strategy: "phone";
76
+ phoneNumber: string;
77
+ }): Promise<void>;
66
78
  disconnect(): void;
67
79
  /**
68
80
  * A callback that is called when a smart account upgrade is rejected.
@@ -76,6 +88,12 @@ declare enum ChainId {
76
88
  MAINNET = 80094,
77
89
  BEPOLIA = 80069
78
90
  }
91
+ type ConnectEvent = {
92
+ type: "connect";
93
+ data: SingleStepAuthArgsType | MultiStepAuthArgsType;
94
+ } | {
95
+ type: "connect_modal";
96
+ };
79
97
  interface IBeraWagmiProviderProps extends PropsWithChildren {
80
98
  config: ReturnType<typeof getConfig>;
81
99
  theme?: "dark" | "light" | "auto";
@@ -94,12 +112,8 @@ interface IBeraWagmiProviderProps extends PropsWithChildren {
94
112
  accountOverride?: Address;
95
113
  };
96
114
  onSmartAccountRejection?: () => void;
97
- /**
98
- * Event triggered when a wallet is connected manually.
99
- *
100
- * This is not triggered when a wallet connect automatically after a refresh.
101
- */
102
- onConnectedWallet?: () => void;
115
+ onConnect?: (event: ConnectEvent) => void;
116
+ onConnectError?: (error: Error) => void;
103
117
  chains?: Chain[];
104
118
  defaultChain: Chain;
105
119
  thirdweb: ThirdwebConfig;
@@ -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 _wagmi = require('wagmi');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var U=_react.createContext.call(void 0, void 0);function R({children:e,address:n,defaultChainId:r}){return _jsxruntime.jsx.call(void 0, U.Provider,{value:{address:n,defaultChainId:r},children:e})}function M(){let e=_react.useContext.call(void 0, U);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');function k({config:e,theme:n,chains:r=[],chain:t,onConnect:c,onConnectError:g,publicJsonRpcUrl:h=t.rpcUrls.default.http[0]}){let{connectors:y,connect:d}=_wagmi.useConnect.call(void 0, ),l=_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([l, '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};d({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([l, '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(){l&&W(l)},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, q);if(!e)throw new Error("BeraWagmiContext not found");return e}var q=_react.createContext.call(void 0, void 0);function Fe({children:e,config:n,flags:{disableEip5792:r,disable5792Upgrade:t,accountOverride:c}={},theme:g,onSmartAccountRejection:h,chains:y=[],defaultChain:d,thirdweb:l,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}=k({config:n,theme:g,chains:y,chain:d,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}),{address:x,chainId:I}=_wagmi.useAccount.call(void 0, ),{disconnect:J}=_wagmi.useDisconnect.call(void 0, ),K=_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:d.id,address:s}),{data:T}=_immutable2.default.call(void 0, s?["BeraWagmiProvider_code",s,I]:null,([Q,V,Pe])=>_optionalChain([K, 'optionalAccess', _11 => _11.getCode, 'call', _12 => _12({address:V})]),{refreshInterval:6e4}),[j,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, q.Provider,{value:{preAuthenticate:i,flags:{disableEip5792:!!r,disable5792Upgrade:!!t},walletClient:S,onSmartAccountRejection:()=>{_optionalChain([h, 'optionalCall', _13 => _13()])},isEmbeddedWalletsEnabled:_nullishCoalesce(l.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:j}}:void 0,connect:f,openConnectModal:async()=>{await v()},disconnect:()=>{J(),P()},defaultChainId:d.id},children:_jsxruntime.jsx.call(void 0, R,{address:s,defaultChainId:d.id,children:e})})}function Ae(){let{account:e,isConnected:n}=C();return{...e,isConnected:n}}function We({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 nt(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 = Ae; exports.c = We; exports.d = nt; 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 = Fe;
@@ -0,0 +1 @@
1
+ import{usePublicClient as ve}from"wagmi";import{useContext as Z}from"react";import{createContext as X}from"react";import{jsx as Y}from"react/jsx-runtime";var U=X(void 0);function R({children:e,address:n,defaultChainId:r}){return Y(U.Provider,{value:{address:n,defaultChainId:r},children:e})}function M(){let e=Z(U);if(!e)throw new Error("LightweightAccountContext not found");let{address:n,defaultChainId:r}=e;return{isConnected:!!n,address:n,defaultChainId:r}}import{useBlockNumber as rt,useChains as at,useConfig as st,useEnsAvatar as _,useEnsName as O,useSwitchChain as ct,useTransactionReceipt as dt}from"wagmi";import{createContext as ue,useContext as pe,useMemo as N}from"react";import me from"swr/immutable";import{normalize as fe}from"viem/ens";import{useAccount as Ce,useDisconnect as ge,usePublicClient as he,useWalletClient as be}from"wagmi";import{useMemo as D}from"react";import{defineChain as L}from"thirdweb";import{ConnectButton as $,useActiveAccount as ee,useActiveWallet as te,useAutoConnect as ne,useProfiles as oe,useConnect as ie,useConnectModal as re,useDisconnect as ae,useWalletInfo as se}from"thirdweb/react";import{preAuthenticate as ce}from"thirdweb/wallets/in-app";import{useConnect as de}from"wagmi";import{jsx as le}from"react/jsx-runtime";function k({config:e,theme:n,chains:r=[],chain:t,onConnect:c,onConnectError:g,publicJsonRpcUrl:h=t.rpcUrls.default.http[0]}){let{connectors:y,connect:d}=de(),l=te(),b=ee(),{disconnect:W}=ae(),{data:A}=se(l?.id),{connect:m}=ie(),{data:v}=oe({client:e.client}),f=D(()=>L({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};d({connector:i,chainId:t.id,...a})}else console.error("no tw connector found")}let{isLoading:P}=ne({...u,onConnect:p}),E=D(()=>"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).substring(2,15),[l?.id,b?.address]),{connect:B}=re();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=>L({id:i.id}))]});c?.({type:"connect_modal"}),await p(o)}catch(o){throw g?.(o),o}},disconnect(){l&&W(l)},isConnecting:P,connectionId:E,connectorName:A?.name??null,isEmbeddedWallet:A?.id==="inApp",wallet:b,profiles:v,preAuthenticate(o){return ce({...o,client:e.client})},DebugConnectButton(){return le($,{...u,connectModal:{size:"compact"},onConnect:o=>p(o)})}}}import{jsx as z}from"react/jsx-runtime";function C(){let e=pe(q);if(!e)throw new Error("BeraWagmiContext not found");return e}var q=ue(void 0);function Fe({children:e,config:n,flags:{disableEip5792:r,disable5792Upgrade:t,accountOverride:c}={},theme:g,onSmartAccountRejection:h,chains:y=[],defaultChain:d,thirdweb:l,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}=k({config:n,theme:g,chains:y,chain:d,publicJsonRpcUrl:b,onConnect:W,onConnectError:A}),{address:x,chainId:I}=Ce(),{disconnect:J}=ge(),K=he(),s=N(()=>{if(!(!x||!m))return c??x},[c,x,m]),{data:w}=O({config:n.wagmi,chainId:d.id,address:s}),{data:T}=me(s?["BeraWagmiProvider_code",s,I]:null,([Q,V,Pe])=>K?.getCode({address:V}),{refreshInterval:6e4}),[j,F]=N(()=>T?T.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[T]),{data:S}=be(),G=N(()=>{try{return w?fe(w):void 0}catch{}},[w]),H=_({name:G});return z(q.Provider,{value:{preAuthenticate:i,flags:{disableEip5792:!!r,disable5792Upgrade:!!t},walletClient:S,onSmartAccountRejection:()=>{h?.()},isEmbeddedWalletsEnabled:l.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:j}}:void 0,connect:f,openConnectModal:async()=>{await v()},disconnect:()=>{J(),P()},defaultChainId:d.id},children:z(R,{address:s,defaultChainId:d.id,children:e})})}function Ae(){let{account:e,isConnected:n}=C();return{...e,isConnected:n}}import{useMemo as we}from"react";import{useCapabilities as ye}from"wagmi";function We({chainId:e}){let{flags:n,account:r}=C(),{data:t}=ye({account:r?.wallet?.address,scopeKey:r?.connectionId,query:{retry:3},chainId:e});return{supportsAtomic:we(()=>n.disableEip5792||!t?!1:t?.atomic?.status==="supported"||!n.disable5792Upgrade&&t?.atomic?.status==="ready",[t,n.disableEip5792,n.disable5792Upgrade,e]),capabilities:t}}function nt(e){let{defaultChainId:n}=M(),{chainId:r,...t}=e??{};return ve({chainId:r??n,...t})}export{M as a,Ae as b,We as c,nt as d,rt as e,at as f,st as g,_ as h,O as i,ct as j,dt as k,C as l,Fe as m};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var _chunkPVMPBWIGcjs = require('../chunk-PVMPBWIG.cjs');var _chunkIPQBC7RQcjs = require('../chunk-IPQBC7RQ.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, _chunkIPQBC7RQcjs.m,{...f,thirdweb:o,chains:i,defaultChain:e,config:n})})})})}exports.WagmiProvider = B;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var _chunkPVMPBWIGcjs = require('../chunk-PVMPBWIG.cjs');var _chunkJNXJQLQCcjs = require('../chunk-JNXJQLQC.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, _chunkJNXJQLQCcjs.m,{...f,thirdweb:o,chains:i,defaultChain:e,config:n})})})})}exports.WagmiProvider = B;
@@ -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-0-HNcmGS.cjs';
3
+ import { I as IBeraWagmiProviderProps } from '../BeraWagmi-D_9r9lFE.cjs';
4
4
  import 'react';
5
5
  import 'thirdweb/wallets';
6
6
  import 'wagmi';
@@ -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-COCKRVoz.js';
3
+ import { I as IBeraWagmiProviderProps } from '../BeraWagmi-BYoBR8sq.js';
4
4
  import 'react';
5
5
  import 'thirdweb/wallets';
6
6
  import 'wagmi';
@@ -1 +1 @@
1
- "use client";import{a as m}from"../chunk-MZZ62TKM.mjs";import{m as a}from"../chunk-EAWOJX7K.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};
1
+ "use client";import{a as m}from"../chunk-MZZ62TKM.mjs";import{m as a}from"../chunk-UEV74GTG.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};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIPQBC7RQcjs = require('../chunk-IPQBC7RQ.cjs');exports.useBeraAccount = _chunkIPQBC7RQcjs.b; exports.useBeraWagmi = _chunkIPQBC7RQcjs.l; exports.useBeraWallet = _chunkIPQBC7RQcjs.a; exports.useBlockNumber = _chunkIPQBC7RQcjs.e; exports.useCapabilities = _chunkIPQBC7RQcjs.c; exports.useChains = _chunkIPQBC7RQcjs.f; exports.useConfig = _chunkIPQBC7RQcjs.g; exports.useEnsAvatar = _chunkIPQBC7RQcjs.h; exports.useEnsName = _chunkIPQBC7RQcjs.i; exports.usePublicClient = _chunkIPQBC7RQcjs.d; exports.useSwitchChain = _chunkIPQBC7RQcjs.j; exports.useTransactionReceipt = _chunkIPQBC7RQcjs.k;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJNXJQLQCcjs = require('../chunk-JNXJQLQC.cjs');exports.useBeraAccount = _chunkJNXJQLQCcjs.b; exports.useBeraWagmi = _chunkJNXJQLQCcjs.l; exports.useBeraWallet = _chunkJNXJQLQCcjs.a; exports.useBlockNumber = _chunkJNXJQLQCcjs.e; exports.useCapabilities = _chunkJNXJQLQCcjs.c; exports.useChains = _chunkJNXJQLQCcjs.f; exports.useConfig = _chunkJNXJQLQCcjs.g; exports.useEnsAvatar = _chunkJNXJQLQCcjs.h; exports.useEnsName = _chunkJNXJQLQCcjs.i; exports.usePublicClient = _chunkJNXJQLQCcjs.d; exports.useSwitchChain = _chunkJNXJQLQCcjs.j; exports.useTransactionReceipt = _chunkJNXJQLQCcjs.k;
@@ -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, C as ChainId } from '../BeraWagmi-0-HNcmGS.cjs';
4
- export { u as useBeraWagmi } from '../BeraWagmi-0-HNcmGS.cjs';
3
+ import { B as BeraWagmiApi, C as ChainId } from '../BeraWagmi-D_9r9lFE.cjs';
4
+ export { u as useBeraWagmi } from '../BeraWagmi-D_9r9lFE.cjs';
5
5
  import 'react';
6
6
  import 'thirdweb/wallets';
7
7
  import 'viem';
@@ -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, C as ChainId } from '../BeraWagmi-COCKRVoz.js';
4
- export { u as useBeraWagmi } from '../BeraWagmi-COCKRVoz.js';
3
+ import { B as BeraWagmiApi, C as ChainId } from '../BeraWagmi-BYoBR8sq.js';
4
+ export { u as useBeraWagmi } from '../BeraWagmi-BYoBR8sq.js';
5
5
  import 'react';
6
6
  import 'thirdweb/wallets';
7
7
  import 'viem';
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l}from"../chunk-EAWOJX7K.mjs";export{b as useBeraAccount,l as useBeraWagmi,a as useBeraWallet,e as useBlockNumber,c as useCapabilities,f as useChains,g as useConfig,h as useEnsAvatar,i as useEnsName,d as usePublicClient,j as useSwitchChain,k as useTransactionReceipt};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l}from"../chunk-UEV74GTG.mjs";export{b as useBeraAccount,l as useBeraWagmi,a as useBeraWallet,e as useBlockNumber,c as useCapabilities,f as useChains,g as useConfig,h as useEnsAvatar,i as useEnsName,d as usePublicClient,j as useSwitchChain,k as useTransactionReceipt};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@berachain/wagmi",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -43,16 +43,16 @@
43
43
  "dependencies": {
44
44
  "@thirdweb-dev/wagmi-adapter": "0.2.207",
45
45
  "@wagmi/core": "2.22.1",
46
- "swr": "2.3.3",
46
+ "swr": "2.4.1",
47
47
  "thirdweb": "5.119.0"
48
48
  },
49
49
  "devDependencies": {
50
+ "@berachain/config": "0.1.3",
50
51
  "@types/node": "24.1.0",
51
52
  "@types/react": "19.1.8",
52
53
  "tsup": "8.4.0",
53
54
  "viem": "2.45.0",
54
- "wagmi": "2.19.5",
55
- "@berachain/config": "0.1.0"
55
+ "wagmi": "2.19.5"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": "^19.1",
@@ -5,7 +5,12 @@ import {
5
5
  useMemo,
6
6
  } from "react";
7
7
  import useSWRImmutable from "swr/immutable";
8
- import type { Profile, SingleStepAuthArgsType, Wallet } from "thirdweb/wallets";
8
+ import type {
9
+ MultiStepAuthArgsType,
10
+ Profile,
11
+ SingleStepAuthArgsType,
12
+ Wallet,
13
+ } from "thirdweb/wallets";
9
14
  import type { Address, Chain } from "viem";
10
15
  import { normalize } from "viem/ens";
11
16
  import {
@@ -16,7 +21,7 @@ import {
16
21
  useWalletClient,
17
22
  } from "wagmi";
18
23
 
19
- import type { getConfig, ThirdwebConfig } from "~/config";
24
+ import type { getConfig, ThirdwebConfig } from "../config";
20
25
  import { useEnsAvatar, useEnsName } from "../hooks";
21
26
  import { LightweightAccountProvider } from "./LightweightAccountProvider";
22
27
  import { useThirdweb } from "./useThirdweb";
@@ -88,8 +93,20 @@ export interface BeraWagmiApi {
88
93
  openConnectModal(): Promise<void> | void;
89
94
  /**
90
95
  * Connects a wallet using a specific strategy.
96
+ * For email/phone use MultiStepAuthArgsType (requires preAuthenticate first).
91
97
  */
92
- connect(args: SingleStepAuthArgsType): Promise<Wallet | null> | undefined;
98
+ connect(
99
+ args: SingleStepAuthArgsType | MultiStepAuthArgsType,
100
+ ): Promise<Wallet | null> | undefined;
101
+ /**
102
+ * Sends an OTP to the user's email or phone number.
103
+ * Call this before connect() when using email or phone strategy.
104
+ */
105
+ preAuthenticate(
106
+ args:
107
+ | { strategy: "email"; email: string }
108
+ | { strategy: "phone"; phoneNumber: string },
109
+ ): Promise<void>;
93
110
  disconnect(): void;
94
111
  /**
95
112
  * A callback that is called when a smart account upgrade is rejected.
@@ -108,6 +125,10 @@ export enum ChainId {
108
125
  BEPOLIA = 80069,
109
126
  }
110
127
 
128
+ export type ConnectEvent =
129
+ | { type: "connect"; data: SingleStepAuthArgsType | MultiStepAuthArgsType }
130
+ | { type: "connect_modal" };
131
+
111
132
  export interface IBeraWagmiProviderProps extends PropsWithChildren {
112
133
  config: ReturnType<typeof getConfig>;
113
134
  theme?: "dark" | "light" | "auto";
@@ -126,12 +147,8 @@ export interface IBeraWagmiProviderProps extends PropsWithChildren {
126
147
  accountOverride?: Address;
127
148
  };
128
149
  onSmartAccountRejection?: () => void;
129
- /**
130
- * Event triggered when a wallet is connected manually.
131
- *
132
- * This is not triggered when a wallet connect automatically after a refresh.
133
- */
134
- onConnectedWallet?: () => void;
150
+ onConnect?: (event: ConnectEvent) => void;
151
+ onConnectError?: (error: Error) => void;
135
152
  chains?: Chain[];
136
153
  defaultChain: Chain;
137
154
  thirdweb: ThirdwebConfig;
@@ -148,6 +165,8 @@ export function BeraWagmiProvider({
148
165
  defaultChain,
149
166
  thirdweb,
150
167
  publicJsonRpcUrl,
168
+ onConnect,
169
+ onConnectError,
151
170
  }: IBeraWagmiProviderProps) {
152
171
  const {
153
172
  wallet,
@@ -159,6 +178,7 @@ export function BeraWagmiProvider({
159
178
  connectorName,
160
179
  isEmbeddedWallet,
161
180
  profiles,
181
+ preAuthenticate,
162
182
  isConnecting,
163
183
  } = useThirdweb({
164
184
  config,
@@ -166,6 +186,8 @@ export function BeraWagmiProvider({
166
186
  chains,
167
187
  chain: defaultChain,
168
188
  publicJsonRpcUrl,
189
+ onConnect,
190
+ onConnectError,
169
191
  });
170
192
 
171
193
  const { address: connectedAddress, chainId } = useAccount(); // wagmi
@@ -233,6 +255,7 @@ export function BeraWagmiProvider({
233
255
  return (
234
256
  <BeraWagmiContext.Provider
235
257
  value={{
258
+ preAuthenticate,
236
259
  flags: {
237
260
  disableEip5792: !!disableEip5792,
238
261
  disable5792Upgrade: !!disable5792Upgrade,
@@ -6,7 +6,7 @@ import { ThirdwebProvider } from "thirdweb/react";
6
6
  import type { Chain, Transport } from "viem";
7
7
  import { WagmiProvider as WagmiProviderBase } from "wagmi";
8
8
 
9
- import { getConfig } from "~/config/defaultWagmiConfig";
9
+ import { getConfig } from "../config/defaultWagmiConfig";
10
10
  import { BeraWagmiProvider, type IBeraWagmiProviderProps } from "./BeraWagmi";
11
11
 
12
12
  type WagmiProviderProps = Omit<
@@ -18,21 +18,24 @@ import type {
18
18
  Profile,
19
19
  Wallet,
20
20
  } from "thirdweb/wallets";
21
+ import { preAuthenticate } from "thirdweb/wallets/in-app";
21
22
  import type { Chain } from "viem";
22
23
  import { useConnect } from "wagmi";
23
24
 
24
- import type { getConfig, InAppWallet } from "~/config";
25
- import type { BeraWagmiApi } from "./BeraWagmi";
25
+ import type { getConfig, InAppWallet } from "../config";
26
+ import type { BeraWagmiApi, ConnectEvent } from "./BeraWagmi";
26
27
 
27
28
  export function useThirdweb({
28
29
  config,
29
30
  theme,
30
31
  chains = [],
31
32
  chain,
32
- onConnectedWallet,
33
+ onConnect,
34
+ onConnectError,
33
35
  publicJsonRpcUrl = chain.rpcUrls.default.http[0],
34
36
  }: {
35
- onConnectedWallet?: () => void;
37
+ onConnect?: (event: ConnectEvent) => void;
38
+ onConnectError?: (error: Error) => void;
36
39
  config: ReturnType<typeof getConfig>;
37
40
  theme: "light" | "dark" | "auto" | undefined;
38
41
  chains?: Chain[];
@@ -45,6 +48,7 @@ export function useThirdweb({
45
48
  | "disconnect"
46
49
  | "isConnecting"
47
50
  | "DebugConnectButton"
51
+ | "preAuthenticate"
48
52
  > & {
49
53
  connectionId: string;
50
54
  connectorName: string | null;
@@ -117,7 +121,11 @@ export function useThirdweb({
117
121
  });
118
122
 
119
123
  const connectionId = useMemo(() => {
120
- return crypto.randomUUID();
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);
121
129
  }, [activeWallet?.id, activeAccount?.address]);
122
130
 
123
131
  const { connect: twConnectModal } = useTwConnectModal();
@@ -146,34 +154,43 @@ export function useThirdweb({
146
154
  ...connectOptions,
147
155
  ...args,
148
156
  })
149
- .then(() => {
150
- onConnectedWallet?.();
151
- syncConnectedWallet(wallet);
157
+ .then(async () => {
158
+ onConnect?.({ type: "connect", data: args });
159
+ await syncConnectedWallet(wallet);
152
160
  return wallet;
161
+ })
162
+ .catch((e) => {
163
+ onConnectError?.(e);
164
+ throw e;
153
165
  });
154
166
  });
155
167
  },
156
168
  async openConnectModal() {
157
- const wallet = await twConnectModal({
158
- ...connectOptions,
159
- wallets: config.wallets,
160
- theme: theme === "auto" ? undefined : theme,
161
- size: "compact",
162
- chains: [
163
- thirdwebChain,
164
- ...chains
165
- // avoid duplicates
166
- .filter((c) => c.id !== thirdwebChain.id)
167
- .map((c) =>
168
- defineChain({
169
- id: c.id,
170
- }),
171
- ),
172
- ],
173
- }); // opens the connect modal
174
-
175
- onConnectedWallet?.();
176
- await syncConnectedWallet(wallet);
169
+ try {
170
+ const wallet = await twConnectModal({
171
+ ...connectOptions,
172
+ wallets: config.wallets,
173
+ theme: theme === "auto" ? undefined : theme,
174
+ size: "compact",
175
+ chains: [
176
+ thirdwebChain,
177
+ ...chains
178
+ // avoid duplicates
179
+ .filter((c) => c.id !== thirdwebChain.id)
180
+ .map((c) =>
181
+ defineChain({
182
+ id: c.id,
183
+ }),
184
+ ),
185
+ ],
186
+ }); // opens the connect modal
187
+
188
+ onConnect?.({ type: "connect_modal" });
189
+ await syncConnectedWallet(wallet);
190
+ } catch (e) {
191
+ onConnectError?.(e as Error);
192
+ throw e;
193
+ }
177
194
  },
178
195
  disconnect() {
179
196
  if (activeWallet) {
@@ -186,6 +203,9 @@ export function useThirdweb({
186
203
  isEmbeddedWallet: walletInfo?.id === "inApp",
187
204
  wallet: activeAccount,
188
205
  profiles,
206
+ preAuthenticate(args) {
207
+ return preAuthenticate({ ...args, client: config.client });
208
+ },
189
209
  DebugConnectButton() {
190
210
  return (
191
211
  <ConnectButton
@@ -1,4 +1,4 @@
1
- import { type BeraWagmiApi, useBeraWagmi } from "~/context/BeraWagmi";
1
+ import { type BeraWagmiApi, useBeraWagmi } from "../context/BeraWagmi";
2
2
 
3
3
  export function useBeraAccount(): Partial<
4
4
  NonNullable<BeraWagmiApi["account"]>
@@ -1,6 +1,6 @@
1
1
  import { useContext } from "react";
2
2
 
3
- import { LightweightAccountContext } from "~/context/LightweightAccountProvider";
3
+ import { LightweightAccountContext } from "../context/LightweightAccountProvider";
4
4
 
5
5
  export function useBeraWallet() {
6
6
  const context = useContext(LightweightAccountContext);
@@ -1 +0,0 @@
1
- import{usePublicClient as we}from"wagmi";import{useContext as V}from"react";import{createContext as H}from"react";import{jsx as Q}from"react/jsx-runtime";var I=H(void 0);function N({children:e,address:n,defaultChainId:i}){return Q(I.Provider,{value:{address:n,defaultChainId:i},children:e})}function E(){let e=V(I);if(!e)throw new Error("LightweightAccountContext not found");let{address:n,defaultChainId:i}=e;return{isConnected:!!n,address:n,defaultChainId:i}}import{useBlockNumber as et,useChains as tt,useConfig as nt,useEnsAvatar as k,useEnsName as z,useSwitchChain as ot,useTransactionReceipt as it}from"wagmi";import{createContext as se,useContext as ce,useMemo as T}from"react";import de from"swr/immutable";import{normalize as le}from"viem/ens";import{useAccount as ue,useDisconnect as pe,usePublicClient as me,useWalletClient as fe}from"wagmi";import{useMemo as R}from"react";import{defineChain as M}from"thirdweb";import{ConnectButton as X,useActiveAccount as Y,useActiveWallet as Z,useAutoConnect as $,useProfiles as ee,useConnect as te,useConnectModal as ne,useDisconnect as oe,useWalletInfo as ie}from"thirdweb/react";import{useConnect as re}from"wagmi";import{jsx as ae}from"react/jsx-runtime";function L({config:e,theme:n,chains:i=[],chain:t,onConnectedWallet:d,publicJsonRpcUrl:C=t.rpcUrls.default.http[0]}){let{connectors:b,connect:w}=re(),r=Z(),g=Y(),{disconnect:A}=oe(),{data:l}=ie(r?.id),{connect:W}=te(),{data:y}=ee({client:e.client}),m=R(()=>M({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:[C]}}}),[C,t]),u={client:e.client,chain:m,wallets:e.wallets};async function p(a){let o=b.find(s=>s.id==="in-app-wallet");if(o){let s={withCapabilities:!0,wallet:a};w({connector:o,chainId:t.id,...s})}else console.error("no tw connector found")}let{isLoading:P}=$({...u,onConnect:p}),v=R(()=>crypto.randomUUID(),[r?.id,g?.address]),{connect:B}=ne();return{connect(a){if(!e.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return W(async()=>{let o=e.wallets.find(s=>s.id==="inApp");if(!o)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return o.connect({...u,...a}).then(()=>(d?.(),p(o),o))})},async openConnectModal(){let a=await B({...u,wallets:e.wallets,theme:n==="auto"?void 0:n,size:"compact",chains:[m,...i.filter(o=>o.id!==m.id).map(o=>M({id:o.id}))]});d?.(),await p(a)},disconnect(){r&&A(r)},isConnecting:P,connectionId:v,connectorName:l?.name??null,isEmbeddedWallet:l?.id==="inApp",wallet:g,profiles:y,DebugConnectButton(){return ae(X,{...u,connectModal:{size:"compact"},onConnect:a=>p(a)})}}}import{jsx as S}from"react/jsx-runtime";function f(){let e=ce(D);if(!e)throw new Error("BeraWagmiContext not found");return e}var D=se(void 0);function _e({children:e,config:n,flags:{disableEip5792:i,disable5792Upgrade:t,accountOverride:d}={},theme:C,onSmartAccountRejection:b,chains:w=[],defaultChain:r,thirdweb:g,publicJsonRpcUrl:A}){let{wallet:l,openConnectModal:W,connect:y,DebugConnectButton:m,connectionId:u,disconnect:p,connectorName:P,isEmbeddedWallet:v,profiles:B,isConnecting:a}=L({config:n,theme:C,chains:w,chain:r,publicJsonRpcUrl:A}),{address:o,chainId:s}=ue(),{disconnect:O}=pe(),_=me(),c=T(()=>{if(!(!o||!l))return d??o},[d,o,l]),{data:h}=z({config:n.wagmi,chainId:r.id,address:c}),{data:x}=de(c?["BeraWagmiProvider_code",c,s]:null,([F,G,Ae])=>_?.getCode({address:G}),{refreshInterval:6e4}),[q,J]=T(()=>x?x.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[x]),{data:U}=fe(),K=T(()=>{try{return h?le(h):void 0}catch{}},[h]),j=k({name:K});return S(D.Provider,{value:{flags:{disableEip5792:!!i,disable5792Upgrade:!!t},walletClient:U,onSmartAccountRejection:()=>{b?.()},isEmbeddedWalletsEnabled:g.embeddedWallets??!0,isConnecting:a,isConnected:!!c&&!!U,DebugConnectButton:m,account:l&&s&&c?{connectionId:u,chainId:s,connectorName:P,isEmbeddedWallet:v,profiles:B,wallet:{address:c,ensName:h?.replace(".bera",".\u{1F43B}\u26D3\uFE0F")??null,ensAvatar:j.data??null,has7702Authorization:J,isContract:q}}:void 0,connect:y,openConnectModal:async()=>{await W()},disconnect:()=>{O(),p()},defaultChainId:r.id},children:S(N,{address:c,defaultChainId:r.id,children:e})})}function Ce(){let{account:e,isConnected:n}=f();return{...e,isConnected:n}}import{useMemo as ge}from"react";import{useCapabilities as he}from"wagmi";function be({chainId:e}){let{flags:n,account:i}=f(),{data:t}=he({account:i?.wallet?.address,scopeKey:i?.connectionId,query:{retry:3},chainId:e});return{supportsAtomic:ge(()=>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}=E(),{chainId:i,...t}=e??{};return we({chainId:i??n,...t})}export{E as a,Ce as b,be as c,Ye as d,et as e,tt as f,nt as g,k as h,z as i,ot as j,it as k,f as l,_e 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; }var _wagmi = require('wagmi');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var I=_react.createContext.call(void 0, void 0);function N({children:e,address:n,defaultChainId:i}){return _jsxruntime.jsx.call(void 0, I.Provider,{value:{address:n,defaultChainId:i},children:e})}function E(){let e=_react.useContext.call(void 0, I);if(!e)throw new Error("LightweightAccountContext not found");let{address:n,defaultChainId:i}=e;return{isConnected:!!n,address:n,defaultChainId:i}}var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _ens = require('viem/ens');var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');function L({config:e,theme:n,chains:i=[],chain:t,onConnectedWallet:d,publicJsonRpcUrl:C=t.rpcUrls.default.http[0]}){let{connectors:b,connect:w}=_wagmi.useConnect.call(void 0, ),r=_react3.useActiveWallet.call(void 0, ),g=_react3.useActiveAccount.call(void 0, ),{disconnect:A}=_react3.useDisconnect.call(void 0, ),{data:l}=_react3.useWalletInfo.call(void 0, _optionalChain([r, 'optionalAccess', _2 => _2.id])),{connect:W}=_react3.useConnect.call(void 0, ),{data:y}=_react3.useProfiles.call(void 0, {client:e.client}),m=_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:[C]}}}),[C,t]),u={client:e.client,chain:m,wallets:e.wallets};async function p(a){let o=b.find(s=>s.id==="in-app-wallet");if(o){let s={withCapabilities:!0,wallet:a};w({connector:o,chainId:t.id,...s})}else console.error("no tw connector found")}let{isLoading:P}=_react3.useAutoConnect.call(void 0, {...u,onConnect:p}),v=_react.useMemo.call(void 0, ()=>crypto.randomUUID(),[_optionalChain([r, 'optionalAccess', _3 => _3.id]),_optionalChain([g, 'optionalAccess', _4 => _4.address])]),{connect:B}=_react3.useConnectModal.call(void 0, );return{connect(a){if(!e.hasEmbeddedWallets){console.error("useBeraWagmi.connect: this function is not available if embedded wallets are disabled");return}return W(async()=>{let o=e.wallets.find(s=>s.id==="inApp");if(!o)throw console.error("useBeraWagmi.connect: no inApp wallet found"),new Error("no inApp wallet found");return o.connect({...u,...a}).then(()=>(_optionalChain([d, 'optionalCall', _5 => _5()]),p(o),o))})},async openConnectModal(){let a=await B({...u,wallets:e.wallets,theme:n==="auto"?void 0:n,size:"compact",chains:[m,...i.filter(o=>o.id!==m.id).map(o=>_thirdweb.defineChain.call(void 0, {id:o.id}))]});_optionalChain([d, 'optionalCall', _6 => _6()]),await p(a)},disconnect(){r&&A(r)},isConnecting:P,connectionId:v,connectorName:_nullishCoalesce(_optionalChain([l, 'optionalAccess', _7 => _7.name]), () => (null)),isEmbeddedWallet:_optionalChain([l, 'optionalAccess', _8 => _8.id])==="inApp",wallet:g,profiles:y,DebugConnectButton(){return _jsxruntime.jsx.call(void 0, _react3.ConnectButton,{...u,connectModal:{size:"compact"},onConnect:a=>p(a)})}}}function f(){let e=_react.useContext.call(void 0, D);if(!e)throw new Error("BeraWagmiContext not found");return e}var D=_react.createContext.call(void 0, void 0);function _e({children:e,config:n,flags:{disableEip5792:i,disable5792Upgrade:t,accountOverride:d}={},theme:C,onSmartAccountRejection:b,chains:w=[],defaultChain:r,thirdweb:g,publicJsonRpcUrl:A}){let{wallet:l,openConnectModal:W,connect:y,DebugConnectButton:m,connectionId:u,disconnect:p,connectorName:P,isEmbeddedWallet:v,profiles:B,isConnecting:a}=L({config:n,theme:C,chains:w,chain:r,publicJsonRpcUrl:A}),{address:o,chainId:s}=_wagmi.useAccount.call(void 0, ),{disconnect:O}=_wagmi.useDisconnect.call(void 0, ),_=_wagmi.usePublicClient.call(void 0, ),c=_react.useMemo.call(void 0, ()=>{if(!(!o||!l))return _nullishCoalesce(d, () => (o))},[d,o,l]),{data:h}=_wagmi.useEnsName.call(void 0, {config:n.wagmi,chainId:r.id,address:c}),{data:x}=_immutable2.default.call(void 0, c?["BeraWagmiProvider_code",c,s]:null,([F,G,Ae])=>_optionalChain([_, 'optionalAccess', _9 => _9.getCode, 'call', _10 => _10({address:G})]),{refreshInterval:6e4}),[q,J]=_react.useMemo.call(void 0, ()=>x?x.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[x]),{data:U}=_wagmi.useWalletClient.call(void 0, ),K=_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:K});return _jsxruntime.jsx.call(void 0, D.Provider,{value:{flags:{disableEip5792:!!i,disable5792Upgrade:!!t},walletClient:U,onSmartAccountRejection:()=>{_optionalChain([b, 'optionalCall', _11 => _11()])},isEmbeddedWalletsEnabled:_nullishCoalesce(g.embeddedWallets, () => (!0)),isConnecting:a,isConnected:!!c&&!!U,DebugConnectButton:m,account:l&&s&&c?{connectionId:u,chainId:s,connectorName:P,isEmbeddedWallet:v,profiles:B,wallet:{address:c,ensName:_nullishCoalesce(_optionalChain([h, 'optionalAccess', _12 => _12.replace, 'call', _13 => _13(".bera",".\u{1F43B}\u26D3\uFE0F")]), () => (null)),ensAvatar:_nullishCoalesce(j.data, () => (null)),has7702Authorization:J,isContract:q}}:void 0,connect:y,openConnectModal:async()=>{await W()},disconnect:()=>{O(),p()},defaultChainId:r.id},children:_jsxruntime.jsx.call(void 0, N,{address:c,defaultChainId:r.id,children:e})})}function Ce(){let{account:e,isConnected:n}=f();return{...e,isConnected:n}}function be({chainId:e}){let{flags:n,account:i}=f(),{data:t}=_wagmi.useCapabilities.call(void 0, {account:_optionalChain([i, 'optionalAccess', _14 => _14.wallet, 'optionalAccess', _15 => _15.address]),scopeKey:_optionalChain([i, 'optionalAccess', _16 => _16.connectionId]),query:{retry:3},chainId:e});return{supportsAtomic:_react.useMemo.call(void 0, ()=>n.disableEip5792||!t?!1:_optionalChain([t, 'optionalAccess', _17 => _17.atomic, 'optionalAccess', _18 => _18.status])==="supported"||!n.disable5792Upgrade&&_optionalChain([t, 'optionalAccess', _19 => _19.atomic, 'optionalAccess', _20 => _20.status])==="ready",[t,n.disableEip5792,n.disable5792Upgrade,e]),capabilities:t}}function Ye(e){let{defaultChainId:n}=E(),{chainId:i,...t}=_nullishCoalesce(e, () => ({}));return _wagmi.usePublicClient.call(void 0, {chainId:_nullishCoalesce(i, () => (n)),...t})}exports.a = E; exports.b = Ce; exports.c = be; 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 = f; exports.m = _e;