Skip to content

Commit

Permalink
Enable dApp staking v3 on Shiden (#1168)
Browse files Browse the repository at this point in the history
* Enable dApp staking v3 on Shiden

* fix: get periodsPerCycle from onchain (#1167)

* feat: get periodsPerCycle from onchain

* refactor: clean up

* Translation fix

* Hide period number if no rewards - my staking

---------

Co-authored-by: impelcrypto <[email protected]>
  • Loading branch information
bobo-k2 and impelcrypto authored Feb 7, 2024
1 parent 54fd24a commit 0091502
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default route<StateInterface>(function (/* { store, ssrContext } */) {
// TODO - remove after the portal v3 is live.
Router.beforeEach((to, from, next) => {
// Prevent accessing to dApp staking pages if v3 is deployed to a node, but not supported by UI
const networksSupportV3 = ['development', 'shibuya-testnet', 'custom-node'];
const networksSupportV3 = ['development', 'shibuya-testnet', 'custom-node', 'shiden'];
const isStakingV3 = $api?.query.hasOwnProperty('dappStaking');
const dontNavigateToDappStaking =
to.path.includes('/dapp-staking') &&
Expand Down
4 changes: 3 additions & 1 deletion src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ const routes: RouteRecordRaw[] = [
{
path: 'discover',
component:
networkParam === '/development' || networkParam === '/shibuya-testnet'
networkParam === '/development' ||
networkParam === '/shibuya-testnet' ||
networkParam === '/shiden'
? DiscoverV3
: StakingTop,
},
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 @@ -108,7 +108,7 @@
<div class="row--my-rewards-header">
<span class="column--left">
<span class="text--rewards">{{ $t('stakingV3.rewards') }}</span>
<span class="text--period">
<span v-if="rewards?.staker.period" class="text--period">
{{ $t('stakingV3.period', { period: formatPeriod(rewards?.staker.period ?? 0) }) }}
</span>
</span>
Expand Down
15 changes: 5 additions & 10 deletions src/staking-v3/hooks/useAprV3.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { u128 } from '@polkadot/types';
import { $api } from 'boot/api';
import { ethers } from 'ethers';
import { container } from 'src/v2/common';
import { IInflationRepository } from 'src/v2/repositories';
import { Symbols } from 'src/v2/symbols';
import { ref, watch, computed } from 'vue';
import { EraInfo, EraLengths, IDappStakingRepository, InflationParam } from '../logic';
import { computed, ref, watch } from 'vue';
import { EraInfo, EraLengths, InflationParam } from '../logic';
import { useDappStaking } from './useDappStaking';
import { u128 } from '@polkadot/types';
import { useNetworkInfo } from 'src/hooks';
import { IInflationRepository } from 'src/v2/repositories';

export const useAprV3 = () => {
const stakerApr = ref<number>(0);
const bonusApr = ref<number>(0);
const { eraLengths, isVotingPeriod, currentEraInfo } = useDappStaking();
const { currentNetworkName } = useNetworkInfo();

const percentageToNumber = (percent: string): number => {
// e.g.: percent 1%: 10000000000000000
Expand All @@ -24,10 +22,7 @@ export const useAprV3 = () => {
return Number(ethers.utils.formatEther(String(wei)));
};

// Todo: fetch it via API
const periodsPerCycle = computed<number>(() => {
return currentNetworkName.value === 'Shibuya' ? 2 : 4;
});
const periodsPerCycle = computed<number>(() => eraLengths.value.periodsPerCycle);

const getCyclePerYear = (eraLength: EraLengths): number => {
const secBlockProductionRate = 12;
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export function useDappStaking() {
) {
return [
false,
t('stakingV3.minBalanceAfterStaking', {
t('stakingV3.voting.minBalanceAfterStaking', {
amount: constants.value.minBalanceAfterStaking,
symbol: nativeTokenSymbol.value,
}),
Expand Down

0 comments on commit 0091502

Please sign in to comment.