From c04007d2968dd587f6fdc0d85798412c2d892f97 Mon Sep 17 00:00:00 2001 From: Bhavesh Gupta <109822630+barrytra@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:41:54 +0530 Subject: [PATCH] feat: display warning on fidelity bond with same expiry date (#741) --- src/components/fb/CreateFidelityBond.tsx | 37 ++++++++++++++++++++---- src/components/fb/LockdateForm.tsx | 1 - src/i18n/locales/en/translation.json | 3 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/components/fb/CreateFidelityBond.tsx b/src/components/fb/CreateFidelityBond.tsx index 0a299a88..8d6f3353 100644 --- a/src/components/fb/CreateFidelityBond.tsx +++ b/src/components/fb/CreateFidelityBond.tsx @@ -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 { @@ -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() @@ -278,11 +294,20 @@ const CreateFidelityBond = ({ otherFidelityBondExists, wallet, walletInfo, onDon } return ( - setLockDate(date)} - /> + <> + setLockDate(date)} + /> + {bondWithSelectedLockDateAlreadyExists && ( + } + /> + )} + ) case steps.selectJar: return ( diff --git a/src/components/fb/LockdateForm.tsx b/src/components/fb/LockdateForm.tsx index 748d2f27..506536c9 100644 --- a/src/components/fb/LockdateForm.tsx +++ b/src/components/fb/LockdateForm.tsx @@ -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' diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 8ddf45d3..59f306ed 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -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": "Warning: A fidelity bond with the same expiry date already exists." }, "select_jar": { "text_primary_button": "Next",