From fd7e19d7125523f2ab4488cea82fa07816d45bc0 Mon Sep 17 00:00:00 2001 From: 0xjaqbek Date: Fri, 26 Jul 2024 17:20:42 +0200 Subject: [PATCH] alert about update to onchain --- src/race/scripts/getData.ts | 55 ++++++++++++++----------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/src/race/scripts/getData.ts b/src/race/scripts/getData.ts index 35f7a64..26a18e2 100644 --- a/src/race/scripts/getData.ts +++ b/src/race/scripts/getData.ts @@ -7,7 +7,8 @@ export async function getDataFromOnChainRace(client: TonClient, onChainRaceAddre try { // Open OnChainRace instance by address const onChainRace = OnChainRace.createFromAddress(onChainRaceAddress); - console.log(`OnChainRace contract address: ${onChainRaceAddress.toString()}`); + const contractAddress = onChainRaceAddress.toString(); + console.log(`OnChainRace contract address: ${contractAddress}`); // Create a ContractProvider for OnChainRace contract const onChainRaceProvider = client.provider(onChainRaceAddress); @@ -15,48 +16,34 @@ export async function getDataFromOnChainRace(client: TonClient, onChainRaceAddre // Retrieve and log run time and user address from the smart contract const runTimeMilliseconds = await onChainRace.getRunTime(onChainRaceProvider); const runTimeSeconds = runTimeMilliseconds / 1000; - console.log("Run Time:", runTimeSeconds.toFixed(3)); // Show the run time with millisecond precision + const runTimeMessage = `Run Time: ${runTimeSeconds.toFixed(3)}`; // Show the run time with millisecond precision + console.log(runTimeMessage); const userAddressObj = await onChainRace.getUserAddress(onChainRaceProvider); - console.log("User Address:", userAddressObj.toString()); + const userAddressMessage = `User Address: ${userAddressObj.toString()}`; + console.log(userAddressMessage); - } catch (error) { - if (axios.isAxiosError(error)) { - // Handle AxiosError - console.error('Axios error:', error.message); - console.error('Response data:', error.response?.data); - } else { - // Handle other errors - console.error('Unexpected error:', error); - } - } -} - -export async function run() { - try { - console.log("Starting interaction with OnChainRace contract..."); - - // Initialize TON RPC client on testnet - const endpoint = await getHttpEndpoint({ network: "testnet" }); - console.log(`Using endpoint: ${endpoint}`); - const client = new TonClient({ endpoint }); - - // Define the OnChainRace contract address - const onChainRaceAddress = Address.parse("kQDW1VLFvS3FJW5rl2tyNfQ-mOfN5nPYGPAHh1vueJsRywwm"); // Replace with your contract address - - // Call the function to get data from OnChainRace - await getDataFromOnChainRace(client, onChainRaceAddress); + // Combine all messages into a single alert + const combinedMessage = ` + OnChainRace contract address: ${contractAddress} + ${runTimeMessage} + ${userAddressMessage} + `; + alert(combinedMessage.trim()); } catch (error) { if (axios.isAxiosError(error)) { // Handle AxiosError - console.error('Axios error:', error.message); - console.error('Response data:', error.response?.data); + const axiosErrorMessage = `Axios error: ${error.message}`; + const responseData = `Response data: ${error.response?.data}`; + console.error(axiosErrorMessage); + console.error(responseData); + alert(`${axiosErrorMessage}\n${responseData}`); } else { // Handle other errors - console.error('Unexpected error:', error); + const unexpectedErrorMessage = `Unexpected error: ${error}`; + console.error(unexpectedErrorMessage); + alert(unexpectedErrorMessage); } } } - -run().catch(console.error);