Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/components/PingPongComponent/PingPongComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ export const PingPongComponent = ({
return;
}

const secondsRemaining = await getTimeToPong();
const msRemaining = await getTimeToPong();

// If backend now returns milliseconds, convert to whole seconds
const secondsRemaining =
msRemaining == null
? msRemaining
: Math.max(0, Math.floor(msRemaining / 1000));
Comment on lines +82 to +85

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ternary expression for calculating secondsRemaining can be simplified for better readability. Since both null and undefined for msRemaining are handled identically downstream, we can use a more direct != null check and explicitly return null when msRemaining is either null or undefined.

Suggested change
const secondsRemaining =
msRemaining == null
? msRemaining
: Math.max(0, Math.floor(msRemaining / 1000));
const secondsRemaining =
msRemaining != null
? Math.max(0, Math.floor(msRemaining / 1000))
: null;


const { canPing, timeRemaining } = setTimeRemaining(secondsRemaining);

setHasPing(canPing);
Expand Down Expand Up @@ -147,6 +154,9 @@ export const PingPongComponent = ({
return <MissingNativeAuthError />;
}

const isPingDisabled = !hasPing || hasPendingTransactions;
const isPongDisabled = !pongAllowed || hasPing || hasPendingTransactions;

return (
<div id={identifier} className={styles.pingPongContainer}>
<div className={styles.infosContainer}>
Expand Down Expand Up @@ -185,8 +195,8 @@ export const PingPongComponent = ({
<div className={styles.buttons}>
<MvxButton
data-testid='btnPing'
disabled={!hasPing || hasPendingTransactions}
onClick={onSendPingTransaction}
disabled={isPingDisabled}
onClick={isPingDisabled ? undefined : onSendPingTransaction}
size='small'
>
<FontAwesomeIcon
Expand All @@ -199,8 +209,8 @@ export const PingPongComponent = ({

<MvxButton
data-testid='btnPong'
disabled={!pongAllowed || hasPing || hasPendingTransactions}
onClick={onSendPongTransaction}
disabled={isPongDisabled}
onClick={isPongDisabled ? undefined : onSendPongTransaction}
size='small'
>
<FontAwesomeIcon
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export * from './sharedConfig';

export const API_URL = 'https://devnet-template-api.multiversx.com';
export const contractAddress =
'erd1qqqqqqqqqqqqqpgqm6ad6xrsjvxlcdcffqe8w58trpec09ug9l5qde96pq';
'erd1qqqqqqqqqqqqqpgqg5aesu869nrjqw2fzq8ljj7wtsfd7cr7d8ss8zquav';
export const environment = EnvironmentsEnum.devnet;
export const sampleAuthenticatedDomains = [API_URL];
39 changes: 27 additions & 12 deletions src/contracts/ping-pong.abi.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"buildInfo": {
"rustc": {
"version": "1.61.0-nightly",
"commitHash": "1d9c262eea411ec5230f8a4c9ba50b3647064da4",
"commitDate": "2022-03-26",
"channel": "Nightly",
"short": "rustc 1.61.0-nightly (1d9c262ee 2022-03-26)"
"version": "1.91.1",
"commitHash": "ed61e7d7e242494fb7057f2657300d9e77bb4fcb",
"commitDate": "2025-11-07",
"channel": "Stable",
"host": "x86_64-unknown-linux-gnu",
"short": "rustc 1.91.1 (ed61e7d7e 2025-11-07)",
"llvmVersion": "21.1"
},
"contractCrate": {
"name": "ping-pong",
"version": "0.0.2",
"git_version": "23ff9bd"
"version": "0.0.2"
},
"framework": {
"name": "elrond-wasm",
"version": "0.34.1"
"name": "multiversx-sc",
"version": "0.63.3"
}
},
"docs": [
Expand All @@ -31,7 +32,7 @@
"docs": [
"Necessary configuration when deploying:",
"`ping_amount` - the exact amount that needs to be sent when `ping`-ing. ",
"`duration_in_seconds` - how much time (in seconds) until `pong` can be called after the initial `ping` call ",
"`duration_in_millis` - how much time (in milliseconds) until `pong` can be called after the initial `ping` call ",
"`token_id` - Optional. The Token Identifier of the token that is going to be used. Default is \"EGLD\"."
],
"inputs": [
Expand All @@ -40,7 +41,7 @@
"type": "BigUint"
},
{
"name": "duration_in_seconds",
"name": "duration_in_millis",
"type": "u64"
},
{
Expand All @@ -51,6 +52,19 @@
],
"outputs": []
},
"upgradeConstructor": {
"inputs": [
{
"name": "ping_amount",
"type": "BigUint"
},
{
"name": "duration_in_millis",
"type": "u64"
}
],
"outputs": []
},
"endpoints": [
{
"docs": [
Expand Down Expand Up @@ -176,6 +190,7 @@
]
}
],
"esdtAttributes": [],
"hasCallback": false,
"types": []
"types": {}
}
2 changes: 1 addition & 1 deletion src/pages/Dashboard/widgets/PingPongAbi/PingPongAbi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getTimeToPong } from '../PingPongService/helpers/getTimeToPong';
import { useGetPingAmount } from './hooks';

export const PingPongAbi = () => {
const pingAmount = useGetPingAmount();
const { sendPingTransactionFromAbi, sendPongTransactionFromAbi } =
useSendPingPongTransaction();
const pingAmount = useGetPingAmount();

const handlePingTransaction = async (payload: PingTransactionPayloadType) => {
if (payload.amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export const getTimeToPong = async () => {
}
);

if (data.timeToPong == null) {
// no timeToPong field → no cooldown
return 0;
}

return data.timeToPong;
} catch (err) {
console.error(err);
return null;
return 0;
}
};