Skip to content

Commit

Permalink
feat: review delegation/undelegation
Browse files Browse the repository at this point in the history
  • Loading branch information
GarageInc committed Oct 8, 2024
1 parent d1a9276 commit 33002b4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { trackBroadcastTx } from '../../utils/track-broadcast-tx';
import { useAddress } from '../use-address/use-address';
import stridLiquidStakingABI from './../../abis/stride-liquid-staking-stride.json';

const DEFAULT_STRIDE_ADDRESS = 'stride1rdzm229m02my0gn4drc7wrdm8tnz2z9g8nty05';
const DEFAULT_STRIDE_ADDRESS =
process.env.NEXT_PUBLIC_LIQUID_STAKING_STRIDE_DEFAULT_ADDRESS ||
'stride1rdzm229m02my0gn4drc7wrdm8tnz2z9g8nty05';

export function useLiquidStakingDelegate() {
const posthog = usePostHog();
Expand Down
70 changes: 55 additions & 15 deletions libs/staking/src/lib/components/stride/statistics/stride-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,10 @@ export function StrideStats() {
);
}

function StrideStatsDesktop({
balance,
stIslmBalance,
redemptionRate,
}: {
balance: number;
stIslmBalance: number;
redemptionRate: number;
}) {
export const useHandleDelegateContinue = () => {
const { executeIfNetworkSupported } = useNetworkAwareAction();
const router = useRouter();

const handleDelegateContinue = useCallback(() => {
executeIfNetworkSupported(() => {
router.push(`/staking/liquid-staking/liquid-staking-delegate`, {
Expand All @@ -129,6 +122,29 @@ function StrideStatsDesktop({
});
}, [executeIfNetworkSupported, router]);

const handleUndelegateContinue = useCallback(() => {
executeIfNetworkSupported(() => {
router.push(`/staking/liquid-staking/liquid-staking-undelegate`, {
scroll: false,
});
});
}, [executeIfNetworkSupported, router]);

return { handleDelegateContinue, handleUndelegateContinue };
};

function StrideStatsDesktop({
balance,
stIslmBalance,
redemptionRate,
}: {
balance: number;
stIslmBalance: number;
redemptionRate: number;
}) {
const { handleDelegateContinue, handleUndelegateContinue } =
useHandleDelegateContinue();

return (
<Container className="flex min-h-[100px] flex-col justify-center gap-[24px]">
<div className="flex flex-row items-center">
Expand Down Expand Up @@ -190,12 +206,7 @@ function StrideStatsDesktop({
disabled={stIslmBalance < MIN_DELEGATION}
data-attr="liquid-staking-undelegate"
onClick={() => {
executeIfNetworkSupported(() => {
router.push(
`/staking/liquid-staking/liquid-staking-undelegate`,
{ scroll: false },
);
});
handleUndelegateContinue();
}}
>
Undelegate
Expand All @@ -217,6 +228,9 @@ function StrideStatsMobile({
stIslmBalance: number;
redemptionRate: number;
}) {
const { handleDelegateContinue, handleUndelegateContinue } =
useHandleDelegateContinue();

return (
<div className="flex flex-col items-start gap-[16px] overflow-x-auto px-[16px] py-[20px] sm:gap-[32px] sm:px-[48px] sm:py-[32px]">
<div className="flex flex-row items-center">
Expand Down Expand Up @@ -246,6 +260,32 @@ function StrideStatsMobile({
uppercaseSymbol={false}
/>
</div>

<div className="grid w-full grid-cols-2 gap-x-[12px]">
<Button
variant={2}
disabled={balance < MIN_BALANCE}
className="w-full"
onClick={() => {
handleDelegateContinue();
}}
data-attr="liquid-staking-delegate"
>
Delegate
</Button>

<Button
variant={2}
className="w-full"
disabled={stIslmBalance < MIN_DELEGATION}
data-attr="liquid-staking-undelegate"
onClick={() => {
handleUndelegateContinue();
}}
>
Undelegate
</Button>
</div>
</div>
);
}

0 comments on commit 33002b4

Please sign in to comment.