@berachain/wagmi 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Berachain Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,100 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { Address, GetCapabilitiesReturnType, Chain } from 'viem';
3
+ import { UseWalletClientReturnType } from 'wagmi';
4
+ import { EdgeConfigSchema } from '@berachain/config/internal/edge-config';
5
+
6
+ declare function useBeraWagmi(): BeraWagmiApi;
7
+ interface BeraWagmiApi {
8
+ /**
9
+ * @deprecated used for prototyping only.
10
+ */
11
+ DebugConnectButton: () => React.ReactNode;
12
+ /**
13
+ * Account connected to berachain dapp. It might include some additional data once embedded wallets are enabled.
14
+ */
15
+ account: {
16
+ /**
17
+ * Chain ID to which the wallet provider is currently connected to.
18
+ */
19
+ chainId: number;
20
+ /**
21
+ * Whether the wallet is an embedded wallet.
22
+ */
23
+ isEmbeddedWallet: boolean;
24
+ connectorName: string | null;
25
+ flags: {
26
+ supportsAtomic: boolean;
27
+ };
28
+ /**
29
+ * Wallet provider capabilities for the current account.
30
+ *
31
+ * Status can be:
32
+ * - supported: User has enabled the feature.
33
+ * - ready: The wallet provider is ready to use the feature.
34
+ * - unsupported: The wallet provider does not support the feature.
35
+ */
36
+ capabilities: GetCapabilitiesReturnType | undefined;
37
+ /**
38
+ * Wallet to display.
39
+ *
40
+ * This might be manually overridden by the accountOverride prop, thus not being the same as the connected wallet.
41
+ */
42
+ wallet: {
43
+ address: Address;
44
+ /**
45
+ * ENS name of the wallet.
46
+ */
47
+ ensName: string | null;
48
+ /**
49
+ * ENS avatar of the wallet.
50
+ */
51
+ ensAvatar: string | null;
52
+ /**
53
+ * Whether the wallet has 7702 authorization.
54
+ */
55
+ has7702Authorization: boolean;
56
+ /**
57
+ * Whether the wallet is a contract.
58
+ */
59
+ isContract: boolean;
60
+ } | undefined;
61
+ } | undefined;
62
+ isEmbeddedWalletsEnabled: boolean;
63
+ isConnected: boolean;
64
+ isConnecting: boolean;
65
+ walletClient: UseWalletClientReturnType["data"];
66
+ connectWallet: () => Promise<void> | void;
67
+ disconnect(): void;
68
+ /**
69
+ * A callback that is called when a smart account upgrade is rejected.
70
+ *
71
+ * This is used to disable EIP-5792 temporarily.
72
+ */
73
+ onSmartAccountRejection: () => void;
74
+ /**
75
+ * List of external chains that are whitelisted for that app.
76
+ */
77
+ externalChainList: Chain[];
78
+ }
79
+ interface IBeraWagmiProviderProps extends PropsWithChildren {
80
+ theme?: "dark" | "light" | "auto";
81
+ isEmbeddedWalletsEnabled: boolean;
82
+ disableEip5792: boolean;
83
+ /**
84
+ * Whether to disable the 5792 upgrade for users that haven't upgraded yet.
85
+ *
86
+ * `atomic.status === "ready"`
87
+ */
88
+ disable5792Upgrade?: boolean;
89
+ accountOverride?: Address;
90
+ onSmartAccountRejection?: () => void;
91
+ edgeConfigChainList: EdgeConfigSchema["wagmi"]["externalChainList"];
92
+ /**
93
+ * Event triggered when a wallet is connected manually.
94
+ *
95
+ * This is not triggered when a wallet connect automatically after a refresh.
96
+ */
97
+ onConnectedWallet?: () => void;
98
+ }
99
+
100
+ export { type BeraWagmiApi as B, type IBeraWagmiProviderProps as I, useBeraWagmi as u };
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,27 @@
1
+ import * as thirdweb from 'thirdweb';
2
+ import { inAppWallet } from 'thirdweb/wallets';
3
+ import { Chain } from 'viem';
4
+ import { Config } from 'wagmi';
5
+
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
+ /**
13
+ * Using default viem chain definition since it also includes ens and other metadata
14
+ */
15
+ declare const chain: Chain;
16
+ declare const defaultBeraNetworkConfig: NetworkConfig;
17
+ interface NetworkConfig {
18
+ chain: Chain;
19
+ }
20
+ /**
21
+ * Exporting this is helpful for the multi-chain zap, to get the list of chains that we want to support.
22
+ */
23
+ declare const externalChains: Chain[];
24
+ declare const chainIdToName: Record<Chain["id"], string>;
25
+ declare const wagmiConfig: Config;
26
+
27
+ export { type NetworkConfig, chain, chainIdToName, defaultBeraNetworkConfig, executionMode, externalChains, thirdwebClient, thirdwebWallet, wagmiConfig };
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h}from"../chunk-G47GYZCF.mjs";export{d as chain,g as chainIdToName,e as defaultBeraNetworkConfig,b as executionMode,f as externalChains,a as thirdwebClient,c as thirdwebWallet,h as wagmiConfig};
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I as IBeraWagmiProviderProps } from '../BeraWagmi-B79qATYX.js';
3
+ import 'react';
4
+ import 'viem';
5
+ import 'wagmi';
6
+ import '@berachain/config/internal/edge-config';
7
+
8
+ declare function WagmiProvider({ ...beraWagmiProps }: IBeraWagmiProviderProps): react_jsx_runtime.JSX.Element;
9
+
10
+ export { WagmiProvider };
@@ -0,0 +1 @@
1
+ "use client";import{l as i}from"../chunk-5IUBG6AE.mjs";import{h as e}from"../chunk-G47GYZCF.mjs";import{QueryClient as t,QueryClientProvider as m}from"@tanstack/react-query";import{Porto as n}from"porto";import{ThirdwebProvider as a}from"thirdweb/react";import{WagmiProvider as d}from"wagmi";import{jsx as r}from"react/jsx-runtime";var P=new t;n.create();function c({...o}){return r(a,{children:r(d,{config:e,reconnectOnMount:!1,children:r(m,{client:P,children:r(i,{...o})})})})}export{c as WagmiProvider};
@@ -0,0 +1 @@
1
+ export { getConnectorClient, getWalletClient, switchChain } from '@wagmi/core';
@@ -0,0 +1 @@
1
+ import{getConnectorClient as n,getWalletClient as i,switchChain as l}from"@wagmi/core";export{n as getConnectorClient,i as getWalletClient,l as switchChain};
@@ -0,0 +1,20 @@
1
+ import { UsePublicClientParameters, UsePublicClientReturnType } from 'wagmi';
2
+ export { useBlockNumber, useChains, useConfig, useEnsAvatar, useEnsName, useSwitchChain, useTransactionReceipt } from 'wagmi';
3
+ import { B as BeraWagmiApi } from '../BeraWagmi-B79qATYX.js';
4
+ export { u as useBeraWagmi } from '../BeraWagmi-B79qATYX.js';
5
+ import 'react';
6
+ import 'viem';
7
+ import '@berachain/config/internal/edge-config';
8
+
9
+ declare function useBeraAccount(): Partial<NonNullable<BeraWagmiApi["account"]>> & {
10
+ isConnected: boolean;
11
+ };
12
+
13
+ declare function useBeraWallet(): {
14
+ readonly isConnected: boolean;
15
+ readonly address: `0x${string}` | undefined;
16
+ };
17
+
18
+ declare function usePublicClient(args?: UsePublicClientParameters): UsePublicClientReturnType;
19
+
20
+ export { useBeraAccount, useBeraWallet, usePublicClient };
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-5IUBG6AE.mjs";import"../chunk-G47GYZCF.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 ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@berachain/wagmi",
3
+ "version": "0.1.0-alpha.0",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "./*": {
16
+ "types": "./dist/*/index.d.ts",
17
+ "import": "./dist/*/index.mjs",
18
+ "require": "./dist/*/index.cjs",
19
+ "default": "./dist/*/index.mjs"
20
+ }
21
+ },
22
+ "dependencies": {
23
+ "@react-native-async-storage/async-storage": "2.2.0",
24
+ "@tanstack/react-query": "5.59.0",
25
+ "@thirdweb-dev/wagmi-adapter": "0.2.193",
26
+ "@wagmi/core": "2.22.1",
27
+ "porto": "0.2.23",
28
+ "swr": "2.3.3",
29
+ "thirdweb": "5.114.1",
30
+ "viem": "2.41.2",
31
+ "wagmi": "2.19.5",
32
+ "@berachain/config": "0.0.5"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^19.1",
36
+ "react-dom": "^19.1"
37
+ },
38
+ "keywords": [],
39
+ "author": "Berachain",
40
+ "license": "MIT",
41
+ "devDependencies": {
42
+ "@types/node": "22.12.0",
43
+ "@types/react": "19.1.8",
44
+ "tsup": "8.4.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsup",
48
+ "clean": "git clean -xdf dist .turbo node_modules",
49
+ "check-types": "tsup --dtsOnly",
50
+ "lint": "biome lint",
51
+ "dev": "tsup --watch"
52
+ }
53
+ }