Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: homepage frontend #588

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
c223caa
feat: get TPS data for dashboard
raghukapur9 Sep 6, 2024
b21900d
add table component
aashaykapoor Sep 6, 2024
b50b66e
Merge branch 'main' of github.com:DevForce99/fuel-explorer into feat/…
aashaykapoor Sep 10, 2024
b0c2149
add home components
aashaykapoor Sep 11, 2024
9e7332d
home page fixed
Sep 12, 2024
d9173cf
Account Data Indexing
raghukapur9 Sep 13, 2024
f64b80e
Merge branch 'feat/TPS' of github.com:DevForce99/fuel-explorer into f…
aashaykapoor Sep 13, 2024
760f3a0
Merge branch 'FuelLabs:main' into feat/accountDataIndexer
raghukapur9 Sep 13, 2024
6ea9887
removed AccountModel class
raghukapur9 Sep 13, 2024
3377401
refactor block ui components
aashaykapoor Sep 14, 2024
5a1c2fe
refactor homepage and add data
aashaykapoor Sep 14, 2024
393baa8
fix:homepage-blocks-ui
aashaykapoor Sep 15, 2024
924c399
Merge branch 'FuelLabs:main' into feat/accountDataIndexer
raghukapur9 Sep 16, 2024
e8bd42e
Account Balance Changes
shivam-25 Sep 16, 2024
8081dca
Block and Transaction stats
shivam-25 Sep 16, 2024
8aebca6
Merge branch 'feat/accountDataIndexer' of https://github.com/DevForce…
shivam-25 Sep 16, 2024
2b7b219
Account stats
shivam-25 Sep 16, 2024
890c920
Daily Account Statistics
shivam-25 Sep 16, 2024
243c78a
tested and fixed account statistics
raghukapur9 Sep 16, 2024
02aaf56
changed query params for CumulativeAccountCreationStatistics
raghukapur9 Sep 16, 2024
dc032a3
Top Accounts
shivam-25 Sep 16, 2024
a87eac6
Top Accounts fix
shivam-25 Sep 16, 2024
208f03f
Paginated top accounts
shivam-25 Sep 17, 2024
c9ca0d8
Export functionlity query
shivam-25 Sep 18, 2024
c3a0cc9
Fixed end to end export data for account
shivam-25 Sep 19, 2024
285a57a
Merge branch 'main' of https://github.com/DevForce99/fuel-explorer in…
shivam-25 Sep 19, 2024
6a58d85
removed WS and added dashboard queries for graph and blocks
raghukapur9 Sep 21, 2024
b5ba01f
fixed time calculation
raghukapur9 Sep 21, 2024
22d1509
moved tps and dashboard blocks to explorer.graphql
raghukapur9 Sep 22, 2024
b0764cc
formatted getBlocksDashboard
raghukapur9 Sep 22, 2024
71ea2e4
Merge branch 'feat/account-stats' of github.com:DevForce99/fuel-explo…
aashaykapoor Sep 22, 2024
eae1c5a
adding generated files
raghukapur9 Sep 22, 2024
6a69c22
totalDeapps added
ankit723 Sep 23, 2024
cec6ebf
Merge branch 'feat/homePageTPS-WS' of github.com:DevForce99/fuel-expl…
aashaykapoor Sep 24, 2024
3a0e58a
blocks and tps data added
ankit723 Sep 24, 2024
513fe23
blocks and tps data added
ankit723 Sep 24, 2024
20d8223
refactor blocks timestamp
aashaykapoor Sep 24, 2024
6e1ce84
bug fixes
ankit723 Sep 24, 2024
2074eec
rebase
ankit723 Sep 24, 2024
5509e12
rebase
ankit723 Sep 24, 2024
8f5dd70
home page
ankit723 Sep 25, 2024
30b13b0
home page done
ankit723 Sep 25, 2024
0c7840a
fix: grid-layout
DivyanshArya09 Sep 25, 2024
0dd8657
fix: grid-layout
DivyanshArya09 Sep 25, 2024
0da59e4
fix: tps ui
aashaykapoor Sep 25, 2024
119e774
fix time on tps
aashaykapoor Sep 25, 2024
6ed902c
fix time
aashaykapoor Sep 25, 2024
4088fcc
fix tps
aashaykapoor Sep 25, 2024
203b346
fix: normalize daily transactions
aashaykapoor Sep 25, 2024
7bacb9b
remove redundant code
aashaykapoor Sep 25, 2024
8e70e19
fix: dapp component
aashaykapoor Sep 25, 2024
df6c110
fix: latest block
aashaykapoor Sep 25, 2024
3c0f26d
fix block table width
aashaykapoor Sep 25, 2024
5018334
home page done
ankit723 Sep 25, 2024
28f2d40
home page done
ankit723 Sep 25, 2024
90b70ac
home page done
ankit723 Sep 25, 2024
a6fb98c
fix: dapps
aashaykapoor Sep 25, 2024
46bcdea
home page done
ankit723 Sep 25, 2024
3d5c759
home page done
ankit723 Sep 25, 2024
83b2dc8
fix: ui related issue
aashaykapoor Sep 25, 2024
8a5951d
remove redundant files
aashaykapoor Sep 25, 2024
a6d2754
revert backend changes
aashaykapoor Sep 25, 2024
26213f9
revert backend changes
aashaykapoor Sep 25, 2024
4ebc49c
revert backend changes
aashaykapoor Sep 25, 2024
23f500a
revert backend changes
aashaykapoor Sep 25, 2024
1bada7b
revert settings
aashaykapoor Sep 25, 2024
89534cc
revert backend changes
aashaykapoor Sep 25, 2024
a475f16
remove stats
aashaykapoor Sep 25, 2024
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
Prev Previous commit
Next Next commit
Account stats
  • Loading branch information
