File tree Expand file tree Collapse file tree 4 files changed +14
-20
lines changed
components/content/home-page Expand file tree Collapse file tree 4 files changed +14
-20
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22
33import { CubeIcon } from '@heroicons/react/24/outline' ;
4- import { type Block } from 'alchemy-sdk' ;
4+ import type { Alchemy , Block } from 'alchemy-sdk' ;
55import {
66 getSecsFromUnixSecs ,
77 getBlockAgeFromSecs ,
88 truncateAddress ,
99 useAlchemy ,
1010} from '@/lib/utilities' ;
11- import { useDataState , useArgs , DataState } from '@/lib/data-state' ;
11+ import { useDataState , DataState } from '@/lib/data-state' ;
1212import Link from 'next/link' ;
1313import PopoverLink from '../../../common/popover-link' ;
1414import LoadingPulse from '@/components/common/indicators/loading-pulse' ;
@@ -23,11 +23,11 @@ export default function Block(props: {
2323 network : string ,
2424} ) {
2525 const alchemy = useAlchemy ( props . network ) ;
26- const blockNumber = props . latestBlockData . value ? props . latestBlockData . value - props . id : undefined ;
26+ const blockNumber = props . latestBlockData . value && props . latestBlockData . value - props . id ;
2727
28- const blockData = useDataState ( {
28+ const blockData = useDataState < Block , [ Alchemy , number ? ] > ( {
2929 fetcher : ( alchemy , num ) => alchemy . core . getBlock ( num ! ) ,
30- args : useArgs ( alchemy , blockNumber ) ,
30+ args : [ alchemy , blockNumber ] ,
3131 } ) ;
3232
3333 return (
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import Transactions from './transactions';
77import Stats from './stats' ;
88import NodeBanner from './node-banner' ;
99import { useAlchemy } from '@/lib/utilities' ;
10- import { useDataState , useArgs } from '@/lib/data-state' ;
10+ import { useDataState } from '@/lib/data-state' ;
1111
1212
1313export default function HomePage ( props : { network : string } ) {
Original file line number Diff line number Diff line change 11'use client' ;
22
33import { useAlchemy } from '@/lib/utilities' ;
4- import { useDataState , useArgs , DataState } from '@/lib/data-state' ;
4+ import { useDataState , DataState } from '@/lib/data-state' ;
5+ import type { Alchemy , BlockWithTransactions } from 'alchemy-sdk' ;
56import Transaction from './transaction' ;
67import ErrorWithRefetch from '@/components/common/indicators/error-with-refetch' ;
78
@@ -12,9 +13,9 @@ export default function Transactions(props: {
1213} ) {
1314 const alchemy = useAlchemy ( props . network ) ;
1415
15- const blockWithTransactionsData = useDataState ( {
16+ const blockWithTransactionsData = useDataState < BlockWithTransactions , [ Alchemy , number ? ] > ( {
1617 fetcher : ( alchemy , num ) => alchemy . core . getBlockWithTransactions ( num ! ) ,
17- args : useArgs ( alchemy , props . latestBlockData . value ) ,
18+ args : [ alchemy , props . latestBlockData . value ] ,
1819 } ) ;
1920
2021 let transactionsDisplay ;
Original file line number Diff line number Diff line change @@ -181,15 +181,6 @@ export const DataState = {
181181 }
182182} ;
183183
184- // Hook that memoizes the argument array to prevent a new array
185- // from being created on every render:
186- // (For inline use in `useDataState()` or `DataState.Init()` calls)
187- export function useArgs < A extends any [ ] > ( ...args : A ) : A {
188- // Prevent infinite loop by NOT refetching unless the arguments actually changed:
189- // eslint-disable-next-line react-hooks/exhaustive-deps
190- return useMemo ( ( ) => args , args ) ;
191- }
192-
193184// To be used as a wrapper for fetch() inside useDataState inline fetcher definition:
194185// (This allows the types to match with the DataState's, instead of returning a fetch Response type)
195186export async function fetchJson < T > ( ...args : any [ ] ) : Promise < T > {
@@ -198,15 +189,17 @@ export async function fetchJson<T>(...args: any[]): Promise<T> {
198189
199190 const json = await response . json ( ) ;
200191 const result = 'result' in json ? json . result : json ;
201- if ( ! result ) throw new FetchError ( `Empty json response or result, json: ${ JSON . stringify ( json ) } ` ) ;
192+ if ( ! result ) throw new FetchError ( `Empty json response or result.
193+ json: ${ JSON . stringify ( json ) }
194+ URL: ${ args [ 0 ] } ` ) ;
202195
203196 return result as T ;
204197}
205198
206199export class FetchError extends Error {
207200 constructor ( message : string ) {
208201 super ( message ) ;
209- this . name = 'FetchWithoutJsonError ' ;
202+ this . name = 'FetchError ' ;
210203 }
211204}
212205
You can’t perform that action at this time.
0 commit comments