Skip to content

feat: add network api information #4

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yougotwill
Copy link
Collaborator

No description provided.

@yougotwill yougotwill marked this pull request as ready for review May 21, 2025 11:29
@yougotwill yougotwill requested review from Copilot and Aerilym May 21, 2025 11:29
@yougotwill yougotwill self-assigned this May 21, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces network API support by adding new types, API call logic, and integrating the network information into various components. Key changes include:

  • Adding Zod-based schemas in lib/network_api/types.ts and a corresponding NetworkApi class.
  • Updating various UI components (e.g., Header, Hero, StatsTilesServer) to consume the new network API data.
  • Refining constants and context values to support new UI features such as staking reward displays.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/network_api/types.ts Added new Zod schemas for network, token, and price information.
lib/network_api/NetworkApi.ts Introduced a new class to fetch network API data with revalidation options.
hooks/screen.tsx Updated useWindowSize import and handled width type conversion.
components/StakingRewardImageText/*.tsx Integrated network API data for staking reward display.
components/FlexibleContent/Modules/Hero/*.tsx Modified hero components to fetch and pass network API data.
components/Contexts/SettingsContext.tsx Extended context to include additional navigation properties.
.env.local.template Removed legacy DATA_API keys and added NETWORK_API configuration.
Comments suppressed due to low confidence (1)

components/FlexibleContent/Modules/StatsTiles/StatsTilesServer.tsx:21

  • [nitpick] The magic string 'SESH in Staking Reward Pool' is used to match a specific tile copy. Consider extracting it to a constant to avoid potential typos and improve maintainability.
if (stakingRewardPool && tile.copy === 'SESH in Staking Reward Pool') {

Comment on lines +19 to 24
const data = await NETWORK_API.getInfo(REVALIDATIONS['1H']);
const stakingRequirement = data?.token.staking_requirement;
const nodeCount = data?.network.network_size;
const totalStaked = data?.network.network_staked_tokens;
const stakingRewardPool = data?.token.staking_reward_pool;

Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling or fallback logic in case NETWORK_API.getInfo returns null, to ensure that subsequent usage of the data does not result in runtime issues.

Suggested change
const data = await NETWORK_API.getInfo(REVALIDATIONS['1H']);
const stakingRequirement = data?.token.staking_requirement;
const nodeCount = data?.network.network_size;
const totalStaked = data?.network.network_staked_tokens;
const stakingRewardPool = data?.token.staking_reward_pool;
let data;
try {
data = await NETWORK_API.getInfo(REVALIDATIONS['1H']);
} catch (error) {
console.error('Failed to fetch network info:', error);
data = null;
}
const stakingRequirement = data?.token?.staking_requirement ?? 0;
const nodeCount = data?.network?.network_size ?? 0;
const totalStaked = data?.network?.network_staked_tokens ?? 0;
const stakingRewardPool = data?.token?.staking_reward_pool ?? 0;

Copilot uses AI. Check for mistakes.


export function useScreenWidth() {
const { width } = useWindowSize();
const { width: _width } = useWindowSize();
const width = Number(_width);
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Ensure that the explicit conversion of _width to a number is necessary; if _width is already numeric, this conversion might be redundant.

Suggested change
const width = Number(_width);
const width = _width;

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant