-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Celo: Block views customizations (#2185)
* show flag next to epoch block * block view customizations * add hint with link * display block epoch transfers * show epoch election reward types * show reward details * show base fee token from API * display current epoch on main page * mobile view * tests * add infinite scroll loading to reward details resource * update useApiQuery options * update screenshots * update layout of reward details on desktop * change hints of block epoch reward distribution
- Loading branch information
Showing
52 changed files
with
1,187 additions
and
36 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { InfiniteData, QueryKey, UseInfiniteQueryResult } from '@tanstack/react-query'; | ||
import { useInfiniteQuery, type UseInfiniteQueryOptions } from '@tanstack/react-query'; | ||
|
||
import type { PaginatedResources, ResourceError, ResourcePayload } from 'lib/api/resources'; | ||
import useApiFetch from 'lib/api/useApiFetch'; | ||
import type { Params as ApiFetchParams } from 'lib/api/useApiFetch'; | ||
|
||
import { getResourceKey } from './useApiQuery'; | ||
|
||
type TQueryData<R extends PaginatedResources> = ResourcePayload<R>; | ||
type TError = ResourceError<unknown>; | ||
type TPageParam<R extends PaginatedResources> = ApiFetchParams<R>['queryParams'] | null; | ||
|
||
export interface Params<R extends PaginatedResources> { | ||
resourceName: R; | ||
// eslint-disable-next-line max-len | ||
queryOptions?: Omit<UseInfiniteQueryOptions<TQueryData<R>, TError, InfiniteData<TQueryData<R>>, TQueryData<R>, QueryKey, TPageParam<R>>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'>; | ||
pathParams?: ApiFetchParams<R>['pathParams']; | ||
} | ||
|
||
type ReturnType<Resource extends PaginatedResources> = UseInfiniteQueryResult<InfiniteData<ResourcePayload<Resource>>, ResourceError<unknown>>; | ||
|
||
export default function useApiInfiniteQuery<R extends PaginatedResources>({ | ||
resourceName, | ||
queryOptions, | ||
pathParams, | ||
}: Params<R>): ReturnType<R> { | ||
const apiFetch = useApiFetch(); | ||
|
||
return useInfiniteQuery<TQueryData<R>, TError, InfiniteData<TQueryData<R>>, QueryKey, TPageParam<R>>({ | ||
// eslint-disable-next-line @tanstack/query/exhaustive-deps | ||
queryKey: getResourceKey(resourceName, { pathParams }), | ||
queryFn: (context) => { | ||
const queryParams = 'pageParam' in context ? (context.pageParam || undefined) : undefined; | ||
return apiFetch(resourceName, { pathParams, queryParams }) as Promise<TQueryData<R>>; | ||
}, | ||
initialPageParam: null, | ||
getNextPageParam: (lastPage) => { | ||
return lastPage.next_page_params as TPageParam<R>; | ||
}, | ||
...queryOptions, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import _padStart from 'lodash/padStart'; | ||
|
||
import type { BlockEpoch, BlockEpochElectionRewardDetails, BlockEpochElectionRewardDetailsResponse } from 'types/api/block'; | ||
|
||
import * as addressMock from '../address/address'; | ||
import * as tokenMock from '../tokens/tokenInfo'; | ||
import * as tokenTransferMock from '../tokens/tokenTransfer'; | ||
|
||
export const blockEpoch1: BlockEpoch = { | ||
number: 1486, | ||
distribution: { | ||
carbon_offsetting_transfer: tokenTransferMock.erc20, | ||
community_transfer: tokenTransferMock.erc20, | ||
reserve_bolster_transfer: null, | ||
}, | ||
aggregated_election_rewards: { | ||
delegated_payment: { | ||
count: 0, | ||
total: '71210001063118670575', | ||
token: tokenMock.tokenInfoERC20d, | ||
}, | ||
group: { | ||
count: 10, | ||
total: '157705500305820107521', | ||
token: tokenMock.tokenInfoERC20b, | ||
}, | ||
validator: { | ||
count: 10, | ||
total: '1348139501689262297152', | ||
token: tokenMock.tokenInfoERC20c, | ||
}, | ||
voter: { | ||
count: 38, | ||
total: '2244419545166303388', | ||
token: tokenMock.tokenInfoERC20a, | ||
}, | ||
}, | ||
}; | ||
|
||
function getRewardDetailsItem(index: number): BlockEpochElectionRewardDetails { | ||
return { | ||
amount: `${ 100 - index }210001063118670575`, | ||
account: { | ||
...addressMock.withoutName, | ||
hash: `0x30D060F129817c4DE5fBc1366d53e19f43c8c6${ _padStart(String(index), 2, '0') }`, | ||
}, | ||
associated_account: { | ||
...addressMock.withoutName, | ||
hash: `0x456f41406B32c45D59E539e4BBA3D7898c3584${ _padStart(String(index), 2, '0') }`, | ||
}, | ||
}; | ||
} | ||
|
||
export const electionRewardDetails1: BlockEpochElectionRewardDetailsResponse = { | ||
items: Array(15).fill('').map((item, index) => getRewardDetailsItem(index)), | ||
next_page_params: null, | ||
}; |
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
| "burger" | ||
| "certified" | ||
| "check" | ||
| "checkered_flag" | ||
| "clock-light" | ||
| "clock" | ||
| "coins/bitcoin" | ||
|
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
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
Oops, something went wrong.