Skip to content

Commit

Permalink
Update oneYear labels and data
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jul 8, 2023
1 parent 57e4179 commit 2993000
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/web/src/composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ export default function useUsers () {
if (new Date(receivedAt).getTime() > oneYear) {
if (!result.oneYear.data.find((obj: any) => obj.walletAddress === walletAddress)) {
result.oneYear.data.push({ walletAddress, walletBalance: Array(12).fill(0) })
const intervalIndex = Math.floor((new Date(receivedAt).getTime() - oneYear) / oneYearInterval)
const monthsAgo = (new Date().getFullYear() - new Date(receivedAt).getFullYear()) * 12 + (new Date().getMonth() - new Date(receivedAt).getMonth())
const intervalIndex = 11 - monthsAgo
result.oneYear.data.find((obj: any) => obj.walletAddress === walletAddress).walletBalance[intervalIndex] = walletBalance
} else {
const intervalIndex = Math.floor((new Date(receivedAt).getTime() - oneYear) / oneYearInterval)
const monthsAgo = (new Date().getFullYear() - new Date(receivedAt).getFullYear()) * 12 + (new Date().getMonth() - new Date(receivedAt).getMonth())
const intervalIndex = 11 - monthsAgo
result.oneYear.data.find((obj: any) => obj.walletAddress === walletAddress).walletBalance[intervalIndex] = walletBalance
}
}
Expand Down Expand Up @@ -214,8 +216,9 @@ export default function useUsers () {

// Set the oneYear labels array to the interval labels
result.oneYear.labels = Array(12).fill(0).map((_, i) => {
const date = new Date(oneYear + (oneYearInterval * i))
return date.getMonth() === 0 ? `${date.getFullYear()} ${months[date.getMonth()]}` : `${months[date.getMonth()]}`
const date = new Date (new Date().setDate(1))
const monthIndex = new Date(date.setMonth(date.getMonth() - (11 - i)))
return `${months[monthIndex.getMonth()]} ${monthIndex.getFullYear()}`
})

// Set the sixMonth labels array to the interval labels
Expand Down

0 comments on commit 2993000

Please sign in to comment.