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

use correct height for unbonding model #192

Merged
merged 1 commit into from
Oct 3, 2024
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.3.2",
"version": "0.3.3",
jeremy-babylonlabs marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
34 changes: 25 additions & 9 deletions src/app/components/Delegations/Delegations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const DelegationsContent: React.FC<DelegationsProps> = ({
const { showError } = useError();
const { isApiNormal, isGeoBlocked } = useHealthCheck();
const [awaitingWalletResponse, setAwaitingWalletResponse] = useState(false);
const [selectedDelegationHeight, setSelectedDelegationHeight] = useState<
number | undefined
>();

const shouldShowPoints =
isApiNormal && !isGeoBlocked && shouldDisplayPoints();
Expand Down Expand Up @@ -171,13 +174,15 @@ const DelegationsContent: React.FC<DelegationsProps> = ({
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);
}
};

Expand Down Expand Up @@ -206,20 +211,23 @@ const DelegationsContent: React.FC<DelegationsProps> = ({
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(() => {
Expand Down Expand Up @@ -325,9 +333,19 @@ const DelegationsContent: React.FC<DelegationsProps> = ({
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}
Expand All @@ -339,11 +357,9 @@ const DelegationsContent: React.FC<DelegationsProps> = ({
</div>
</>
)}

{modalMode && txID && (
{modalMode && txID && selectedDelegationHeight !== undefined && (
<UnbondWithdrawModal
unbondingTimeBlocks={globalParamsVersion.unbondingTime}
unbondingFeeSat={globalParamsVersion.unbondingFeeSat}
delegationHeight={selectedDelegationHeight}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy-babylonlabs you don't need selectedDelegationHeight state.
You can reuse what's been done for the handleUnbond(txID) where it use the ID to locate the delegation from delegationsAPI

open={modalOpen}
onClose={() => setModalOpen(false)}
onProceed={() => {
Expand Down
21 changes: 17 additions & 4 deletions src/app/components/Modals/UnbondWithdrawModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { IoMdClose } from "react-icons/io";

import { useGlobalParams } from "@/app/context/api/GlobalParamsProvider";
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";
Expand All @@ -14,8 +16,7 @@ export const MODE_WITHDRAW = "withdraw";
export type MODE = typeof MODE_UNBOND | typeof MODE_WITHDRAW;

interface PreviewModalProps {
unbondingTimeBlocks: number;
unbondingFeeSat: number;
delegationHeight: number;
open: boolean;
onClose: (value: boolean) => void;
onProceed: () => void;
Expand All @@ -24,15 +25,27 @@ interface PreviewModalProps {
}

export const UnbondWithdrawModal: React.FC<PreviewModalProps> = ({
unbondingTimeBlocks,
unbondingFeeSat,
delegationHeight,
open,
onClose,
onProceed,
mode,
awaitingWalletResponse,
}) => {
const { coinName, networkName } = getNetworkConfig();
const { data: allGlobalParamsVersions } = useGlobalParams();

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";

Expand Down