Skip to content

Commit 1994b8c

Browse files
authored
fix: multiple issues (#140)
* add warning for wrong network, and react max depth errors * code rabbit fixed valid issues * add wallet modal list for account page * change modal style and animate list * add hover effect to connect wallet button in modal * fix padding top issue on mobile * wallet logs for network * remove logs * show toast on console errors * reset wallet state on network mismatch * add toast to copy url for vpn link on mobil or desktop Signed-off-by: JaeBrian <[email protected]>
1 parent 3492591 commit 1994b8c

File tree

11 files changed

+724
-289
lines changed

11 files changed

+724
-289
lines changed

src/api/__tests__/client.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { describe, it, expect, beforeEach, vi } from "vitest";
22
import { apiClient, get, post, API_BASE_URL } from "../client";
33

4+
const createHeaders = (contentType: string) => ({
5+
get: (name: string) =>
6+
name.toLowerCase() === "content-type" ? contentType : null,
7+
});
8+
49
describe("API Client", () => {
510
beforeEach(() => {
611
vi.resetAllMocks();
@@ -11,6 +16,8 @@ describe("API Client", () => {
1116
const mockData = { message: "success" };
1217
global.fetch = vi.fn().mockResolvedValueOnce({
1318
ok: true,
19+
status: 200,
20+
headers: createHeaders("application/json"),
1421
json: async () => mockData,
1522
});
1623

@@ -30,6 +37,7 @@ describe("API Client", () => {
3037
ok: false,
3138
status: 404,
3239
statusText: "Not Found",
40+
headers: createHeaders("text/plain"),
3341
text: async () => "Resource not found",
3442
});
3543

@@ -52,6 +60,8 @@ describe("API Client", () => {
5260
const mockData = { data: "test" };
5361
global.fetch = vi.fn().mockResolvedValueOnce({
5462
ok: true,
63+
status: 200,
64+
headers: createHeaders("application/json"),
5565
json: async () => mockData,
5666
});
5767

@@ -76,6 +86,8 @@ describe("API Client", () => {
7686
const mockData = { id: 1, name: "test" };
7787
global.fetch = vi.fn().mockResolvedValueOnce({
7888
ok: true,
89+
status: 200,
90+
headers: createHeaders("application/json"),
7991
json: async () => mockData,
8092
});
8193

@@ -99,6 +111,8 @@ describe("API Client", () => {
99111

100112
global.fetch = vi.fn().mockResolvedValueOnce({
101113
ok: true,
114+
status: 200,
115+
headers: createHeaders("application/json"),
102116
json: async () => mockData,
103117
});
104118

@@ -120,6 +134,8 @@ describe("API Client", () => {
120134

121135
global.fetch = vi.fn().mockResolvedValueOnce({
122136
ok: true,
137+
status: 200,
138+
headers: createHeaders("application/json"),
123139
json: async () => mockData,
124140
});
125141

src/api/hooks/useClientPolling.ts

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@ interface PollingState {
1414
maxAttempts: number;
1515
}
1616

17+
const DEFAULT_MAX_ATTEMPTS = 20;
18+
1719
export function useClientPolling() {
18-
const [pollingState, setPollingState] = useState<PollingState>({
19-
isPolling: false,
20-
clientId: null,
21-
attempts: 0,
22-
maxAttempts: 20, // 20 minutes max (20 * 60 seconds)
20+
const [pollingState, setPollingState] = useState<PollingState>(() => {
21+
const pendingTransactions = getActivePendingTransactions();
22+
const firstPending = pendingTransactions[0];
23+
24+
if (firstPending) {
25+
return {
26+
isPolling: true,
27+
clientId: firstPending.id,
28+
attempts: firstPending.attempts,
29+
maxAttempts: DEFAULT_MAX_ATTEMPTS,
30+
};
31+
}
32+
33+
return {
34+
isPolling: false,
35+
clientId: null,
36+
attempts: 0,
37+
maxAttempts: DEFAULT_MAX_ATTEMPTS,
38+
};
2339
});
2440

2541
const queryClient = useQueryClient();
@@ -31,7 +47,7 @@ export function useClientPolling() {
3147
isPolling: true,
3248
clientId,
3349
attempts: initialAttempts,
34-
maxAttempts: 20,
50+
maxAttempts: DEFAULT_MAX_ATTEMPTS,
3551
});
3652
},
3753
[],
@@ -59,15 +75,6 @@ export function useClientPolling() {
5975
}
6076
}, []);
6177

62-
useEffect(() => {
63-
const pendingTransactions = getActivePendingTransactions();
64-
65-
if (pendingTransactions.length > 0) {
66-
const firstPending = pendingTransactions[0];
67-
startPolling(firstPending.id, firstPending.attempts);
68-
}
69-
}, [startPolling]);
70-
7178
useEffect(() => {
7279
if (!pollingState.isPolling || !pollingState.clientId) {
7380
return;
@@ -89,33 +96,45 @@ export function useClientPolling() {
8996
return;
9097
}
9198

92-
const newAttempts = pollingState.attempts + 1;
93-
setPollingState((prev) => ({
94-
...prev,
95-
attempts: newAttempts,
96-
}));
99+
let shouldStop = false;
100+
setPollingState((prev) => {
101+
const newAttempts = prev.attempts + 1;
97102

98-
if (pollingState.clientId) {
99-
updateTransactionAttempts(pollingState.clientId, newAttempts);
100-
}
103+
if (prev.clientId) {
104+
updateTransactionAttempts(prev.clientId, newAttempts);
105+
}
106+
107+
shouldStop = newAttempts >= prev.maxAttempts;
101108

102-
if (newAttempts >= pollingState.maxAttempts) {
109+
return {
110+
...prev,
111+
attempts: newAttempts,
112+
};
113+
});
114+
115+
if (shouldStop) {
103116
stopPolling(false);
104117
}
105118
} catch (error) {
106119
console.error("Error polling client availability:", error);
107120

108-
const newAttempts = pollingState.attempts + 1;
109-
setPollingState((prev) => ({
110-
...prev,
111-
attempts: newAttempts,
112-
}));
121+
let shouldStop = false;
122+
setPollingState((prev) => {
123+
const newAttempts = prev.attempts + 1;
113124

114-
if (pollingState.clientId) {
115-
updateTransactionAttempts(pollingState.clientId, newAttempts);
116-
}
125+
if (prev.clientId) {
126+
updateTransactionAttempts(prev.clientId, newAttempts);
127+
}
128+
129+
shouldStop = newAttempts >= prev.maxAttempts;
130+
131+
return {
132+
...prev,
133+
attempts: newAttempts,
134+
};
135+
});
117136

118-
if (newAttempts >= pollingState.maxAttempts) {
137+
if (shouldStop) {
119138
stopPolling(false);
120139
}
121140
}

src/api/hooks/useClientProfile.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ export function useClientProfile() {
1313
return useMutation({
1414
mutationFn: async (clientId: string) => {
1515
const timestamp = Math.floor(Date.now() / 1000).toString();
16-
console.log("Timestamp:", timestamp);
1716
const challenge = `${clientId}${timestamp}`;
1817

1918
const signResult = (await signMessage(challenge)) as SignDataResponse;
20-
console.log("Sign result:", signResult);
2119

2220
const profileRequest = {
2321
id: clientId,

0 commit comments

Comments
 (0)