-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bonus rewards distribution per dApp * Error fix * Restake initial implementation * Text fix * Code cleanup * Button color fix * Restake on claim * Disable restaking if no stakes
- Loading branch information
Showing
16 changed files
with
430 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<template> | ||
<div @click="setShowRestakeModal(true)"> | ||
<slot> | ||
<astar-button :disabled="amountToClaim <= 0" :width="width" :height="height"> | ||
{{ $t('stakingV3.claim') }} | ||
</astar-button> | ||
</slot> | ||
<Teleport to="#app--main"> | ||
<modal-restake | ||
:show="showRestakeModal" | ||
:set-is-open="setShowRestakeModal" | ||
:rewards="amountToClaim" | ||
:on-confirm="handleRestakeConfirm" | ||
/> | ||
</Teleport> | ||
</div> | ||
</template> | ||
|
||
<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'; | ||
export default defineComponent({ | ||
components: { | ||
ModalRestake, | ||
}, | ||
props: { | ||
claimType: { | ||
type: Number, | ||
required: false, | ||
default: ClaimType.Staker, | ||
}, | ||
width: { | ||
type: Number, | ||
required: false, | ||
default: 100, | ||
}, | ||
height: { | ||
type: Number, | ||
required: false, | ||
default: 32, | ||
}, | ||
}, | ||
setup(props) { | ||
const { | ||
totalStakerRewards, | ||
rewards, | ||
stakerInfo, | ||
claimStakerRewards, | ||
claimBonusRewards, | ||
claimStakerAndBonusRewards, | ||
} = useDappStaking(); | ||
const { vote } = useVote(ref([])); | ||
const showRestakeModal = ref<boolean>(false); | ||
const amountToClaim = computed<bigint>(() => { | ||
if (props.claimType === ClaimType.Staker) { | ||
return rewards.value.staker.amount; | ||
} else if (props.claimType === ClaimType.Bonus) { | ||
return rewards.value.bonus; | ||
} else { | ||
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) { | ||
await handleRestakeConfirm(false); | ||
} else { | ||
showRestakeModal.value = value; | ||
} | ||
}; | ||
const handleRestakeConfirm = async (restake: boolean): Promise<void> => { | ||
if (restake && stakerInfo.value.size > 0) { | ||
await vote(restake); | ||
} else { | ||
if (props.claimType === ClaimType.Staker) { | ||
await claimStakerRewards(); | ||
} else if (props.claimType === ClaimType.Bonus) { | ||
await claimBonusRewards(); | ||
} else { | ||
await claimStakerAndBonusRewards(); | ||
} | ||
} | ||
}; | ||
return { | ||
showRestakeModal, | ||
amountToClaim, | ||
setShowRestakeModal, | ||
handleRestakeConfirm, | ||
}; | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.