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