Skip to content

Commit

Permalink
feat: use height based param look up
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Dec 11, 2024
1 parent ae05353 commit 6ace8f6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/app/components/Delegations/Delegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export const Delegation: React.FC<DelegationProps> = ({

const onTransition = async () => {
// TODO: Open the transaction signing modal

await transitionPhase1Delegation(
stakingTx.txHex,
stakingTx.startHeight,
{
finalityProviderPkNoCoordHex: finalityProviderPkHex,
stakingAmountSat: stakingValueSat,
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/Modals/PreviewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Loader,
Text,
} from "@babylonlabs-io/bbn-core-ui";
import { Fragment } from "react";

import { useNetworkInfo } from "@/app/hooks/client/api/useNetworkInfo";
import { useIsMobileView } from "@/app/hooks/useBreakpoint";
Expand Down Expand Up @@ -124,15 +125,15 @@ export const PreviewModal = ({
<DialogBody className="flex flex-col pb-8 pt-4 text-primary-dark gap-4">
<div className="flex flex-col">
{previewFields.map((field, index) => (
<>
<Fragment key={field.key}>
<div key={field.key} className="flex justify-between">
<Text variant="body1">{field.key}</Text>
<div className="text-right">{field.value}</div>
</div>
{index < previewFields.length - 1 && (
<div className="divider mx-0 my-2" />
)}
</>
</Fragment>
))}
</div>
<div className="flex flex-col gap-2">
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/client/api/useBTCTipHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export function useBTCTipHeight() {
return useAPIQuery({
queryKey: [BTC_TIP_HEIGHT_KEY],
queryFn: getTipHeight,
refetchInterval: 60000, // Refetch every 60 seconds
});
}
23 changes: 13 additions & 10 deletions src/app/hooks/services/useDelegationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ActionType = keyof typeof ACTIONS;
interface TxProps {
stakingTxHashHex: string;
stakingTxHex: string;
stakingHeight: number;
paramsVersion: number;
unbondingTxHex: string;
covenantUnbondingSignatures?: {
Expand Down Expand Up @@ -90,7 +91,7 @@ export function useDelegationService() {

[ACTIONS.UNBOUND]: async ({
stakingInput,
paramsVersion,
stakingHeight,
stakingTxHashHex,
stakingTxHex,
unbondingTxHex,
Expand All @@ -102,7 +103,7 @@ export function useDelegationService() {

await submitUnbondingTx(
stakingInput,
paramsVersion,
stakingHeight,
stakingTxHex,
unbondingTxHex,
covenantUnbondingSignatures.map((sig) => ({
Expand All @@ -120,12 +121,12 @@ export function useDelegationService() {
[ACTIONS.WITHDRAW_ON_EARLY_UNBOUNDING]: async ({
stakingTxHashHex,
stakingInput,
paramsVersion,
stakingHeight,
unbondingTxHex,
}: TxProps) => {
await submitEarlyUnbondedWithdrawalTx(
stakingInput,
paramsVersion,
stakingHeight,
unbondingTxHex,
);

Expand All @@ -138,7 +139,7 @@ export function useDelegationService() {
[ACTIONS.WITHDRAW_ON_EARLY_UNBOUNDING_SLASHING]: async ({
stakingTxHashHex,
stakingInput,
paramsVersion,
stakingHeight,
unbondingSlashingTxHex,
}) => {
if (!unbondingSlashingTxHex) {
Expand All @@ -149,7 +150,7 @@ export function useDelegationService() {

await submitEarlyUnbondedWithdrawalTx(
stakingInput,
paramsVersion,
stakingHeight,
unbondingSlashingTxHex,
);

Expand All @@ -161,13 +162,13 @@ export function useDelegationService() {

[ACTIONS.WITHDRAW_ON_TIMELOCK]: async ({
stakingInput,
paramsVersion,
stakingHeight,
stakingTxHashHex,
stakingTxHex,
}: TxProps) => {
await submitTimelockUnbondedWithdrawalTx(
stakingInput,
paramsVersion,
stakingHeight,
stakingTxHex,
);

Expand All @@ -179,7 +180,7 @@ export function useDelegationService() {

[ACTIONS.WITHDRAW_ON_TIMELOCK_SLASHING]: async ({
stakingInput,
paramsVersion,
stakingHeight,
stakingTxHashHex,
slashingTxHex,
}) => {
Expand All @@ -189,7 +190,7 @@ export function useDelegationService() {

await submitTimelockUnbondedWithdrawalTx(
stakingInput,
paramsVersion,
stakingHeight,
slashingTxHex,
);

Expand Down Expand Up @@ -244,6 +245,7 @@ export function useDelegationService() {
state,
slashingTxHex,
unbondingSlashingTxHex,
startHeight,
} = delegation;

const finalityProviderPk = finalityProviderBtcPksHex[0];
Expand All @@ -261,6 +263,7 @@ export function useDelegationService() {
await execute?.({
stakingTxHashHex,
stakingTxHex,
stakingHeight: startHeight,
paramsVersion,
unbondingTxHex,
covenantUnbondingSignatures,
Expand Down
Loading

0 comments on commit 6ace8f6

Please sign in to comment.