Skip to content

Commit

Permalink
Display a dApp tier rank (#1363)
Browse files Browse the repository at this point in the history
* Display a dApp tier rank

* PR comments fixes
  • Loading branch information
bobo-k2 authored Aug 27, 2024
1 parent 42dcf25 commit aeefe34
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 149 deletions.
8 changes: 1 addition & 7 deletions src/components/common/Balance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<script lang="ts">
import { defineComponent, watch, ref } from 'vue';
import { BN } from '@polkadot/util';
import { formatBalance } from '@polkadot/util';
import { balanceFormatter } from 'src/hooks/helper/plasmUtils';
export default defineComponent({
props: {
Expand All @@ -22,12 +21,7 @@ export default defineComponent({
() => props.balance,
(balance) => {
if (balance) {
const formatted = formatBalance(props.balance, {
withSiFull: true,
decimals: props.decimals,
});
formattedBalance.value = balanceFormatter(props.balance);
formattedBalance.value = balanceFormatter(props.balance, props.decimals, !!props.unit);
}
},
{ immediate: true }
Expand Down
13 changes: 9 additions & 4 deletions src/components/common/FormatBalance.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<balance :balance="balance" :decimals="decimal" :unit="defaultUnitToken" />
<balance :balance="balance" :decimals="decimal" :unit="tokenUnit" />
</template>
<script lang="ts">
import { defineComponent, toRefs } from 'vue';
import { defineComponent, computed } from 'vue';
import { useChainMetadata } from 'src/hooks';
import { BN } from '@polkadot/util';
Expand All @@ -15,14 +15,19 @@ export default defineComponent({
type: [BN, String],
required: true,
},
showTokenUnit: {
type: Boolean,
required: false,
default: true,
},
},
setup(props) {
const { defaultUnitToken, decimal } = useChainMetadata();
const tokenUnit = computed<string>(() => (props.showTokenUnit ? defaultUnitToken.value : ''));
return {
defaultUnitToken,
decimal,
...toRefs(props),
tokenUnit,
};
},
methods: {},
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/helper/plasmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import { LOCAL_STORAGE } from 'src/config/localStorage';
* @param decimal eg: 18
* @returns '0.244 SDN'
*/
export const balanceFormatter = (bal: BN | string, decimal = ASTAR_DECIMALS): string => {
export const balanceFormatter = (
bal: BN | string,
decimal = ASTAR_DECIMALS,
includeCurrency = true
): string => {
let amount;
amount = defaultAmountWithDecimals(bal.toString(), decimal);

const defaultCurrency = localStorage.getItem(LOCAL_STORAGE.DEFAULT_CURRENCY);
return `${nFormatter(Number(amount))} ${defaultCurrency}`;
return `${nFormatter(Number(amount))} ${includeCurrency ? defaultCurrency : ''}`;
};
3 changes: 2 additions & 1 deletion src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export default {
unlockingAmount: 'Unlocking amount',
withdraw: 'Withdraw',
relock: 'Re-lock',
currentTier: 'Current Tier',
currentTier: 'Current Tier / Rank',
numberOfStakers: 'Number of stakers',
totalEarned: 'Total Earned',
yourDashboard: 'Your Dashboard',
Expand Down Expand Up @@ -920,6 +920,7 @@ export default {
'Real time amount of tokens that are entitled to receive bonus rewards.',
bonusPool: 'Bonus pool',
bonusPoolDescription: 'Fixed bonus allocation from block rewards. Check our ',
dappTierDescription: 'dApp tier and rank. Check our ',
dAppsSlots: 'dApps slots',
dAppsSlotsDescription:
'Number of project rewards for the slots filled by projects in the current era.',
Expand Down
128 changes: 0 additions & 128 deletions src/staking-v3/components/FeatureDapp.vue

This file was deleted.

4 changes: 2 additions & 2 deletions src/staking-v3/components/KpiCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="`wrapper--kpi-card ${description !== '' ? 'flip' : ''}`">
<div :class="`wrapper--kpi-card ${description !== '' || $slots.description ? 'flip' : ''}`">
<div class="card--inner">
<div class="card--front">
<div class="card__top">
Expand All @@ -10,7 +10,7 @@
</div>
</div>
<div class="card--back">
<div>{{ description }}</div>
<slot name="description">{{ description }}</slot>
</div>
</div>
</div>
Expand Down
28 changes: 23 additions & 5 deletions src/staking-v3/components/dapp/DappStatistics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,27 @@
</button>
<kpi-card v-if="!small" :title="$t('dappStaking.dappPage.totalStaked')">
<format-balance :balance="dapp.chain.totalStake?.toString() || '0'" />
<format-balance
:balance="dapp.chain.totalStake?.toString() || '0'"
:show-token-unit="false"
/>
<span class="unit">{{ defaultUnitToken }}</span>
</kpi-card>
<kpi-card v-if="!small" :title="$t('stakingV3.currentTier')">
<span>{{ getDappTier(dapp.chain.id) ?? '--' }}</span>
<span>{{ getDappTier(dapp.chain.id) ?? '--' }}</span> /
<span>{{ getDappRank(dapp.chain.id) ?? '--' }}</span>
<template #description>
<span>
{{ $t('stakingV3.dappTierDescription') }}
<a
href="https://docs.astar.network/docs/learn/dapp-staking/dapp-staking-protocol#tier-system"
target="_blank"
class="text--link"
rel="noopener noreferrer"
>{{ $t('common.docs') }}</a
>
</span>
</template>
</kpi-card>
<kpi-card v-if="!small" :title="$t('stakingV3.numberOfStakers')">
<span>{{ dapp.dappDetails?.stakersCount ?? '--' }}</span>
Expand All @@ -29,7 +46,7 @@ import { defineComponent, PropType } from 'vue';
import KpiCard from '../KpiCard.vue';
import VoteStakeButtonBg from '../VoteStakeButtonBg.vue';
import FormatBalance from 'components/common/FormatBalance.vue';
import { useNetworkInfo } from 'src/hooks';
import { useChainMetadata, useNetworkInfo } from 'src/hooks';
export default defineComponent({
components: {
Expand All @@ -49,11 +66,12 @@ export default defineComponent({
},
},
setup(props) {
const { getDappTier } = useDappStaking();
const { getDappTier, getDappRank } = useDappStaking();
const { isZkEvm } = useNetworkInfo();
const { navigateToVote } = useDappStakingNavigation();
const { defaultUnitToken } = useChainMetadata();
return { getDappTier, navigateToVote, isZkEvm };
return { getDappTier, getDappRank, navigateToVote, defaultUnitToken, isZkEvm };
},
});
</script>
Expand Down
12 changes: 12 additions & 0 deletions src/staking-v3/components/dapp/styles/dapp-statistics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@
}
}
}

.unit {
font-size: 16px;
}

.text--link {
color: $astar-blue-dark;
text-transform: lowercase;
&:hover {
color: lighten($astar-blue-dark, 15%);
}
}
6 changes: 6 additions & 0 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ export function useDappStaking() {
return tier !== undefined ? tier.tierId + 1 : undefined;
};

const getDappRank = (dappId: number): number | undefined => {
const tier = leaderboard.value?.get(dappId);
return tier?.rank;
};

const fetchStakerInfoToStore = async (): Promise<void> => {
if (!currentAccount.value) {
return;
Expand Down Expand Up @@ -676,6 +681,7 @@ export function useDappStaking() {
getCurrentEraInfo,
getDappTiers,
getDappTier,
getDappRank,
fetchStakerInfoToStore,
fetchTiersConfigurationToStore,
withdraw,
Expand Down

0 comments on commit aeefe34

Please sign in to comment.