From 77f4ddc0bc4c7d3ee25c7c106cd641f5ff99ab11 Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Thu, 3 Apr 2025 14:57:34 -0700 Subject: [PATCH 1/2] Remove unneeded logging --- apps/staking/src/middleware.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/staking/src/middleware.ts b/apps/staking/src/middleware.ts index 83cf4ebbfd..d6e19980d4 100644 --- a/apps/staking/src/middleware.ts +++ b/apps/staking/src/middleware.ts @@ -27,10 +27,6 @@ const proxyCheckClient = PROXYCHECK_API_KEY : undefined; export const middleware = async (request: NextRequest) => { - // eslint-disable-next-line no-console - console.log("IP Allowlist:", IP_ALLOWLIST); - // eslint-disable-next-line no-console - console.log("Are they allowed?", isIpAllowlisted("163.116.252.75")); const ip = ipAddress(request); if (isIpAllowlisted(ip)) { return isBlockedSegment(request) From 0c647f1fe0f5cbeaabb0440bcd36e063d6f4c580 Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Thu, 3 Apr 2025 15:49:23 -0700 Subject: [PATCH 2/2] feat(staking): improve tester app feedback --- .../src/components/WalletTester/index.tsx | 86 ++++++++++++------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/apps/staking/src/components/WalletTester/index.tsx b/apps/staking/src/components/WalletTester/index.tsx index 4810816a89..63574a20c2 100644 --- a/apps/staking/src/components/WalletTester/index.tsx +++ b/apps/staking/src/components/WalletTester/index.tsx @@ -12,15 +12,20 @@ import { useConnection } from "@solana/wallet-adapter-react"; import { useWalletModal } from "@solana/wallet-adapter-react-ui"; import { PublicKey, Connection } from "@solana/web3.js"; import type { ComponentProps } from "react"; -import { useCallback, useState } from "react"; +import { useCallback } from "react"; import WalletTesterIDL from "./wallet-tester-idl.json"; import { StateType as ApiStateType, useApi } from "../../hooks/use-api"; -import { useData, StateType } from "../../hooks/use-data"; -import { useLogger } from "../../hooks/use-logger"; +import { + useAsync, + StateType as UseAsyncStateType, +} from "../../hooks/use-async"; +import { useData, StateType as UseDataStateType } from "../../hooks/use-data"; import { useToast } from "../../hooks/use-toast"; import { Button } from "../Button"; +const MAX_TEST_RETRIES = 10; + export const WalletTester = () => (
@@ -101,11 +106,11 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => { ); switch (testedStatus.type) { - case StateType.NotLoaded: - case StateType.Loading: { + case UseDataStateType.NotLoaded: + case UseDataStateType.Loading: { return Loading...; } - case StateType.Error: { + case UseDataStateType.Error: { return ( Uh oh, we ran into an issue while checking if your wallet has been @@ -113,7 +118,7 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => { ); } - case StateType.Loaded: { + case UseDataStateType.Loaded: { return testedStatus.data.hasTested ? (

Your wallet has already been tested succesfully! @@ -126,37 +131,57 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => { }; const Tester = ({ wallet }: { wallet: AnchorWallet }) => { - const logger = useLogger(); const toast = useToast(); - const [tested, setTested] = useState(false); const { connection } = useConnection(); - const test = useCallback(() => { - testWallet(connection, wallet) + const { state, execute } = useAsync(() => testWallet(connection, wallet)); + const doTest = useCallback(() => { + execute() .then(() => { - setTested(true); toast.success("Successfully tested wallet, thank you!"); }) .catch((error: unknown) => { - logger.error(error); toast.error(error); }); - }, [setTested, logger, toast, wallet, connection]); + }, [execute, toast]); - return tested ? ( -

Your wallet has been tested succesfully!

- ) : ( - <> - - Please click the button below and accept the transaction in your wallet - to test the browser wallet compatibility. You will need 0.001 SOL. - -
- -
- - ); + switch (state.type) { + case UseAsyncStateType.Base: + case UseAsyncStateType.Error: + case UseAsyncStateType.Running: { + return ( + <> + + Please click the button below and accept the transaction in your + wallet to test the browser wallet compatibility. You will need 0.001 + SOL. + +
+ +
+ {state.type === UseAsyncStateType.Error && ( +

+ Uh oh, an error occurred! Please try again +

+ )} + + ); + } + case UseAsyncStateType.Complete: { + return ( +

+ Your wallet has been tested succesfully! +

+ ); + } + } }; const getHasAlreadyTested = async ( @@ -178,7 +203,7 @@ const testWallet = async (connection: Connection, wallet: AnchorWallet) => { ); const testMethod = walletTester.methods.test; if (testMethod) { - return sendTransactions( + await sendTransactions( await TransactionBuilder.batchIntoVersionedTransactions( wallet.publicKey, connection, @@ -192,6 +217,7 @@ const testWallet = async (connection: Connection, wallet: AnchorWallet) => { ), connection, wallet, + MAX_TEST_RETRIES, ); } else { throw new Error("No test method found in program");