Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: last claimed #427

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/Pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const Dashboard: FC = () => {
annualRewards,
currentEpoch,
totalGlobalClaimable,
daysSinceLastClaim,
lastClaimedTime,
globalAvailableRewards,
globalIndexInfo,
isLoading,
Expand Down Expand Up @@ -217,7 +217,7 @@ const Dashboard: FC = () => {
annualRewards={annualRewards}
globalAvailableRewards={globalAvailableRewards}
totalGlobalClaimable={totalGlobalClaimable}
daysSinceLastClaim={daysSinceLastClaim}
daysSinceLastClaim={lastClaimedTime}
weightInfo={weightInfo}
globalInfo={globalIndexInfo}
/>
Expand Down
5 changes: 2 additions & 3 deletions components/Pages/Dashboard/hooks/getClaimable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ export const getClaimable = async (
const data = await fetchClaimableData(
client, address, config,
)
const daysSinceLastClaim = data?.epochs.length

const lastClaimedTime = (Number(data?.epochs[data?.epochs.length - 1]?.start_time) / 1e6) || 0
const claimableAmounts = data?.epochs.
flatMap((e) => e.available.map((a) => a.amount)).
reduce((acc, amount) => acc + parseFloat(amount), 0)

const totalGlobalClaimable = convertMicroDenomToDenom(claimableAmounts, 6)
return { totalGlobalClaimable,
daysSinceLastClaim }
lastClaimedTime }
}
const fetchClaimableData = async (
client: CosmWasmClient,
Expand Down
14 changes: 9 additions & 5 deletions util/conversion/numberUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ export const aggregateAndSortTaxAmounts = (amounts: { denom: string, amount: str
return acc;
}, [] as { denom: string, amount: string }[]).sort((a, b) => a.denom.localeCompare(b.denom));

export const lastClaimed = (daysSinceLastClaim: number) => {
if (daysSinceLastClaim >= 21) {
export const lastClaimed = (latestEpochStartDate: number) => {
let days = Math.ceil((Date.now() - latestEpochStartDate) / 86400000)
if (latestEpochStartDate === 0) {
days = 0
}
if (days >= 21) {
return '21+ days ago'
} else if (daysSinceLastClaim === 0) {
} else if (days === 0) {
return 'Today'
}
const multiple = daysSinceLastClaim === 1 ? '' : 's'
return `${daysSinceLastClaim} day${multiple} ago`
const multiple = days === 1 ? '' : 's'
return `${days} day${multiple} ago`
}
Loading