Skip to content

Commit

Permalink
Release hotfix to main (#1394)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
bobo-k2 authored Oct 1, 2024
1 parent a0f1a9d commit cb47638
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
33 changes: 26 additions & 7 deletions src/staking-v3/components/ClaimAndRestakeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import ModalRestake from './vote/re-stake/ModalRestake.vue';
import { useDappStaking, useVote } from '../hooks';
import { ClaimType } from '../logic';
import { useDappStaking, useVote, useDapps } from '../hooks';
import { ClaimType, type SingularStakingInfo } from '../logic';
export default defineComponent({
components: {
Expand Down Expand Up @@ -53,30 +53,49 @@ export default defineComponent({
claimStakerAndBonusRewards,
} = useDappStaking();
const { vote } = useVote(ref([]));
const { getDapp } = useDapps();
const showRestakeModal = ref<boolean>(false);
// Staker info containing registered dApps only.
// Rewards can't be re-staked for unregistered dApps.
const stakerInfoRegisteredDapps =
computed<Map<string, SingularStakingInfo>>(() => {
const result = new Map<string, SingularStakingInfo>();
stakerInfo.value.forEach((value, key) => {
const dapp = getDapp(key);
if (dapp) {
result.set(key, value);
}
});
return result;
});
const amountToClaim = computed<bigint>(() => {
if (props.claimType === ClaimType.Staker) {
return rewards.value.staker.amount;
} else if (props.claimType === ClaimType.Bonus) {
}
if (props.claimType === ClaimType.Bonus) {
return rewards.value.bonus;
} else {
return totalStakerRewards.value;
}
return totalStakerRewards.value;
});
const setShowRestakeModal = async (value: boolean) => {
// Idea is to restake proportionally to already staked dApps.
// At the beginning of a period all stakes are reset so user will be able to claim rewards only.
if (value && stakerInfo.value.size === 0) {
if (value && stakerInfoRegisteredDapps.value.size === 0) {
await handleRestakeConfirm(false);
} else {
showRestakeModal.value = value;
}
};
const handleRestakeConfirm = async (restake: boolean): Promise<void> => {
if (restake && stakerInfo.value.size > 0) {
if (restake && stakerInfoRegisteredDapps.value.size > 0) {
await vote(restake);
} else {
if (props.claimType === ClaimType.Staker) {
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/components/my-staking/MyStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default defineComponent({
formatPeriod,
} = useDappStaking();

const bonus = ref<BigInt>(BigInt(0));
const bonus = ref<bigint>(BigInt(0));
const { getEstimatedBonus } = useAprV3({ isWatch: false });

const { navigateToVote } = useDappStakingNavigation();
Expand Down
8 changes: 4 additions & 4 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function useDappStaking() {
);
const staker = await stakingService.getStakerRewards(currentAccount.value);
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus });
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount });
getCurrentEraInfo();
fetchStakeAmountsToStore();
await fetchStakerInfoToStore();
Expand All @@ -214,7 +214,7 @@ export function useDappStaking() {
stakingService.getBonusRewards(currentAccount.value),
stakingService.getDappRewards(dappAddress),
]);
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus, dApp });
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount, dApp });
fetchStakerInfoToStore();
getCurrentEraInfo();
fetchStakeAmountsToStore();
Expand Down Expand Up @@ -272,7 +272,7 @@ export function useDappStaking() {
t('stakingV3.claimBonusRewardSuccess')
);
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, bonus });
store.commit('stakingV3/setRewards', { ...rewards.value, bonus: bonus.amount });
};

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

const withdraw = async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/hooks/useVote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ref, computed, ref, watch } from 'vue';
import { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
import type { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
import { ethers } from 'ethers';
import { useAccount, useBalance } from 'src/hooks';
import { useDappStaking } from './useDappStaking';
Expand Down

0 comments on commit cb47638

Please sign in to comment.