From b65aae7ff24c0009123db887d6a4901322b00d9b Mon Sep 17 00:00:00 2001 From: Gregory Luneau Date: Mon, 19 Feb 2024 12:21:24 -0500 Subject: [PATCH] from stakers to stakers and lockers --- src/i18n/en-US/index.ts | 4 ++-- src/staking-v3/components/data/DataList.vue | 10 ++++---- src/staking-v3/hooks/useDapps.ts | 9 ++++---- src/staking-v3/hooks/useDataCalculations.ts | 12 +++++++--- src/staking-v3/logic/models/DappStaking.ts | 9 +++++--- .../repositories/IDataProviderRepository.ts | 4 ++-- .../TokenApiProviderRepository.ts | 23 +++++++------------ src/staking-v3/store/getters.ts | 2 +- src/staking-v3/store/mutations.ts | 10 +++++--- src/staking-v3/store/state.ts | 13 +++++++++-- 10 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/i18n/en-US/index.ts b/src/i18n/en-US/index.ts index 2fe1d4a65..6a9a76e22 100644 --- a/src/i18n/en-US/index.ts +++ b/src/i18n/en-US/index.ts @@ -867,8 +867,8 @@ export default { numberOfDapps: 'Number of dApps', numberOfDappsDescription: 'The total number of dApps that are currently listed on dApp Staking.', - lockAccounts: 'Lock accounts', - numberOfParticipantsDescription: 'The total number of dApp Staking users.', + stakingAndLockingAccounts: 'Staking & Locking accounts', + numberOfStakersAndLockersDescription: 'The total number of dApp Staking & Locking users.', tokenomics: 'tokenomics', general: 'General', totalValueLocked: 'Total Value Locked ({token})', diff --git a/src/staking-v3/components/data/DataList.vue b/src/staking-v3/components/data/DataList.vue index d007cc6e0..c9016d7d4 100644 --- a/src/staking-v3/components/data/DataList.vue +++ b/src/staking-v3/components/data/DataList.vue @@ -20,10 +20,10 @@ {{ protocolState?.era ?? '--' }} - {{ numberOfParticipants }} + {{ numberOfStakersAndLockers.stakersCount }} / {{ numberOfStakersAndLockers.lockersCount }} @@ -130,7 +130,7 @@ export default defineComponent({ tvlPercentage, totalVolumeOfVotesPercentage, bonusEligibleTokens, - numberOfParticipants, + numberOfStakersAndLockers, } = useDataCalculations(); const { activeInflationConfiguration } = useInflation(); @@ -170,7 +170,7 @@ export default defineComponent({ totalVolumeOfVotesPercentage, bonusEligibleTokens, activeInflationConfiguration, - numberOfParticipants, + numberOfStakersAndLockers, nativeTokenSymbol, periodRemainingDays, isVotingPeriod, diff --git a/src/staking-v3/hooks/useDapps.ts b/src/staking-v3/hooks/useDapps.ts index 669517acc..695b6e0b8 100644 --- a/src/staking-v3/hooks/useDapps.ts +++ b/src/staking-v3/hooks/useDapps.ts @@ -44,10 +44,11 @@ export function useDapps() { // Memo: this can a heavy operations since we are querying all dapps stakes for a chain. await fetchStakeAmountsToStore(); - const numberOfParticipants = await tokenApiProviderRepository.getNumberOfParticipants( - currentNetworkName.value.toLowerCase() - ); - store.commit('stakingV3/setNumberOfParticipants', numberOfParticipants); + const numberOfStakersAndLockers = + await tokenApiProviderRepository.getNumberOfStakersAndLockers( + currentNetworkName.value.toLowerCase() + ); + store.commit('stakingV3/setNumberOfStakersAndLockers', numberOfStakersAndLockers); } finally { aggregator.publish(new BusyMessage(false)); } diff --git a/src/staking-v3/hooks/useDataCalculations.ts b/src/staking-v3/hooks/useDataCalculations.ts index d127fe362..9d1723f32 100644 --- a/src/staking-v3/hooks/useDataCalculations.ts +++ b/src/staking-v3/hooks/useDataCalculations.ts @@ -3,6 +3,7 @@ import { useDappStaking } from './useDappStaking'; import { useTokenCirculation } from 'src/hooks/useTokenCirculation'; import { ethers } from 'ethers'; import { useStore } from 'src/store'; +import { NumberOfStakersAndLockers } from '../logic'; export function useDataCalculations() { const { totalSupply } = useTokenCirculation(); @@ -46,9 +47,14 @@ export function useDataCalculations() { : currentEraInfo.value.currentStakeAmount.voting; }); - const numberOfParticipants = computed( - () => store.getters['stakingV3/getNumberOfParticipants'] + const numberOfStakersAndLockers = computed( + () => store.getters['stakingV3/getNumberOfStakersAndLockers'] ); - return { tvlPercentage, totalVolumeOfVotesPercentage, bonusEligibleTokens, numberOfParticipants }; + return { + tvlPercentage, + totalVolumeOfVotesPercentage, + bonusEligibleTokens, + numberOfStakersAndLockers, + }; } diff --git a/src/staking-v3/logic/models/DappStaking.ts b/src/staking-v3/logic/models/DappStaking.ts index d98ba9d0d..3f937ff29 100644 --- a/src/staking-v3/logic/models/DappStaking.ts +++ b/src/staking-v3/logic/models/DappStaking.ts @@ -204,9 +204,12 @@ export interface ProviderDappData { dappId: number; } -export interface NumberOfParticipantsData { - timestamp: string; - participants: number; +export interface NumberOfStakersAndLockers { + date: string; + tvl: string; + lockersCount: number; + tvs: string; + stakersCount: number; } export interface StakerRewards { diff --git a/src/staking-v3/logic/repositories/IDataProviderRepository.ts b/src/staking-v3/logic/repositories/IDataProviderRepository.ts index 3670ce156..10dcec1d6 100644 --- a/src/staking-v3/logic/repositories/IDataProviderRepository.ts +++ b/src/staking-v3/logic/repositories/IDataProviderRepository.ts @@ -1,9 +1,9 @@ -import { ProviderDappData } from '../models'; +import { ProviderDappData, NumberOfStakersAndLockers } from '../models'; /** * Interface for provider to fetch dapp staking v3 data from other sources */ export interface IDataProviderRepository { getDapps(network: string): Promise; - getNumberOfParticipants(network: string): Promise; + getNumberOfStakersAndLockers(network: string): Promise; } diff --git a/src/staking-v3/logic/repositories/TokenApiProviderRepository.ts b/src/staking-v3/logic/repositories/TokenApiProviderRepository.ts index 0fc36b5f6..35fd1a084 100644 --- a/src/staking-v3/logic/repositories/TokenApiProviderRepository.ts +++ b/src/staking-v3/logic/repositories/TokenApiProviderRepository.ts @@ -1,6 +1,6 @@ import { injectable } from 'inversify'; import { IDataProviderRepository } from './IDataProviderRepository'; -import { ProviderDappData, NumberOfParticipantsData } from '../models'; +import { ProviderDappData, NumberOfStakersAndLockers } from '../models'; import { TOKEN_API_URL } from '@astar-network/astar-sdk-core'; import { Guard } from 'src/v2/common'; import axios from 'axios'; @@ -21,27 +21,20 @@ export class TokenApiProviderRepository implements IDataProviderRepository { return []; } - async getNumberOfParticipants(network: string): Promise { + async getNumberOfStakersAndLockers(network: string): Promise { + // Modify the return type to remove the possibility of undefined Guard.ThrowIfUndefined(network, 'network'); - const numberOfParticipantsUrl = `${TOKEN_API_URL}/v3/${network.toLowerCase()}/dapps-staking/stakerscount-total/1 day`; + const numberOfStakersAndLockersUrl = `${TOKEN_API_URL}/v3/${network.toLowerCase()}/dapps-staking/lockers-and-stakers-total/1 day`; try { - const numberOfParticipants = await axios.get>>( - numberOfParticipantsUrl + const numberOfStakersAndLockers = await axios.get>( + numberOfStakersAndLockersUrl ); - const transformedData: NumberOfParticipantsData[] = numberOfParticipants.data.map((item) => { - return { - timestamp: item[0] as string, - participants: item[1] as number, - }; - }); - - return transformedData.length > 0 ? transformedData[0].participants : 0; + return numberOfStakersAndLockers.data[0]; } catch (error) { console.error(error); + throw error; // Throw the error instead of returning undefined } - - return 0; } } diff --git a/src/staking-v3/store/getters.ts b/src/staking-v3/store/getters.ts index d62198a6c..3cd37ab2e 100644 --- a/src/staking-v3/store/getters.ts +++ b/src/staking-v3/store/getters.ts @@ -37,7 +37,7 @@ const getters: GetterTree & DappStakingGetters getVersion: (state) => state.version, getDapps: (state) => state.dapps, getNewDapps: (state) => state.newDapps, - getNumberOfParticipants: (state) => state.numberOfParticipants, + getNumberOfStakersAndLockers: (state) => state.numberOfStakersAndLockers, getRegisteredDapps: (state) => state.dapps.filter((x) => x.chain.state === DappState.Registered), getProtocolState: (state) => state.protocolState, getLedger: (state) => state.ledger, diff --git a/src/staking-v3/store/mutations.ts b/src/staking-v3/store/mutations.ts index e6b3e6af0..1535a197c 100644 --- a/src/staking-v3/store/mutations.ts +++ b/src/staking-v3/store/mutations.ts @@ -6,6 +6,7 @@ import { Dapp, ProtocolState, SingularStakingInfo, + NumberOfStakersAndLockers, Rewards, Constants, EraInfo, @@ -23,7 +24,10 @@ export interface DappStakingMutations { updateDappExtended(state: DappStakingState, dapp: Dapp): void; updateDappChain(state: DappStakingState, dapp: DappInfo): void; updateDappDetails(state: DappStakingState, dapp: ProviderDappData): void; - setNumberOfParticipants(state: DappStakingState, numberOfParticipants: number): void; + setNumberOfStakersAndLockers( + state: DappStakingState, + numberOfStakersAndLockers: NumberOfStakersAndLockers + ): void; setProtocolState(state: DappStakingState, protocolState: ProtocolState): void; setLedger(state: DappStakingState, ledger: AccountLedger): void; setStakerInfo(state: DappStakingState, stakerInfo: Map): void; @@ -74,8 +78,8 @@ const mutations: MutationTree & DappStakingMutations = { updateDappDetails(state: DappStakingState, dapp: ProviderDappData): void { updateDapp(state, dapp.contractAddress, dapp, 'dappDetails'); }, - setNumberOfParticipants(state, numberOfParticipants) { - state.numberOfParticipants = numberOfParticipants; + setNumberOfStakersAndLockers(state, numberOfStakersAndLockers) { + state.numberOfStakersAndLockers = numberOfStakersAndLockers; }, setProtocolState(state, protocolState) { state.protocolState = protocolState; diff --git a/src/staking-v3/store/state.ts b/src/staking-v3/store/state.ts index 6df35c051..3b8ed111b 100644 --- a/src/staking-v3/store/state.ts +++ b/src/staking-v3/store/state.ts @@ -3,6 +3,7 @@ import { CombinedDappInfo, ProtocolState, SingularStakingInfo, + NumberOfStakersAndLockers, Rewards, Constants, EraInfo, @@ -16,7 +17,7 @@ export interface DappStakingState { version: string; dapps: CombinedDappInfo[]; newDapps: DappInfo[]; - numberOfParticipants: number; + numberOfStakersAndLockers: NumberOfStakersAndLockers; protocolState: ProtocolState | undefined; ledger: AccountLedger | undefined; stakerInfo: Map | undefined; @@ -34,7 +35,7 @@ function state(): DappStakingState { version: '3.0.0', dapps: [], newDapps: [], - numberOfParticipants: 0, + numberOfStakersAndLockers: initialNumberOfStakersAndLockers, protocolState: undefined, ledger: undefined, stakerInfo: undefined, @@ -48,6 +49,14 @@ function state(): DappStakingState { }; } +export const initialNumberOfStakersAndLockers: NumberOfStakersAndLockers = { + date: '', + tvl: '', + lockersCount: 0, + tvs: '', + stakersCount: 0, +}; + export const initialTiersConfiguration: TiersConfiguration = { numberOfSlots: 0, slotsPerTier: [],