Skip to content
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
28 changes: 21 additions & 7 deletions packages/client/src/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type UserSuppliesRequest,
type UserSupplyItem,
} from '@aave/graphql-next';
import type { ResultAsync } from '@aave/types-next';
import type { Prettify, ResultAsync } from '@aave/types-next';
import type { AaveClient } from '../AaveClient';
import {
type CurrencyQueryOptions,
Expand Down Expand Up @@ -88,6 +88,10 @@ export function userBorrows(
return client.query(UserBorrowsQuery, { request, ...options });
}

export type UserSummaryQueryOptions = Prettify<
CurrencyQueryOptions & TimeWindowQueryOptions
>;

/**
* Fetches a user's summary across all positions.
*
Expand All @@ -108,11 +112,15 @@ export function userBorrows(
export function userSummary(
client: AaveClient,
request: UserSummaryRequest,
options: Required<TimeWindowQueryOptions> = DEFAULT_QUERY_OPTIONS,
{
currency = DEFAULT_QUERY_OPTIONS.currency,
timeWindow = DEFAULT_QUERY_OPTIONS.timeWindow,
}: UserSummaryQueryOptions = DEFAULT_QUERY_OPTIONS,
): ResultAsync<UserSummary, UnexpectedError> {
return client.query(UserSummaryQuery, {
request,
timeWindow: options.timeWindow,
currency,
timeWindow,
});
}

Expand All @@ -138,9 +146,12 @@ export type UserPositionQueryOptions = CurrencyQueryOptions &
export function userPositions(
client: AaveClient,
request: UserPositionsRequest,
options: Required<UserPositionQueryOptions> = DEFAULT_QUERY_OPTIONS,
{
currency = DEFAULT_QUERY_OPTIONS.currency,
timeWindow = DEFAULT_QUERY_OPTIONS.timeWindow,
}: UserPositionQueryOptions = DEFAULT_QUERY_OPTIONS,
): ResultAsync<UserPosition[], UnexpectedError> {
return client.query(UserPositionsQuery, { request, ...options });
return client.query(UserPositionsQuery, { request, currency, timeWindow });
}

/**
Expand All @@ -160,9 +171,12 @@ export function userPositions(
export function userPosition(
client: AaveClient,
request: UserPositionRequest,
options: Required<UserPositionQueryOptions> = DEFAULT_QUERY_OPTIONS,
{
currency = DEFAULT_QUERY_OPTIONS.currency,
timeWindow = DEFAULT_QUERY_OPTIONS.timeWindow,
}: UserPositionQueryOptions = DEFAULT_QUERY_OPTIONS,
): ResultAsync<UserPosition | null, UnexpectedError> {
return client.query(UserPositionQuery, { request, ...options });
return client.query(UserPositionQuery, { request, currency, timeWindow });
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql/src/fragments/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ export const UserSummaryFragment = graphql(
`fragment UserSummary on UserSummary {
__typename
totalPositions
netBalance {
netBalance(currency: $currency) {
...FiatAmountWithChange
}
totalCollateral {
totalCollateral(currency: $currency) {
...FiatAmount
}
totalSupplied {
totalSupplied(currency: $currency) {
...FiatAmount
}
totalDebt {
totalDebt(currency: $currency) {
...FiatAmount
}
netApy {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type UserBorrowsRequest = RequestOf<typeof UserBorrowsQuery>;
* @internal
*/
export const UserSummaryQuery = graphql(
`query UserSummary($request: UserSummaryRequest!, $timeWindow: TimeWindow!) {
`query UserSummary($request: UserSummaryRequest!, $currency: Currency!, $timeWindow: TimeWindow!) {
value: userSummary(request: $request) {
...UserSummary
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function useUserBorrows({
}

export type UseUserSummaryArgs = Prettify<
UserSummaryRequest & TimeWindowQueryOptions
UserSummaryRequest & TimeWindowQueryOptions & CurrencyQueryOptions
>;

/**
Expand Down Expand Up @@ -203,6 +203,7 @@ export function useUserSummary(

export function useUserSummary({
suspense = false,
currency = DEFAULT_QUERY_OPTIONS.currency,
timeWindow = DEFAULT_QUERY_OPTIONS.timeWindow,
...request
}: UseUserSummaryArgs & {
Expand All @@ -212,6 +213,7 @@ export function useUserSummary({
document: UserSummaryQuery,
variables: {
request,
currency,
timeWindow,
},
suspense,
Expand Down