Skip to content

Commit

Permalink
Staking panels and leaderboard (#1056)
Browse files Browse the repository at this point in the history
* Get contract stake

* Initial leaderboard version

* voting call refactoring

* Tier rewards updates

* Leaderboard rendering fix

* My staking components

* Staking components logic done

* Re-lock unlocking chunks

* Unbonding modal

* Bonus rewards calculation bug fix

* Minor navigation refactoring

* Display total stake

* PropType fix

* Total stake calculation fix
  • Loading branch information
bobo-k2 committed Nov 29, 2023
1 parent e3be666 commit 988912e
Show file tree
Hide file tree
Showing 37 changed files with 1,492 additions and 149 deletions.
24 changes: 9 additions & 15 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@ import { container } from 'src/v2/common';
import { Symbols } from 'src/v2/symbols';
import { useAccount, useAppRouter } from 'src/hooks';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import { ETHEREUM_EXTENSION } from 'src/hooks';
import {
AccountLedgerChangedMessage,
IDappStakingRepository,
IDappStakingService,
ProtocolStateChangedMessage,
StakerInfoChangedMessage,
} from './staking-v3';
import { useDappStaking } from './staking-v3/hooks';
import { useDappStaking, useDapps } from './staking-v3/hooks';
export default defineComponent({
name: 'App',
Expand All @@ -88,7 +85,9 @@ export default defineComponent({
useAppRouter();
const store = useStore();
const { currentAccountName, currentAccount } = useAccount();
const { getAllRewards, getCurrentEraInfo, getDappTiers } = useDappStaking();
const { getAllRewards, getCurrentEraInfo, getDappTiers, fetchStakerInfoToStore } =
useDappStaking();
const { fetchStakeAmountsToStore } = useDapps();
const isLoading = computed(() => store.getters['general/isLoading']);
const showAlert = computed(() => store.getters['general/showAlert']);
Expand All @@ -107,7 +106,7 @@ export default defineComponent({
showDisclaimerModal.value = isOpen;
};
// Handle busy and extrisnsic call status messages.
// Handle busy and extrinsic call status messages.
const eventAggregator = container.get<IEventAggregator>(Symbols.EventAggregator);
eventAggregator.subscribe(ExtrinsicStatusMessage.name, (m) => {
const message = m as ExtrinsicStatusMessage;
Expand Down Expand Up @@ -148,6 +147,8 @@ export default defineComponent({
getAllRewards(),
getCurrentEraInfo(),
getDappTiers(message.state.era - 1),
fetchStakeAmountsToStore(),
fetchStakerInfoToStore(),
]);
});
Expand All @@ -157,11 +158,6 @@ export default defineComponent({
console.log('ledger', message.ledger);
});
eventAggregator.subscribe(StakerInfoChangedMessage.name, (m) => {
const message = m as StakerInfoChangedMessage;
store.commit('stakingV3/setStakerInfo', message.stakerInfo, { root: true });
});
// **** end dApp staking v3
// Handle wallet change so we can inject proper wallet
Expand All @@ -174,10 +170,8 @@ export default defineComponent({
container
.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3)
.startAccountLedgerSubscription(currentAccount.value);
container
.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3)
.startGetStakerInfoSubscription(currentAccount.value);
fetchStakerInfoToStore();
getAllRewards();
previousAddress = currentAccount.value;
}
Expand Down
42 changes: 42 additions & 0 deletions src/components/common/TokenBalanceNative.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<token-balance
:balance="ethers.utils.formatEther(balance)"
:text="text"
:decimals="decimals"
:symbol="nativeTokenSymbol"
/>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { ethers } from 'ethers';
import TokenBalance from './TokenBalance.vue';
import { useNetworkInfo } from 'src/hooks';
export default defineComponent({
components: {
TokenBalance,
},
props: {
balance: {
type: String,
required: true,
},
text: {
type: String,
required: false,
default: '',
},
decimals: {
type: Number,
required: false,
default: 3,
},
},
setup() {
const { nativeTokenSymbol } = useNetworkInfo();
return { nativeTokenSymbol, ethers };
},
});
</script>
18 changes: 18 additions & 0 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,24 @@ export default {
vote: 'Vote',
voteToday: 'Vote today and be eligible for bonus rewards',
stakeOn: 'Stake on {name}',
tier: 'Tier',
tierLeaderboard: 'Tier Leaderboard',
myStaking: 'My Staking',
myDapps: 'My dApps',
unbonding: 'Unbonding',
totalEstimatedRewards: 'Total estimated rewards',
claim: 'Claim',
dApp: 'dApp',
stakedAmount: 'Staked amount',
bonusReward: 'Bonus reward',
manage: 'Manage',
add: 'Add',
unbond: 'Unbond',
index: 'Index',
chunk: 'Chunk',
unbondingAmount: 'Unbonding amount',
withdraw: 'Withdraw',
relock: 'Re-lock',
},
bridge: {
bridge: 'Bridge',
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Dashboard from 'src/pages/Dashboard.vue';
import RegisterDapp from 'src/pages/RegisterDapp.vue';
import StakeManage from 'src/pages/StakeManage.vue';
import DappPage from 'src/pages/DappPage.vue';
import { Vote } from 'src/staking-v3';
import Vote from 'src/staking-v3/components/Vote.vue';
import DiscoverV3 from 'src/staking-v3/components/DiscoverV3.vue';
import { RouteRecordRaw } from 'vue-router';

Expand Down
Binary file added src/staking-v3/assets/burn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 11 additions & 13 deletions src/staking-v3/components/Dapps.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="wrapper--dapps">
<div v-for="(dapp, index) in registeredDapps" :key="index">
<div v-if="dapp" class="card--dapp" @click="goDappPageLink(dapp.basic.address)">
<div v-if="dapp" class="card--dapp" @click="navigateDappPage(dapp.basic.address)">
<div class="card__top">
<div>
<img :src="dapp.basic.iconUrl" alt="icon" class="icon--dapp" />
Expand All @@ -18,7 +18,9 @@
<span class="text--label">2,432</span>
</div>
<div>
<span class="text--label">1.078M ASTR</span>
<span class="text--label">
<token-balance-native :balance="dapp.chain.totalStake?.toString() ?? '0'" />
</span>
</div>
</div>
</div>
Expand All @@ -27,24 +29,20 @@
</template>

<script lang="ts">
import { Path, networkParam } from 'src/router/routes';
import { defineComponent } from 'vue';
import { useDappStaking, useDapps } from '../hooks';
import { useRouter } from 'vue-router';
import { useDappStaking, useDappStakingNavigation, useDapps } from '../hooks';
import TokenBalanceNative from 'src/components/common/TokenBalanceNative.vue';

export default defineComponent({
components: {
TokenBalanceNative,
},
setup() {
const { registeredDapps } = useDapps();
const { getDappTier } = useDappStaking();
const router = useRouter();

const goDappPageLink = (address: string): void => {
const base = networkParam + Path.DappStaking + Path.Dapp;
const url = `${base}?dapp=${address?.toLowerCase()}`;
router.push(url);
};
const { navigateDappPage } = useDappStakingNavigation();

return { registeredDapps, getDappTier, goDappPageLink };
return { registeredDapps, getDappTier, navigateDappPage };
},
});
</script>
Expand Down
10 changes: 7 additions & 3 deletions src/staking-v3/components/DiscoverV3.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<template>
<div class="wrapper--discover">
<!-- Todo: Delete -->
<staking-home />
<!-- <staking-home /> -->
<feature-dapp />
<staking />
<leaderboard />
<ad />
<dapps />
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import StakingHome from './StakingHome.vue';
import FeatureDapp from './FeatureDapp.vue';
import Ad from './Ad.vue';
import Dapps from './Dapps.vue';
import Leaderboard from './leaderboard/Leaderboard.vue';
import Staking from './my-staking/Staking.vue';
export default defineComponent({
components: {
StakingHome,
FeatureDapp,
Ad,
Dapps,
Leaderboard,
Staking,
},
setup() {
return {};
Expand Down
15 changes: 4 additions & 11 deletions src/staking-v3/components/FeatureDapp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@
</kpi-card>
</div>
<div v-if="!isVotingPeriod" class="row--start-staking">
<button class="button--staking">
<span class="text--start-staking" @click="navigateToVote()">Start Staking Now</span>
<button class="button--staking" @click="navigateToVote()">
<span class="text--start-staking">Start Staking Now</span>
</button>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';
import { useDappStaking, useDapps, useCampaign } from '../hooks';
import { useDappStaking, useDapps, useCampaign, useDappStakingNavigation } from '../hooks';
import { Campaign } from 'src/v2/models';
import { Path, networkParam } from 'src/router/routes';
import FormatBalance from 'src/components/common/FormatBalance.vue';
import KpiCard from './KpiCard.vue';
import { useRouter } from 'vue-router';

export default defineComponent({
components: {
Expand All @@ -61,7 +59,7 @@ export default defineComponent({
const { constants, currentEraInfo, isVotingPeriod } = useDappStaking();
const { registeredDapps } = useDapps();
const { newListings } = useCampaign();
const router = useRouter();
const { navigateToVote } = useDappStakingNavigation();
// const { totalSupply } = useTokenCirculation();

// const tvlPercentage = computed<number>(
Expand All @@ -74,11 +72,6 @@ export default defineComponent({
newListings.value.length ? newListings.value[0] : undefined
);

const navigateToVote = (dAppAddress: string | undefined = undefined): void => {
const base = networkParam + Path.DappStaking + Path.Vote;
router.push(`${base}?dappAddress=${dAppAddress ?? ''}`);
};
return {
constants,
registeredDapps,
Expand Down
11 changes: 2 additions & 9 deletions src/staking-v3/components/StakingHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
<script lang="ts">
import { defineComponent, onMounted, watch } from 'vue';
import { useAccount } from 'src/hooks';
import { useDappStaking, useDapps } from '../hooks';
import { Path, networkParam } from 'src/router/routes';
import { useRouter } from 'vue-router';
import { useDappStaking, useDapps, useDappStakingNavigation } from '../hooks';
export default defineComponent({
components: {},
setup() {
const router = useRouter();
const { registeredDapps, fetchDappsToStore, fetchDappToStore } = useDapps();
const {
protocolState,
Expand All @@ -44,13 +41,9 @@ export default defineComponent({
claimBonusRewards,
getAllRewards,
} = useDappStaking();
const { navigateToVote } = useDappStakingNavigation();
const { currentAccount } = useAccount();
const navigateToVote = (): void => {
const base = networkParam + Path.DappStaking + Path.Vote;
router.push(base);
};
onMounted(async () => {
await fetchDappsToStore();
});
Expand Down
Loading

0 comments on commit 988912e

Please sign in to comment.