Skip to content

Commit 4618acc

Browse files
fix: convert chainId better (#10)
* fix: convert chainId better * fix: prettier * fix: add readclient + number instead of parseint * fix: prettier
1 parent b7cd453 commit 4618acc

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

components/upProvider.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
createClientUPProvider,
2121
type UPClientProvider,
2222
} from "@lukso/up-provider";
23-
import { createWalletClient, custom } from "viem";
23+
import { createPublicClient, createWalletClient, custom } from "viem";
2424
import { lukso, luksoTestnet } from "viem/chains";
2525
import {
2626
createContext,
@@ -85,6 +85,16 @@ export function UpProvider({ children }: UpProviderProps) {
8585
return null;
8686
}, [chainId]);
8787

88+
const readClient = useMemo(() => {
89+
if (provider && chainId) {
90+
return createPublicClient({
91+
chain: chainId === 42 ? lukso : luksoTestnet,
92+
transport: custom(provider),
93+
});
94+
}
95+
return null;
96+
}, [chainId]);
97+
8898
useEffect(() => {
8999
let mounted = true;
90100

@@ -99,7 +109,9 @@ export function UpProvider({ children }: UpProviderProps) {
99109
if (!mounted) return;
100110
setAccounts(_accounts);
101111

102-
const _chainId = (await provider.request("eth_chainId")) as number;
112+
const _chainId = Number(
113+
(await provider.request("eth_chainId")) as string
114+
);
103115
if (!mounted) return;
104116
setChainId(_chainId);
105117

@@ -156,6 +168,7 @@ export function UpProvider({ children }: UpProviderProps) {
156168
provider,
157169
client,
158170
chainId,
171+
readClient,
159172
accounts,
160173
contextAccounts,
161174
walletConnected,
@@ -167,6 +180,7 @@ export function UpProvider({ children }: UpProviderProps) {
167180
}, [
168181
client,
169182
chainId,
183+
readClient,
170184
accounts,
171185
contextAccounts,
172186
walletConnected,

0 commit comments

Comments
 (0)