From 5c4be817a3941f286f8ac9429d6558bb71a11ffa Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Wed, 6 Nov 2024 10:23:56 +0100 Subject: [PATCH] Earn protocol WIP #20 (#559) # 20 of N pull requests. This pull request introduces several enhancements to the `apps/earn-protocol` application, focusing on incorporating user activity data and top depositors into various pages and components. The most important changes include updates to the `EarnVaultManagePage`, `EarnVaultOpenPage`, and `UserActivityPage` to fetch and display this new data, as well as modifications to the server handlers and components to support these updates. ### Enhancements to data fetching and display: * `apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsx`: Added `getUserActivity` to fetch user activity and top depositors, and updated `EarnVaultManagePage` to include this data in the component props. ([apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsxR6](diffhunk://#diff-aec0650e1d631148c7236a9124bdf58ab593e3e089754ba25c6ca8b08b32ed61R6), [apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsxL22-R23](diffhunk://#diff-aec0650e1d631148c7236a9124bdf58ab593e3e089754ba25c6ca8b08b32ed61L22-R23), [apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsxR34-R38](diffhunk://#diff-aec0650e1d631148c7236a9124bdf58ab593e3e089754ba25c6ca8b08b32ed61R34-R38), [apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsxR65-R66](diffhunk://#diff-aec0650e1d631148c7236a9124bdf58ab593e3e089754ba25c6ca8b08b32ed61R65-R66)) * `apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsx`: Updated `EarnVaultOpenPage` to fetch user activity and top depositors and pass this data to the `VaultOpenView` component. ([apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsxR4](diffhunk://#diff-eaafa83dbaa20354e007ae0e12db9f7a702c4eda62f13e8ac7f97562a32e633cR4), [apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsxL18-R25](diffhunk://#diff-eaafa83dbaa20354e007ae0e12db9f7a702c4eda62f13e8ac7f97562a32e633cL18-R25), [apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsxL34-R43](diffhunk://#diff-eaafa83dbaa20354e007ae0e12db9f7a702c4eda62f13e8ac7f97562a32e633cL34-R43)) * [`apps/earn-protocol/app/earn/user-activity/page.tsx`](diffhunk://#diff-00a406f55b8254b1f7ebb56bdffb224cf8036f0c3b2bf475a55323c66fe4bf24L16-R16): Modified `UserActivityPage` to include top depositors in the fetched data and pass it to the `UserActivityView` component. [[1]](diffhunk://#diff-00a406f55b8254b1f7ebb56bdffb224cf8036f0c3b2bf475a55323c66fe4bf24L16-R16) [[2]](diffhunk://#diff-00a406f55b8254b1f7ebb56bdffb224cf8036f0c3b2bf475a55323c66fe4bf24R25) ### Updates to server handlers: * [`apps/earn-protocol/app/server-handlers/sdk/get-user-activity.ts`](diffhunk://#diff-410dafcceab060e8269aee988d0fec5ba9126561247c8a7181761fe1f2b6b48cR1-R74): Created a new function `getUserActivity` to fetch user activity and top depositors. * [`apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts`](diffhunk://#diff-e5a3f2bcbd2b174bc55aaec59dde8bca644433d0ab0ef25de8ec779eb53c10d4L3-R14): Updated `getUsersActivity` to include top depositors in the returned data. [[1]](diffhunk://#diff-e5a3f2bcbd2b174bc55aaec59dde8bca644433d0ab0ef25de8ec779eb53c10d4L3-R14) [[2]](diffhunk://#diff-e5a3f2bcbd2b174bc55aaec59dde8bca644433d0ab0ef25de8ec779eb53c10d4L41-R39) [[3]](diffhunk://#diff-e5a3f2bcbd2b174bc55aaec59dde8bca644433d0ab0ef25de8ec779eb53c10d4R58-R66) ### Component modifications: * [`apps/earn-protocol/components/layout/VaultManageView/VaultManageView.tsx`](diffhunk://#diff-180e4453ecde0323c93bedc67a55441498ddf30fa5f732446fd12cc2dc575ba9L3-R8): Updated `VaultManageView` to accept and pass user activity and top depositors to the `VaultManageViewComponent`. [[1]](diffhunk://#diff-180e4453ecde0323c93bedc67a55441498ddf30fa5f732446fd12cc2dc575ba9L3-R8) [[2]](diffhunk://#diff-180e4453ecde0323c93bedc67a55441498ddf30fa5f732446fd12cc2dc575ba9R18-R26) [[3]](diffhunk://#diff-180e4453ecde0323c93bedc67a55441498ddf30fa5f732446fd12cc2dc575ba9R35-R36) * [`apps/earn-protocol/components/layout/VaultManageView/VaultManageViewComponent.tsx`](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccR1): Enhanced `VaultManageViewComponent` to display user activity, top depositors, and other related data. [[1]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccR1) [[2]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccR11-R35) [[3]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccR44-R75) [[4]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccL71-R94) [[5]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccL82-R117) [[6]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccL101-R127) [[7]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccL148-R174) [[8]](diffhunk://#diff-093401e3ee1390c1d36183263365baea6f0df465c9bc2cdafe8c6205c965caccL178-R209) * [`apps/earn-protocol/components/layout/VaultOpenView/VaultOpenView.tsx`](diffhunk://#diff-a40498ddbf1bf5830448800c7d93442c21fc90a4f6c4eed0b672478679ce71a9L3-R8): Updated `VaultOpenView` to accept and pass user activity and top depositors to the `VaultOpenViewComponent`. [[1]](diffhunk://#diff-a40498ddbf1bf5830448800c7d93442c21fc90a4f6c4eed0b672478679ce71a9L3-R8) [[2]](diffhunk://#diff-a40498ddbf1bf5830448800c7d93442c21fc90a4f6c4eed0b672478679ce71a9R17-R32) --------- Co-authored-by: sebastianPiekarczyk --- .../[vaultId]/[walletAddress]/page.tsx | 10 +- .../[network]/position/[vaultId]/page.tsx | 13 +- .../app/earn/user-activity/page.tsx | 3 +- .../server-handlers/sdk/get-user-activity.ts | 74 +++++++++ .../server-handlers/sdk/get-users-activity.ts | 31 ++-- .../VaultManageView/VaultManageView.tsx | 13 +- .../VaultManageViewComponent.tsx | 67 +++++--- .../layout/VaultOpenView/VaultOpenView.tsx | 18 ++- .../VaultOpenView/VaultOpenViewComponent.tsx | 73 +++++---- .../components/layout/VaultOpenView/mocks.ts | 24 --- .../organisms/Charts/HistoricalYieldChart.tsx | 11 +- .../organisms/UserActivity/UserActivity.tsx | 68 ++++---- .../TopDepositorsTable/TopDepositorsTable.tsx | 40 +++++ .../UserActivityTable/UserActivityTable.tsx | 4 +- .../UserActivityView/UserActivityView.tsx | 148 +++++++++++++----- .../table/filters/top-depositors-filter.ts | 30 ++++ .../{filters.ts => user-activity-filters.ts} | 2 +- .../table/top-depositors-columns.ts | 42 +++++ .../table/top-depositors-mapper.tsx | 113 +++++++++++++ .../table/top-depositors-sorter.ts | 69 ++++++++ .../{columns.ts => user-activity-columns.ts} | 0 .../{mapper.tsx => user-activity-mapper.tsx} | 2 +- .../{sorter.ts => user-activity-sorter.ts} | 0 .../features/user-activity/types/tabs.ts | 4 + apps/earn-protocol/hooks/use-amount.ts | 103 ++++++++++++ apps/earn-protocol/hooks/use-client.ts | 107 +++++++++++++ apps/earn-protocol/hooks/use-transaction.ts | 108 ++++--------- .../InputWithDropdown/InputWithDropdown.tsx | 13 +- .../types/src/earn-protocol/index.ts | 11 ++ .../src/helpers/get-past-timestamp.ts | 25 +++ packages/app-utils/src/index.ts | 1 + .../src/common/index.ts | 1 + .../src/common/interfaces/IArmadaManager.ts | 11 ++ .../common/implementation/ArmadaManager.ts | 10 +- .../ArmadaManager/ArmadaManagerUsersClient.ts | 5 + .../IArmadaManagerUsersClient.ts | 11 ++ sdk/sdk-server/src/SDKAppRouter.ts | 2 + .../users/getUserActivityRaw.ts | 13 ++ .../src/generated/client.ts | 46 +++++- .../src/interfaces/IArmadaSubgraphManager.ts | 11 ++ .../src/queries/user-activity.graphql | 28 ++++ .../src/queries/users-activity.graphql | 1 + .../src/queries/vaults.graphql | 1 + .../armada/ArmadaSubgraphManager.ts | 4 + 44 files changed, 1129 insertions(+), 242 deletions(-) create mode 100644 apps/earn-protocol/app/server-handlers/sdk/get-user-activity.ts create mode 100644 apps/earn-protocol/features/user-activity/components/TopDepositorsTable/TopDepositorsTable.tsx create mode 100644 apps/earn-protocol/features/user-activity/table/filters/top-depositors-filter.ts rename apps/earn-protocol/features/user-activity/table/filters/{filters.ts => user-activity-filters.ts} (95%) create mode 100644 apps/earn-protocol/features/user-activity/table/top-depositors-columns.ts create mode 100644 apps/earn-protocol/features/user-activity/table/top-depositors-mapper.tsx create mode 100644 apps/earn-protocol/features/user-activity/table/top-depositors-sorter.ts rename apps/earn-protocol/features/user-activity/table/{columns.ts => user-activity-columns.ts} (100%) rename apps/earn-protocol/features/user-activity/table/{mapper.tsx => user-activity-mapper.tsx} (99%) rename apps/earn-protocol/features/user-activity/table/{sorter.ts => user-activity-sorter.ts} (100%) create mode 100644 apps/earn-protocol/features/user-activity/types/tabs.ts create mode 100644 apps/earn-protocol/hooks/use-amount.ts create mode 100644 apps/earn-protocol/hooks/use-client.ts create mode 100644 packages/app-utils/src/helpers/get-past-timestamp.ts create mode 100644 sdk/sdk-server/src/armada-protocol-handlers/users/getUserActivityRaw.ts create mode 100644 sdk/subgraph-manager-common/src/queries/user-activity.graphql diff --git a/apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsx b/apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsx index 91d7374bc..3345a873e 100644 --- a/apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsx +++ b/apps/earn-protocol/app/earn/[network]/position/[vaultId]/[walletAddress]/page.tsx @@ -3,6 +3,7 @@ import { type SDKNetwork } from '@summerfi/app-types' import { parseServerResponseToClient } from '@summerfi/app-utils' import { type IArmadaPosition } from '@summerfi/sdk-client-react' +import { getUserActivity } from '@/app/server-handlers/sdk/get-user-activity' import { getUserPosition } from '@/app/server-handlers/sdk/get-user-position' import { getVaultDetails } from '@/app/server-handlers/sdk/get-vault-details' import { getVaultsList } from '@/app/server-handlers/sdk/get-vaults-list' @@ -19,7 +20,7 @@ type EarnVaultManagePageProps = { export const revalidate = 60 const EarnVaultManagePage = async ({ params }: EarnVaultManagePageProps) => { - const [vault, { vaults }, position] = await Promise.all([ + const [vault, { vaults }, position, { userActivity, topDepositors }] = await Promise.all([ getVaultDetails({ vaultAddress: params.vaultId, network: params.network, @@ -30,6 +31,11 @@ const EarnVaultManagePage = async ({ params }: EarnVaultManagePageProps) => { network: params.network, walletAddress: params.walletAddress, }), + getUserActivity({ + vaultAddress: params.vaultId, + network: params.network, + walletAddress: params.walletAddress, + }), ]) if (!vault) { @@ -56,6 +62,8 @@ const EarnVaultManagePage = async ({ params }: EarnVaultManagePageProps) => { vaults={vaults} position={positionJsonSafe} viewWalletAddress={params.walletAddress} + userActivity={userActivity} + topDepositors={topDepositors} /> ) } diff --git a/apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsx b/apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsx index ba31e84e7..a9ab0ed77 100644 --- a/apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsx +++ b/apps/earn-protocol/app/earn/[network]/position/[vaultId]/page.tsx @@ -1,6 +1,7 @@ import { Text } from '@summerfi/app-earn-ui' import { type SDKNetwork } from '@summerfi/app-types' +import { getUserActivity } from '@/app/server-handlers/sdk/get-user-activity' import { getVaultDetails } from '@/app/server-handlers/sdk/get-vault-details' import { getVaultsList } from '@/app/server-handlers/sdk/get-vaults-list' import { VaultOpenView } from '@/components/layout/VaultOpenView/VaultOpenView' @@ -15,12 +16,13 @@ type EarnVaultOpenPageProps = { export const revalidate = 60 const EarnVaultOpenPage = async ({ params }: EarnVaultOpenPageProps) => { - const [vault, { vaults }] = await Promise.all([ + const [vault, { vaults }, { userActivity, topDepositors }] = await Promise.all([ getVaultDetails({ vaultAddress: params.vaultId, network: params.network, }), getVaultsList(), + getUserActivity({ vaultAddress: params.vaultId, network: params.network }), ]) if (!vault) { @@ -31,7 +33,14 @@ const EarnVaultOpenPage = async ({ params }: EarnVaultOpenPageProps) => { ) } - return + return ( + + ) } export default EarnVaultOpenPage diff --git a/apps/earn-protocol/app/earn/user-activity/page.tsx b/apps/earn-protocol/app/earn/user-activity/page.tsx index 626e8f0d7..86c246429 100644 --- a/apps/earn-protocol/app/earn/user-activity/page.tsx +++ b/apps/earn-protocol/app/earn/user-activity/page.tsx @@ -13,7 +13,7 @@ interface UserActivityPageProps { } const UserActivityPage: FC = async ({ searchParams }) => { - const [{ vaults }, { usersActivity, totalUsers }] = await Promise.all([ + const [{ vaults }, { usersActivity, totalUsers, topDepositors }] = await Promise.all([ getVaultsList(), getUsersActivity(), ]) @@ -22,6 +22,7 @@ const UserActivityPage: FC = async ({ searchParams }) => diff --git a/apps/earn-protocol/app/server-handlers/sdk/get-user-activity.ts b/apps/earn-protocol/app/server-handlers/sdk/get-user-activity.ts new file mode 100644 index 000000000..d09d12ce6 --- /dev/null +++ b/apps/earn-protocol/app/server-handlers/sdk/get-user-activity.ts @@ -0,0 +1,74 @@ +import { + type SDKNetwork, + type SDKUsersActivityType, + UserActivityType, + type UsersActivity, +} from '@summerfi/app-types' +import { simpleSort, SortDirection } from '@summerfi/app-utils' +import { ArmadaVaultId } from '@summerfi/armada-protocol-service' +import { Address, getChainInfoByChainId } from '@summerfi/sdk-common' + +import { backendSDK } from '@/app/server-handlers/sdk/sdk-backend-client' +import { subgraphNetworkToId } from '@/helpers/network-helpers' + +export async function getUserActivity({ + network, + vaultAddress, + walletAddress, +}: { + network: SDKNetwork + vaultAddress: string + walletAddress?: string +}): Promise<{ + userActivity: UsersActivity + topDepositors: SDKUsersActivityType + callDataTimestamp: number +}> { + const chainId = subgraphNetworkToId(network) + const chainInfo = getChainInfoByChainId(chainId) + + const fleetAddress = Address.createFromEthereum({ + value: vaultAddress, + }) + const poolId = ArmadaVaultId.createFrom({ + chainInfo, + fleetAddress, + }) + + const { positions } = await backendSDK.armada.users.getUserActivityRaw({ + poolId, + }) + + const userActivityList = positions + .filter((position) => + walletAddress ? position.account.id === walletAddress.toLowerCase() : true, + ) + .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, + })), + ]) + + const topDepositors = positions + .sort((a, b) => + simpleSort({ a: a.inputTokenBalance, b: b.inputTokenBalance, direction: SortDirection.DESC }), + ) + .filter((item) => item.deposits.length > 0) + + return { + userActivity: userActivityList, + topDepositors, + callDataTimestamp: Date.now(), + } +} diff --git a/apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts b/apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts index ebb542dd4..b1920bfcd 100644 --- a/apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts +++ b/apps/earn-protocol/app/server-handlers/sdk/get-users-activity.ts @@ -1,25 +1,17 @@ import { sdkSupportedNetworks, - type SDKUserActivityType, + type SDKUsersActivityType, UserActivityType, + type UsersActivity, } from '@summerfi/app-types' +import { simpleSort, SortDirection } from '@summerfi/app-utils' 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 + topDepositors: SDKUsersActivityType totalUsers: number callDataTimestamp: number }> { @@ -38,7 +30,13 @@ export async function getUsersActivity(): Promise<{ (typeof usersActivityByNetwork)[number]['positions'] >((acc, { positions }) => [...acc, ...positions], []) - const totalUsers = usersActivityListRaw.filter((position) => position.deposits.length > 0).length + const totalUsers = [ + ...new Set( + usersActivityListRaw + .filter((position) => position.deposits.length > 0) + .map((position) => position.account.id), + ), + ].length const usersActivityList = usersActivityListRaw.flatMap((position) => [ ...position.deposits.map((deposit) => ({ @@ -57,8 +55,15 @@ export async function getUsersActivity(): Promise<{ })), ]) + const topDepositors = usersActivityListRaw + .sort((a, b) => + simpleSort({ a: a.inputTokenBalance, b: b.inputTokenBalance, direction: SortDirection.DESC }), + ) + .filter((item) => item.deposits.length > 0) + return { usersActivity: usersActivityList, + topDepositors, totalUsers, callDataTimestamp: Date.now(), } diff --git a/apps/earn-protocol/components/layout/VaultManageView/VaultManageView.tsx b/apps/earn-protocol/components/layout/VaultManageView/VaultManageView.tsx index 03b2d0965..aea13d967 100644 --- a/apps/earn-protocol/components/layout/VaultManageView/VaultManageView.tsx +++ b/apps/earn-protocol/components/layout/VaultManageView/VaultManageView.tsx @@ -1,6 +1,11 @@ 'use client' -import { type SDKVaultishType, type SDKVaultsListType } from '@summerfi/app-types' +import { + type SDKUsersActivityType, + type SDKVaultishType, + type SDKVaultsListType, + type UsersActivity, +} from '@summerfi/app-types' import { type IArmadaPosition, SDKContextProvider } from '@summerfi/sdk-client-react' import { VaultManageViewComponent } from '@/components/layout/VaultManageView/VaultManageViewComponent' @@ -10,11 +15,15 @@ export const VaultManageView = ({ vault, vaults, position, + userActivity, + topDepositors, viewWalletAddress, }: { vault: SDKVaultishType vaults: SDKVaultsListType position: IArmadaPosition + userActivity: UsersActivity + topDepositors: SDKUsersActivityType viewWalletAddress: string }) => { return ( @@ -23,6 +32,8 @@ export const VaultManageView = ({ vault={vault} vaults={vaults} position={position} + userActivity={userActivity} + topDepositors={topDepositors} viewWalletAddress={viewWalletAddress} /> diff --git a/apps/earn-protocol/components/layout/VaultManageView/VaultManageViewComponent.tsx b/apps/earn-protocol/components/layout/VaultManageView/VaultManageViewComponent.tsx index 96f7032bf..6a5e30941 100644 --- a/apps/earn-protocol/components/layout/VaultManageView/VaultManageViewComponent.tsx +++ b/apps/earn-protocol/components/layout/VaultManageView/VaultManageViewComponent.tsx @@ -1,3 +1,4 @@ +import { useUser } from '@account-kit/react' import { Button, Expander, @@ -7,27 +8,31 @@ import { SidebarFootnote, sidebarFootnote, type SidebarProps, + SkeletonLine, Text, VaultManageGrid, } from '@summerfi/app-earn-ui' import { type DropdownOption, + type SDKUsersActivityType, type SDKVaultishType, type SDKVaultsListType, type TokenSymbolsList, + type UsersActivity, } from '@summerfi/app-types' import { formatCryptoBalance } from '@summerfi/app-utils' import { type IArmadaPosition } from '@summerfi/sdk-client-react' -import BigNumber from 'bignumber.js' import { capitalize } from 'lodash-es' -import { userActivityRawData, vaultExposureRawData } from '@/components/layout/VaultOpenView/mocks' +import { vaultExposureRawData } from '@/components/layout/VaultOpenView/mocks' import { TransactionHashPill } from '@/components/molecules/TransactionHashPill/TransactionHashPill' -import { MockedLineChart } from '@/components/organisms/Charts/MockedLineChart' +import { HistoricalYieldChart } from '@/components/organisms/Charts/HistoricalYieldChart' import { RebalancingActivity } from '@/components/organisms/RebalancingActivity/RebalancingActivity' import { UserActivity } from '@/components/organisms/UserActivity/UserActivity' import { VaultExposure } from '@/components/organisms/VaultExposure/VaultExposure' import { TransactionAction } from '@/constants/transaction-actions' +import { useAmount } from '@/hooks/use-amount' +import { useClient } from '@/hooks/use-client' import { useTransaction } from '@/hooks/use-transaction' import vaultManageViewStyles from './VaultManageView.module.scss' @@ -36,26 +41,38 @@ export const VaultManageViewComponent = ({ vault, vaults, position, + userActivity, + topDepositors, viewWalletAddress, }: { vault: SDKVaultishType vaults: SDKVaultsListType position: IArmadaPosition + userActivity: UsersActivity + topDepositors: SDKUsersActivityType viewWalletAddress: string }) => { + const user = useUser() + const { publicClient, transactionClient, tokenBalance, tokenBalanceLoading } = useClient({ + vault, + }) + const { amountParsed, amountDisplay, manualSetAmount, handleAmountChange, onFocus, onBlur } = + useAmount({ vault }) const { - amountDisplayValue, - handleAmountChange, sidebar, - amount, txHashes, removeTxHash, vaultChainId, reset, - user, - setTransactionType, transactionType, - } = useTransaction({ vault }) + setTransactionType, + } = useTransaction({ + vault, + publicClient, + transactionClient, + amountParsed, + manualSetAmount, + }) const options: DropdownOption[] = [ ...[...new Set(vaults.map(({ inputToken }) => inputToken.symbol))].map((symbol) => ({ @@ -68,7 +85,13 @@ export const VaultManageViewComponent = ({ const dropdownValue = options.find((option) => option.value === vault.inputToken.symbol) ?? options[0] - const balance = new BigNumber(123123) + const balanceValue = tokenBalanceLoading ? ( + + ) : tokenBalance ? ( + `${formatCryptoBalance(tokenBalance)} ${vault.inputToken.symbol}` + ) : ( + '-' + ) const sidebarProps: SidebarProps = { title: capitalize(transactionType), @@ -79,16 +102,19 @@ export const VaultManageViewComponent = ({ content: ( <> console.log('clicked'), + value: balanceValue, + action: () => { + manualSetAmount(tokenBalance?.toString()) + }, }} /> @@ -98,7 +124,7 @@ export const VaultManageViewComponent = ({ primaryButton: sidebar.primaryButton, footnote: ( <> - {sidebar.error ?? amount?.gt(0) ? ( + {sidebar.error ?? amountParsed.gt(0) ? (