Skip to content

Commit

Permalink
UI(fb): 5 sec timer before confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
barrytra committed Aug 20, 2024
1 parent 94df8aa commit 6b758a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
34 changes: 30 additions & 4 deletions src/components/fb2/CreateFidelityBond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ const CreateFidelityBond2 = ({ otherFidelityBondExists, wallet, walletInfo, onDo
if (lockDate) loadTimeLockedAddress(lockDate)
}, [lockDate, loadTimeLockedAddress])

const [countdown, setCountdown] = useState(5)
const [isClickable, setIsClickable] = useState(false)

const startCountdown = () => {
const interval = setInterval(() => {
console.log(countdown)
setCountdown((prevCountdown) => {
if (prevCountdown <= 1) {
clearInterval(interval)
setIsClickable(true)
return 0
}
return prevCountdown - 1
})
}, 1000)
}

const primaryButtonText = (currentStep: number) => {
switch (currentStep) {
case steps.selectDate:
Expand All @@ -171,7 +188,8 @@ const CreateFidelityBond2 = ({ otherFidelityBondExists, wallet, walletInfo, onDo
}
return t('earn.fidelity_bond.select_utxos.text_primary_button')
case steps.confirmation:
return t('earn.fidelity_bond.confirmation.text_primary_button')
if (isClickable) return t('earn.fidelity_bond.confirmation.text_primary_button')
else return `Wait ${countdown} Seconds`
default:
return null
}
Expand Down Expand Up @@ -216,10 +234,12 @@ const CreateFidelityBond2 = ({ otherFidelityBondExists, wallet, walletInfo, onDo
}

if (currentStep === steps.confirmation) {
if (alert) {
return steps.failed
if (isClickable) {
if (alert) {
return steps.failed
}
return steps.done
}
return steps.done
}

return null
Expand All @@ -230,6 +250,12 @@ const CreateFidelityBond2 = ({ otherFidelityBondExists, wallet, walletInfo, onDo
return
}

if (nextStep(step) === steps.confirmation) {
setIsClickable(false)
setCountdown(5)
startCountdown()
}

if (nextStep(step) === steps.failed) {
reset()
return
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
"body": "It will be impossible to spend time-locked funds until the fidelity bond expires. Date of expiration is {{ humanReadableDuration }} on {{date}}."
},
"confirmation": {
"text_primary_button": "Done",
"text_primary_button": "Create fidelity bond",
"text_secondary_button": "Back"
},
"title": "Configure Fidelity Bond",
Expand Down

0 comments on commit 6b758a2

Please sign in to comment.