Skip to content
Merged
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
15 changes: 14 additions & 1 deletion roll-dice/anchor/app/app/delegated/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ export default function DiceRollerDelegated() {
deferredSaturatedUpdateRef.current = null
}, [])

const cancelBackgroundRoll = useCallback(() => {
const backgroundRoll = backgroundRollRef.current
if (!backgroundRoll) return

backgroundRollRef.current = null
clearRequestTracking()
backgroundRoll.resolve()
}, [clearRequestTracking])

const clearAllIntervals = useCallback(() => {
if (rollIntervalRef.current) {
clearInterval(rollIntervalRef.current)
Expand Down Expand Up @@ -474,6 +483,8 @@ export default function DiceRollerDelegated() {
getBlockhashAsync(connection, true),
])

if (!backgroundRollRef.current) return

tx.recentBlockhash = latestBlockhash.blockhash
tx.feePayer = playerKeypairRef.current.publicKey
tx.sign(playerKeypairRef.current)
Expand Down Expand Up @@ -891,6 +902,8 @@ export default function DiceRollerDelegated() {
delegationPollIntervalRef.current = setInterval(async () => {
const delegated = await refreshDelegationStatus()
if (!delegated) {
cancelBackgroundRoll()
setIsDelegating(false)
if (delegationPollIntervalRef.current) {
clearInterval(delegationPollIntervalRef.current)
delegationPollIntervalRef.current = null
Expand Down Expand Up @@ -933,7 +946,7 @@ export default function DiceRollerDelegated() {
}
setIsUndelegating(false)
}
}, [isDelegated, refreshDelegationStatus])
}, [cancelBackgroundRoll, isDelegated, refreshDelegationStatus])

const handleRollDice = useCallback(async () => {
if (
Expand Down
Loading
Loading