From 8271759e3689575f0243f5a8d8c568012377d515 Mon Sep 17 00:00:00 2001 From: jeremy-babylonchain Date: Thu, 3 Oct 2024 00:32:47 +1000 Subject: [PATCH] use correct height for unbonding model --- package-lock.json | 4 +- package.json | 2 +- .../components/Delegations/Delegations.tsx | 49 +++++++++++++------ .../components/Modals/UnbondWithdrawModal.tsx | 22 +++++++-- src/app/page.tsx | 4 +- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index f33be58f..b92b1e8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-staking", - "version": "0.3.2", + "version": "0.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-staking", - "version": "0.3.2", + "version": "0.3.3", "dependencies": { "@babylonlabs-io/btc-staking-ts": "0.3.0", "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3", diff --git a/package.json b/package.json index 2756104e..61111947 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-staking", - "version": "0.3.2", + "version": "0.3.3", "private": true, "scripts": { "dev": "next dev", diff --git a/src/app/components/Delegations/Delegations.tsx b/src/app/components/Delegations/Delegations.tsx index 17a31e3b..25f38e00 100644 --- a/src/app/components/Delegations/Delegations.tsx +++ b/src/app/components/Delegations/Delegations.tsx @@ -34,7 +34,8 @@ import { Delegation } from "./Delegation"; interface DelegationsProps { delegationsAPI: DelegationInterface[]; delegationsLocalStorage: DelegationInterface[]; - globalParamsVersion: GlobalParamsVersion; + currentGlobalParamsVersion: GlobalParamsVersion; + allGlobalParamsVersions: GlobalParamsVersion[]; publicKeyNoCoord: string; btcWalletNetwork: networks.Network; address: string; @@ -48,7 +49,8 @@ interface DelegationsProps { export const Delegations: React.FC = ({ delegationsAPI, delegationsLocalStorage, - globalParamsVersion, + currentGlobalParamsVersion, + allGlobalParamsVersions, signPsbtTx, pushTx, queryMeta, @@ -68,7 +70,8 @@ export const Delegations: React.FC = ({ = ({ const DelegationsContent: React.FC = ({ delegationsAPI, delegationsLocalStorage, - globalParamsVersion, + currentGlobalParamsVersion, + allGlobalParamsVersions, signPsbtTx, pushTx, queryMeta, @@ -100,6 +104,9 @@ const DelegationsContent: React.FC = ({ const { showError } = useError(); const { isApiNormal, isGeoBlocked } = useHealthCheck(); const [awaitingWalletResponse, setAwaitingWalletResponse] = useState(false); + const [selectedDelegationHeight, setSelectedDelegationHeight] = useState< + number | undefined + >(); const shouldShowPoints = isApiNormal && !isGeoBlocked && shouldDisplayPoints(); @@ -171,13 +178,15 @@ const DelegationsContent: React.FC = ({ message: error.message, errorState: ErrorState.UNBONDING, }, - retryAction: () => handleModal(id, MODE_UNBOND), + retryAction: () => + handleModal(id, MODE_UNBOND, selectedDelegationHeight!), }); } finally { setModalOpen(false); setTxID(""); setModalMode(undefined); setAwaitingWalletResponse(false); + setSelectedDelegationHeight(undefined); } }; @@ -206,20 +215,23 @@ const DelegationsContent: React.FC = ({ message: error.message, errorState: ErrorState.WITHDRAW, }, - retryAction: () => handleModal(id, MODE_WITHDRAW), + retryAction: () => + handleModal(id, MODE_WITHDRAW, selectedDelegationHeight!), }); } finally { setModalOpen(false); setTxID(""); setModalMode(undefined); setAwaitingWalletResponse(false); + setSelectedDelegationHeight(undefined); } }; - const handleModal = (txID: string, mode: MODE) => { + const handleModal = (txID: string, mode: MODE, delegationHeight: number) => { setModalOpen(true); setTxID(txID); setModalMode(mode); + setSelectedDelegationHeight(delegationHeight); }; useEffect(() => { @@ -325,13 +337,23 @@ const DelegationsContent: React.FC = ({ stakingValueSat={stakingValueSat} stakingTxHash={stakingTxHashHex} state={state} - onUnbond={() => handleModal(stakingTxHashHex, MODE_UNBOND)} + onUnbond={() => + handleModal( + stakingTxHashHex, + MODE_UNBOND, + stakingTx.startHeight, + ) + } onWithdraw={() => - handleModal(stakingTxHashHex, MODE_WITHDRAW) + handleModal( + stakingTxHashHex, + MODE_WITHDRAW, + stakingTx.startHeight, + ) } intermediateState={intermediateDelegation?.state} isOverflow={isOverflow} - globalParamsVersion={globalParamsVersion} + globalParamsVersion={currentGlobalParamsVersion} /> ); })} @@ -339,11 +361,10 @@ const DelegationsContent: React.FC = ({ )} - - {modalMode && txID && ( + {modalMode && txID && selectedDelegationHeight !== undefined && ( setModalOpen(false)} onProceed={() => { diff --git a/src/app/components/Modals/UnbondWithdrawModal.tsx b/src/app/components/Modals/UnbondWithdrawModal.tsx index 6fbe90c8..5f0a99eb 100644 --- a/src/app/components/Modals/UnbondWithdrawModal.tsx +++ b/src/app/components/Modals/UnbondWithdrawModal.tsx @@ -1,8 +1,10 @@ import { IoMdClose } from "react-icons/io"; +import { GlobalParamsVersion } from "@/app/types/globalParams"; import { getNetworkConfig } from "@/config/network.config"; import { blocksToDisplayTime } from "@/utils/blocksToDisplayTime"; import { satoshiToBtc } from "@/utils/btcConversions"; +import { getCurrentGlobalParamsVersion } from "@/utils/globalParams"; import { maxDecimals } from "@/utils/maxDecimals"; import { LoadingView } from "../Loading/Loading"; @@ -14,8 +16,8 @@ export const MODE_WITHDRAW = "withdraw"; export type MODE = typeof MODE_UNBOND | typeof MODE_WITHDRAW; interface PreviewModalProps { - unbondingTimeBlocks: number; - unbondingFeeSat: number; + delegationHeight: number; + allGlobalParamsVersions: GlobalParamsVersion[]; open: boolean; onClose: (value: boolean) => void; onProceed: () => void; @@ -24,8 +26,8 @@ interface PreviewModalProps { } export const UnbondWithdrawModal: React.FC = ({ - unbondingTimeBlocks, - unbondingFeeSat, + delegationHeight, + allGlobalParamsVersions, open, onClose, onProceed, @@ -34,6 +36,18 @@ export const UnbondWithdrawModal: React.FC = ({ }) => { const { coinName, networkName } = getNetworkConfig(); + const getGlobalParamsForDelegation = (startHeight: number) => { + const { currentVersion } = getCurrentGlobalParamsVersion( + startHeight, + allGlobalParamsVersions, + ); + return currentVersion; + }; + + const globalParams = getGlobalParamsForDelegation(delegationHeight); + const unbondingFeeSat = globalParams?.unbondingFeeSat || 0; + const unbondingTimeBlocks = globalParams?.unbondingTime || 0; + const unbondTitle = "Unbond"; const unbondContent = ( diff --git a/src/app/page.tsx b/src/app/page.tsx index 02db8f43..34627d69 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -72,6 +72,7 @@ const Home: React.FC = () => { // so this verification should take this into account. currentHeight: height, nextBlockParams: getCurrentGlobalParamsVersion(height + 1, versions), + globalParams: versions, // Include the full globalParams version list }; }, refetchInterval: 60000, // 1 minute @@ -355,9 +356,10 @@ const Home: React.FC = () => {