shivam-25 committed Sep 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2b7b21975c4ba5523397367b1dc6fb5c43d2c840
122 changes: 122 additions & 0 deletions packages/app-explorer/src/systems/Statistics/getAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use server';

import { z } from 'zod';
import { act } from '../../systems/Core/utils/act-server';
import { sdk } from '../../systems/Core/utils/sdk';
import {
createIntervals,
getUnitAndInterval,
processAccounts, // You would need to implement this to handle account-specific data
} from '../utils/utils';

const schema = z.object({
timeFilter: z.string().optional().nullable(),
});

interface AccountParams {
timeFilter?: string;
}

interface AccountNode {
__typename: 'Account';
timestamp: string;
}

// Common function to process account statistics
async function fetchAccountStatistics(
params: AccountParams,
fieldName:
| 'accountCreationStatistics'
| 'cumulativeAccountCreationStatistics',
unit: 'minute' | 'hour' | 'day' | 'month',
intervalSize: number,
isCumulative = false,
) {
const data = await (isCumulative
? sdk.cumulativeAccountCreationStatistics(params)
: sdk.accountCreationStatistics(params));

const { nodes, offset } = extractAccountData(data, fieldName);

if (!nodes.length) {
return isCumulative ? { accounts: [], offset: 0 } : { accounts: [] };
}

const firstTimestamp = Number(nodes[0].timestamp);
const lastTimestamp = Number(nodes[nodes.length - 1].timestamp);

const intervalMap = createIntervals(
firstTimestamp,
lastTimestamp,
unit,
intervalSize,
);
const accounts = processAccounts(nodes, intervalMap); // Use this function for account-specific logic

if (isCumulative) {
return { accounts, offset };
}

return accounts;
}

// Helper to extract nodes and timestamps from the response
function extractAccountData(
data: any,
fieldName: string,
): { nodes: AccountNode[]; offset?: number } {
const nodes = data.data[fieldName]?.nodes || [];
const offset = data.data[fieldName]?.accountOffset;
return { nodes, offset };
}

async function getCumulativeAccountCreationStats(
params: AccountParams,
unit: 'minute' | 'hour' | 'day' | 'month',
intervalSize: number,
) {
return fetchAccountStatistics(
params,
'cumulativeAccountCreationStatistics',
unit,
intervalSize,
true,
);
}

export async function getAccountCreationStats(
params: AccountParams,
unit: 'minute' | 'hour' | 'day' | 'month',
intervalSize: number,
) {
return fetchAccountStatistics(
params,
'accountCreationStatistics',
unit,
intervalSize,
);
}

export const getAccountStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as { timeFilter?: string };
const { unit, intervalSize } = getUnitAndInterval(params.timeFilter || '');

return getAccountCreationStats(params, unit, intervalSize);
});

export const getDailyAccountCreationStats = act(
schema,
async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as { timeFilter?: string };

// Use 'day' as the unit and 1 as the interval size
return getAccountCreationStats(params, 'day', 1);
},
);

export const getCumulativeAccountStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as { timeFilter?: string };
const { unit, intervalSize } = getUnitAndInterval(params.timeFilter || '');

return getCumulativeAccountCreationStats(params, unit, intervalSize);
});
23 changes: 23 additions & 0 deletions packages/app-explorer/src/systems/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@ interface TransactionNode {
timestamp: string;
}

interface AccountNode {
timestamp: string;
}

interface Interval {
start: Date;
end: Date;
@@ -174,3 +178,22 @@ export function processTransactions(
});
return intervalMap;
}

