From 2b680c48e5adc08baf4ab1b2d3fc44893f9dc155 Mon Sep 17 00:00:00 2001 From: 0xjaqbek Date: Fri, 26 Jul 2024 11:54:31 +0200 Subject: [PATCH] saveOnChainAll --- race | 1 + src/LeaderboardPage.tsx | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 160000 race diff --git a/race b/race new file mode 160000 index 0000000..269ccc2 --- /dev/null +++ b/race @@ -0,0 +1 @@ +Subproject commit 269ccc239349eefe22255b6ebb2af7430facd4ba diff --git a/src/LeaderboardPage.tsx b/src/LeaderboardPage.tsx index ef33bd9..cce0fb9 100644 --- a/src/LeaderboardPage.tsx +++ b/src/LeaderboardPage.tsx @@ -4,6 +4,7 @@ import { StyledButton } from './StyledButton'; import { TonConnectButton } from "@tonconnect/ui-react"; import { useTonAddress } from "@tonconnect/ui-react"; import { getLeaderboard, updateLeaderboard, LeaderboardEntry } from './gistService'; +import { sendTransactionToOnChainRace } from '../race/scripts/onChainRaceService'; // Import the function interface LeaderboardPageProps { elapsedTime: number; @@ -214,6 +215,22 @@ const LeaderboardPage: React.FC = ({ elapsedTime, onClose, const topScores = getTopScores(leaderboard); const paginatedScores = topScores.slice(pageIndex * itemsPerPage, (pageIndex + 1) * itemsPerPage); + const handleOnChainRaceClick = async () => { + try { + console.log("OnChain Race clicked"); + console.log(`Wallet Address: ${rawAddress}`); + console.log(`User ID: ${userId}`); + console.log(`User Name: ${userName}`); + console.log(`Elapsed Time: ${elapsedTime.toFixed(3)} seconds`); + + // Call the function to send transaction + await sendTransactionToOnChainRace(rawAddress, elapsedTime); + + } catch (error) { + console.error("Error during OnChain Race:", error); + } + }; + return ( @@ -253,18 +270,12 @@ const LeaderboardPage: React.FC = ({ elapsedTime, onClose,

Connect your wallet to play OnChain:

{ - console.log("OnChain Race clicked"); - console.log(`Wallet Address: ${rawAddress}`); - console.log(`User ID: ${userId}`); - console.log(`User Name: ${userName}`); - console.log(`Elapsed Time: ${elapsedTime.toFixed(3)} seconds`); - }} - style={{ marginTop: '10px' }} - disabled={!rawAddress} -> - OnChain Race - + onClick={handleOnChainRaceClick} + style={{ marginTop: '10px' }} + disabled={!rawAddress} + > + OnChain Race + Save Score

Close