diff --git a/packages/dapp/src/__generated__/ees/gql.ts b/packages/dapp/src/__generated__/ees/gql.ts index ba9c5bb..fd2c862 100644 --- a/packages/dapp/src/__generated__/ees/gql.ts +++ b/packages/dapp/src/__generated__/ees/gql.ts @@ -14,13 +14,18 @@ import * as types from './graphql'; * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - "query GetTopEndorsersAndDonators($account: String!) {\n topEndorsers: aggregatedInformations(\n where: {to: $account}\n orderBy: from__totalEndorsementsReceived\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n totalEndorsementsReceived\n }\n }\n topDonators: aggregatedInformations(\n where: {to: $account}\n orderBy: donationAmount\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n donationAmount\n }\n}": types.GetTopEndorsersAndDonatorsDocument, + "query GetAggregatedAccountData($account: ID!) {\n account(id: $account) {\n id\n totalEndorsementsReceived\n totalEndorsementsSent\n totalDonationsReceived\n totalDonationsSent\n }\n}": types.GetAggregatedAccountDataDocument, + "query GetTopEndorsersAndDonators($account: String!) {\n topEndorsers: aggregatedInformations(\n where: {to: $account}\n orderBy: from__totalEndorsementsReceived\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n }\n topDonators: aggregatedInformations(\n where: {to: $account, donationAmount_gt: 0}\n orderBy: donationAmount\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n donationAmount\n }\n}": types.GetTopEndorsersAndDonatorsDocument, }; /** * The gqlEES function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function gqlEES(source: "query GetTopEndorsersAndDonators($account: String!) {\n topEndorsers: aggregatedInformations(\n where: {to: $account}\n orderBy: from__totalEndorsementsReceived\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n totalEndorsementsReceived\n }\n }\n topDonators: aggregatedInformations(\n where: {to: $account}\n orderBy: donationAmount\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n donationAmount\n }\n}"): typeof import('./graphql').GetTopEndorsersAndDonatorsDocument; +export function gqlEES(source: "query GetAggregatedAccountData($account: ID!) {\n account(id: $account) {\n id\n totalEndorsementsReceived\n totalEndorsementsSent\n totalDonationsReceived\n totalDonationsSent\n }\n}"): typeof import('./graphql').GetAggregatedAccountDataDocument; +/** + * The gqlEES function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function gqlEES(source: "query GetTopEndorsersAndDonators($account: String!) {\n topEndorsers: aggregatedInformations(\n where: {to: $account}\n orderBy: from__totalEndorsementsReceived\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n }\n topDonators: aggregatedInformations(\n where: {to: $account, donationAmount_gt: 0}\n orderBy: donationAmount\n orderDirection: desc\n first: 6\n ) {\n id\n from {\n id\n }\n donationAmount\n }\n}"): typeof import('./graphql').GetTopEndorsersAndDonatorsDocument; export function gqlEES(source: string) { diff --git a/packages/dapp/src/__generated__/ees/graphql.ts b/packages/dapp/src/__generated__/ees/graphql.ts index 3437cdd..b6ef2ff 100644 --- a/packages/dapp/src/__generated__/ees/graphql.ts +++ b/packages/dapp/src/__generated__/ees/graphql.ts @@ -916,12 +916,19 @@ export enum _SubgraphErrorPolicy_ { Deny = 'deny' } +export type GetAggregatedAccountDataQueryVariables = Exact<{ + account: Scalars['ID']['input']; +}>; + + +export type GetAggregatedAccountDataQuery = { __typename?: 'Query', account?: { __typename?: 'Account', id: any, totalEndorsementsReceived: any, totalEndorsementsSent: any, totalDonationsReceived: any, totalDonationsSent: any } | null }; + export type GetTopEndorsersAndDonatorsQueryVariables = Exact<{ account: Scalars['String']['input']; }>; -export type GetTopEndorsersAndDonatorsQuery = { __typename?: 'Query', topEndorsers: Array<{ __typename?: 'AggregatedInformation', id: any, from: { __typename?: 'Account', id: any, totalEndorsementsReceived: any } }>, topDonators: Array<{ __typename?: 'AggregatedInformation', id: any, donationAmount: any, from: { __typename?: 'Account', id: any } }> }; +export type GetTopEndorsersAndDonatorsQuery = { __typename?: 'Query', topEndorsers: Array<{ __typename?: 'AggregatedInformation', id: any, from: { __typename?: 'Account', id: any } }>, topDonators: Array<{ __typename?: 'AggregatedInformation', id: any, donationAmount: any, from: { __typename?: 'Account', id: any } }> }; export class TypedDocumentString extends String @@ -938,6 +945,17 @@ export class TypedDocumentString } } +export const GetAggregatedAccountDataDocument = new TypedDocumentString(` + query GetAggregatedAccountData($account: ID!) { + account(id: $account) { + id + totalEndorsementsReceived + totalEndorsementsSent + totalDonationsReceived + totalDonationsSent + } +} + `) as unknown as TypedDocumentString; export const GetTopEndorsersAndDonatorsDocument = new TypedDocumentString(` query GetTopEndorsersAndDonators($account: String!) { topEndorsers: aggregatedInformations( @@ -949,11 +967,10 @@ export const GetTopEndorsersAndDonatorsDocument = new TypedDocumentString(` id from { id - totalEndorsementsReceived } } topDonators: aggregatedInformations( - where: {to: $account} + where: {to: $account, donationAmount_gt: 0} orderBy: donationAmount orderDirection: desc first: 6 diff --git a/packages/dapp/src/app/profile/[slug]/PageSkeleton.tsx b/packages/dapp/src/app/profile/[slug]/PageSkeleton.tsx index 3547554..326a091 100644 --- a/packages/dapp/src/app/profile/[slug]/PageSkeleton.tsx +++ b/packages/dapp/src/app/profile/[slug]/PageSkeleton.tsx @@ -18,6 +18,7 @@ export const PageSkeleton = () => { +
diff --git a/packages/dapp/src/app/profile/[slug]/ShareDialog.tsx b/packages/dapp/src/app/profile/[slug]/ShareDialog.tsx index 0df18b5..af9087f 100644 --- a/packages/dapp/src/app/profile/[slug]/ShareDialog.tsx +++ b/packages/dapp/src/app/profile/[slug]/ShareDialog.tsx @@ -46,7 +46,7 @@ export function ShareDialog({ Share this profile - Share your profile with others to get more endorsements! + Share the profile with others to get more endorsements! diff --git a/packages/dapp/src/app/profile/[slug]/Summary.tsx b/packages/dapp/src/app/profile/[slug]/Summary.tsx index 49f84ab..dc67283 100644 --- a/packages/dapp/src/app/profile/[slug]/Summary.tsx +++ b/packages/dapp/src/app/profile/[slug]/Summary.tsx @@ -43,11 +43,10 @@ export const Summary = async ({ account, network }: SummaryProps) => { )} {topEndorsers.map((endorser) => ( - }> - + } + > + ))} @@ -76,7 +75,9 @@ export const Summary = async ({ account, network }: SummaryProps) => { )} {topDonators.map((donator) => ( - }> + } + > { const data = await getMinimalProfileFromAddress(address); - const title = totalEndorsements ? 'Endorsements' : 'Tips'; - const value = totalEndorsements - ? totalEndorsements - : `${Number(formatEther(BigInt(donationAmount ?? '0'))).toFixed(4)} ETH`; + const value = `${Number(formatEther(BigInt(donationAmount ?? '0'))).toFixed( + 4 + )} ETH`; return ( {data.displayName ?? formatAddress(address)}
-
- {title} -
-
- {value} -
+ {donationAmount && ( + <> +
+ Tips +
+
+ {value} +
+ + )} @@ -55,7 +56,9 @@ export const UserBadge = async ({ ); }; -export const UserBadgeSkeleton = () => { +export const UserBadgeSkeleton = ({ + isEndorsementBadge, +}: { isEndorsementBadge: boolean }) => { return (
@@ -70,8 +73,12 @@ export const UserBadgeSkeleton = () => {
- - + {!isEndorsementBadge && ( + <> + + + + )}
diff --git a/packages/dapp/src/app/profile/[slug]/page.tsx b/packages/dapp/src/app/profile/[slug]/page.tsx index 94e69c3..bb21b37 100644 --- a/packages/dapp/src/app/profile/[slug]/page.tsx +++ b/packages/dapp/src/app/profile/[slug]/page.tsx @@ -16,6 +16,7 @@ import { Badges } from './Badges'; import { ShareDialog } from './ShareDialog'; import { ProfileAvatar } from '@/components/ProfileAvatar'; import { Feed } from './Feed'; +import { getAggregatedAccountData } from '@/lib/ees'; type PageProps = { params: { slug: string }; @@ -34,6 +35,11 @@ export default async function Page({ const avatar = getAvatarForPlatform(data, _platform); const basicProfileInfo = getBasicPlatformProfileInfo(data, _platform); + const accountAggregatedData = await getAggregatedAccountData({ + account: mainAddress, + chainId: _network, + }); + return (
@@ -54,6 +60,9 @@ export default async function Page({ } />
+
+ Endorsements: {accountAggregatedData.totalEndorsementsReceived} +
{basicProfileInfo.description && (
{basicProfileInfo.description} diff --git a/packages/dapp/src/components/Navbar/Searchbar.tsx b/packages/dapp/src/components/Navbar/Searchbar.tsx index c53a968..f85328d 100644 --- a/packages/dapp/src/components/Navbar/Searchbar.tsx +++ b/packages/dapp/src/components/Navbar/Searchbar.tsx @@ -193,7 +193,7 @@ export const Searchbar = () => { return (
diff --git a/packages/dapp/src/lib/ees/getAggregatedAccountData.ts b/packages/dapp/src/lib/ees/getAggregatedAccountData.ts new file mode 100644 index 0000000..e48d7ca --- /dev/null +++ b/packages/dapp/src/lib/ees/getAggregatedAccountData.ts @@ -0,0 +1,82 @@ +import { + GetAggregatedAccountDataDocument, + type GetAggregatedAccountDataQuery, +} from '@/__generated__/ees/graphql'; +import { getGraphqlApiUrl } from './getGraphqlApiUrl'; + +type GetTopEndorsersAndDonatorsDocument = { + totalEndorsementsReceived: string; + totalEndorsementsSent: string; + totalDonationsReceived: string; + totalDonationsSent: string; + error: string | null; +}; + +export const getAggregatedAccountData = async ({ + chainId, + account, +}: { + chainId: number; + account: string; +}): Promise => { + try { + const graphqlUrl = getGraphqlApiUrl(chainId); + + const result = await fetch(graphqlUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query: GetAggregatedAccountDataDocument, + variables: { + account, + }, + }), + // Cache for 1 minute + next: { revalidate: 60 }, + }); + + // Check if request was successful + if (!result.ok) { + return { + totalEndorsementsReceived: '0', + totalEndorsementsSent: '0', + totalDonationsReceived: '0', + totalDonationsSent: '0', + error: 'Failed to fetch data', + }; + } + + const jsonResponse = await result.json(); + + // Check if we successfully decoded the response + if (!jsonResponse) { + return { + totalEndorsementsReceived: '0', + totalEndorsementsSent: '0', + totalDonationsReceived: '0', + totalDonationsSent: '0', + error: 'Failed to fetch data', + }; + } + + const data = jsonResponse.data as GetAggregatedAccountDataQuery; + + return { + totalEndorsementsReceived: data.account?.totalEndorsementsReceived ?? '0', + totalEndorsementsSent: data.account?.totalEndorsementsSent ?? '0', + totalDonationsReceived: data.account?.totalDonationsReceived ?? '0', + totalDonationsSent: data.account?.totalDonationsSent ?? '0', + error: null, + }; + } catch (error) { + return { + totalEndorsementsReceived: '0', + totalEndorsementsSent: '0', + totalDonationsReceived: '0', + totalDonationsSent: '0', + error: 'Failed to fetch data', + }; + } +}; diff --git a/packages/dapp/src/lib/ees/getTopEndorsersAndDonators.ts b/packages/dapp/src/lib/ees/getTopEndorsersAndDonators.ts index dc67db2..fe7ad56 100644 --- a/packages/dapp/src/lib/ees/getTopEndorsersAndDonators.ts +++ b/packages/dapp/src/lib/ees/getTopEndorsersAndDonators.ts @@ -55,9 +55,11 @@ export const getTopEndorsersAndDonators = async ({ }; } + const data = jsonResponse.data as GetTopEndorsersAndDonatorsQuery; + return { - topEndorsers: jsonResponse.data.topEndorsers ?? [], - topDonators: jsonResponse.data.topDonators ?? [], + topEndorsers: data.topEndorsers ?? [], + topDonators: data.topDonators ?? [], error: null, }; } catch (error) { diff --git a/packages/dapp/src/lib/ees/index.ts b/packages/dapp/src/lib/ees/index.ts index a57b6b2..dc0ce64 100644 --- a/packages/dapp/src/lib/ees/index.ts +++ b/packages/dapp/src/lib/ees/index.ts @@ -1,2 +1,3 @@ export * from './getGraphqlApiUrl'; export * from './getTopEndorsersAndDonators'; +export * from './getAggregatedAccountData'; diff --git a/packages/dapp/src/lib/graphql/ees/getAggregatedAccountData.query.graphql b/packages/dapp/src/lib/graphql/ees/getAggregatedAccountData.query.graphql new file mode 100644 index 0000000..b232769 --- /dev/null +++ b/packages/dapp/src/lib/graphql/ees/getAggregatedAccountData.query.graphql @@ -0,0 +1,9 @@ +query GetAggregatedAccountData($account: ID!) { + account(id: $account) { + id + totalEndorsementsReceived + totalEndorsementsSent + totalDonationsReceived + totalDonationsSent + } +} diff --git a/packages/dapp/src/lib/graphql/ees/getTopEndorsersAndDonators.query.graphql b/packages/dapp/src/lib/graphql/ees/getTopEndorsersAndDonators.query.graphql index a01dc96..6df0a78 100644 --- a/packages/dapp/src/lib/graphql/ees/getTopEndorsersAndDonators.query.graphql +++ b/packages/dapp/src/lib/graphql/ees/getTopEndorsersAndDonators.query.graphql @@ -8,11 +8,10 @@ query GetTopEndorsersAndDonators($account: String!) { id from { id - totalEndorsementsReceived } } topDonators: aggregatedInformations( - where: {to: $account} + where: {to: $account, donationAmount_gt: 0} orderBy: donationAmount orderDirection: desc first: 6