export function processAccounts(nodes: AccountNode[], intervalMap: Interval[]) {
nodes.forEach((account) => {
const accountTimestamp = Number(account.timestamp);

// Find the correct interval for the current account
for (const interval of intervalMap) {
const intervalStart = new Date(interval.start).getTime();
const intervalEnd = new Date(interval.end).getTime();

if (accountTimestamp >= intervalStart && accountTimestamp < intervalEnd) {
// Increment count for the number of accounts created
interval.count += 1;
break; // Account assigned, no need to check further
}
}
});
return intervalMap;
}
2 changes: 1 addition & 1 deletion packages/graphql/src/application/uc/NewAddBlockRange.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import Block from '~/infra/dao/Block';
import Transaction from '~/infra/dao/Transaction';
import { DatabaseConnection } from '~/infra/database/DatabaseConnection';
import { AccountEntity } from '../../domain/Account/AccountEntity';
import { AccountDAO } from '../../infra/dao/AccountDAO';
import AccountDAO from '../../infra/dao/AccountDAO';

export default class NewAddBlockRange {
private accountDAO = new AccountDAO();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query accountCreationStatistics($timeFilter: String) {
accountCreationStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
accountOffset
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query cumulativeAccountCreationStatistics($timeFilter: String) {
cumulativeAccountCreationStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
accountOffset
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query newAccountStatistics($timeFilter: String) {
newAccountStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query accountCreationStatistics($timeFilter: String) {
accountCreationStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
accountOffset
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query cumulativeAccountCreationStatistics($timeFilter: String) {
cumulativeAccountCreationStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
accountOffset
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query newAccountStatistics($timeFilter: String) {
newAccountStatistics(timeFilter: $timeFilter) {
nodes {
timestamp
}
}
}
36 changes: 36 additions & 0 deletions packages/graphql/src/graphql/resolvers/AccountResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type {
GQLQueryAccountCreationStatisticsArgs,
GQLQueryNewAccountStatisticsArgs,
} from '../../graphql/generated/sdk-provider';
import AccountDAO from '../../infra/dao/AccountDAO';

export class AccountResolver {
static create() {
const resolvers = new AccountResolver();
return {
Query: {
accountCreationStatistics: resolvers.accountCreationStatistics,
newAccountStatistics: resolvers.newAccountStatistics,
},
};
}

async accountCreationStatistics(
_: any,
params: GQLQueryAccountCreationStatisticsArgs,
) {
const accountDAO = new AccountDAO();
const accounts = await accountDAO.accountCreationStatistics(
params.timeFilter || '',
);
return accounts;
}

async newAccountStatistics(_: any, params: GQLQueryNewAccountStatisticsArgs) {
const accountDAO = new AccountDAO();
const accounts = await accountDAO.newAccountStatistics(
params.timeFilter || '',
);
return accounts;
}
}
3 changes: 3 additions & 0 deletions packages/graphql/src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountResolver } from './AccountResolver';
import { BalanceResolver } from './BalanceResolver';
import { BlockResolver } from './BlockResolver';
import { ChainResolver } from './ChainResolver';
@@ -15,6 +16,7 @@ const nodeResolver = NodeResolver.create();
const predicateResolver = PredicateResolver.create();
const searchResolver = SearchResolver.create();
const transactionResolver = TransactionResolver.create();
const accountResolver = AccountResolver.create();

export const resolvers = {
Query: {
@@ -26,6 +28,7 @@ export const resolvers = {
...predicateResolver.Query,
...searchResolver.Query,
...transactionResolver.Query,
...accountResolver.Query,
},
Balance: balanceResolver.Balance,
};
21 changes: 21 additions & 0 deletions packages/graphql/src/graphql/schemas/fuelcore.graphql
Original file line number Diff line number Diff line change
@@ -784,6 +784,9 @@ type Query {
transactionsByBlockId(after: String, before: String, first: Int, last: Int, blockId: String!): TransactionConnection!
transactionsFeeStatistics(timeFilter: String): TransactionFeeConnection!
cumulativeTransactionsFeeStatistics(timeFilter: String): CumulativeTransactionFeeConnection!
accountCreationStatistics(timeFilter: String): CumulativeAccountCreationConnection!
newAccountStatistics(timeFilter: String): NewAccountStatisticsConnection!
cumulativeAccountCreationStatistics(timeFilter: String): CumulativeAccountCreationConnection!
}

type Receipt {
@@ -1051,4 +1054,22 @@ type BlockReward {
type BlockRewardConnection {
"""A list of nodes."""
nodes: [BlockReward!]
}

type CumulativeAccountCreationConnection {
nodes: [AccountCreationNode!]
accountOffset: Int!
}

type NewAccountStatisticsConnection {
nodes: [NewAccountNode!]
count: Int!
}

type AccountCreationNode {
timestamp: String!
}

type NewAccountNode {
timestamp: String!
}
Loading