|
1 | 1 | import "./styles/App.css"; |
2 | 2 |
|
3 | 3 | import { Porto } from "porto"; |
4 | | -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; |
| 4 | +import { useCallback, useEffect, useRef, useState } from "react"; |
5 | 5 | import { |
6 | 6 | type Address, |
7 | 7 | type Chain, |
@@ -48,45 +48,8 @@ export function App() { |
48 | 48 | const [lastTxReceipt, setLastTxReceipt] = useState<TransactionReceipt | null>(null); |
49 | 49 | const [lastTxHash, setLastTxHash] = useState<string | null>(null); |
50 | 50 |
|
51 | | - const lastPendingIdRef = useRef<string | null>(null); |
52 | 51 | const prevSelectedUuidRef = useRef<string | null>(null); |
53 | 52 |
|
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 | | - |
90 | 53 | const connect = async () => { |
91 | 54 | if (!selected || confirmed) return; |
92 | 55 |
|
@@ -119,7 +82,12 @@ export function App() { |
119 | 82 | }; |
120 | 83 |
|
121 | 84 | 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 | + }); |
123 | 91 |
|
124 | 92 | try { |
125 | 93 | const hash = (await selected.provider.request({ |
@@ -161,7 +129,6 @@ export function App() { |
161 | 129 | setPending(null); |
162 | 130 | setLastTxHash(null); |
163 | 131 | setLastTxReceipt(null); |
164 | | - lastPendingIdRef.current = null; |
165 | 132 |
|
166 | 133 | setAccount(undefined); |
167 | 134 | setChainId(undefined); |
|
0 commit comments