-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
export interface ChainSettings { | ||
network: string; | ||
chainType: string; | ||
genesis: { | ||
time: string; | ||
height: number; | ||
}; | ||
prefix: { | ||
consensus: string; | ||
validator: string; | ||
account: string; | ||
}; | ||
primaryTokenUnit: string; | ||
priceTokenUnit: string; | ||
votingPowerTokenUnit: string; | ||
tokenUnits: { | ||
[token: string]: { | ||
display: string; | ||
exponent: number; | ||
}; | ||
}; | ||
endpoints: { | ||
graphql?: string; | ||
graphqlWebsocket?: string; | ||
publicRpcWebsocket?: string; | ||
}; | ||
marketing: { | ||
matomoURL?: string; | ||
matomoSiteID?: string; | ||
}; | ||
} | ||
|
||
export interface PaletteSettings { | ||
primary: { | ||
main?: string; | ||
contractText?: string; | ||
}; | ||
background: { | ||
default?: string; | ||
paper?: string; | ||
}; | ||
divider?: string; | ||
text: { | ||
primary?: string; | ||
secondary?: string; | ||
}; | ||
custom: { | ||
general: { | ||
background?: string; | ||
surfaceOne?: string; | ||
surfaceTwo?: string; | ||
surfaceThree?: string; | ||
icon?: string; | ||
}; | ||
fonts: { | ||
fontOne?: string; | ||
fontTwo?: string; | ||
fontThree?: string; | ||
fontFour?: string; | ||
fontFive?: string; | ||
highlight?: string; | ||
}; | ||
primaryData: { | ||
one?: string; | ||
two?: string; | ||
three?: string; | ||
four?: string; | ||
}; | ||
results: { | ||
pass?: string; | ||
fail?: string; | ||
}; | ||
tokenomics: { | ||
one?: string; | ||
two?: string; | ||
three?: string; | ||
}; | ||
conditions: { | ||
zero?: string; | ||
one?: string; | ||
two?: string; | ||
three?: string; | ||
}; | ||
charts: { | ||
zero?: string; | ||
one?: string; | ||
two?: string; | ||
three?: string; | ||
four?: string; | ||
five?: string; | ||
}; | ||
tags: { | ||
zero?: string; | ||
one?: string; | ||
two?: string; | ||
three?: string; | ||
four?: string; | ||
five?: string; | ||
six?: string; | ||
seven?: string; | ||
eight?: string; | ||
nine?: string; | ||
ten?: string; | ||
eleven?: string; | ||
twelve?: string; | ||
thirteen?: string; | ||
fourteen?: string; | ||
fifteen?: string; | ||
sixteen?: string; | ||
seventeen?: string; | ||
eighteen?: string; | ||
nineteen?: string; | ||
twenty?: string; | ||
}; | ||
wallet: { | ||
background?: string; | ||
backgroundTwo?: string; | ||
surfaceOne: string; | ||
surfaceTwo: string; | ||
surfaceThree: string; | ||
surfaceFour: string; | ||
surfaceFive: string; | ||
divider?: string; | ||
textPrimary?: string; | ||
textSecondary?: string; | ||
active?: string; | ||
inactive?: string; | ||
}; | ||
}; | ||
} | ||
|
||
export interface ChainConfig extends ChainSettings { | ||
chainName: string; | ||
title: string; | ||
extra: { | ||
profile: boolean; | ||
graphqlWs: boolean; | ||
votingPowerExponent?: number; | ||
}; | ||
basePath: string; | ||
previewImage?: string; | ||
themes: { | ||
default: string; | ||
themeList: Array<'dark' | 'light' | 'deuteranopia' | 'tritanopia'>; | ||
dark: PaletteSettings; | ||
light: PaletteSettings; | ||
}; | ||
keplr: string | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apps/web-nym/src/screens/home/components/data_blocks/hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import numeral from 'numeral'; | ||
import { useState } from 'react'; | ||
import chainConfig from '@/chainConfig'; | ||
import { | ||
ActiveValidatorCountQuery, | ||
AverageBlockTimeQuery, | ||
TokenPriceListenerSubscription, | ||
useActiveValidatorCountQuery, | ||
useAverageBlockTimeQuery, | ||
useLatestBlockHeightListenerSubscription, | ||
useTokenPriceListenerSubscription, | ||
} from '@/graphql/types/general_types'; | ||
|
||
const { priceTokenUnit, tokenUnits } = chainConfig(); | ||
|
||
type DataBlocksState = { | ||
blockHeight: number; | ||
blockTime: number; | ||
price: number | null; | ||
validators: { | ||
active: number; | ||
total: number; | ||
}; | ||
}; | ||
|
||
const formatAverageBlockTime = (data: AverageBlockTimeQuery, state: DataBlocksState) => | ||
data.averageBlockTime[0]?.averageTime ?? state.blockTime; | ||
|
||
const formatTokenPrice = (data: TokenPriceListenerSubscription, state: DataBlocksState) => { | ||
if (data?.tokenPrice[0]?.price) { | ||
return numeral(numeral(data?.tokenPrice[0]?.price).format('0.0000', Math.floor)).value(); | ||
} | ||
return state.price; | ||
}; | ||
|
||
const formatActiveValidatorsCount = (data: ActiveValidatorCountQuery) => ({ | ||
active: data.activeTotal.aggregate?.count ?? 0, | ||
total: data.total?.aggregate?.count ?? 0, | ||
}); | ||
|
||
export const useDataBlocks = () => { | ||
const [state, setState] = useState<DataBlocksState>({ | ||
blockHeight: 0, | ||
blockTime: 0, | ||
price: null, | ||
validators: { | ||
active: 0, | ||
total: 0, | ||
}, | ||
}); | ||
|
||
// ==================================== | ||
// block height | ||
// ==================================== | ||
|
||
useLatestBlockHeightListenerSubscription({ | ||
onData: (data) => { | ||
setState((prevState) => ({ | ||
...prevState, | ||
blockHeight: data.data.data?.height?.[0]?.height ?? 0, | ||
})); | ||
}, | ||
}); | ||
|
||
// ==================================== | ||
// block time | ||
// ==================================== | ||
useAverageBlockTimeQuery({ | ||
onCompleted: (data) => { | ||
setState((prevState) => ({ | ||
...prevState, | ||
blockTime: formatAverageBlockTime(data, state), | ||
})); | ||
}, | ||
}); | ||
|
||
// ==================================== | ||
// token price | ||
// ==================================== | ||
useTokenPriceListenerSubscription({ | ||
variables: { | ||
denom: tokenUnits?.[priceTokenUnit]?.display, | ||
}, | ||
onData: (data) => { | ||
setState((prevState) => ({ | ||
...prevState, | ||
price: data.data.data ? formatTokenPrice(data.data.data, state) : 0, | ||
})); | ||
}, | ||
}); | ||
|
||
// ==================================== | ||
// validators | ||
// ==================================== | ||
useActiveValidatorCountQuery({ | ||
onCompleted: (data) => { | ||
setState((prevState) => ({ | ||
...prevState, | ||
validators: formatActiveValidatorsCount(data), | ||
})); | ||
}, | ||
}); | ||
|
||
return { | ||
state, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as R from 'ramda'; | ||
import { useCallback, useState } from 'react'; | ||
import chainConfig from '@/chainConfig'; | ||
import { useTokenPriceHistoryQuery } from '@/graphql/types/general_types'; | ||
import type { HeroState } from '@/screens/home/components/hero/types'; | ||
|
||
const { priceTokenUnit, tokenUnits } = chainConfig(); | ||
|
||
export const useHero = () => { | ||
const [state, setState] = useState<HeroState>({ | ||
loading: true, | ||
exists: true, | ||
tokenPriceHistory: [], | ||
}); | ||
|
||
const handleSetState = useCallback((stateChange: (prevState: HeroState) => HeroState) => { | ||
setState((prevState) => { | ||
const newState = stateChange(prevState); | ||
return R.equals(prevState, newState) ? prevState : newState; | ||
}); | ||
}, []); | ||
|
||
useTokenPriceHistoryQuery({ | ||
variables: { | ||
limit: 48, | ||
denom: tokenUnits?.[priceTokenUnit]?.display, | ||
}, | ||
onCompleted: (data) => { | ||
handleSetState((prevState) => { | ||
const newState = { | ||
...prevState, | ||
loading: false, | ||
tokenPriceHistory: | ||
data.tokenPrice.length === 48 | ||
? [...data.tokenPrice].reverse().map((x) => ({ | ||
time: x.timestamp, | ||
value: x.price, | ||
})) | ||
: prevState.tokenPriceHistory, | ||
}; | ||
return R.equals(prevState, newState) ? prevState : newState; | ||
}); | ||
}, | ||
onError: () => { | ||
handleSetState((prevState) => ({ ...prevState, loading: false })); | ||
}, | ||
}); | ||
|
||
return { | ||
state, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters