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

fix: add unbonding period time to staking #1443

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ const DelegatePopup: React.FC<PopupProps> = ({
/>
<p className="text-[#FFC13C] text-b1">Important</p>
<p className="text-b1-light">
Staking will lock your funds for 21 days.
Staking will lock your funds for {singleStake.getChainUnbondingPeriod(chainID)} days.
</p>
</div>
<div className="text-b1 pl-7">
To make your staked assets liquid, undelegation will take 21 days.
To make your staked assets liquid, undelegation will take {singleStake.getChainUnbondingPeriod(chainID)} days.
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ const NewDelegationDialog: React.FC<PopupProps> = ({
/>
<p className="text-[#FFC13C] text-b1">Important</p>
<p className="text-b1-light">
Staking will lock your funds for 21 days.
Staking will lock your funds for {singleStake.getChainUnbondingPeriod(chainID)} days.
</p>
</div>
<div className="text-b1 pl-6">
To make your staked assets liquid, undelegation will take 21 days.
To make your staked assets liquid, undelegation will take {singleStake.getChainUnbondingPeriod(chainID)} days.
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const ReDelegatePopup: React.FC<PopupProps> = ({
/>
<p className="text-[#FFC13C] text-b1">Important</p>
<p className="text-b1-light">
Staking will lock your funds for 21 days
Staking will lock your funds for {singleStake.getChainUnbondingPeriod(chainID)} days
</p>
</div>
<div className="text-b1 pl-7">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ const UndelegatePopup: React.FC<PopupProps> = ({
/>
<p className="text-[#FFC13C] text-b1">Important</p>
<p className="text-b1-light">
Staking will lock your funds for 21 days.
Staking will lock your funds for {singleStake.getChainUnbondingPeriod(chainID)} days.
</p>
</div>
<div className="text-b1 pl-7">
To make your staked assets liquid, undelegation will take 21 days.
To make your staked assets liquid, undelegation will take {singleStake.getChainUnbondingPeriod(chainID)} days.
</div>
</div>

Expand Down
28 changes: 27 additions & 1 deletion frontend/src/custom-hooks/useSingleStaking.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useAppDispatch, useAppSelector } from './StateHooks';
import { RootState } from '@/store/store';
import useGetChainInfo from './useGetChainInfo';
import { getValidator } from '@/store/features/staking/stakeSlice';
import { getParams, getValidator } from '@/store/features/staking/stakeSlice';
import useGetAssetsAmount from './useGetAssetsAmount';
import { useEffect } from 'react';

/* eslint-disable react-hooks/rules-of-hooks */
const useSingleStaking = (chainID: string) => {
Expand All @@ -16,10 +17,18 @@ const useSingleStaking = (chainID: string) => {
// getValueFromToken, getTokenValueByChainId
} = useGetChainInfo();

const { restURLs } = getChainInfo(chainID);

useEffect(() => {
dispatch(getParams({ chainID: chainID, baseURLs: restURLs }))
}, [chainID])
charymalloju marked this conversation as resolved.
Show resolved Hide resolved

const rewardsChains = useAppSelector((state: RootState) =>
isAuthzMode ? state.distribution.authzChains : state.distribution.chains
);



// const totalData = useAppSelector((state: RootState) => state.staking)

const [
Expand All @@ -40,6 +49,22 @@ const useSingleStaking = (chainID: string) => {
);
const commonStakingData = useAppSelector((state) => state.staking.chains);

const getChainUnbondingPeriod = (cID: string) => {
const secs = stakeData[cID].params?.unbonding_time || ''

// Use regex to match all digits in the string
const numberInString = secs.match(/\d+/);

// If a number is found, convert to seconds and then to days
if (numberInString) {
const seconds = parseInt(numberInString[0], 10);
const days = seconds / 86400;
return days;
}

return 21
}
charymalloju marked this conversation as resolved.
Show resolved Hide resolved

const getAvaiailableAmount = (chainID: string) => {
let amount = 0;

Expand Down Expand Up @@ -145,6 +170,7 @@ const useSingleStaking = (chainID: string) => {
getDenomWithChainID,
getAvaiailableAmount,
totalValStakedAssets,
getChainUnbondingPeriod
};
};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { GOV_VOTE_OPTIONS } from '@/constants/gov-constants';
export function initializeGA () {
ReactGA.initialize('G-RTXGXXDNNS');
console.log("GA INITIALIZED");
trackEvent('TRANSFER', 'MULTI_SEND', 'SUCCESS')
};

export const trackEvent = (category: string, action: string, label: string) => {
Expand Down
Loading