Skip to content

Commit

Permalink
dev: reset user confirmation on data change
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Jun 7, 2022
1 parent 8ead4c3 commit 6e03a96
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/FidelityBondSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,9 @@ interface SelectLockdateStepProps {
const SelectLockdateStep = ({ utxos, onChange }: SelectLockdateStepProps) => {
const settings = useSettings()
const [lockdate, setLockdate] = useState<Api.Lockdate | null>(null)
const now = useMemo(() => Date.now(), [])
const timeTillUnlockString = useMemo(
() => lockdate && timeUtils.timeElapsed(lockdateToTimestamp(lockdate), now),
[now, lockdate]
() => lockdate && timeUtils.timeElapsed(lockdateToTimestamp(lockdate), Date.now()),
[lockdate]
)

const selectedUtxosAmountSum = useMemo(() => utxos.reduce((acc, current) => acc + current.value, 0), [utxos])
Expand Down Expand Up @@ -770,14 +769,18 @@ interface ConfirmationStepProps {
account: Account
utxos: Utxos
lockdate: Api.Lockdate
confirmed: boolean
onChange: (confirmed: boolean) => void
}

const ConfirmationStep = ({ balanceSummary, account, utxos, lockdate, onChange }: ConfirmationStepProps) => {
const ConfirmationStep = ({ balanceSummary, account, utxos, lockdate, confirmed, onChange }: ConfirmationStepProps) => {
const { t } = useTranslation()
const settings = useSettings()
const now = useMemo(() => Date.now(), [])
const timeTillUnlockString = useMemo(() => timeUtils.timeElapsed(lockdateToTimestamp(lockdate), now), [now, lockdate])

const timeTillUnlockString = useMemo(
() => timeUtils.timeElapsed(lockdateToTimestamp(lockdate), Date.now()),
[lockdate]
)

const selectedUtxosAmountSum = useMemo(() => utxos.reduce((acc, current) => acc + current.value, 0), [utxos])

Expand Down Expand Up @@ -836,6 +839,7 @@ const ConfirmationStep = ({ balanceSummary, account, utxos, lockdate, onChange }
<div className="my-4 d-flex justify-content-center">
<ToggleSwitch
label={t('create_wallet.confirmation_toggle_fidelity_bond_summary')}
defaultChecked={confirmed}
onToggle={(isToggled: boolean) => onChange(isToggled)}
/>
</div>
Expand Down Expand Up @@ -885,6 +889,11 @@ export const FidelityBondSimple = () => {
}
}, [selectedAccount])

useEffect(() => {
// TODO: toggle button has no way to reflect this change currently
setUserConfirmed(false)
}, [step, selectedAccount, selectedUtxos, selectedLockdate])

useEffect(() => {
if (!currentWallet) {
setAlert({ variant: 'danger', message: t('current_wallet.error_loading_failed') })
Expand Down Expand Up @@ -1010,6 +1019,7 @@ export const FidelityBondSimple = () => {
account={selectedAccount}
utxos={selectedUtxos}
lockdate={selectedLockdate}
confirmed={userConfirmed}
onChange={setUserConfirmed}
/>

Expand Down

0 comments on commit 6e03a96

Please sign in to comment.