Skip to content

Commit cb47638

Browse files
authored
Release hotfix to main (#1394)
* Remove Age of Chronos promotion (#1386) * Fetch block time from chain (#1384) * Fetch block time to store * Apr calculation fix * Type fix * PR comments fix and code cleanup * Fix/selected dapp index (#1387) * Voting wizard search bug fix * Keep selected dApps while switching categories * APR calculation fix to use block time for a given block (#1389) * APR calculation fix to use block time for a given block * Small fix * Fix for re-staking on unregistered dApps (#1392)
1 parent a0f1a9d commit cb47638

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/staking-v3/components/ClaimAndRestakeButton.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<script lang="ts">
2020
import { defineComponent, ref, computed } from 'vue';
2121
import ModalRestake from './vote/re-stake/ModalRestake.vue';
22-
import { useDappStaking, useVote } from '../hooks';
23-
import { ClaimType } from '../logic';
22+
import { useDappStaking, useVote, useDapps } from '../hooks';
23+
import { ClaimType, type SingularStakingInfo } from '../logic';
2424
2525
export default defineComponent({
2626
components: {
@@ -53,30 +53,49 @@ export default defineComponent({
5353
claimStakerAndBonusRewards,
5454
} = useDappStaking();
5555
const { vote } = useVote(ref([]));
56+
const { getDapp } = useDapps();
5657
const showRestakeModal = ref<boolean>(false);
5758
59+
// Staker info containing registered dApps only.
60+
// Rewards can't be re-staked for unregistered dApps.
61+
const stakerInfoRegisteredDapps =
62+
computed<Map<string, SingularStakingInfo>>(() => {
63+
const result = new Map<string, SingularStakingInfo>();
64+
65+
stakerInfo.value.forEach((value, key) => {
66+
const dapp = getDapp(key);
67+
if (dapp) {
68+
result.set(key, value);
69+
}
70+
});
71+
72+
return result;
73+
});
74+
5875
const amountToClaim = computed<bigint>(() => {
5976
if (props.claimType === ClaimType.Staker) {
6077
return rewards.value.staker.amount;
61-
} else if (props.claimType === ClaimType.Bonus) {
78+
}
79+
80+
if (props.claimType === ClaimType.Bonus) {
6281
return rewards.value.bonus;
63-
} else {
64-
return totalStakerRewards.value;
6582
}
83+
84+
return totalStakerRewards.value;
6685
});
6786
6887
const setShowRestakeModal = async (value: boolean) => {
6988
// Idea is to restake proportionally to already staked dApps.
7089
// At the beginning of a period all stakes are reset so user will be able to claim rewards only.
71-
if (value && stakerInfo.value.size === 0) {
90+
if (value && stakerInfoRegisteredDapps.value.size === 0) {
7291
await handleRestakeConfirm(false);
7392
} else {
7493
showRestakeModal.value = value;
7594
}
7695
};
7796
7897
const handleRestakeConfirm = async (restake: boolean): Promise<void> => {
79-
if (restake && stakerInfo.value.size > 0) {
98+
if (restake && stakerInfoRegisteredDapps.value.size > 0) {
8099
await vote(restake);
81100
} else {
82101
if (props.claimType === ClaimType.Staker) {

src/staking-v3/components/my-staking/MyStaking.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export default defineComponent({
206206
formatPeriod,
207207
} = useDappStaking();
208208
209-
const bonus = ref<BigInt>(BigInt(0));
209+
const bonus = ref<bigint>(BigInt(0));
210210
const { getEstimatedBonus } = useAprV3({ isWatch: false });
211211
212212
const { navigateToVote } = useDappStakingNavigation();

src/staking-v3/hooks/useDappStaking.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function useDappStaking() {
192192
);
193193
const staker = await stakingService.getStakerRewards(currentAccount.value);
194194
const bonus = await stakingService.getBonusRewards(currentAccount.value);
195-
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus });
195+
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount });
196196
getCurrentEraInfo();
197197
fetchStakeAmountsToStore();
198198
await fetchStakerInfoToStore();
@@ -214,7 +214,7 @@ export function useDappStaking() {
214214
stakingService.getBonusRewards(currentAccount.value),
215215
stakingService.getDappRewards(dappAddress),
216216
]);
217-
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus, dApp });
217+
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount, dApp });
218218
fetchStakerInfoToStore();
219219
getCurrentEraInfo();
220220
fetchStakeAmountsToStore();
@@ -272,7 +272,7 @@ export function useDappStaking() {
272272
t('stakingV3.claimBonusRewardSuccess')
273273
);
274274
const bonus = await stakingService.getBonusRewards(currentAccount.value);
275-
store.commit('stakingV3/setRewards', { ...rewards.value, bonus });
275+
store.commit('stakingV3/setRewards', { ...rewards.value, bonus: bonus.amount });
276276
};
277277

278278
const claimDappRewards = async (contractAddress: string): Promise<void> => {
@@ -303,7 +303,7 @@ export function useDappStaking() {
303303
);
304304
const staker = await stakingService.getStakerRewards(currentAccount.value);
305305
const bonus = await stakingService.getBonusRewards(currentAccount.value);
306-
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus });
306+
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount });
307307
};
308308

309309
const withdraw = async (): Promise<void> => {

src/staking-v3/hooks/useVote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Ref, computed, ref, watch } from 'vue';
2-
import { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
2+
import type { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
33
import { ethers } from 'ethers';
44
import { useAccount, useBalance } from 'src/hooks';
55
import { useDappStaking } from './useDappStaking';

0 commit comments

Comments
 (0)