From e8f72a362d787ccf4f2e118dd4a467b9aab03862 Mon Sep 17 00:00:00 2001 From: jeremy-babylonchain Date: Thu, 28 Nov 2024 16:57:12 +0800 Subject: [PATCH 1/4] feat: add eligibility for transition in delegations and update UI accordingly --- src/app/api/getDelegations.ts | 3 + src/app/components/Delegations/Delegation.tsx | 58 ++++++++++++------- .../components/Delegations/Delegations.tsx | 17 +++--- src/app/components/Staking/Staking.tsx | 8 ++- src/app/types/delegations.ts | 3 + src/utils/getState.ts | 4 ++ .../toLocalStorageIntermediateDelegation.ts | 1 + tests/helper/generateMockDelegation.ts | 1 + 8 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/app/api/getDelegations.ts b/src/app/api/getDelegations.ts index 4507b70e..412c9399 100644 --- a/src/app/api/getDelegations.ts +++ b/src/app/api/getDelegations.ts @@ -25,6 +25,7 @@ interface DelegationAPI { unbonding_tx?: UnbondingTxAPI; is_overflow: boolean; transitioned: boolean; + is_eligible_for_transition: boolean; } interface StakingTxAPI { @@ -56,6 +57,7 @@ export const getDelegations = async ( // "pagination_reverse": reverse, // "pagination_limit": limit, staker_btc_pk: encode(publicKeyNoCoord), + state: ["active", "unbonded"], }; const response = await apiWrapper( @@ -89,6 +91,7 @@ export const getDelegations = async ( } : undefined, transitioned: apiDelegation.transitioned, + isEligibleForTransition: apiDelegation.is_eligible_for_transition, }), ); diff --git a/src/app/components/Delegations/Delegation.tsx b/src/app/components/Delegations/Delegation.tsx index 971e7e89..4bedb4fa 100644 --- a/src/app/components/Delegations/Delegation.tsx +++ b/src/app/components/Delegations/Delegation.tsx @@ -82,11 +82,21 @@ export const Delegation: React.FC = ({ }; const generateActionButton = () => { - // This function generates the transition or withdraw button - // based on the state of the delegation - // It also disables the button if the delegation - // is in an intermediate state (local storage) - if (state === DelegationState.ACTIVE) { + if (delegation.isEligibleForTransition) { + return ( +
+ +
+ ); + } else if (state === DelegationState.ACTIVE) { return (
-
- ); - } else if (state === DelegationState.ACTIVE) { - return ( -
+
+
); } else if (state === DelegationState.UNBONDED) { diff --git a/src/app/types/delegations.ts b/src/app/types/delegations.ts index 1edd0194..a596639c 100644 --- a/src/app/types/delegations.ts +++ b/src/app/types/delegations.ts @@ -7,7 +7,6 @@ export interface Delegation { stakingTx: StakingTx; unbondingTx: UnbondingTx | undefined; isOverflow: boolean; - transitioned: boolean; isEligibleForTransition: boolean; } diff --git a/src/utils/getState.ts b/src/utils/getState.ts index e5520d60..f5104665 100644 --- a/src/utils/getState.ts +++ b/src/utils/getState.ts @@ -38,7 +38,7 @@ export const getState = (state: string) => { // Create state tooltips for the additional information export const getStateTooltip = (state: string) => { switch (state) { - case DelegationState.ACTIVE: + case DelegationState.ACTIVE: // active state is shwon return "Stake is active"; case DelegationState.UNBONDED: return "Stake has been unbonded"; From da88d6d30b3785eb5f6dcbe9ca82e53980c7ed5b Mon Sep 17 00:00:00 2001 From: jeremy-babylonchain Date: Thu, 28 Nov 2024 18:29:13 +0800 Subject: [PATCH 3/4] resolve test fail --- .../local_storage/toLocalStorageIntermediateDelegation.ts | 1 - tests/helper/generateMockDelegation.ts | 1 - .../toLocalStorageIntermediateDelegation.test.ts | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/local_storage/toLocalStorageIntermediateDelegation.ts b/src/utils/local_storage/toLocalStorageIntermediateDelegation.ts index 3fd835d5..6b2a43be 100644 --- a/src/utils/local_storage/toLocalStorageIntermediateDelegation.ts +++ b/src/utils/local_storage/toLocalStorageIntermediateDelegation.ts @@ -24,5 +24,4 @@ export const toLocalStorageIntermediateDelegation = ( isOverflow: false, isEligibleForTransition: false, unbondingTx: undefined, - transitioned: false, }); diff --git a/tests/helper/generateMockDelegation.ts b/tests/helper/generateMockDelegation.ts index 4a36d14a..b08115f9 100644 --- a/tests/helper/generateMockDelegation.ts +++ b/tests/helper/generateMockDelegation.ts @@ -26,6 +26,5 @@ export function generateMockDelegation( isOverflow: false, isEligibleForTransition: false, unbondingTx: undefined, - transitioned: false, }; } diff --git a/tests/utils/local_storage/toLocalStorageIntermediateDelegation.test.ts b/tests/utils/local_storage/toLocalStorageIntermediateDelegation.test.ts index 330392d2..5814a543 100644 --- a/tests/utils/local_storage/toLocalStorageIntermediateDelegation.test.ts +++ b/tests/utils/local_storage/toLocalStorageIntermediateDelegation.test.ts @@ -36,7 +36,7 @@ describe("utils/local_storage/toLocalStorageIntermediateDelegation", () => { }, isOverflow: false, unbondingTx: undefined, - transitioned: false, + isEligibleForTransition: false, }); // Validate startTimestamp is a valid ISO date string @@ -79,7 +79,7 @@ describe("utils/local_storage/toLocalStorageIntermediateDelegation", () => { }, isOverflow: false, unbondingTx: undefined, - transitioned: false, + isEligibleForTransition: false, }); // Validate startTimestamp is a valid ISO date string From a0f8a3ad111f0b4bddd37090f880bc05f959ee8a Mon Sep 17 00:00:00 2001 From: jeremy-babylonchain Date: Fri, 29 Nov 2024 13:09:28 +0800 Subject: [PATCH 4/4] remove slashed state --- src/app/types/delegations.ts | 2 -- src/utils/getState.ts | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/app/types/delegations.ts b/src/app/types/delegations.ts index a596639c..3c18409a 100644 --- a/src/app/types/delegations.ts +++ b/src/app/types/delegations.ts @@ -30,7 +30,6 @@ export const UNBONDED = "unbonded"; export const WITHDRAWN = "withdrawn"; export const PENDING = "pending"; export const OVERFLOW = "overflow"; -export const SLASHED = "slashed"; export const EXPIRED = "expired"; export const INTERMEDIATE_UNBONDING = "intermediate_unbonding"; export const INTERMEDIATE_WITHDRAWAL = "intermediate_withdrawal"; @@ -46,7 +45,6 @@ export const DelegationState = { WITHDRAWN, PENDING, OVERFLOW, - SLASHED, EXPIRED, INTERMEDIATE_UNBONDING, INTERMEDIATE_WITHDRAWAL, diff --git a/src/utils/getState.ts b/src/utils/getState.ts index f5104665..8f04e44e 100644 --- a/src/utils/getState.ts +++ b/src/utils/getState.ts @@ -28,8 +28,6 @@ export const getState = (state: string) => { return "Transitioning"; case DelegationState.TRANSITIONED: return "Transitioned"; - case DelegationState.SLASHED: - return "Slashed"; default: return "Unknown"; } @@ -57,8 +55,6 @@ export const getStateTooltip = (state: string) => { return "Stake is transitioning to the Babylon chain network"; case DelegationState.TRANSITIONED: return "Stake has been transitioned to the Babylon chain network"; - case DelegationState.SLASHED: - return "Stake has been slashed"; default: return "Unknown"; }