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

[release] Kintsugi 2.30.5 #1173

Merged
merged 24 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cbcc720
refactor: disable second rewards api call and set initial value from …
tomjeatt Apr 27, 2023
20defe1
fix: only estimate reward amount when form is valid
tomjeatt Apr 27, 2023
118674d
fix: don't show new vKint gained when form state is invalid
tomjeatt Apr 27, 2023
038fcb1
fix: revert config change which introduced validation regression
tomjeatt Apr 27, 2023
4be2add
fix: only calculate newTotalStake if form is valid
tomjeatt Apr 28, 2023
1622590
fix: correct dependency array for estimating stake rewards
tomjeatt Apr 28, 2023
d59c8bd
Merge pull request #1164 from interlay/tom/fix/staking-rewards-edge-case
tomjeatt Apr 28, 2023
5f4f917
chore: release v2.30.3
tomjeatt Apr 28, 2023
6e092be
fix: apply patch (change committed to wrong branch)
tomjeatt Apr 28, 2023
5fa73bf
Merge pull request #1167 from interlay/fix/additional-staking-validat…
tomjeatt Apr 28, 2023
6f7c8ab
chore: release v2.30.4
tomjeatt Apr 28, 2023
20d5d08
refactor: invalidate queries
tomjeatt Apr 28, 2023
0f3f117
fix: reset form state to 0 to match initial state
tomjeatt Apr 28, 2023
8cb23c8
refactor: better form defaults and reset values
tomjeatt Apr 28, 2023
33758cb
refactor: only invalidate escrow queries
tomjeatt Apr 28, 2023
a2333f1
wip
tomjeatt Apr 28, 2023
b5e068b
refactor: revert change to initial values
tomjeatt Apr 28, 2023
38261dc
refactor: revert conditional change
tomjeatt Apr 28, 2023
e1c6032
refactor: revert change to reset values
tomjeatt Apr 28, 2023
1ee800d
refactor: consistent query invalidation
tomjeatt Apr 28, 2023
c3ae461
Merge pull request #1171 from interlay/tom/staking-refactor
tomjeatt Apr 28, 2023
3788fbd
Merge branch 'master' into tom/release/kintsugi/2.30.5
tomjeatt Apr 28, 2023
43eaf6c
chore: release v2.30.5
tomjeatt Apr 28, 2023
122ae4a
Merge branch 'master' into tom/release/kintsugi/2.30.5
tomjeatt Apr 28, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interbtc-ui",
"version": "2.30.2",
"version": "2.30.5",
"private": true,
"dependencies": {
"@craco/craco": "^6.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/config/relay-chains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ switch (process.env.REACT_APP_RELAY_CHAIN_NAME) {
CROWDLOAN_LINK = INTERLAY_CROWDLOAN_LINK;
OPEN_GRAPH_IMAGE_FILE_NAME = 'interlay-meta-image.jpg';
STAKE_LOCK_TIME = {
MIN: 0,
MIN: 1,
MAX: 192
};
// TODO: temporary
Expand Down Expand Up @@ -191,7 +191,7 @@ switch (process.env.REACT_APP_RELAY_CHAIN_NAME) {
CROWDLOAN_LINK = KINTSUGI_CROWDLOAN_LINK;
OPEN_GRAPH_IMAGE_FILE_NAME = 'kintsugi-meta-image.jpg';
STAKE_LOCK_TIME = {
MIN: 0,
MIN: 1,
MAX: 96
};
// TODO: temporary
Expand Down
58 changes: 25 additions & 33 deletions src/pages/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react';
import { useErrorHandler, withErrorBoundary } from 'react-error-boundary';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useMutation, useQuery } from 'react-query';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useSelector } from 'react-redux';

