Skip to content

Commit 1fccda8

Browse files
committed
clean up
1 parent 83a858d commit 1fccda8

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

src/App.tsx

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./styles/App.css";
22

33
import { Porto } from "porto";
4-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4+
import { useCallback, useEffect, useRef, useState } from "react";
55
import {
66
type Address,
77
type Chain,
@@ -48,45 +48,8 @@ export function App() {
4848
const [lastTxReceipt, setLastTxReceipt] = useState<TransactionReceipt | null>(null);
4949
const [lastTxHash, setLastTxHash] = useState<string | null>(null);
5050

51-
const lastPendingIdRef = useRef<string | null>(null);
5251
const prevSelectedUuidRef = useRef<string | null>(null);
5352

54-
const walletClient = useMemo(() => {
55-
if (!selected) return undefined;
56-
return createWalletClient({
57-
transport: custom(selected.provider),
58-
chain: chain ?? undefined,
59-
});
60-
}, [selected, chain]);
61-
62-
const ensureServerConnected = useCallback(async () => {
63-
try {
64-
const resp = await api<
65-
ApiOk<{ connected: boolean; account?: string; chainId?: number }> | ApiErr
66-
>("/api/connection");
67-
68-
if (!isOk(resp)) return;
69-
70-
const serverConnected = !!resp.data?.connected;
71-
const serverAccount = (resp.data?.account as string | undefined)?.toLowerCase();
72-
const serverChainId = resp.data?.chainId as number | undefined;
73-
74-
if (!account || chainId == null) {
75-
if (serverConnected) {
76-
await api("/api/connection", "POST", null);
77-
}
78-
} else {
79-
if (
80-
!serverConnected ||
81-
serverAccount !== account.toLowerCase() ||
82-
serverChainId !== chainId
83-
) {
84-
await api("/api/connection", "POST", [account, chainId]);
85-
}
86-
}
87-
} catch {}
88-
}, [account, chainId]);
89-
9053
const connect = async () => {
9154
if (!selected || confirmed) return;
9255

@@ -119,7 +82,12 @@ export function App() {
11982
};
12083

12184
const signAndSendCurrent = async () => {
122-
if (!walletClient || !selected || !pending?.request) return;
85+
if (!selected || !pending?.request) return;
86+
87+
const walletClient = createWalletClient({
88+
transport: custom(selected.provider),
89+
chain: chain ?? undefined,
90+
});
12391

12492
try {
12593
const hash = (await selected.provider.request({
@@ -161,7 +129,6 @@ export function App() {
161129
setPending(null);
162130
setLastTxHash(null);
163131
setLastTxReceipt(null);
164-
lastPendingIdRef.current = null;
165132

166133
setAccount(undefined);
167134
setChainId(undefined);

src/styles/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
border: 1px solid #e1e4e8;
5353
border-radius: 8px;
5454
padding: 8px 12px;
55-
}
55+
}

0 commit comments

Comments
 (0)