From c1c5cb8ed006831e6e54d4b4256f243e7204ffc4 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 11 Sep 2023 10:11:50 +0300 Subject: [PATCH] Add account details --- schema.gql | 1 + src/modules/analytics/analytics.module.ts | 6 ++++++ src/modules/analytics/holders.resolver.ts | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/modules/analytics/holders.resolver.ts diff --git a/schema.gql b/schema.gql index 17252cb08..5d508b87e 100644 --- a/schema.gql +++ b/schema.gql @@ -788,6 +788,7 @@ input HistoryPagination { } type HoldersCount { + accountDetails: Account! address: String! count: Int! } diff --git a/src/modules/analytics/analytics.module.ts b/src/modules/analytics/analytics.module.ts index 4453f7e5c..7aeff0f6a 100644 --- a/src/modules/analytics/analytics.module.ts +++ b/src/modules/analytics/analytics.module.ts @@ -26,6 +26,9 @@ import { CollectionDetailsRedisHandler } from './loaders/collection-details.redi import { ListingAuctionAnalyticsHandler } from './events-parsers/listing-event-analytics.parser'; import { UpdateListingEventParser } from './events-parsers/updateListing-event.parser'; import { UpdatePriceEventParser } from './events-parsers/updatePrice-event.parser'; +import { HoldersResolver } from './holders.resolver'; +import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; +import { AccountsRedisHandler } from '../account-stats/loaders/accounts.redis-handler'; @Module({ providers: [ @@ -48,6 +51,9 @@ import { UpdatePriceEventParser } from './events-parsers/updatePrice-event.parse CollectionDetailsRedisHandler, UpdatePriceEventParser, UpdateListingEventParser, + AccountsProvider, + AccountsRedisHandler, + HoldersResolver, ], imports: [ ConfigModule.forRoot({ diff --git a/src/modules/analytics/holders.resolver.ts b/src/modules/analytics/holders.resolver.ts new file mode 100644 index 000000000..7709d465a --- /dev/null +++ b/src/modules/analytics/holders.resolver.ts @@ -0,0 +1,21 @@ +import { Resolver, ResolveField, Parent } from '@nestjs/graphql'; +import { BaseResolver } from '../common/base.resolver'; +import { HoldersCount } from './models/general-stats.model'; +import { Account } from '../account-stats/models'; +import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; + +@Resolver(() => HoldersCount) +export class HoldersResolver extends BaseResolver(HoldersCount) { + constructor(private readonly accountsProvider: AccountsProvider) { + super(); + } + + @ResolveField(() => Account) + async accountDetails(@Parent() holders: HoldersCount) { + const { address } = holders; + + if (!address) return null; + const account = await this.accountsProvider.load(address); + return Account.fromEntity(account?.value, address); + } +}