Skip to content

Commit cd44d2b

Browse files
authored
Merge pull request #2556 from pyth-network/cprussin/remove-logging
feat(staking): improve tester app feedback
2 parents 501b04f + 0c647f1 commit cd44d2b

File tree

2 files changed

+56
-34
lines changed

2 files changed

+56
-34
lines changed

apps/staking/src/components/WalletTester/index.tsx

+56-30
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ import { useConnection } from "@solana/wallet-adapter-react";
1212
import { useWalletModal } from "@solana/wallet-adapter-react-ui";
1313
import { PublicKey, Connection } from "@solana/web3.js";
1414
import type { ComponentProps } from "react";
15-
import { useCallback, useState } from "react";
15+
import { useCallback } from "react";
1616

1717
import WalletTesterIDL from "./wallet-tester-idl.json";
1818
import { StateType as ApiStateType, useApi } from "../../hooks/use-api";
19-
import { useData, StateType } from "../../hooks/use-data";
20-
import { useLogger } from "../../hooks/use-logger";
19+
import {
20+
useAsync,
21+
StateType as UseAsyncStateType,
22+
} from "../../hooks/use-async";
23+
import { useData, StateType as UseDataStateType } from "../../hooks/use-data";
2124
import { useToast } from "../../hooks/use-toast";
2225
import { Button } from "../Button";
2326

27+
const MAX_TEST_RETRIES = 10;
28+
2429
export const WalletTester = () => (
2530
<div className="grid size-full place-content-center">
2631
<div className="w-96 border border-neutral-600 p-10">
@@ -101,19 +106,19 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
101106
);
102107

103108
switch (testedStatus.type) {
104-
case StateType.NotLoaded:
105-
case StateType.Loading: {
109+
case UseDataStateType.NotLoaded:
110+
case UseDataStateType.Loading: {
106111
return <Description>Loading...</Description>;
107112
}
108-
case StateType.Error: {
113+
case UseDataStateType.Error: {
109114
return (
110115
<Description>
111116
Uh oh, we ran into an issue while checking if your wallet has been
112117
tested. Please reload and try again.
113118
</Description>
114119
);
115120
}
116-
case StateType.Loaded: {
121+
case UseDataStateType.Loaded: {
117122
return testedStatus.data.hasTested ? (
118123
<p className="text-green-600">
119124
Your wallet has already been tested succesfully!
@@ -126,37 +131,57 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
126131
};
127132

128133
const Tester = ({ wallet }: { wallet: AnchorWallet }) => {
129-
const logger = useLogger();
130134
const toast = useToast();
131-
const [tested, setTested] = useState(false);
132135
const { connection } = useConnection();
133-
const test = useCallback(() => {
134-
testWallet(connection, wallet)
136+
const { state, execute } = useAsync(() => testWallet(connection, wallet));
137+
const doTest = useCallback(() => {
138+
execute()
135139
.then(() => {
136-
setTested(true);
137140
toast.success("Successfully tested wallet, thank you!");
138141
})
139142
.catch((error: unknown) => {
140-
logger.error(error);
141143
toast.error(error);
142144
});
143-
}, [setTested, logger, toast, wallet, connection]);
145+
}, [execute, toast]);
144146

145-
return tested ? (
146-
<p className="text-green-600">Your wallet has been tested succesfully!</p>
147-
) : (
148-
<>
149-
<Description>
150-
Please click the button below and accept the transaction in your wallet
151-
to test the browser wallet compatibility. You will need 0.001 SOL.
152-
</Description>
153-
<div className="flex justify-center">
154-
<Button className="px-10 py-4" size="nopad" onPress={test}>
155-
Click to test
156-
</Button>
157-
</div>
158-
</>
159-
);
147+
switch (state.type) {
148+
case UseAsyncStateType.Base:
149+
case UseAsyncStateType.Error:
150+
case UseAsyncStateType.Running: {
151+
return (
152+
<>
153+
<Description>
154+
Please click the button below and accept the transaction in your
155+
wallet to test the browser wallet compatibility. You will need 0.001
156+
SOL.
157+
</Description>
158+
<div className="flex justify-center">
159+
<Button
160+
className="px-10 py-4"
161+
size="nopad"
162+
{...(state.type === UseAsyncStateType.Running
163+
? { isLoading: true }
164+
: { onPress: doTest })}
165+
>
166+
Click to test
167+
</Button>
168+
</div>
169+
{state.type === UseAsyncStateType.Error && (
170+
<p className="mt-4 text-red-600">
171+
Uh oh, an error occurred! Please try again
172+
</p>
173+
)}
174+
</>
175+
);
176+
}
177+
case UseAsyncStateType.Complete: {
178+
return (
179+
<p className="text-green-600">
180+
Your wallet has been tested succesfully!
181+
</p>
182+
);
183+
}
184+
}
160185
};
161186

162187
const getHasAlreadyTested = async (
@@ -178,7 +203,7 @@ const testWallet = async (connection: Connection, wallet: AnchorWallet) => {
178203
);
179204
const testMethod = walletTester.methods.test;
180205
if (testMethod) {
181-
return sendTransactions(
206+
await sendTransactions(
182207
await TransactionBuilder.batchIntoVersionedTransactions(
183208
wallet.publicKey,
184209
connection,
@@ -192,6 +217,7 @@ const testWallet = async (connection: Connection, wallet: AnchorWallet) => {
192217
),
193218
connection,
194219
wallet,
220+
MAX_TEST_RETRIES,
195221
);
196222
} else {
197223
throw new Error("No test method found in program");

apps/staking/src/middleware.ts

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ const proxyCheckClient = PROXYCHECK_API_KEY
2727
: undefined;
2828

2929
export const middleware = async (request: NextRequest) => {
30-
// eslint-disable-next-line no-console
31-
console.log("IP Allowlist:", IP_ALLOWLIST);
32-
// eslint-disable-next-line no-console
33-
console.log("Are they allowed?", isIpAllowlisted("163.116.252.75"));
3430
const ip = ipAddress(request);
3531
if (isIpAllowlisted(ip)) {
3632
return isBlockedSegment(request)

0 commit comments

Comments
 (0)