Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

616: (feat) prevent multiple fidelity bonds with same expiry date #741

Merged
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
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 @@ -448,7 +448,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
Loading