Skip to content

Commit

Permalink
feat: display warning on fidelity bond with same expiry date (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrytra authored Apr 23, 2024
1 parent 09e2d75 commit c04007d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
37 changes: 31 additions & 6 deletions src/components/fb/CreateFidelityBond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { useState, useEffect, useMemo } from 'react'
import * as rb from 'react-bootstrap'
import * as Api from '../../libs/JmWalletApi'
import { Trans, useTranslation } from 'react-i18next'
import { CurrentWallet, Utxo, Utxos, WalletInfo, useReloadCurrentWalletInfo } from '../../context/WalletContext'
import {
CurrentWallet,
Utxo,
Utxos,
WalletInfo,
useCurrentWalletInfo,
useReloadCurrentWalletInfo,
} from '../../context/WalletContext'
import Alert from '../Alert'
import Sprite from '../Sprite'
import {
Expand Down Expand Up @@ -112,6 +119,15 @@ const CreateFidelityBond = ({ otherFidelityBondExists, wallet, walletInfo, onDon
setUtxoIdsToBeSpent([])
}

const currentWalletInfo = useCurrentWalletInfo()
const fidelityBonds = useMemo(() => {
return currentWalletInfo?.fidelityBondSummary.fbOutputs || []
}, [currentWalletInfo])

const bondWithSelectedLockDateAlreadyExists = useMemo(() => {
return lockDate && fidelityBonds.some((it) => fb.utxo.getLocktime(it) === fb.lockdate.toTimestamp(lockDate))
}, [fidelityBonds, lockDate])

useEffect(() => {
if (!isExpanded) {
reset()
Expand Down Expand Up @@ -278,11 +294,20 @@ const CreateFidelityBond = ({ otherFidelityBondExists, wallet, walletInfo, onDon
}

return (
<SelectDate
description={t('earn.fidelity_bond.select_date.description')}
yearsRange={yearsRange}
onChange={(date) => setLockDate(date)}
/>
<>
<SelectDate
description={t('earn.fidelity_bond.select_date.description')}
yearsRange={yearsRange}
onChange={(date) => setLockDate(date)}
/>
{bondWithSelectedLockDateAlreadyExists && (
<Alert
className="text-start mt-4"
variant="warning"
message={<Trans i18nKey="earn.fidelity_bond.select_date.warning_fb_with_same_expiry" />}
/>
)}
</>
)
case steps.selectJar:
return (
Expand Down
1 change: 0 additions & 1 deletion src/components/fb/LockdateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useMemo, useState } from 'react'
import * as rb from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'

import * as Api from '../../libs/JmWalletApi'
import * as fb from './utils'

Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@
"text_secondary_button": "Cancel",
"form_label_year": "Year",
"form_label_month": "Month",
"description": "Fidelity bond expiration date:"
"description": "Fidelity bond expiration date:",
"warning_fb_with_same_expiry": "<strong>Warning</strong>: A fidelity bond with the same expiry date already exists."
},
"select_jar": {
"text_primary_button": "Next",
Expand Down

0 comments on commit c04007d

Please sign in to comment.