From 54e141f6d5dab409238f119c2acc6894367a9bee Mon Sep 17 00:00:00 2001 From: Yarre Date: Tue, 21 Jan 2025 11:23:28 +0100 Subject: [PATCH 1/2] refactor: update instruction components to use span instead of p and improve question handling in game section --- src/components/common/section/index.tsx | 8 ++++---- src/components/pages/game/game.tsx | 7 +++++-- src/hooks/contracts/write/use-send-sol.ts | 8 +++++--- src/hooks/contracts/write/use-send.ts | 6 ++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/components/common/section/index.tsx b/src/components/common/section/index.tsx index 12d957d..533d43f 100644 --- a/src/components/common/section/index.tsx +++ b/src/components/common/section/index.tsx @@ -23,10 +23,10 @@ const INSTRUCTIONS = [ description: ( <> Once the payment is complete, the page will load your results
-

+ IMPORTANT: DO NOT refresh the page if you’ve made a payment but haven’t received the result yet. Wait until the process is complete -

+ ), }, @@ -37,10 +37,10 @@ const INSTRUCTIONS = [ { subtitle: 'Ask another question:', description: ( -

+ To start a new session, click " Make a New Forecast" or refresh the page -

+ ), }, ]; diff --git a/src/components/pages/game/game.tsx b/src/components/pages/game/game.tsx index 52f6264..fe54522 100644 --- a/src/components/pages/game/game.tsx +++ b/src/components/pages/game/game.tsx @@ -57,6 +57,7 @@ export const GameSection = () => { const [isRetry, setRetry] = useState(false); const [dontReload, setDontReload] = useState(false); const [currencyName, setCurrencyName] = useState(Object.keys(currencies)[0] as Currencies); + const [question, setQuestion] = useState(''); const { register, @@ -70,6 +71,7 @@ export const GameSection = () => { const onSubmit: SubmitHandler = async (data, e) => { e?.preventDefault(); + setQuestion(data.question.trim()); await transfer({ question: data.question.trim(), tokenName: currencyName }); }; @@ -93,8 +95,9 @@ export const GameSection = () => { if (predictionAnswer) { const timer = setTimeout(() => { const formatted = predictionAnswer.answer.replaceAll('*', ''); + const response = `Your answer:\n${formatted}\n\n\nYour question:\n${question}`; - setValue('question', formatted); + setValue('question', response); setShowTip(true); setRetry(true); }, 3200); @@ -103,7 +106,7 @@ export const GameSection = () => { clearTimeout(timer); }; } - }, [isSuccess, predictionAnswer, setValue, watch]); + }, [isSuccess, predictionAnswer, question, setValue, watch]); useEffect(() => { if (isTipSuccess) { diff --git a/src/hooks/contracts/write/use-send-sol.ts b/src/hooks/contracts/write/use-send-sol.ts index 5d3864e..e164328 100644 --- a/src/hooks/contracts/write/use-send-sol.ts +++ b/src/hooks/contracts/write/use-send-sol.ts @@ -1,5 +1,5 @@ import { useWallet } from '@solana/wallet-adapter-react'; -import { SystemProgram, Transaction } from '@solana/web3.js'; +import { LAMPORTS_PER_SOL, SystemProgram, Transaction } from '@solana/web3.js'; import { useMutation } from '@tanstack/react-query'; import { useGetTokenAndSolBalance } from '../read/use-get-token-and-sol-balance'; @@ -38,8 +38,10 @@ const useSendSol = () => { const fee = await rawTx.getEstimatedFee(connection); const solBalance = tokens?.find((token) => token.mint === wSolMint.toBase58())?.amount; - if (fee && solBalance && Number(solBalance) + Number(amount) < fee) { - throw new Error('Insufficient SOL for transaction fee'); + console.log(Number(solBalance), fee, amount * LAMPORTS_PER_SOL); + + if (fee && solBalance && Number(solBalance) < fee + amount * LAMPORTS_PER_SOL) { + throw new Error('Insufficient funds'); } return await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); diff --git a/src/hooks/contracts/write/use-send.ts b/src/hooks/contracts/write/use-send.ts index baa921c..3058886 100644 --- a/src/hooks/contracts/write/use-send.ts +++ b/src/hooks/contracts/write/use-send.ts @@ -70,8 +70,10 @@ const useSend = () => { const fee = await rawTx.getEstimatedFee(connection); const solBalance = tokens?.find((token) => token.mint === wSolMint.toBase58())?.amount; - if (fee && solBalance && Number(solBalance) + Number(amount) < fee) { - throw new Error('Insufficient SOL for transaction fee'); + console.log('fee', fee, 'solBalance', solBalance, 'amount', amount); + + if (fee && solBalance && Number(solBalance) < fee) { + throw new Error('Insufficient funds'); } return await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); From 2a795f6b391388ee2a2cc9a69f9f7d672b000732 Mon Sep 17 00:00:00 2001 From: Yarre Date: Tue, 21 Jan 2025 11:24:45 +0100 Subject: [PATCH 2/2] refactor: remove console.log statements from send hooks to clean up code --- src/hooks/contracts/write/use-send-sol.ts | 2 -- src/hooks/contracts/write/use-send.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/hooks/contracts/write/use-send-sol.ts b/src/hooks/contracts/write/use-send-sol.ts index e164328..a1bc7fa 100644 --- a/src/hooks/contracts/write/use-send-sol.ts +++ b/src/hooks/contracts/write/use-send-sol.ts @@ -38,8 +38,6 @@ const useSendSol = () => { const fee = await rawTx.getEstimatedFee(connection); const solBalance = tokens?.find((token) => token.mint === wSolMint.toBase58())?.amount; - console.log(Number(solBalance), fee, amount * LAMPORTS_PER_SOL); - if (fee && solBalance && Number(solBalance) < fee + amount * LAMPORTS_PER_SOL) { throw new Error('Insufficient funds'); } diff --git a/src/hooks/contracts/write/use-send.ts b/src/hooks/contracts/write/use-send.ts index 3058886..1a185fa 100644 --- a/src/hooks/contracts/write/use-send.ts +++ b/src/hooks/contracts/write/use-send.ts @@ -70,8 +70,6 @@ const useSend = () => { const fee = await rawTx.getEstimatedFee(connection); const solBalance = tokens?.find((token) => token.mint === wSolMint.toBase58())?.amount; - console.log('fee', fee, 'solBalance', solBalance, 'amount', amount); - if (fee && solBalance && Number(solBalance) < fee) { throw new Error('Insufficient funds'); }