import { StoreType } from '@/common/types/util.types';
Expand Down Expand Up @@ -119,12 +119,14 @@ const Staking = (): JSX.Element => {
const { data: balances, isLoading: isBalancesLoading } = useGetBalances();
const governanceTokenBalance = balances?.[GOVERNANCE_TOKEN.ticker];

const queryClient = useQueryClient();

const {
register,
handleSubmit,
watch,
reset,
formState: { errors, isDirty, isValid },
formState: { errors, isValid, isValidating },
trigger,
setValue
} = useForm<StakingFormData>({
Expand All @@ -151,8 +153,7 @@ const Staking = (): JSX.Element => {
isIdle: voteGovernanceTokenBalanceIdle,
isLoading: voteGovernanceTokenBalanceLoading,
data: voteGovernanceTokenBalance,
error: voteGovernanceTokenBalanceError,
refetch: voteGovernanceTokenBalanceRefetch
error: voteGovernanceTokenBalanceError
} = useQuery<VoteGovernanceTokenMonetaryAmount, Error>(
[GENERIC_FETCHER, 'escrow', 'votingBalance', selectedAccountAddress],
genericFetcher<VoteGovernanceTokenMonetaryAmount>(),
Expand All @@ -167,8 +168,7 @@ const Staking = (): JSX.Element => {
isIdle: claimableRewardAmountIdle,
isLoading: claimableRewardAmountLoading,
data: claimableRewardAmount,
error: claimableRewardAmountError,
refetch: claimableRewardAmountRefetch
error: claimableRewardAmountError
} = useQuery<GovernanceTokenMonetaryAmount, Error>(
[GENERIC_FETCHER, 'escrow', 'getRewards', selectedAccountAddress],
genericFetcher<GovernanceTokenMonetaryAmount>(),
Expand All @@ -183,8 +183,7 @@ const Staking = (): JSX.Element => {
isIdle: projectedRewardAmountAndAPYIdle,
isLoading: projectedRewardAmountAndAPYLoading,
data: projectedRewardAmountAndAPY,
error: rewardAmountAndAPYError,
refetch: rewardAmountAndAPYRefetch
error: rewardAmountAndAPYError
} = useQuery<EstimatedRewardAmountAndAPY, Error>(
[GENERIC_FETCHER, 'escrow', 'getRewardEstimate', selectedAccountAddress],
genericFetcher<EstimatedRewardAmountAndAPY>(),
Expand All @@ -197,7 +196,6 @@ const Staking = (): JSX.Element => {
// Estimated governance token Rewards & APY
const monetaryLockingAmount = newMonetaryAmount(lockingAmount, GOVERNANCE_TOKEN, true);
const {
isIdle: estimatedRewardAmountAndAPYIdle,
isLoading: estimatedRewardAmountAndAPYLoading,
data: estimatedRewardAmountAndAPY,
error: estimatedRewardAmountAndAPYError,
Expand All @@ -219,19 +217,11 @@ const Staking = (): JSX.Element => {
);
useErrorHandler(estimatedRewardAmountAndAPYError);

// MEMO: This is being set outside of a useEffect because of
// an race condition. This is a underlying issue with the
// component and can't be easily fixed.
if (isValid || !isDirty) {
estimatedRewardAmountAndAPYRefetch();
}

const {
isIdle: stakedAmountAndEndBlockIdle,
isLoading: stakedAmountAndEndBlockLoading,
data: stakedAmountAndEndBlock,
error: stakedAmountAndEndBlockError,
refetch: stakedAmountAndEndBlockRefetch
error: stakedAmountAndEndBlockError
} = useQuery<StakedAmountAndEndBlock, Error>(
[GENERIC_FETCHER, 'escrow', 'getStakedBalance', selectedAccountAddress],
genericFetcher<StakedAmountAndEndBlock>(),
Expand Down Expand Up @@ -266,10 +256,7 @@ const Staking = (): JSX.Element => {
},
{
onSuccess: () => {
voteGovernanceTokenBalanceRefetch();
stakedAmountAndEndBlockRefetch();
claimableRewardAmountRefetch();
rewardAmountAndAPYRefetch();
queryClient.invalidateQueries({ queryKey: [GENERIC_FETCHER, 'escrow'] });
reset({
[LOCKING_AMOUNT]: '0.0',
[LOCK_TIME]: '0'
Expand Down Expand Up @@ -307,10 +294,7 @@ const Staking = (): JSX.Element => {
},
{
onSuccess: () => {
voteGovernanceTokenBalanceRefetch();
stakedAmountAndEndBlockRefetch();
claimableRewardAmountRefetch();
rewardAmountAndAPYRefetch();
queryClient.invalidateQueries({ queryKey: [GENERIC_FETCHER, 'escrow'] });
reset({
[LOCKING_AMOUNT]: '0.0',
[LOCK_TIME]: '0'
Expand All @@ -319,6 +303,13 @@ const Staking = (): JSX.Element => {
}
);

React.useEffect(() => {
if (isValidating || !isValid || !estimatedRewardAmountAndAPYRefetch) return;

estimatedRewardAmountAndAPYRefetch();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isValid, isValidating, lockTime, lockingAmount, estimatedRewardAmountAndAPYRefetch]);

React.useEffect(() => {
if (!lockTime) return;
if (!currentBlockNumber) return;
Expand All @@ -331,10 +322,12 @@ const Staking = (): JSX.Element => {
}, [currentBlockNumber, lockTime, stakedAmountAndEndBlock]);

React.useEffect(() => {
queryClient.invalidateQueries({ queryKey: [GENERIC_FETCHER, 'escrow'] });
reset({
[LOCKING_AMOUNT]: '',
[LOCK_TIME]: ''
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedAccount, reset]);

const votingBalanceGreaterThanZero = voteGovernanceTokenBalance?.gt(ZERO_VOTE_GOVERNANCE_TOKEN_AMOUNT);
Expand Down Expand Up @@ -583,7 +576,7 @@ const Staking = (): JSX.Element => {

const renderNewVoteGovernanceTokenGainedLabel = () => {
const newTotalStakeAmount = getNewTotalStake();
if (voteGovernanceTokenBalance === undefined || newTotalStakeAmount === undefined) {
if (voteGovernanceTokenBalance === undefined || newTotalStakeAmount === undefined || !isValid) {
return '-';
}

Expand All @@ -595,7 +588,7 @@ const Staking = (): JSX.Element => {
};

const getNewTotalStake = () => {
if (remainingBlockNumbersToUnstake === undefined || stakedAmount === undefined) {
if (remainingBlockNumbersToUnstake === undefined || stakedAmount === undefined || !isValid) {
return undefined;
}

Expand Down Expand Up @@ -633,31 +626,31 @@ const Staking = (): JSX.Element => {

const renderEstimatedAPYLabel = () => {
if (
estimatedRewardAmountAndAPYIdle ||
estimatedRewardAmountAndAPYLoading ||
!projectedRewardAmountAndAPY ||
errors[LOCK_TIME] ||
errors[LOCKING_AMOUNT]
) {
return '-';
}
if (estimatedRewardAmountAndAPY === undefined) {
throw new Error('Something went wrong!');
return formatPercentage(projectedRewardAmountAndAPY.apy.toNumber());
}

return formatPercentage(estimatedRewardAmountAndAPY.apy.toNumber());
};

const renderEstimatedRewardAmountLabel = () => {
if (
estimatedRewardAmountAndAPYIdle ||
estimatedRewardAmountAndAPYLoading ||
!projectedRewardAmountAndAPY ||
errors[LOCK_TIME] ||
errors[LOCKING_AMOUNT]
) {
return '-';
}
if (estimatedRewardAmountAndAPY === undefined) {
throw new Error('Something went wrong!');
return `${displayMonetaryAmount(projectedRewardAmountAndAPY.amount)} ${GOVERNANCE_TOKEN_SYMBOL}`;
}

return `${displayMonetaryAmount(estimatedRewardAmountAndAPY.amount)} ${GOVERNANCE_TOKEN_SYMBOL}`;
Expand Down Expand Up @@ -714,7 +707,6 @@ const Staking = (): JSX.Element => {
claimableRewardAmountLoading ||
projectedRewardAmountAndAPYIdle ||
projectedRewardAmountAndAPYLoading ||
estimatedRewardAmountAndAPYIdle ||
estimatedRewardAmountAndAPYLoading ||
stakedAmountAndEndBlockIdle ||
stakedAmountAndEndBlockLoading;
Expand Down