-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Marcin Ciarka <[email protected]>
- Loading branch information
1 parent
2eb4e91
commit 9105d24
Showing
39 changed files
with
897 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { type FC } from 'react' | ||
import { parseQueryStringServerSide } from '@summerfi/app-utils' | ||
import { type ReadonlyURLSearchParams } from 'next/navigation' | ||
|
||
import { getUsersActivity } from '@/app/server-handlers/sdk/get-users-activity' | ||
import { getVaultsList } from '@/app/server-handlers/sdk/get-vaults-list' | ||
import { UserActivityView } from '@/features/user-activity/components/UserActivityView/UserActivityView' | ||
|
||
export const revalidate = 60 | ||
|
||
interface UserActivityPageProps { | ||
searchParams: ReadonlyURLSearchParams | ||
} | ||
|
||
const UserActivityPage: FC<UserActivityPageProps> = async ({ searchParams }) => { | ||
const [{ vaults }, { usersActivity, totalUsers }] = await Promise.all([ | ||
getVaultsList(), | ||
getUsersActivity(), | ||
]) | ||
|
||
return ( | ||
<UserActivityView | ||
vaultsList={vaults} | ||
usersActivity={usersActivity} | ||
totalUsers={totalUsers} | ||
searchParams={parseQueryStringServerSide({ searchParams })} | ||
/> | ||
) | ||
} | ||
|
||
export default UserActivityPage |
65 changes: 65 additions & 0 deletions
65
apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
sdkSupportedNetworks, | ||
type SDKUserActivityType, | ||
UserActivityType, | ||
} from '@summerfi/app-types' | ||
import { getChainInfoByChainId } from '@summerfi/sdk-common' | ||
|
||
import { backendSDK } from '@/app/server-handlers/sdk/sdk-backend-client' | ||
|
||
export interface UserActivity { | ||
timestamp: SDKUserActivityType['deposits'][0]['timestamp'] | ||
amount: SDKUserActivityType['deposits'][0]['amount'] | ||
balance: SDKUserActivityType['inputTokenBalance'] | ||
vault: SDKUserActivityType['vault'] | ||
account: SDKUserActivityType['account']['id'] | ||
activity: UserActivityType | ||
} | ||
|
||
export type UsersActivity = UserActivity[] | ||
|
||
export async function getUsersActivity(): Promise<{ | ||
usersActivity: UsersActivity | ||
totalUsers: number | ||
callDataTimestamp: number | ||
}> { | ||
const usersActivityByNetwork = await Promise.all( | ||
sdkSupportedNetworks.map((networkId) => { | ||
const chainInfo = getChainInfoByChainId(networkId) | ||
|
||
return backendSDK.armada.users.getUsersActivityRaw({ | ||
chainInfo, | ||
}) | ||
}), | ||
) | ||
|
||
// flatten the list | ||
const usersActivityListRaw = usersActivityByNetwork.reduce< | ||
(typeof usersActivityByNetwork)[number]['positions'] | ||
>((acc, { positions }) => [...acc, ...positions], []) | ||
|
||
const totalUsers = usersActivityListRaw.filter((position) => position.deposits.length > 0).length | ||
|
||
const usersActivityList = usersActivityListRaw.flatMap((position) => [ | ||
...position.deposits.map((deposit) => ({ | ||
...deposit, | ||
balance: position.inputTokenBalance, | ||
vault: position.vault, | ||
account: position.account.id, | ||
activity: UserActivityType.DEPOSIT, | ||
})), | ||
...position.withdrawals.map((deposit) => ({ | ||
...deposit, | ||
balance: position.inputTokenBalance, | ||
vault: position.vault, | ||
account: position.account.id, | ||
activity: UserActivityType.WITHDRAW, | ||
})), | ||
]) | ||
|
||
return { | ||
usersActivity: usersActivityList, | ||
totalUsers, | ||
callDataTimestamp: Date.now(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
apps/earn-protocol/components/organisms/Charts/HistoricalYieldChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use client' | ||
|
||
import { useMemo, useState } from 'react' | ||
import { Card } from '@summerfi/app-earn-ui' | ||
import { type CardVariant } from '@summerfi/app-earn-ui/dist/types/src/components/atoms/Card/Card' | ||
import { type TimeframesType } from '@summerfi/app-types' | ||
import BigNumber from 'bignumber.js' | ||
import dayjs from 'dayjs' | ||
|
||
import { ChartHeader } from '@/components/organisms/Charts/ChartHeader' | ||
import { ComparisonChart } from '@/components/organisms/Charts/ComparisonChart' | ||
|
||
const dataNames = ['Summer Strategy'] | ||
|
||
const colors = { | ||
'Summer Strategy-color': '#FF49A4', | ||
} | ||
|
||
export const HistoricalYieldChart = ({ | ||
aprHourlyList, | ||
cardVariant = 'cardSecondary', | ||
}: { | ||
cardVariant?: CardVariant | ||
aprHourlyList: string[] | ||
}) => { | ||
const [compare, setCompare] = useState(true) | ||
const [timeframe, setTimeframe] = useState<TimeframesType>('90d') | ||
const _unused = setTimeframe | ||
|
||
const parsedData = useMemo(() => { | ||
const now = dayjs().startOf('hour') | ||
|
||
return [...aprHourlyList].reverse().map((item, itemIndex) => ({ | ||
name: now.subtract(itemIndex, 'hour').format('MMM DD, HH:mm'), | ||
'Summer Strategy': new BigNumber(item).toFixed(2), | ||
})) | ||
}, [aprHourlyList]) | ||
|
||
return ( | ||
<Card | ||
variant={cardVariant} | ||
style={{ marginTop: 'var(--spacing-space-medium)', flexDirection: 'column' }} | ||
> | ||
<ChartHeader | ||
compare={compare} | ||
setCompare={setCompare} | ||
timeframe={timeframe} | ||
setTimeframe={(_nextTimeFrame) => null} | ||
/> | ||
<ComparisonChart | ||
timeframe={timeframe} | ||
colors={colors} | ||
data={parsedData} | ||
compare={compare} | ||
dataNames={dataNames} | ||
/> | ||
</Card> | ||
) | ||
} |
40 changes: 40 additions & 0 deletions
40
apps/earn-protocol/features/user-activity/components/UserActivityTable/UserActivityTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { type FC, type ReactNode, useMemo, useState } from 'react' | ||
import { Table, type TableSortedColumn } from '@summerfi/app-earn-ui' | ||
|
||
import { type UsersActivity } from '@/app/server-handlers/sdk/get-users-activity' | ||
import { userActivityColumns } from '@/features/user-activity/table/columns' | ||
import { userActivityMapper } from '@/features/user-activity/table/mapper' | ||
|
||
interface UserActivityTableProps { | ||
userActivityList: UsersActivity | ||
customRow?: { | ||
idx: number | ||
content: ReactNode | ||
} | ||
hiddenColumns?: string[] | ||
rowsToDisplay?: number | ||
} | ||
|
||
export const UserActivityTable: FC<UserActivityTableProps> = ({ | ||
userActivityList, | ||
customRow, | ||
hiddenColumns, | ||
rowsToDisplay, | ||
}) => { | ||
const [sortConfig, setSortConfig] = useState<TableSortedColumn<string>>() | ||
|
||
const rows = useMemo( | ||
() => userActivityMapper(userActivityList, sortConfig), | ||
[userActivityList, sortConfig], | ||
) | ||
|
||
return ( | ||
<Table | ||
rows={rows.slice(0, rowsToDisplay)} | ||
columns={userActivityColumns} | ||
customRow={customRow} | ||
handleSort={(_sortConfig) => setSortConfig(_sortConfig)} | ||
hiddenColumns={hiddenColumns} | ||
/> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
...-protocol/features/user-activity/components/UserActivityView/UserActivityView.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 0 var(--general-space-16); | ||
|
||
@media screen and (min-width: 768px) { | ||
padding: unset; | ||
} | ||
} | ||
|
||
.filtersWrapper { | ||
display: flex; | ||
justify-content: flex-start; | ||
gap: var(--general-space-16); | ||
flex-wrap: wrap; | ||
margin-bottom: var(--general-space-24); | ||
} |
Oops, something went wrong.