@berachain/wagmi 0.1.0 → 0.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BeraWagmi-B79qATYX.d.cts → BeraWagmi-BfIT9GJt.d.cts} +5 -2
- package/dist/{BeraWagmi-B79qATYX.d.ts → BeraWagmi-BfIT9GJt.d.ts} +5 -2
- package/dist/chunk-5Q3SXXEY.mjs +1 -0
- package/dist/chunk-DYMS6OAP.cjs +1 -0
- package/dist/chunk-S2KJM5XB.cjs +1 -0
- package/dist/chunk-TZTB265J.mjs +1 -0
- package/dist/config/index.cjs +1 -1
- package/dist/config/index.d.cts +7 -9
- package/dist/config/index.d.ts +7 -9
- package/dist/config/index.mjs +1 -1
- package/dist/context/index.cjs +1 -1
- package/dist/context/index.d.cts +5 -2
- package/dist/context/index.d.ts +5 -2
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +3 -2
- package/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.mjs +1 -1
- package/package.json +6 -5
- package/src/config/defaultWagmiConfig.ts +183 -0
- package/src/config/index.ts +1 -0
- package/src/context/BeraWagmi.tsx +348 -0
- package/src/context/LightweightAccountProvider.tsx +25 -0
- package/src/context/WagmiProvider.tsx +42 -0
- package/src/context/index.ts +3 -0
- package/src/context/types.ts +16 -0
- package/src/context/useThirdweb.tsx +147 -0
- package/src/core/index.ts +1 -0
- package/src/hooks/index.ts +28 -0
- package/src/hooks/useBeraAccounts.ts +8 -0
- package/src/hooks/useBeraWallet.ts +18 -0
- package/dist/chunk-44WGYPR4.cjs +0 -1
- package/dist/chunk-5IUBG6AE.mjs +0 -1
- package/dist/chunk-G47GYZCF.mjs +0 -1
- package/dist/chunk-GVIEHLWT.cjs +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ThirdwebClient } from 'thirdweb';
|
|
2
3
|
import { Address, GetCapabilitiesReturnType, Chain } from 'viem';
|
|
3
|
-
import { UseWalletClientReturnType } from 'wagmi';
|
|
4
|
+
import { Config, UseWalletClientReturnType } from 'wagmi';
|
|
4
5
|
import { EdgeConfigSchema } from '@berachain/config/internal/edge-config';
|
|
5
6
|
|
|
6
7
|
declare function useBeraWagmi(): BeraWagmiApi;
|
|
@@ -23,7 +24,7 @@ interface BeraWagmiApi {
|
|
|
23
24
|
isEmbeddedWallet: boolean;
|
|
24
25
|
connectorName: string | null;
|
|
25
26
|
flags: {
|
|
26
|
-
|
|
27
|
+
getSupportsAtomic: (chainId: number) => boolean;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* Wallet provider capabilities for the current account.
|
|
@@ -77,6 +78,8 @@ interface BeraWagmiApi {
|
|
|
77
78
|
externalChainList: Chain[];
|
|
78
79
|
}
|
|
79
80
|
interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
81
|
+
thirdwebClient: ThirdwebClient;
|
|
82
|
+
wagmi: Config;
|
|
80
83
|
theme?: "dark" | "light" | "auto";
|
|
81
84
|
isEmbeddedWalletsEnabled: boolean;
|
|
82
85
|
disableEip5792: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ThirdwebClient } from 'thirdweb';
|
|
2
3
|
import { Address, GetCapabilitiesReturnType, Chain } from 'viem';
|
|
3
|
-
import { UseWalletClientReturnType } from 'wagmi';
|
|
4
|
+
import { Config, UseWalletClientReturnType } from 'wagmi';
|
|
4
5
|
import { EdgeConfigSchema } from '@berachain/config/internal/edge-config';
|
|
5
6
|
|
|
6
7
|
declare function useBeraWagmi(): BeraWagmiApi;
|
|
@@ -23,7 +24,7 @@ interface BeraWagmiApi {
|
|
|
23
24
|
isEmbeddedWallet: boolean;
|
|
24
25
|
connectorName: string | null;
|
|
25
26
|
flags: {
|
|
26
|
-
|
|
27
|
+
getSupportsAtomic: (chainId: number) => boolean;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* Wallet provider capabilities for the current account.
|
|
@@ -77,6 +78,8 @@ interface BeraWagmiApi {
|
|
|
77
78
|
externalChainList: Chain[];
|
|
78
79
|
}
|
|
79
80
|
interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
81
|
+
thirdwebClient: ThirdwebClient;
|
|
82
|
+
wagmi: Config;
|
|
80
83
|
theme?: "dark" | "light" | "auto";
|
|
81
84
|
isEmbeddedWalletsEnabled: boolean;
|
|
82
85
|
disableEip5792: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-TZTB265J.mjs";import{usePublicClient as ke}from"wagmi";import{defaultChainId as De}from"@berachain/config/internal";import{useBlockNumber as wt,useChains as At,useConfig as Wt,useEnsAvatar as D,useEnsName as z,useSwitchChain as yt,useTransactionReceipt as vt}from"wagmi";import{createContext as ue,useCallback as me,useContext as pe,useMemo as W}from"react";import fe from"swr/immutable";import{arbitrum as Ce,avalanche as he,base as be,bsc as ge,mainnet as we,optimism as Ae,polygon as We}from"viem/chains";import{normalize as ye}from"viem/ens";import{useAccount as ve,useCapabilities as xe,useDisconnect as Pe,usePublicClient as Be,useWalletClient as Ie}from"wagmi";import{defaultChainId as Te}from"@berachain/config/internal";import{isFlagEnabled as Ee}from"@berachain/config/internal/edge-config";import{createContext as Q}from"react";import{jsx as V}from"react/jsx-runtime";var T=Q(void 0);function L({children:e,address:t}){return V(T.Provider,{value:{address:t},children:e})}import{useMemo as X}from"react";import{defineChain as N}from"thirdweb";import{ConnectButton as Y,useActiveAccount as Z,useActiveWallet as $,useAutoConnect as ee,useConnectModal as te,useDisconnect as ne,useWalletInfo as oe}from"thirdweb/react";import{createWallet as A,getInstalledWallets as ie}from"thirdweb/wallets";import{useConnect as re}from"wagmi";import{defaultChainId as ae,publicJsonRpcUrl as se}from"@berachain/config/internal";import{jsx as de}from"react/jsx-runtime";var ce=ie(),le=[...ce,A("io.rabby"),A("io.metamask"),A("com.coinbase.wallet"),A("walletConnect")].filter((e,t,n)=>n.findIndex(i=>i.id===e.id)===t),U=N({id:o.id,blockExplorers:o.blockExplorers,blockTime:o.blockTime,ensTlds:o.ensTlds,testnet:o.testnet,contracts:o.contracts,nativeCurrency:o.nativeCurrency,name:o.name,rpcUrls:{default:{http:[se]}}});function S({isEmbeddedWalletsEnabled:e,theme:t,extenalChains:n,thirdwebClient:i}){let{connectors:f,connect:C}=re(),c=$(),u=Z(),{disconnect:y}=ne(),{data:m}=oe(c?.id),l={client:i,chain:U,wallets:e?void 0:le};async function r(a){let d=f.find(h=>h.id==="in-app-wallet");d?C({connector:d,chainId:ae,...{withCapabilities:!0,wallet:a}}):console.error("no tw connector found")}let{isLoading:v}=ee({...l,onConnect:r}),x=X(()=>crypto.randomUUID(),[c?.id,u?.address]),{connect:P}=te();return{async connect(){let a=await P({...l,theme:t==="auto"?void 0:t,chains:[U,...n.map(d=>N({id:d.id}))]});await r(a)},disconnect(){c&&y(c)},isConnecting:v,connectionId:x,connectorName:m?.name??null,isEmbeddedWallet:m?.id==="inApp",wallet:u,DebugConnectButton(){return de(Y,{...l,onConnect:a=>r(a)})}}}import{jsx as k}from"react/jsx-runtime";function E(){let e=pe(M);if(!e)throw new Error("BeraWagmiContext not found");return e}var M=ue(void 0),Re=[we,We,Ae,be,ge,he,Ce];function Le({externalChainList:e}){return Re.filter(t=>{let n=e?.find(i=>i.chainId===t.id);return!n||Ee(n.enabled)})}function at({children:e,thirdwebClient:t,wagmi:n,isEmbeddedWalletsEnabled:i,disableEip5792:f,disable5792Upgrade:C,theme:c,accountOverride:u,onSmartAccountRejection:y,edgeConfigChainList:m}){let l=W(()=>Le({externalChainList:m}),[m]),{wallet:r,connect:v,DebugConnectButton:x,connectionId:P,disconnect:a,connectorName:d,isEmbeddedWallet:h,isConnecting:_}=S({thirdwebClient:t,isEmbeddedWalletsEnabled:i,theme:c,extenalChains:l}),{address:b,chainId:B}=ve(),{disconnect:O}=Pe(),G=Be(),s=W(()=>{if(!(!b||!r))return u??b},[u,b,r]),{data:p}=xe({account:b,scopeKey:P,query:{retry:3}}),q=me(w=>f||!p?!1:p?.[w]?.atomic?.status==="supported"||!C&&p?.[w]?.atomic?.status==="ready",[p,f,C]),{data:g}=z({config:n,chainId:Te,address:s}),{data:I}=fe(s?["BeraWagmiProvider_code",s,B]:null,([w,H,ze])=>G?.getCode({address:H}),{refreshInterval:6e4}),[F,J]=W(()=>I?I.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[I]),{data:R}=Ie(),K=W(()=>{try{return g?ye(g):void 0}catch{}},[g]),j=D({name:K});return k(M.Provider,{value:{walletClient:R,onSmartAccountRejection:()=>{y?.()},isEmbeddedWalletsEnabled:i,isConnecting:_,isConnected:!!s&&!!R,DebugConnectButton:x,account:r&&B&&s?{chainId:B,connectorName:d,isEmbeddedWallet:h,capabilities:p,flags:{getSupportsAtomic:q},wallet:{address:s,ensName:g??null,ensAvatar:j.data??null,has7702Authorization:J,isContract:F}}:void 0,connectWallet:async()=>{console.log("connectWallet.called"),await v()},disconnect:()=>{O(),a()},externalChainList:l},children:k(L,{address:s,children:e})})}function Ue(){let{account:e,isConnected:t}=E();return{...e,isConnected:t}}import{useContext as Ne}from"react";function Se(){let e=Ne(T);if(!e)throw new Error("LightweightAccountContext not found");let{address:t}=e;return{isConnected:!!t,address:t}}function ht(e){let{chainId:t,...n}=e??{};return ke({chainId:t??De,...n})}export{Ue as a,Se as b,ht as c,wt as d,At as e,Wt as f,D as g,z as h,yt as i,vt as j,E as k,at as l};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _wagmiadapter = require('@thirdweb-dev/wagmi-adapter');var _thirdweb = require('thirdweb');var _chains = require('viem/chains');var _wagmi = require('wagmi');var _internal = require('@berachain/config/internal');var m=_internal.chainId===_chains.berachain.id?_chains.berachain:_chains.berachainBepolia,r= exports.b ={chain:m},A=!!_optionalChain([m, 'access', _ => _.contracts, 'optionalAccess', _2 => _2.multicall3]),u= exports.c =[_chains.mainnet,_chains.polygon,_chains.optimism,_chains.base,_chains.bsc,_chains.arbitrum,_chains.avalanche],E= exports.d =[...u,_chains.berachain,_chains.berachainBepolia].reduce((i,t)=>(i[t.id]=t.name,i),{}),M={[_chains.mainnet.id]:["https://1.rpc.thirdweb.com/","https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/"],[_chains.polygon.id]:["https://137.rpc.thirdweb.com/","https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/"],[_chains.optimism.id]:["https://10.rpc.thirdweb.com/","https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/"],[_chains.base.id]:["https://8453.rpc.thirdweb.com/","https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/"],[_chains.bsc.id]:["https://56.rpc.thirdweb.com/","https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/"],[_chains.avalanche.id]:["https://43114.rpc.thirdweb.com/","https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/"],[_chains.arbitrum.id]:["https://42161.rpc.thirdweb.com/","https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/"]};function G({sponsorGas:i}){let t=_thirdweb.createThirdwebClient.call(void 0, {clientId:_internal.appConfig.apiKeys.public.thirdweb}),C={mode:"EIP7702",sponsorGas:i};return{thirdwebClient:t,wagmi:_wagmi.createConfig.call(void 0, {chains:[r.chain,...u],ssr:!0,connectors:[_wagmiadapter.inAppWalletConnector.call(void 0, {client:t,executionMode:C})],storage:_wagmi.createStorage.call(void 0, {key:"wagmi-berachain-thirdweb",storage:typeof window<"u"?localStorage:void 0}),batch:{multicall:A?{wait:15}:void 0},transports:{[r.chain.id]:_wagmi.fallback.call(void 0, [_internal.privateRcpUrl,_internal.jsonRpcUrl,_internal.alchemyJsonRpcUrl,_internal.publicJsonRpcUrl].filter(e=>e).map(e=>_wagmi.http.call(void 0, e,{batch:{wait:35}}))),...Object.entries(M).reduce((e,[w,g])=>(e[Number(w)]=_wagmi.fallback.call(void 0, [...g,void 0].map(k=>_wagmi.http.call(void 0, k,{batch:{wait:15}}))),e),{})}})}}exports.a = m; exports.b = r; exports.c = u; exports.d = E; exports.e = G;
|
|
@@ -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 _chunkDYMS6OAPcjs = require('./chunk-DYMS6OAP.cjs');var _wagmi = require('wagmi');var _internal = require('@berachain/config/internal');var _react = require('react');var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _chains = require('viem/chains');var _ens = require('viem/ens');var _edgeconfig = require('@berachain/config/internal/edge-config');var _jsxruntime = require('react/jsx-runtime');var T=_react.createContext.call(void 0, void 0);function L({children:e,address:t}){return _jsxruntime.jsx.call(void 0, T.Provider,{value:{address:t},children:e})}var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');var _wallets = require('thirdweb/wallets');var ce=_wallets.getInstalledWallets.call(void 0, ),le=[...ce,_wallets.createWallet.call(void 0, "io.rabby"),_wallets.createWallet.call(void 0, "io.metamask"),_wallets.createWallet.call(void 0, "com.coinbase.wallet"),_wallets.createWallet.call(void 0, "walletConnect")].filter((e,t,n)=>n.findIndex(i=>i.id===e.id)===t),U=_thirdweb.defineChain.call(void 0, {id:_chunkDYMS6OAPcjs.a.id,blockExplorers:_chunkDYMS6OAPcjs.a.blockExplorers,blockTime:_chunkDYMS6OAPcjs.a.blockTime,ensTlds:_chunkDYMS6OAPcjs.a.ensTlds,testnet:_chunkDYMS6OAPcjs.a.testnet,contracts:_chunkDYMS6OAPcjs.a.contracts,nativeCurrency:_chunkDYMS6OAPcjs.a.nativeCurrency,name:_chunkDYMS6OAPcjs.a.name,rpcUrls:{default:{http:[_internal.publicJsonRpcUrl]}}});function S({isEmbeddedWalletsEnabled:e,theme:t,extenalChains:n,thirdwebClient:i}){let{connectors:f,connect:C}=_wagmi.useConnect.call(void 0, ),c=_react3.useActiveWallet.call(void 0, ),u=_react3.useActiveAccount.call(void 0, ),{disconnect:y}=_react3.useDisconnect.call(void 0, ),{data:m}=_react3.useWalletInfo.call(void 0, _optionalChain([c, 'optionalAccess', _2 => _2.id])),l={client:i,chain:U,wallets:e?void 0:le};async function r(a){let d=f.find(h=>h.id==="in-app-wallet");d?C({connector:d,chainId:_internal.defaultChainId,...{withCapabilities:!0,wallet:a}}):console.error("no tw connector found")}let{isLoading:v}=_react3.useAutoConnect.call(void 0, {...l,onConnect:r}),x=_react.useMemo.call(void 0, ()=>crypto.randomUUID(),[_optionalChain([c, 'optionalAccess', _3 => _3.id]),_optionalChain([u, 'optionalAccess', _4 => _4.address])]),{connect:P}=_react3.useConnectModal.call(void 0, );return{async connect(){let a=await P({...l,theme:t==="auto"?void 0:t,chains:[U,...n.map(d=>_thirdweb.defineChain.call(void 0, {id:d.id}))]});await r(a)},disconnect(){c&&y(c)},isConnecting:v,connectionId:x,connectorName:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _5 => _5.name]), () => (null)),isEmbeddedWallet:_optionalChain([m, 'optionalAccess', _6 => _6.id])==="inApp",wallet:u,DebugConnectButton(){return _jsxruntime.jsx.call(void 0, _react3.ConnectButton,{...l,onConnect:a=>r(a)})}}}function E(){let e=_react.useContext.call(void 0, M);if(!e)throw new Error("BeraWagmiContext not found");return e}var M=_react.createContext.call(void 0, void 0),Re=[_chains.mainnet,_chains.polygon,_chains.optimism,_chains.base,_chains.bsc,_chains.avalanche,_chains.arbitrum];function Le({externalChainList:e}){return Re.filter(t=>{let n=_optionalChain([e, 'optionalAccess', _7 => _7.find, 'call', _8 => _8(i=>i.chainId===t.id)]);return!n||_edgeconfig.isFlagEnabled.call(void 0, n.enabled)})}function at({children:e,thirdwebClient:t,wagmi:n,isEmbeddedWalletsEnabled:i,disableEip5792:f,disable5792Upgrade:C,theme:c,accountOverride:u,onSmartAccountRejection:y,edgeConfigChainList:m}){let l=_react.useMemo.call(void 0, ()=>Le({externalChainList:m}),[m]),{wallet:r,connect:v,DebugConnectButton:x,connectionId:P,disconnect:a,connectorName:d,isEmbeddedWallet:h,isConnecting:_}=S({thirdwebClient:t,isEmbeddedWalletsEnabled:i,theme:c,extenalChains:l}),{address:b,chainId:B}=_wagmi.useAccount.call(void 0, ),{disconnect:O}=_wagmi.useDisconnect.call(void 0, ),G=_wagmi.usePublicClient.call(void 0, ),s=_react.useMemo.call(void 0, ()=>{if(!(!b||!r))return _nullishCoalesce(u, () => (b))},[u,b,r]),{data:p}=_wagmi.useCapabilities.call(void 0, {account:b,scopeKey:P,query:{retry:3}}),q=_react.useCallback.call(void 0, w=>f||!p?!1:_optionalChain([p, 'optionalAccess', _9 => _9[w], 'optionalAccess', _10 => _10.atomic, 'optionalAccess', _11 => _11.status])==="supported"||!C&&_optionalChain([p, 'optionalAccess', _12 => _12[w], 'optionalAccess', _13 => _13.atomic, 'optionalAccess', _14 => _14.status])==="ready",[p,f,C]),{data:g}=_wagmi.useEnsName.call(void 0, {config:n,chainId:_internal.defaultChainId,address:s}),{data:I}=_immutable2.default.call(void 0, s?["BeraWagmiProvider_code",s,B]:null,([w,H,ze])=>_optionalChain([G, 'optionalAccess', _15 => _15.getCode, 'call', _16 => _16({address:H})]),{refreshInterval:6e4}),[F,J]=_react.useMemo.call(void 0, ()=>I?I.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[I]),{data:R}=_wagmi.useWalletClient.call(void 0, ),K=_react.useMemo.call(void 0, ()=>{try{return g?_ens.normalize.call(void 0, g):void 0}catch (e2){}},[g]),j=_wagmi.useEnsAvatar.call(void 0, {name:K});return _jsxruntime.jsx.call(void 0, M.Provider,{value:{walletClient:R,onSmartAccountRejection:()=>{_optionalChain([y, 'optionalCall', _17 => _17()])},isEmbeddedWalletsEnabled:i,isConnecting:_,isConnected:!!s&&!!R,DebugConnectButton:x,account:r&&B&&s?{chainId:B,connectorName:d,isEmbeddedWallet:h,capabilities:p,flags:{getSupportsAtomic:q},wallet:{address:s,ensName:_nullishCoalesce(g, () => (null)),ensAvatar:_nullishCoalesce(j.data, () => (null)),has7702Authorization:J,isContract:F}}:void 0,connectWallet:async()=>{console.log("connectWallet.called"),await v()},disconnect:()=>{O(),a()},externalChainList:l},children:_jsxruntime.jsx.call(void 0, L,{address:s,children:e})})}function Ue(){let{account:e,isConnected:t}=E();return{...e,isConnected:t}}function Se(){let e=_react.useContext.call(void 0, T);if(!e)throw new Error("LightweightAccountContext not found");let{address:t}=e;return{isConnected:!!t,address:t}}function ht(e){let{chainId:t,...n}=_nullishCoalesce(e, () => ({}));return _wagmi.usePublicClient.call(void 0, {chainId:_nullishCoalesce(t, () => (_internal.defaultChainId)),...n})}exports.a = Ue; exports.b = Se; exports.c = ht; exports.d = _wagmi.useBlockNumber; exports.e = _wagmi.useChains; exports.f = _wagmi.useConfig; exports.g = _wagmi.useEnsAvatar; exports.h = _wagmi.useEnsName; exports.i = _wagmi.useSwitchChain; exports.j = _wagmi.useTransactionReceipt; exports.k = E; exports.l = at;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{inAppWalletConnector as x}from"@thirdweb-dev/wagmi-adapter";import{createThirdwebClient as y}from"thirdweb";import{arbitrum as c,avalanche as p,base as s,berachain as a,berachainBepolia as d,bsc as h,mainnet as l,optimism as f,polygon as b}from"viem/chains";import{createConfig as q,createStorage as R,fallback as o,http as n}from"wagmi";import{alchemyJsonRpcUrl as N,appConfig as I,chainId as v,jsonRpcUrl as T,privateRcpUrl as U,publicJsonRpcUrl as W}from"@berachain/config/internal";var m=v===a.id?a:d,r={chain:m},A=!!m.contracts?.multicall3,u=[l,b,f,s,h,c,p],E=[...u,a,d].reduce((i,t)=>(i[t.id]=t.name,i),{}),M={[l.id]:["https://1.rpc.thirdweb.com/","https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/"],[b.id]:["https://137.rpc.thirdweb.com/","https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/"],[f.id]:["https://10.rpc.thirdweb.com/","https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/"],[s.id]:["https://8453.rpc.thirdweb.com/","https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/"],[h.id]:["https://56.rpc.thirdweb.com/","https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/"],[p.id]:["https://43114.rpc.thirdweb.com/","https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/"],[c.id]:["https://42161.rpc.thirdweb.com/","https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/"]};function G({sponsorGas:i}){let t=y({clientId:I.apiKeys.public.thirdweb}),C={mode:"EIP7702",sponsorGas:i};return{thirdwebClient:t,wagmi:q({chains:[r.chain,...u],ssr:!0,connectors:[x({client:t,executionMode:C})],storage:R({key:"wagmi-berachain-thirdweb",storage:typeof window<"u"?localStorage:void 0}),batch:{multicall:A?{wait:15}:void 0},transports:{[r.chain.id]:o([U,T,N,W].filter(e=>e).map(e=>n(e,{batch:{wait:35}}))),...Object.entries(M).reduce((e,[w,g])=>(e[Number(w)]=o([...g,void 0].map(k=>n(k,{batch:{wait:15}}))),e),{})}})}}export{m as a,r as b,u as c,E as d,G as e};
|
package/dist/config/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkDYMS6OAPcjs = require('../chunk-DYMS6OAP.cjs');exports.chain = _chunkDYMS6OAPcjs.a; exports.chainIdToName = _chunkDYMS6OAPcjs.d; exports.defaultBeraNetworkConfig = _chunkDYMS6OAPcjs.b; exports.externalChains = _chunkDYMS6OAPcjs.c; exports.getWagmiConfig = _chunkDYMS6OAPcjs.e;
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as thirdweb from 'thirdweb';
|
|
2
|
-
import { inAppWallet } from 'thirdweb/wallets';
|
|
3
2
|
import { Chain } from 'viem';
|
|
4
3
|
import { Config } from 'wagmi';
|
|
5
4
|
|
|
6
|
-
declare const thirdwebClient: thirdweb.ThirdwebClient;
|
|
7
|
-
declare const executionMode: {
|
|
8
|
-
readonly mode: "EIP7702";
|
|
9
|
-
readonly sponsorGas: true;
|
|
10
|
-
};
|
|
11
|
-
declare const thirdwebWallet: ReturnType<typeof inAppWallet>;
|
|
12
5
|
/**
|
|
13
6
|
* Using default viem chain definition since it also includes ens and other metadata
|
|
14
7
|
*/
|
|
@@ -22,6 +15,11 @@ interface NetworkConfig {
|
|
|
22
15
|
*/
|
|
23
16
|
declare const externalChains: Chain[];
|
|
24
17
|
declare const chainIdToName: Record<Chain["id"], string>;
|
|
25
|
-
declare
|
|
18
|
+
declare function getWagmiConfig({ sponsorGas }: {
|
|
19
|
+
sponsorGas?: boolean;
|
|
20
|
+
}): {
|
|
21
|
+
thirdwebClient: thirdweb.ThirdwebClient;
|
|
22
|
+
wagmi: Config;
|
|
23
|
+
};
|
|
26
24
|
|
|
27
|
-
export { type NetworkConfig, chain, chainIdToName, defaultBeraNetworkConfig,
|
|
25
|
+
export { type NetworkConfig, chain, chainIdToName, defaultBeraNetworkConfig, externalChains, getWagmiConfig };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as thirdweb from 'thirdweb';
|
|
2
|
-
import { inAppWallet } from 'thirdweb/wallets';
|
|
3
2
|
import { Chain } from 'viem';
|
|
4
3
|
import { Config } from 'wagmi';
|
|
5
4
|
|
|
6
|
-
declare const thirdwebClient: thirdweb.ThirdwebClient;
|
|
7
|
-
declare const executionMode: {
|
|
8
|
-
readonly mode: "EIP7702";
|
|
9
|
-
readonly sponsorGas: true;
|
|
10
|
-
};
|
|
11
|
-
declare const thirdwebWallet: ReturnType<typeof inAppWallet>;
|
|
12
5
|
/**
|
|
13
6
|
* Using default viem chain definition since it also includes ens and other metadata
|
|
14
7
|
*/
|
|
@@ -22,6 +15,11 @@ interface NetworkConfig {
|
|
|
22
15
|
*/
|
|
23
16
|
declare const externalChains: Chain[];
|
|
24
17
|
declare const chainIdToName: Record<Chain["id"], string>;
|
|
25
|
-
declare
|
|
18
|
+
declare function getWagmiConfig({ sponsorGas }: {
|
|
19
|
+
sponsorGas?: boolean;
|
|
20
|
+
}): {
|
|
21
|
+
thirdwebClient: thirdweb.ThirdwebClient;
|
|
22
|
+
wagmi: Config;
|
|
23
|
+
};
|
|
26
24
|
|
|
27
|
-
export { type NetworkConfig, chain, chainIdToName, defaultBeraNetworkConfig,
|
|
25
|
+
export { type NetworkConfig, chain, chainIdToName, defaultBeraNetworkConfig, externalChains, getWagmiConfig };
|
package/dist/config/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e
|
|
1
|
+
import{a,b,c,d,e}from"../chunk-TZTB265J.mjs";export{a as chain,d as chainIdToName,b as defaultBeraNetworkConfig,c as externalChains,e as getWagmiConfig};
|
package/dist/context/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";var _chunkS2KJM5XBcjs = require('../chunk-S2KJM5XB.cjs');var _chunkDYMS6OAPcjs = require('../chunk-DYMS6OAP.cjs');var _reactquery = require('@tanstack/react-query');var _porto = require('porto');var _react = require('thirdweb/react');var _wagmi = require('wagmi');var _jsxruntime = require('react/jsx-runtime');var P=new _reactquery.QueryClient;_porto.Porto.create();function C({sponsorGas:t,...n}){let{wagmi:e,thirdwebClient:m}=_chunkDYMS6OAPcjs.e.call(void 0, {sponsorGas:t});return _jsxruntime.jsx.call(void 0, _react.ThirdwebProvider,{children:_jsxruntime.jsx.call(void 0, _wagmi.WagmiProvider,{config:e,reconnectOnMount:!1,children:_jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider,{client:P,children:_jsxruntime.jsx.call(void 0, _chunkS2KJM5XBcjs.l,{...n,thirdwebClient:m,wagmi:e})})})})}exports.WagmiProvider = C;
|
package/dist/context/index.d.cts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-
|
|
2
|
+
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-BfIT9GJt.cjs';
|
|
3
3
|
import 'react';
|
|
4
|
+
import 'thirdweb';
|
|
4
5
|
import 'viem';
|
|
5
6
|
import 'wagmi';
|
|
6
7
|
import '@berachain/config/internal/edge-config';
|
|
7
8
|
|
|
8
|
-
declare function WagmiProvider({ ...beraWagmiProps }: IBeraWagmiProviderProps
|
|
9
|
+
declare function WagmiProvider({ sponsorGas, ...beraWagmiProps }: Omit<IBeraWagmiProviderProps, "thirdwebClient" | "wagmi"> & {
|
|
10
|
+
sponsorGas?: boolean;
|
|
11
|
+
}): react_jsx_runtime.JSX.Element;
|
|
9
12
|
|
|
10
13
|
export { WagmiProvider };
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-
|
|
2
|
+
import { I as IBeraWagmiProviderProps } from '../BeraWagmi-BfIT9GJt.js';
|
|
3
3
|
import 'react';
|
|
4
|
+
import 'thirdweb';
|
|
4
5
|
import 'viem';
|
|
5
6
|
import 'wagmi';
|
|
6
7
|
import '@berachain/config/internal/edge-config';
|
|
7
8
|
|
|
8
|
-
declare function WagmiProvider({ ...beraWagmiProps }: IBeraWagmiProviderProps
|
|
9
|
+
declare function WagmiProvider({ sponsorGas, ...beraWagmiProps }: Omit<IBeraWagmiProviderProps, "thirdwebClient" | "wagmi"> & {
|
|
10
|
+
sponsorGas?: boolean;
|
|
11
|
+
}): react_jsx_runtime.JSX.Element;
|
|
9
12
|
|
|
10
13
|
export { WagmiProvider };
|
package/dist/context/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{l as
|
|
1
|
+
"use client";import{l as o}from"../chunk-5Q3SXXEY.mjs";import{e as i}from"../chunk-TZTB265J.mjs";import{QueryClient as a,QueryClientProvider as d}from"@tanstack/react-query";import{Porto as g}from"porto";import{ThirdwebProvider as s}from"thirdweb/react";import{WagmiProvider as f}from"wagmi";import{jsx as r}from"react/jsx-runtime";var P=new a;g.create();function C({sponsorGas:t,...n}){let{wagmi:e,thirdwebClient:m}=i({sponsorGas:t});return r(s,{children:r(f,{config:e,reconnectOnMount:!1,children:r(d,{client:P,children:r(o,{...n,thirdwebClient:m,wagmi:e})})})})}export{C as WagmiProvider};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkS2KJM5XBcjs = require('../chunk-S2KJM5XB.cjs');require('../chunk-DYMS6OAP.cjs');exports.useBeraAccount = _chunkS2KJM5XBcjs.a; exports.useBeraWagmi = _chunkS2KJM5XBcjs.k; exports.useBeraWallet = _chunkS2KJM5XBcjs.b; exports.useBlockNumber = _chunkS2KJM5XBcjs.d; exports.useChains = _chunkS2KJM5XBcjs.e; exports.useConfig = _chunkS2KJM5XBcjs.f; exports.useEnsAvatar = _chunkS2KJM5XBcjs.g; exports.useEnsName = _chunkS2KJM5XBcjs.h; exports.usePublicClient = _chunkS2KJM5XBcjs.c; exports.useSwitchChain = _chunkS2KJM5XBcjs.i; exports.useTransactionReceipt = _chunkS2KJM5XBcjs.j;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UsePublicClientParameters, UsePublicClientReturnType } from 'wagmi';
|
|
2
2
|
export { useBlockNumber, useChains, useConfig, useEnsAvatar, useEnsName, useSwitchChain, useTransactionReceipt } from 'wagmi';
|
|
3
|
-
import { B as BeraWagmiApi } from '../BeraWagmi-
|
|
4
|
-
export { u as useBeraWagmi } from '../BeraWagmi-
|
|
3
|
+
import { B as BeraWagmiApi } from '../BeraWagmi-BfIT9GJt.cjs';
|
|
4
|
+
export { u as useBeraWagmi } from '../BeraWagmi-BfIT9GJt.cjs';
|
|
5
5
|
import 'react';
|
|
6
|
+
import 'thirdweb';
|
|
6
7
|
import 'viem';
|
|
7
8
|
import '@berachain/config/internal/edge-config';
|
|
8
9
|
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UsePublicClientParameters, UsePublicClientReturnType } from 'wagmi';
|
|
2
2
|
export { useBlockNumber, useChains, useConfig, useEnsAvatar, useEnsName, useSwitchChain, useTransactionReceipt } from 'wagmi';
|
|
3
|
-
import { B as BeraWagmiApi } from '../BeraWagmi-
|
|
4
|
-
export { u as useBeraWagmi } from '../BeraWagmi-
|
|
3
|
+
import { B as BeraWagmiApi } from '../BeraWagmi-BfIT9GJt.js';
|
|
4
|
+
export { u as useBeraWagmi } from '../BeraWagmi-BfIT9GJt.js';
|
|
5
5
|
import 'react';
|
|
6
|
+
import 'thirdweb';
|
|
6
7
|
import 'viem';
|
|
7
8
|
import '@berachain/config/internal/edge-config';
|
|
8
9
|
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-5Q3SXXEY.mjs";import"../chunk-TZTB265J.mjs";export{a as useBeraAccount,k as useBeraWagmi,b as useBeraWallet,d as useBlockNumber,e as useChains,f as useConfig,g as useEnsAvatar,h as useEnsName,c as usePublicClient,i as useSwitchChain,j as useTransactionReceipt};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@berachain/wagmi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
|
-
"dist"
|
|
6
|
+
"dist",
|
|
7
|
+
"src"
|
|
7
8
|
],
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
10
|
"module": "./dist/index.mjs",
|
|
@@ -35,15 +36,15 @@
|
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@react-native-async-storage/async-storage": "2.2.0",
|
|
37
38
|
"@tanstack/react-query": "5.59.0",
|
|
38
|
-
"@thirdweb-dev/wagmi-adapter": "0.2.
|
|
39
|
+
"@thirdweb-dev/wagmi-adapter": "0.2.204",
|
|
39
40
|
"@wagmi/core": "2.22.1",
|
|
40
41
|
"porto": "0.2.23",
|
|
41
42
|
"swr": "2.3.3",
|
|
42
|
-
"thirdweb": "5.
|
|
43
|
+
"thirdweb": "5.118.0",
|
|
43
44
|
"@berachain/config": "0.0.7"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@types/node": "
|
|
47
|
+
"@types/node": "24.1.0",
|
|
47
48
|
"@types/react": "19.1.8",
|
|
48
49
|
"tsup": "8.4.0",
|
|
49
50
|
"viem": "2.41.2",
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
2
|
+
import { createThirdwebClient } from "thirdweb";
|
|
3
|
+
import type { InAppWalletCreationOptions } from "thirdweb/wallets";
|
|
4
|
+
import type { Chain, Transport } from "viem";
|
|
5
|
+
import {
|
|
6
|
+
arbitrum,
|
|
7
|
+
avalanche,
|
|
8
|
+
base,
|
|
9
|
+
berachain,
|
|
10
|
+
berachainBepolia,
|
|
11
|
+
bsc,
|
|
12
|
+
mainnet,
|
|
13
|
+
optimism,
|
|
14
|
+
polygon,
|
|
15
|
+
} from "viem/chains";
|
|
16
|
+
import {
|
|
17
|
+
type Config,
|
|
18
|
+
createConfig,
|
|
19
|
+
createStorage,
|
|
20
|
+
fallback,
|
|
21
|
+
http,
|
|
22
|
+
} from "wagmi";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
alchemyJsonRpcUrl,
|
|
26
|
+
appConfig,
|
|
27
|
+
chainId,
|
|
28
|
+
jsonRpcUrl,
|
|
29
|
+
privateRcpUrl,
|
|
30
|
+
publicJsonRpcUrl,
|
|
31
|
+
} from "@berachain/config/internal";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Using default viem chain definition since it also includes ens and other metadata
|
|
35
|
+
*/
|
|
36
|
+
export const chain: Chain =
|
|
37
|
+
chainId === berachain.id ? berachain : berachainBepolia;
|
|
38
|
+
|
|
39
|
+
export const defaultBeraNetworkConfig: NetworkConfig = {
|
|
40
|
+
chain: chain,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface NetworkConfig {
|
|
44
|
+
chain: Chain;
|
|
45
|
+
}
|
|
46
|
+
const hasMulticall = !!chain.contracts?.multicall3;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Exporting this is helpful for the multi-chain zap, to get the list of chains that we want to support.
|
|
50
|
+
*/
|
|
51
|
+
export const externalChains: Chain[] = [
|
|
52
|
+
mainnet,
|
|
53
|
+
polygon,
|
|
54
|
+
optimism,
|
|
55
|
+
base,
|
|
56
|
+
bsc,
|
|
57
|
+
arbitrum,
|
|
58
|
+
avalanche,
|
|
59
|
+
] as const;
|
|
60
|
+
|
|
61
|
+
export const chainIdToName: Record<Chain["id"], string> = [
|
|
62
|
+
...externalChains,
|
|
63
|
+
berachain,
|
|
64
|
+
berachainBepolia,
|
|
65
|
+
].reduce(
|
|
66
|
+
(acc, chain) => {
|
|
67
|
+
acc[chain.id] = chain.name;
|
|
68
|
+
return acc;
|
|
69
|
+
},
|
|
70
|
+
{} as Record<Chain["id"], string>,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Thirdweb RPC URLs have a rate limit of 3 RPS.
|
|
75
|
+
* http() uses default viem transport which varies based on the chain definition.
|
|
76
|
+
*
|
|
77
|
+
* Quicknode RPC URLs are CORS restricted to *.berachain.com, *.berachain-staging.com. They have a 100rpm rate limit.
|
|
78
|
+
*/
|
|
79
|
+
const externalTransports: Record<Chain["id"], (string | undefined)[]> = {
|
|
80
|
+
[mainnet.id]: [
|
|
81
|
+
"https://1.rpc.thirdweb.com/",
|
|
82
|
+
"https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/",
|
|
83
|
+
],
|
|
84
|
+
[polygon.id]: [
|
|
85
|
+
"https://137.rpc.thirdweb.com/",
|
|
86
|
+
"https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/",
|
|
87
|
+
],
|
|
88
|
+
[optimism.id]: [
|
|
89
|
+
"https://10.rpc.thirdweb.com/",
|
|
90
|
+
"https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/",
|
|
91
|
+
],
|
|
92
|
+
[base.id]: [
|
|
93
|
+
"https://8453.rpc.thirdweb.com/",
|
|
94
|
+
"https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/",
|
|
95
|
+
],
|
|
96
|
+
[bsc.id]: [
|
|
97
|
+
"https://56.rpc.thirdweb.com/",
|
|
98
|
+
"https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/",
|
|
99
|
+
],
|
|
100
|
+
[avalanche.id]: [
|
|
101
|
+
"https://43114.rpc.thirdweb.com/",
|
|
102
|
+
"https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/",
|
|
103
|
+
],
|
|
104
|
+
[arbitrum.id]: [
|
|
105
|
+
"https://42161.rpc.thirdweb.com/",
|
|
106
|
+
"https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/",
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function getWagmiConfig({ sponsorGas }: { sponsorGas?: boolean }) {
|
|
111
|
+
const thirdwebClient = createThirdwebClient({
|
|
112
|
+
clientId: appConfig.apiKeys.public.thirdweb,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const executionMode = {
|
|
116
|
+
mode: "EIP7702",
|
|
117
|
+
sponsorGas,
|
|
118
|
+
} as const satisfies NonNullable<InAppWalletCreationOptions>["executionMode"];
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
thirdwebClient,
|
|
122
|
+
wagmi: createConfig({
|
|
123
|
+
chains: [defaultBeraNetworkConfig.chain, ...externalChains],
|
|
124
|
+
|
|
125
|
+
// recommended by wagmi docs https://wagmi.sh/react/guides/ssr#ssr
|
|
126
|
+
ssr: true,
|
|
127
|
+
connectors: [
|
|
128
|
+
// add the in-app wallet connector
|
|
129
|
+
inAppWalletConnector({
|
|
130
|
+
client: thirdwebClient,
|
|
131
|
+
executionMode,
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
134
|
+
storage: createStorage({
|
|
135
|
+
key: `wagmi-berachain-thirdweb`,
|
|
136
|
+
storage: typeof window !== "undefined" ? localStorage : undefined,
|
|
137
|
+
}),
|
|
138
|
+
batch: {
|
|
139
|
+
/**
|
|
140
|
+
* Undefined multicall address will disable batching
|
|
141
|
+
*
|
|
142
|
+
* @see https://viem.sh/docs/clients/public#batchmulticallwait-optional
|
|
143
|
+
*/
|
|
144
|
+
multicall: hasMulticall
|
|
145
|
+
? {
|
|
146
|
+
wait: 15,
|
|
147
|
+
}
|
|
148
|
+
: undefined,
|
|
149
|
+
},
|
|
150
|
+
transports: {
|
|
151
|
+
[defaultBeraNetworkConfig.chain.id]: fallback(
|
|
152
|
+
[privateRcpUrl, jsonRpcUrl, alchemyJsonRpcUrl, publicJsonRpcUrl]
|
|
153
|
+
.filter((i) => i)
|
|
154
|
+
.map((url) =>
|
|
155
|
+
http(url, {
|
|
156
|
+
batch: {
|
|
157
|
+
wait: 35,
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
...Object.entries(externalTransports).reduce<
|
|
163
|
+
Record<Chain["id"], Transport>
|
|
164
|
+
>((acc, [chainId, urls]) => {
|
|
165
|
+
acc[Number(chainId) as Chain["id"]] = fallback(
|
|
166
|
+
[
|
|
167
|
+
...urls,
|
|
168
|
+
// undefined for default rpc
|
|
169
|
+
undefined,
|
|
170
|
+
].map((url) =>
|
|
171
|
+
http(url, {
|
|
172
|
+
batch: {
|
|
173
|
+
wait: 15,
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
return acc;
|
|
179
|
+
}, {}),
|
|
180
|
+
},
|
|
181
|
+
}) as Config,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./defaultWagmiConfig";
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type PropsWithChildren,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
} from "react";
|
|
8
|
+
import useSWRImmutable from "swr/immutable";
|
|
9
|
+
import type { ThirdwebClient } from "thirdweb";
|
|
10
|
+
import type { Address, Chain, GetCapabilitiesReturnType } from "viem";
|
|
11
|
+
import {
|
|
12
|
+
arbitrum,
|
|
13
|
+
avalanche,
|
|
14
|
+
base,
|
|
15
|
+
bsc,
|
|
16
|
+
mainnet,
|
|
17
|
+
optimism,
|
|
18
|
+
polygon,
|
|
19
|
+
} from "viem/chains";
|
|
20
|
+
import { normalize } from "viem/ens";
|
|
21
|
+
import {
|
|
22
|
+
type Config,
|
|
23
|
+
type UseWalletClientReturnType,
|
|
24
|
+
useAccount,
|
|
25
|
+
useCapabilities,
|
|
26
|
+
useDisconnect,
|
|
27
|
+
usePublicClient,
|
|
28
|
+
useWalletClient,
|
|
29
|
+
} from "wagmi";
|
|
30
|
+
|
|
31
|
+
import { defaultChainId } from "@berachain/config/internal";
|
|
32
|
+
import type { EdgeConfigSchema } from "@berachain/config/internal/edge-config";
|
|
33
|
+
import { isFlagEnabled } from "@berachain/config/internal/edge-config";
|
|
34
|
+
|
|
35
|
+
import { useEnsAvatar, useEnsName } from "../hooks";
|
|
36
|
+
import { LightweightAccountProvider } from "./LightweightAccountProvider";
|
|
37
|
+
import { useThirdweb } from "./useThirdweb";
|
|
38
|
+
|
|
39
|
+
export function useBeraWagmi() {
|
|
40
|
+
const context = useContext(BeraWagmiContext);
|
|
41
|
+
if (!context) {
|
|
42
|
+
throw new Error("BeraWagmiContext not found");
|
|
43
|
+
}
|
|
44
|
+
return context;
|
|
45
|
+
}
|
|
46
|
+
export interface BeraWagmiApi {
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated used for prototyping only.
|
|
49
|
+
*/
|
|
50
|
+
DebugConnectButton: () => React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Account connected to berachain dapp. It might include some additional data once embedded wallets are enabled.
|
|
53
|
+
*/
|
|
54
|
+
account:
|
|
55
|
+
| {
|
|
56
|
+
/**
|
|
57
|
+
* Chain ID to which the wallet provider is currently connected to.
|
|
58
|
+
*/
|
|
59
|
+
chainId: number;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the wallet is an embedded wallet.
|
|
62
|
+
*/
|
|
63
|
+
isEmbeddedWallet: boolean;
|
|
64
|
+
connectorName: string | null;
|
|
65
|
+
flags: {
|
|
66
|
+
getSupportsAtomic: (chainId: number) => boolean;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Wallet provider capabilities for the current account.
|
|
70
|
+
*
|
|
71
|
+
* Status can be:
|
|
72
|
+
* - supported: User has enabled the feature.
|
|
73
|
+
* - ready: The wallet provider is ready to use the feature.
|
|
74
|
+
* - unsupported: The wallet provider does not support the feature.
|
|
75
|
+
*/
|
|
76
|
+
capabilities: GetCapabilitiesReturnType | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Wallet to display.
|
|
79
|
+
*
|
|
80
|
+
* This might be manually overridden by the accountOverride prop, thus not being the same as the connected wallet.
|
|
81
|
+
*/
|
|
82
|
+
wallet:
|
|
83
|
+
| {
|
|
84
|
+
address: Address;
|
|
85
|
+
/**
|
|
86
|
+
* ENS name of the wallet.
|
|
87
|
+
*/
|
|
88
|
+
ensName: string | null;
|
|
89
|
+
/**
|
|
90
|
+
* ENS avatar of the wallet.
|
|
91
|
+
*/
|
|
92
|
+
ensAvatar: string | null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether the wallet has 7702 authorization.
|
|
96
|
+
*/
|
|
97
|
+
has7702Authorization: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Whether the wallet is a contract.
|
|
100
|
+
*/
|
|
101
|
+
isContract: boolean;
|
|
102
|
+
}
|
|
103
|
+
| undefined;
|
|
104
|
+
}
|
|
105
|
+
| undefined;
|
|
106
|
+
isEmbeddedWalletsEnabled: boolean;
|
|
107
|
+
isConnected: boolean;
|
|
108
|
+
isConnecting: boolean;
|
|
109
|
+
walletClient: UseWalletClientReturnType["data"];
|
|
110
|
+
connectWallet: () => Promise<void> | 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
|
+
* List of external chains that are whitelisted for that app.
|
|
120
|
+
*/
|
|
121
|
+
externalChainList: Chain[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const BeraWagmiContext = createContext<BeraWagmiApi | undefined>(undefined);
|
|
125
|
+
|
|
126
|
+
export interface IBeraWagmiProviderProps extends PropsWithChildren {
|
|
127
|
+
thirdwebClient: ThirdwebClient;
|
|
128
|
+
wagmi: Config;
|
|
129
|
+
theme?: "dark" | "light" | "auto";
|
|
130
|
+
isEmbeddedWalletsEnabled: boolean;
|
|
131
|
+
disableEip5792: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Whether to disable the 5792 upgrade for users that haven't upgraded yet.
|
|
134
|
+
*
|
|
135
|
+
* `atomic.status === "ready"`
|
|
136
|
+
*/
|
|
137
|
+
disable5792Upgrade?: boolean;
|
|
138
|
+
accountOverride?: Address;
|
|
139
|
+
onSmartAccountRejection?: () => void;
|
|
140
|
+
edgeConfigChainList: EdgeConfigSchema["wagmi"]["externalChainList"];
|
|
141
|
+
/**
|
|
142
|
+
* Event triggered when a wallet is connected manually.
|
|
143
|
+
*
|
|
144
|
+
* This is not triggered when a wallet connect automatically after a refresh.
|
|
145
|
+
*/
|
|
146
|
+
onConnectedWallet?: () => void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* This are the chains that have been approved by the Bera team to be used in the BeraHub,
|
|
151
|
+
* for multi chain zapping.
|
|
152
|
+
*/
|
|
153
|
+
const externalApprovedChains = [
|
|
154
|
+
mainnet,
|
|
155
|
+
polygon,
|
|
156
|
+
optimism,
|
|
157
|
+
base,
|
|
158
|
+
bsc,
|
|
159
|
+
avalanche,
|
|
160
|
+
arbitrum,
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The chain is selected
|
|
165
|
+
* - if it's part of the pre-approved array
|
|
166
|
+
* - if it's not present in the edge config
|
|
167
|
+
* - if it's present and it is enabled on this env, branch & app
|
|
168
|
+
*/
|
|
169
|
+
function getExternalChainList({
|
|
170
|
+
externalChainList,
|
|
171
|
+
}: {
|
|
172
|
+
externalChainList: EdgeConfigSchema["wagmi"]["externalChainList"];
|
|
173
|
+
}): Chain[] {
|
|
174
|
+
return externalApprovedChains.filter((aChain): boolean => {
|
|
175
|
+
const extChain = externalChainList?.find((c) => c.chainId === aChain.id);
|
|
176
|
+
return !extChain || isFlagEnabled(extChain.enabled);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function BeraWagmiProvider({
|
|
181
|
+
children,
|
|
182
|
+
thirdwebClient,
|
|
183
|
+
wagmi,
|
|
184
|
+
isEmbeddedWalletsEnabled,
|
|
185
|
+
disableEip5792,
|
|
186
|
+
disable5792Upgrade,
|
|
187
|
+
theme,
|
|
188
|
+
accountOverride,
|
|
189
|
+
onSmartAccountRejection,
|
|
190
|
+
edgeConfigChainList,
|
|
191
|
+
}: IBeraWagmiProviderProps) {
|
|
192
|
+
const externalChainList = useMemo(() => {
|
|
193
|
+
return getExternalChainList({
|
|
194
|
+
externalChainList: edgeConfigChainList,
|
|
195
|
+
});
|
|
196
|
+
}, [edgeConfigChainList]);
|
|
197
|
+
|
|
198
|
+
const {
|
|
199
|
+
wallet,
|
|
200
|
+
connect,
|
|
201
|
+
DebugConnectButton,
|
|
202
|
+
connectionId,
|
|
203
|
+
disconnect: disconnectProvider,
|
|
204
|
+
connectorName,
|
|
205
|
+
isEmbeddedWallet,
|
|
206
|
+
isConnecting,
|
|
207
|
+
} = useThirdweb({
|
|
208
|
+
thirdwebClient,
|
|
209
|
+
isEmbeddedWalletsEnabled,
|
|
210
|
+
theme,
|
|
211
|
+
extenalChains: externalChainList,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const { address: connectedAddress, chainId } = useAccount(); // wagmi
|
|
215
|
+
|
|
216
|
+
const { disconnect: disconnectWagmi } = useDisconnect();
|
|
217
|
+
const publicClient = usePublicClient();
|
|
218
|
+
|
|
219
|
+
const address = useMemo<Address | undefined>(() => {
|
|
220
|
+
// no address anyway if no connected address
|
|
221
|
+
if (!connectedAddress || !wallet) return undefined;
|
|
222
|
+
|
|
223
|
+
return accountOverride ?? connectedAddress;
|
|
224
|
+
}, [accountOverride, connectedAddress, wallet]);
|
|
225
|
+
|
|
226
|
+
const { data: capabilities } = useCapabilities({
|
|
227
|
+
account: connectedAddress,
|
|
228
|
+
// This is needed to avoid cache issues with the capabilities when switching wallets
|
|
229
|
+
scopeKey: connectionId,
|
|
230
|
+
query: {
|
|
231
|
+
retry: 3,
|
|
232
|
+
},
|
|
233
|
+
// chainId: defaultChainId,
|
|
234
|
+
});
|
|
235
|
+
const getSupportsAtomic = useCallback(
|
|
236
|
+
(targetChainId: number) => {
|
|
237
|
+
if (disableEip5792) return false;
|
|
238
|
+
if (!capabilities) return false;
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
capabilities?.[targetChainId]?.atomic?.status === "supported" ||
|
|
242
|
+
(!disable5792Upgrade &&
|
|
243
|
+
capabilities?.[targetChainId]?.atomic?.status === "ready")
|
|
244
|
+
);
|
|
245
|
+
},
|
|
246
|
+
[capabilities, disableEip5792, disable5792Upgrade],
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const { data: ens } = useEnsName({
|
|
250
|
+
config: wagmi,
|
|
251
|
+
chainId: defaultChainId,
|
|
252
|
+
address,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const { data: code } = useSWRImmutable(
|
|
256
|
+
address ? (["BeraWagmiProvider_code", address, chainId] as const) : null,
|
|
257
|
+
([_, walletAddress, _chainId]) => {
|
|
258
|
+
return publicClient?.getCode({
|
|
259
|
+
address: walletAddress,
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
refreshInterval: 60_000,
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
const [isContract, has7702Authorization] = useMemo(() => {
|
|
267
|
+
if (!code)
|
|
268
|
+
// if no code, it's not a contract or has 7702 authorization
|
|
269
|
+
return [false, false];
|
|
270
|
+
|
|
271
|
+
const has7702Authorization = code.startsWith("0xef01");
|
|
272
|
+
|
|
273
|
+
if (has7702Authorization) {
|
|
274
|
+
// if has 7702 authorization, it's not a contract
|
|
275
|
+
return [false, true];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// if doesn't have 7702 authorization but has code, it's a contract
|
|
279
|
+
return [true, false];
|
|
280
|
+
}, [code]);
|
|
281
|
+
|
|
282
|
+
const { data: walletClient } = useWalletClient();
|
|
283
|
+
|
|
284
|
+
const normalizedEns = useMemo(() => {
|
|
285
|
+
try {
|
|
286
|
+
// some characters might throw an error when normalizing
|
|
287
|
+
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
288
|
+
return ens ? normalize(ens) : undefined;
|
|
289
|
+
} catch {
|
|
290
|
+
// not catching the error here, just returning undefined
|
|
291
|
+
// @see https://berachain-dapps.sentry.io/issues/6949741717/?alert_rule_id=16379160&alert_type=issue¬ification_uuid=b01366a6-78b0-4348-a3c1-5f76ced1d539&project=4509842561630209
|
|
292
|
+
}
|
|
293
|
+
}, [ens]);
|
|
294
|
+
|
|
295
|
+
const avatar = useEnsAvatar({
|
|
296
|
+
name: normalizedEns,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<BeraWagmiContext.Provider
|
|
301
|
+
value={{
|
|
302
|
+
walletClient,
|
|
303
|
+
onSmartAccountRejection: () => {
|
|
304
|
+
onSmartAccountRejection?.();
|
|
305
|
+
},
|
|
306
|
+
isEmbeddedWalletsEnabled,
|
|
307
|
+
isConnecting,
|
|
308
|
+
isConnected:
|
|
309
|
+
!!address &&
|
|
310
|
+
// this seems obvious but might fix some re-render issues.
|
|
311
|
+
!!walletClient,
|
|
312
|
+
DebugConnectButton,
|
|
313
|
+
account:
|
|
314
|
+
wallet && chainId && address
|
|
315
|
+
? {
|
|
316
|
+
chainId,
|
|
317
|
+
connectorName,
|
|
318
|
+
isEmbeddedWallet,
|
|
319
|
+
capabilities,
|
|
320
|
+
flags: {
|
|
321
|
+
getSupportsAtomic,
|
|
322
|
+
},
|
|
323
|
+
wallet: {
|
|
324
|
+
address,
|
|
325
|
+
ensName: ens ?? null,
|
|
326
|
+
ensAvatar: avatar.data ?? null,
|
|
327
|
+
has7702Authorization,
|
|
328
|
+
isContract,
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
: undefined,
|
|
332
|
+
connectWallet: async () => {
|
|
333
|
+
console.log("connectWallet.called");
|
|
334
|
+
await connect();
|
|
335
|
+
},
|
|
336
|
+
disconnect: () => {
|
|
337
|
+
disconnectWagmi();
|
|
338
|
+
disconnectProvider();
|
|
339
|
+
},
|
|
340
|
+
externalChainList,
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
<LightweightAccountProvider address={address}>
|
|
344
|
+
{children}
|
|
345
|
+
</LightweightAccountProvider>
|
|
346
|
+
</BeraWagmiContext.Provider>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContext, type PropsWithChildren } from "react";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
|
|
4
|
+
export const LightweightAccountContext = createContext<
|
|
5
|
+
| {
|
|
6
|
+
address: Address | undefined;
|
|
7
|
+
}
|
|
8
|
+
| undefined
|
|
9
|
+
>(undefined);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This is needed to read connected wallet address without re-rendering on each wallet change.
|
|
13
|
+
*
|
|
14
|
+
* Any additional data should probably be kept in the BeraWagmiProvider. Think twice before adding something here.
|
|
15
|
+
*/
|
|
16
|
+
export function LightweightAccountProvider({
|
|
17
|
+
children,
|
|
18
|
+
address,
|
|
19
|
+
}: PropsWithChildren<{ address: Address | undefined }>) {
|
|
20
|
+
return (
|
|
21
|
+
<LightweightAccountContext.Provider value={{ address }}>
|
|
22
|
+
{children}
|
|
23
|
+
</LightweightAccountContext.Provider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
+
import { Porto } from "porto";
|
|
5
|
+
import { ThirdwebProvider } from "thirdweb/react";
|
|
6
|
+
import { WagmiProvider as WagmiProviderBase } from "wagmi";
|
|
7
|
+
|
|
8
|
+
import { getWagmiConfig } from "~/config/defaultWagmiConfig";
|
|
9
|
+
import { BeraWagmiProvider, type IBeraWagmiProviderProps } from "./BeraWagmi";
|
|
10
|
+
|
|
11
|
+
const queryClient = new QueryClient();
|
|
12
|
+
|
|
13
|
+
// Initialize Porto to inject it into Dynamic via EIP-6963
|
|
14
|
+
Porto.create();
|
|
15
|
+
|
|
16
|
+
export function WagmiProvider({
|
|
17
|
+
sponsorGas,
|
|
18
|
+
...beraWagmiProps
|
|
19
|
+
}: Omit<IBeraWagmiProviderProps, "thirdwebClient" | "wagmi"> & {
|
|
20
|
+
sponsorGas?: boolean;
|
|
21
|
+
}) {
|
|
22
|
+
const { wagmi: wagmiConfig, thirdwebClient } = getWagmiConfig({
|
|
23
|
+
sponsorGas,
|
|
24
|
+
});
|
|
25
|
+
return (
|
|
26
|
+
<ThirdwebProvider>
|
|
27
|
+
<WagmiProviderBase
|
|
28
|
+
config={wagmiConfig}
|
|
29
|
+
// must be false if using thirdweb autoconnect
|
|
30
|
+
reconnectOnMount={false}
|
|
31
|
+
>
|
|
32
|
+
<QueryClientProvider client={queryClient}>
|
|
33
|
+
<BeraWagmiProvider
|
|
34
|
+
{...beraWagmiProps}
|
|
35
|
+
thirdwebClient={thirdwebClient}
|
|
36
|
+
wagmi={wagmiConfig}
|
|
37
|
+
/>
|
|
38
|
+
</QueryClientProvider>
|
|
39
|
+
</WagmiProviderBase>
|
|
40
|
+
</ThirdwebProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
|
|
3
|
+
export type UseWalletProviderReturnType<
|
|
4
|
+
wallet extends {
|
|
5
|
+
address: string;
|
|
6
|
+
},
|
|
7
|
+
> = {
|
|
8
|
+
connect(): void;
|
|
9
|
+
disconnect(): void;
|
|
10
|
+
connectorName: string | null;
|
|
11
|
+
connectionId: string;
|
|
12
|
+
isConnecting: boolean;
|
|
13
|
+
wallet: wallet | null | undefined;
|
|
14
|
+
DebugConnectButton: () => React.ReactNode;
|
|
15
|
+
isEmbeddedWallet: boolean;
|
|
16
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
|
|
3
|
+
import { defineChain, type ThirdwebClient } from "thirdweb";
|
|
4
|
+
import {
|
|
5
|
+
ConnectButton,
|
|
6
|
+
useActiveAccount,
|
|
7
|
+
useActiveWallet,
|
|
8
|
+
useAutoConnect,
|
|
9
|
+
useConnectModal as useTwConnectModal,
|
|
10
|
+
useDisconnect as useTwDisconnect,
|
|
11
|
+
useWalletInfo,
|
|
12
|
+
} from "thirdweb/react";
|
|
13
|
+
import {
|
|
14
|
+
type Account,
|
|
15
|
+
type AutoConnectProps,
|
|
16
|
+
createWallet,
|
|
17
|
+
getInstalledWallets,
|
|
18
|
+
type Wallet,
|
|
19
|
+
} from "thirdweb/wallets";
|
|
20
|
+
import type { Chain } from "viem";
|
|
21
|
+
import { useConnect } from "wagmi";
|
|
22
|
+
|
|
23
|
+
import { defaultChainId, publicJsonRpcUrl } from "@berachain/config/internal";
|
|
24
|
+
|
|
25
|
+
import { chain } from "~/config";
|
|
26
|
+
import type { UseWalletProviderReturnType } from "./types";
|
|
27
|
+
|
|
28
|
+
const installedWallets = getInstalledWallets();
|
|
29
|
+
const wallets = [
|
|
30
|
+
...installedWallets,
|
|
31
|
+
createWallet("io.rabby"),
|
|
32
|
+
createWallet("io.metamask"),
|
|
33
|
+
createWallet("com.coinbase.wallet"),
|
|
34
|
+
createWallet("walletConnect"),
|
|
35
|
+
].filter((w, index, self) => self.findIndex((t) => t.id === w.id) === index);
|
|
36
|
+
|
|
37
|
+
const thirdwebChain = defineChain({
|
|
38
|
+
id: chain.id,
|
|
39
|
+
blockExplorers: chain.blockExplorers,
|
|
40
|
+
blockTime: chain.blockTime,
|
|
41
|
+
ensTlds: chain.ensTlds,
|
|
42
|
+
testnet: chain.testnet,
|
|
43
|
+
contracts: chain.contracts,
|
|
44
|
+
nativeCurrency: chain.nativeCurrency,
|
|
45
|
+
name: chain.name,
|
|
46
|
+
rpcUrls: {
|
|
47
|
+
default: {
|
|
48
|
+
http: [publicJsonRpcUrl],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export function useThirdweb({
|
|
54
|
+
isEmbeddedWalletsEnabled,
|
|
55
|
+
theme,
|
|
56
|
+
extenalChains,
|
|
57
|
+
thirdwebClient,
|
|
58
|
+
}: {
|
|
59
|
+
isEmbeddedWalletsEnabled: boolean;
|
|
60
|
+
theme: "light" | "dark" | "auto" | undefined;
|
|
61
|
+
extenalChains: Chain[];
|
|
62
|
+
thirdwebClient: ThirdwebClient;
|
|
63
|
+
}): UseWalletProviderReturnType<Account> {
|
|
64
|
+
const { connectors, connect: wagmiConnect } = useConnect();
|
|
65
|
+
|
|
66
|
+
const activeWallet = useActiveWallet();
|
|
67
|
+
const activeAccount = useActiveAccount(); // thirdweb
|
|
68
|
+
const { disconnect: disconnectThirdweb } = useTwDisconnect();
|
|
69
|
+
const { data: walletInfo } = useWalletInfo(activeWallet?.id);
|
|
70
|
+
|
|
71
|
+
const connectOptions = {
|
|
72
|
+
client: thirdwebClient,
|
|
73
|
+
chain: thirdwebChain,
|
|
74
|
+
wallets: isEmbeddedWalletsEnabled ? undefined : wallets,
|
|
75
|
+
} as const satisfies AutoConnectProps;
|
|
76
|
+
|
|
77
|
+
async function syncConnectedWallet(wallet: Wallet) {
|
|
78
|
+
// console.debug("syncConnectedWallet", wallet);
|
|
79
|
+
// now "connect" the wagmi connector
|
|
80
|
+
const twConnector = connectors.find((c) => c.id === "in-app-wallet");
|
|
81
|
+
|
|
82
|
+
if (twConnector) {
|
|
83
|
+
const options: ConnectionOptions = {
|
|
84
|
+
withCapabilities: true,
|
|
85
|
+
wallet,
|
|
86
|
+
} as const;
|
|
87
|
+
|
|
88
|
+
wagmiConnect({
|
|
89
|
+
connector: twConnector,
|
|
90
|
+
chainId: defaultChainId,
|
|
91
|
+
...options,
|
|
92
|
+
});
|
|
93
|
+
} else {
|
|
94
|
+
// captureException is not available here since we don't have shared-ui
|
|
95
|
+
// however this happens only if wagmi is misconfigured
|
|
96
|
+
console.error("no tw connector found");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { isLoading: isAutoConnecting } = useAutoConnect({
|
|
101
|
+
...connectOptions,
|
|
102
|
+
onConnect: syncConnectedWallet,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const connectionId = useMemo(() => {
|
|
106
|
+
return crypto.randomUUID();
|
|
107
|
+
}, [activeWallet?.id, activeAccount?.address]);
|
|
108
|
+
|
|
109
|
+
const { connect: twConnectModal } = useTwConnectModal();
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
async connect() {
|
|
113
|
+
const wallet = await twConnectModal({
|
|
114
|
+
...connectOptions,
|
|
115
|
+
theme: theme === "auto" ? undefined : theme,
|
|
116
|
+
chains: [
|
|
117
|
+
thirdwebChain,
|
|
118
|
+
...extenalChains.map((c) =>
|
|
119
|
+
defineChain({
|
|
120
|
+
id: c.id,
|
|
121
|
+
}),
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
}); // opens the connect modal
|
|
125
|
+
|
|
126
|
+
await syncConnectedWallet(wallet);
|
|
127
|
+
},
|
|
128
|
+
disconnect() {
|
|
129
|
+
if (activeWallet) {
|
|
130
|
+
disconnectThirdweb(activeWallet);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
isConnecting: isAutoConnecting,
|
|
134
|
+
connectionId,
|
|
135
|
+
connectorName: walletInfo?.name ?? null,
|
|
136
|
+
isEmbeddedWallet: walletInfo?.id === "inApp",
|
|
137
|
+
wallet: activeAccount,
|
|
138
|
+
DebugConnectButton() {
|
|
139
|
+
return (
|
|
140
|
+
<ConnectButton
|
|
141
|
+
{...connectOptions}
|
|
142
|
+
onConnect={(wallet) => syncConnectedWallet(wallet)}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConnectorClient, getWalletClient, switchChain } from "@wagmi/core";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type UsePublicClientParameters,
|
|
3
|
+
type UsePublicClientReturnType,
|
|
4
|
+
usePublicClient as useClient,
|
|
5
|
+
} from "wagmi";
|
|
6
|
+
|
|
7
|
+
import { defaultChainId } from "@berachain/config/internal";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
useBlockNumber,
|
|
11
|
+
useChains,
|
|
12
|
+
useConfig,
|
|
13
|
+
useEnsAvatar,
|
|
14
|
+
useEnsName,
|
|
15
|
+
useSwitchChain,
|
|
16
|
+
useTransactionReceipt,
|
|
17
|
+
} from "wagmi";
|
|
18
|
+
|
|
19
|
+
export { useBeraWagmi } from "../context/BeraWagmi";
|
|
20
|
+
export { useBeraAccount } from "./useBeraAccounts";
|
|
21
|
+
export { useBeraWallet } from "./useBeraWallet";
|
|
22
|
+
|
|
23
|
+
export function usePublicClient(
|
|
24
|
+
args?: UsePublicClientParameters,
|
|
25
|
+
): UsePublicClientReturnType {
|
|
26
|
+
const { chainId, ...rest } = args ?? {};
|
|
27
|
+
return useClient({ chainId: chainId ?? defaultChainId, ...rest });
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BeraWagmiApi, useBeraWagmi } from "~/context/BeraWagmi";
|
|
2
|
+
|
|
3
|
+
export function useBeraAccount(): Partial<
|
|
4
|
+
NonNullable<BeraWagmiApi["account"]>
|
|
5
|
+
> & { isConnected: boolean } {
|
|
6
|
+
const { account, isConnected } = useBeraWagmi();
|
|
7
|
+
return { ...account, isConnected };
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { LightweightAccountContext } from "~/context/LightweightAccountProvider";
|
|
4
|
+
|
|
5
|
+
export function useBeraWallet() {
|
|
6
|
+
const context = useContext(LightweightAccountContext);
|
|
7
|
+
|
|
8
|
+
if (!context) {
|
|
9
|
+
throw new Error("LightweightAccountContext not found");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { address } = context;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
isConnected: !!address,
|
|
16
|
+
address,
|
|
17
|
+
} as const;
|
|
18
|
+
}
|
package/dist/chunk-44WGYPR4.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _wagmiadapter = require('@thirdweb-dev/wagmi-adapter');var _thirdweb = require('thirdweb');var _wallets = require('thirdweb/wallets');var _chains = require('viem/chains');var _wagmi = require('wagmi');var _internal = require('@berachain/config/internal');var A=_thirdweb.createThirdwebClient.call(void 0, {clientId:_internal.appConfig.apiKeys.public.thirdweb}),b= exports.b ={mode:"EIP7702",sponsorGas:!0},G= exports.c =_wallets.inAppWallet.call(void 0, {executionMode:b}),m= exports.d =_internal.chainId===_chains.berachain.id?_chains.berachain:_chains.berachainBepolia,r= exports.e ={chain:m},U=!!_optionalChain([m, 'access', _ => _.contracts, 'optionalAccess', _2 => _2.multicall3]),u= exports.f =[_chains.mainnet,_chains.polygon,_chains.optimism,_chains.base,_chains.bsc,_chains.arbitrum,_chains.avalanche],K= exports.g =[...u,_chains.berachain,_chains.berachainBepolia].reduce((e,t)=>(e[t.id]=t.name,e),{}),M={[_chains.mainnet.id]:["https://1.rpc.thirdweb.com/","https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/"],[_chains.polygon.id]:["https://137.rpc.thirdweb.com/","https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/"],[_chains.optimism.id]:["https://10.rpc.thirdweb.com/","https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/"],[_chains.base.id]:["https://8453.rpc.thirdweb.com/","https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/"],[_chains.bsc.id]:["https://56.rpc.thirdweb.com/","https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/"],[_chains.avalanche.id]:["https://43114.rpc.thirdweb.com/","https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/"],[_chains.arbitrum.id]:["https://42161.rpc.thirdweb.com/","https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/"]},P= exports.h =_wagmi.createConfig.call(void 0, {chains:[r.chain,...u],ssr:!0,connectors:[_wagmiadapter.inAppWalletConnector.call(void 0, {client:A,executionMode:b})],storage:_wagmi.createStorage.call(void 0, {key:"wagmi-berachain-thirdweb",storage:typeof window<"u"?localStorage:void 0}),batch:{multicall:U?{wait:15}:void 0},transports:{[r.chain.id]:_wagmi.fallback.call(void 0, [_internal.privateRcpUrl,_internal.jsonRpcUrl,_internal.alchemyJsonRpcUrl,_internal.publicJsonRpcUrl].filter(e=>e).map(e=>_wagmi.http.call(void 0, e,{batch:{wait:35}}))),...Object.entries(M).reduce((e,[t,C])=>(e[Number(t)]=_wagmi.fallback.call(void 0, [...C,void 0].map(w=>_wagmi.http.call(void 0, w,{batch:{wait:15}}))),e),{})}});exports.a = A; exports.b = b; exports.c = G; exports.d = m; exports.e = r; exports.f = u; exports.g = K; exports.h = P;
|
package/dist/chunk-5IUBG6AE.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as R,d as o,h as L}from"./chunk-G47GYZCF.mjs";import{usePublicClient as Se}from"wagmi";import{defaultChainId as De}from"@berachain/config/internal";import{useBlockNumber as Wt,useChains as wt,useConfig as vt,useEnsAvatar as z,useEnsName as M,useSwitchChain as xt,useTransactionReceipt as yt}from"wagmi";import{createContext as pe,useContext as fe,useMemo as p}from"react";import Ce from"swr/immutable";import{arbitrum as he,avalanche as ge,base as be,bsc as Ae,mainnet as We,optimism as we,polygon as ve}from"viem/chains";import{normalize as xe}from"viem/ens";import{useAccount as ye,useCapabilities as Pe,useDisconnect as Be,usePublicClient as Ie,useWalletClient as Ee}from"wagmi";import{defaultChainId as I}from"@berachain/config/internal";import{isFlagEnabled as Te}from"@berachain/config/internal/edge-config";import{createContext as X}from"react";import{jsx as Y}from"react/jsx-runtime";var B=X(void 0);function U({children:e,address:t}){return Y(B.Provider,{value:{address:t},children:e})}import{useMemo as Z}from"react";import{defineChain as k}from"thirdweb";import{ConnectButton as $,useActiveAccount as ee,useActiveWallet as te,useAutoConnect as ne,useConnectModal as oe,useDisconnect as ie,useWalletInfo as ae}from"thirdweb/react";import{createWallet as g,getInstalledWallets as re}from"thirdweb/wallets";import{useConnect as se}from"wagmi";import{defaultChainId as ce,publicJsonRpcUrl as le}from"@berachain/config/internal";import{jsx as me}from"react/jsx-runtime";var de=re(),ue=[...de,g("io.rabby"),g("io.metamask"),g("com.coinbase.wallet"),g("walletConnect")].filter((e,t,n)=>n.findIndex(i=>i.id===e.id)===t),N=k({id:o.id,blockExplorers:o.blockExplorers,blockTime:o.blockTime,ensTlds:o.ensTlds,testnet:o.testnet,contracts:o.contracts,nativeCurrency:o.nativeCurrency,name:o.name,rpcUrls:{default:{http:[le]}}});function S({isEmbeddedWalletsEnabled:e,theme:t,extenalChains:n}){let{connectors:i,connect:b}=se(),a=te(),A=ee(),{disconnect:W}=ie(),{data:u}=ae(a?.id),l={client:R,chain:N,wallets:e?void 0:ue};async function r(s){let d=i.find(f=>f.id==="in-app-wallet");d?b({connector:d,chainId:ce,...{withCapabilities:!0,wallet:s}}):console.error("no tw connector found")}let{isLoading:w}=ne({...l,onConnect:r}),v=Z(()=>crypto.randomUUID(),[a?.id,A?.address]),{connect:x}=oe();return{async connect(){let s=await x({...l,theme:t==="auto"?void 0:t,chains:[N,...n.map(d=>k({id:d.id}))]});await r(s)},disconnect(){a&&W(a)},isConnecting:w,connectionId:v,connectorName:u?.name??null,isEmbeddedWallet:u?.id==="inApp",wallet:A,DebugConnectButton(){return me($,{...l,onConnect:s=>r(s)})}}}import{jsx as D}from"react/jsx-runtime";function E(){let e=fe(_);if(!e)throw new Error("BeraWagmiContext not found");return e}var _=pe(void 0),Re=[We,ve,we,be,Ae,ge,he];function Le({externalChainList:e}){return Re.filter(t=>{let n=e?.find(i=>i.chainId===t.id);return!n||Te(n.enabled)})}function st({children:e,isEmbeddedWalletsEnabled:t,disableEip5792:n,disable5792Upgrade:i,theme:b,accountOverride:a,onConnectedWallet:A,onSmartAccountRejection:W,edgeConfigChainList:u}){let l=p(()=>Le({externalChainList:u}),[u]),{wallet:r,connect:w,DebugConnectButton:v,connectionId:x,disconnect:s,connectorName:d,isEmbeddedWallet:f,isConnecting:O}=S({isEmbeddedWalletsEnabled:t,theme:b,extenalChains:l}),{address:C,chainId:y}=ye(),{disconnect:G}=Be(),q=Ie(),c=p(()=>{if(!(!C||!r))return a??C},[a,C,r]),{data:m}=Pe({account:C,scopeKey:x,query:{retry:3}}),F=p(()=>n||!m?!1:m?.[I]?.atomic?.status==="supported"||!i&&m?.[I]?.atomic?.status==="ready",[m,n,i]),{data:h}=M({config:L,chainId:I,address:c}),{data:P}=Ce(c?["BeraWagmiProvider_code",c,y]:null,([Q,V,ze])=>q?.getCode({address:V}),{refreshInterval:6e4}),[J,K]=p(()=>P?P.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[P]),{data:T}=Ee(),j=p(()=>{try{return h?xe(h):void 0}catch{}},[h]),H=z({name:j});return D(_.Provider,{value:{walletClient:T,onSmartAccountRejection:()=>{W?.()},isEmbeddedWalletsEnabled:t,isConnecting:O,isConnected:!!c&&!!T,DebugConnectButton:v,account:r&&y&&c?{chainId:y,connectorName:d,isEmbeddedWallet:f,capabilities:m,flags:{supportsAtomic:F},wallet:{address:c,ensName:h??null,ensAvatar:H.data??null,has7702Authorization:K,isContract:J}}:void 0,connectWallet:async()=>{console.log("connectWallet.called"),await w()},disconnect:()=>{G(),s()},externalChainList:l},children:D(U,{address:c,children:e})})}function Ue(){let{account:e,isConnected:t}=E();return{...e,isConnected:t}}import{useContext as Ne}from"react";function ke(){let e=Ne(B);if(!e)throw new Error("LightweightAccountContext not found");let{address:t}=e;return{isConnected:!!t,address:t}}function gt(e){let{chainId:t,...n}=e??{};return Se({chainId:t??De,...n})}export{Ue as a,ke as b,gt as c,Wt as d,wt as e,vt as f,z as g,M as h,xt as i,yt as j,E as k,st as l};
|
package/dist/chunk-G47GYZCF.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{inAppWalletConnector as g}from"@thirdweb-dev/wagmi-adapter";import{createThirdwebClient as k}from"thirdweb";import{inAppWallet as x}from"thirdweb/wallets";import{arbitrum as n,avalanche as c,base as p,berachain as i,berachainBepolia as s,bsc as d,mainnet as l,optimism as h,polygon as f}from"viem/chains";import{createConfig as y,createStorage as R,fallback as o,http as a}from"wagmi";import{alchemyJsonRpcUrl as q,appConfig as N,chainId as I,jsonRpcUrl as T,privateRcpUrl as W,publicJsonRpcUrl as v}from"@berachain/config/internal";var A=k({clientId:N.apiKeys.public.thirdweb}),b={mode:"EIP7702",sponsorGas:!0},G=x({executionMode:b}),m=I===i.id?i:s,r={chain:m},U=!!m.contracts?.multicall3,u=[l,f,h,p,d,n,c],K=[...u,i,s].reduce((e,t)=>(e[t.id]=t.name,e),{}),M={[l.id]:["https://1.rpc.thirdweb.com/","https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/"],[f.id]:["https://137.rpc.thirdweb.com/","https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/"],[h.id]:["https://10.rpc.thirdweb.com/","https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/"],[p.id]:["https://8453.rpc.thirdweb.com/","https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/"],[d.id]:["https://56.rpc.thirdweb.com/","https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/"],[c.id]:["https://43114.rpc.thirdweb.com/","https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/"],[n.id]:["https://42161.rpc.thirdweb.com/","https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/"]},P=y({chains:[r.chain,...u],ssr:!0,connectors:[g({client:A,executionMode:b})],storage:R({key:"wagmi-berachain-thirdweb",storage:typeof window<"u"?localStorage:void 0}),batch:{multicall:U?{wait:15}:void 0},transports:{[r.chain.id]:o([W,T,q,v].filter(e=>e).map(e=>a(e,{batch:{wait:35}}))),...Object.entries(M).reduce((e,[t,C])=>(e[Number(t)]=o([...C,void 0].map(w=>a(w,{batch:{wait:15}}))),e),{})}});export{A as a,b,G as c,m as d,r as e,u as f,K as g,P as h};
|
package/dist/chunk-GVIEHLWT.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk44WGYPR4cjs = require('./chunk-44WGYPR4.cjs');var _wagmi = require('wagmi');var _internal = require('@berachain/config/internal');var _react = require('react');var _immutable = require('swr/immutable'); var _immutable2 = _interopRequireDefault(_immutable);var _chains = require('viem/chains');var _ens = require('viem/ens');var _edgeconfig = require('@berachain/config/internal/edge-config');var _jsxruntime = require('react/jsx-runtime');var B=_react.createContext.call(void 0, void 0);function U({children:e,address:t}){return _jsxruntime.jsx.call(void 0, B.Provider,{value:{address:t},children:e})}var _thirdweb = require('thirdweb');var _react3 = require('thirdweb/react');var _wallets = require('thirdweb/wallets');var de=_wallets.getInstalledWallets.call(void 0, ),ue=[...de,_wallets.createWallet.call(void 0, "io.rabby"),_wallets.createWallet.call(void 0, "io.metamask"),_wallets.createWallet.call(void 0, "com.coinbase.wallet"),_wallets.createWallet.call(void 0, "walletConnect")].filter((e,t,n)=>n.findIndex(i=>i.id===e.id)===t),N=_thirdweb.defineChain.call(void 0, {id:_chunk44WGYPR4cjs.d.id,blockExplorers:_chunk44WGYPR4cjs.d.blockExplorers,blockTime:_chunk44WGYPR4cjs.d.blockTime,ensTlds:_chunk44WGYPR4cjs.d.ensTlds,testnet:_chunk44WGYPR4cjs.d.testnet,contracts:_chunk44WGYPR4cjs.d.contracts,nativeCurrency:_chunk44WGYPR4cjs.d.nativeCurrency,name:_chunk44WGYPR4cjs.d.name,rpcUrls:{default:{http:[_internal.publicJsonRpcUrl]}}});function S({isEmbeddedWalletsEnabled:e,theme:t,extenalChains:n}){let{connectors:i,connect:b}=_wagmi.useConnect.call(void 0, ),a=_react3.useActiveWallet.call(void 0, ),A=_react3.useActiveAccount.call(void 0, ),{disconnect:W}=_react3.useDisconnect.call(void 0, ),{data:u}=_react3.useWalletInfo.call(void 0, _optionalChain([a, 'optionalAccess', _2 => _2.id])),l={client:_chunk44WGYPR4cjs.a,chain:N,wallets:e?void 0:ue};async function r(s){let d=i.find(f=>f.id==="in-app-wallet");d?b({connector:d,chainId:_internal.defaultChainId,...{withCapabilities:!0,wallet:s}}):console.error("no tw connector found")}let{isLoading:w}=_react3.useAutoConnect.call(void 0, {...l,onConnect:r}),v=_react.useMemo.call(void 0, ()=>crypto.randomUUID(),[_optionalChain([a, 'optionalAccess', _3 => _3.id]),_optionalChain([A, 'optionalAccess', _4 => _4.address])]),{connect:x}=_react3.useConnectModal.call(void 0, );return{async connect(){let s=await x({...l,theme:t==="auto"?void 0:t,chains:[N,...n.map(d=>_thirdweb.defineChain.call(void 0, {id:d.id}))]});await r(s)},disconnect(){a&&W(a)},isConnecting:w,connectionId:v,connectorName:_nullishCoalesce(_optionalChain([u, 'optionalAccess', _5 => _5.name]), () => (null)),isEmbeddedWallet:_optionalChain([u, 'optionalAccess', _6 => _6.id])==="inApp",wallet:A,DebugConnectButton(){return _jsxruntime.jsx.call(void 0, _react3.ConnectButton,{...l,onConnect:s=>r(s)})}}}function E(){let e=_react.useContext.call(void 0, _);if(!e)throw new Error("BeraWagmiContext not found");return e}var _=_react.createContext.call(void 0, void 0),Re=[_chains.mainnet,_chains.polygon,_chains.optimism,_chains.base,_chains.bsc,_chains.avalanche,_chains.arbitrum];function Le({externalChainList:e}){return Re.filter(t=>{let n=_optionalChain([e, 'optionalAccess', _7 => _7.find, 'call', _8 => _8(i=>i.chainId===t.id)]);return!n||_edgeconfig.isFlagEnabled.call(void 0, n.enabled)})}function st({children:e,isEmbeddedWalletsEnabled:t,disableEip5792:n,disable5792Upgrade:i,theme:b,accountOverride:a,onConnectedWallet:A,onSmartAccountRejection:W,edgeConfigChainList:u}){let l=_react.useMemo.call(void 0, ()=>Le({externalChainList:u}),[u]),{wallet:r,connect:w,DebugConnectButton:v,connectionId:x,disconnect:s,connectorName:d,isEmbeddedWallet:f,isConnecting:O}=S({isEmbeddedWalletsEnabled:t,theme:b,extenalChains:l}),{address:C,chainId:y}=_wagmi.useAccount.call(void 0, ),{disconnect:G}=_wagmi.useDisconnect.call(void 0, ),q=_wagmi.usePublicClient.call(void 0, ),c=_react.useMemo.call(void 0, ()=>{if(!(!C||!r))return _nullishCoalesce(a, () => (C))},[a,C,r]),{data:m}=_wagmi.useCapabilities.call(void 0, {account:C,scopeKey:x,query:{retry:3}}),F=_react.useMemo.call(void 0, ()=>n||!m?!1:_optionalChain([m, 'optionalAccess', _9 => _9[_internal.defaultChainId], 'optionalAccess', _10 => _10.atomic, 'optionalAccess', _11 => _11.status])==="supported"||!i&&_optionalChain([m, 'optionalAccess', _12 => _12[_internal.defaultChainId], 'optionalAccess', _13 => _13.atomic, 'optionalAccess', _14 => _14.status])==="ready",[m,n,i]),{data:h}=_wagmi.useEnsName.call(void 0, {config:_chunk44WGYPR4cjs.h,chainId:_internal.defaultChainId,address:c}),{data:P}=_immutable2.default.call(void 0, c?["BeraWagmiProvider_code",c,y]:null,([Q,V,ze])=>_optionalChain([q, 'optionalAccess', _15 => _15.getCode, 'call', _16 => _16({address:V})]),{refreshInterval:6e4}),[J,K]=_react.useMemo.call(void 0, ()=>P?P.startsWith("0xef01")?[!1,!0]:[!0,!1]:[!1,!1],[P]),{data:T}=_wagmi.useWalletClient.call(void 0, ),j=_react.useMemo.call(void 0, ()=>{try{return h?_ens.normalize.call(void 0, h):void 0}catch (e2){}},[h]),H=_wagmi.useEnsAvatar.call(void 0, {name:j});return _jsxruntime.jsx.call(void 0, _.Provider,{value:{walletClient:T,onSmartAccountRejection:()=>{_optionalChain([W, 'optionalCall', _17 => _17()])},isEmbeddedWalletsEnabled:t,isConnecting:O,isConnected:!!c&&!!T,DebugConnectButton:v,account:r&&y&&c?{chainId:y,connectorName:d,isEmbeddedWallet:f,capabilities:m,flags:{supportsAtomic:F},wallet:{address:c,ensName:_nullishCoalesce(h, () => (null)),ensAvatar:_nullishCoalesce(H.data, () => (null)),has7702Authorization:K,isContract:J}}:void 0,connectWallet:async()=>{console.log("connectWallet.called"),await w()},disconnect:()=>{G(),s()},externalChainList:l},children:_jsxruntime.jsx.call(void 0, U,{address:c,children:e})})}function Ue(){let{account:e,isConnected:t}=E();return{...e,isConnected:t}}function ke(){let e=_react.useContext.call(void 0, B);if(!e)throw new Error("LightweightAccountContext not found");let{address:t}=e;return{isConnected:!!t,address:t}}function gt(e){let{chainId:t,...n}=_nullishCoalesce(e, () => ({}));return _wagmi.usePublicClient.call(void 0, {chainId:_nullishCoalesce(t, () => (_internal.defaultChainId)),...n})}exports.a = Ue; exports.b = ke; exports.c = gt; exports.d = _wagmi.useBlockNumber; exports.e = _wagmi.useChains; exports.f = _wagmi.useConfig; exports.g = _wagmi.useEnsAvatar; exports.h = _wagmi.useEnsName; exports.i = _wagmi.useSwitchChain; exports.j = _wagmi.useTransactionReceipt; exports.k = E; exports.l = st;
|