-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2277 from blockscout/fe-2261
Celo: Epoch rewards tab on Address view
- Loading branch information
Showing
18 changed files
with
424 additions
and
39 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
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,41 @@ | ||
import type { AddressEpochRewardsResponse } from 'types/api/address'; | ||
|
||
import { tokenInfo } from 'mocks/tokens/tokenInfo'; | ||
|
||
import { withEns, withName, withoutName } from './address'; | ||
|
||
export const epochRewards: AddressEpochRewardsResponse = { | ||
items: [ | ||
{ | ||
type: 'delegated_payment', | ||
amount: '136609473658452408568', | ||
account: withName, | ||
associated_account: withName, | ||
block_hash: '0x', | ||
block_number: 26369280, | ||
epoch_number: 1526, | ||
token: tokenInfo, | ||
}, | ||
{ | ||
type: 'group', | ||
amount: '117205842355246195095', | ||
account: withoutName, | ||
associated_account: withoutName, | ||
block_hash: '0x', | ||
block_number: 26352000, | ||
epoch_number: 1525, | ||
token: tokenInfo, | ||
}, | ||
{ | ||
type: 'validator', | ||
amount: '125659647325556554060', | ||
account: withEns, | ||
associated_account: withEns, | ||
block_hash: '0x', | ||
block_number: 26300160, | ||
epoch_number: 1524, | ||
token: tokenInfo, | ||
}, | ||
], | ||
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
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,25 @@ | ||
import { Box } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import { epochRewards } from 'mocks/address/epochRewards'; | ||
import { test, expect } from 'playwright/lib'; | ||
|
||
import AddressEpochRewards from './AddressEpochRewards'; | ||
|
||
const ADDRESS_HASH = '0x1234'; | ||
const hooksConfig = { | ||
router: { | ||
query: { hash: ADDRESS_HASH }, | ||
}, | ||
}; | ||
|
||
test('base view +@mobile', async({ render, mockApiResponse }) => { | ||
await mockApiResponse('address_epoch_rewards', epochRewards, { pathParams: { hash: ADDRESS_HASH } }); | ||
const component = await render( | ||
<Box pt={{ base: '134px', lg: 6 }}> | ||
<AddressEpochRewards/> | ||
</Box>, | ||
{ hooksConfig }, | ||
); | ||
await expect(component).toHaveScreenshot(); | ||
}); |
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,89 @@ | ||
import { Hide, Show } from '@chakra-ui/react'; | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import useIsMounted from 'lib/hooks/useIsMounted'; | ||
import getQueryParamString from 'lib/router/getQueryParamString'; | ||
import { EPOCH_REWARD_ITEM } from 'stubs/address'; | ||
import { generateListStub } from 'stubs/utils'; | ||
import AddressEpochRewardsTable from 'ui/address/epochRewards/AddressEpochRewardsTable'; | ||
import ActionBar, { ACTION_BAR_HEIGHT_DESKTOP } from 'ui/shared/ActionBar'; | ||
import DataListDisplay from 'ui/shared/DataListDisplay'; | ||
import Pagination from 'ui/shared/pagination/Pagination'; | ||
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages'; | ||
|
||
import AddressEpochRewardsListItem from './epochRewards/AddressEpochRewardsListItem'; | ||
|
||
type Props = { | ||
scrollRef?: React.RefObject<HTMLDivElement>; | ||
shouldRender?: boolean; | ||
isQueryEnabled?: boolean; | ||
} | ||
|
||
const AddressEpochRewards = ({ scrollRef, shouldRender = true, isQueryEnabled = true }: Props) => { | ||
const router = useRouter(); | ||
const isMounted = useIsMounted(); | ||
|
||
const hash = getQueryParamString(router.query.hash); | ||
|
||
const rewardsQuery = useQueryWithPages({ | ||
resourceName: 'address_epoch_rewards', | ||
pathParams: { | ||
hash, | ||
}, | ||
scrollRef, | ||
options: { | ||
enabled: isQueryEnabled && Boolean(hash), | ||
placeholderData: generateListStub<'address_epoch_rewards'>(EPOCH_REWARD_ITEM, 50, { next_page_params: { | ||
amount: '1', | ||
items_count: 50, | ||
type: 'voter', | ||
associated_account_address_hash: '1', | ||
block_number: 10355938, | ||
} }), | ||
}, | ||
}); | ||
|
||
if (!isMounted || !shouldRender) { | ||
return null; | ||
} | ||
|
||
const content = rewardsQuery.data?.items ? ( | ||
<> | ||
<Hide below="lg" ssr={ false }> | ||
<AddressEpochRewardsTable | ||
items={ rewardsQuery.data.items } | ||
top={ rewardsQuery.pagination.isVisible ? ACTION_BAR_HEIGHT_DESKTOP : 0 } | ||
isLoading={ rewardsQuery.isPlaceholderData } | ||
/> | ||
</Hide> | ||
<Show below="lg" ssr={ false }> | ||
{ rewardsQuery.data.items.map((item, index) => ( | ||
<AddressEpochRewardsListItem | ||
key={ item.block_hash + item.type + item.account.hash + item.associated_account.hash + (rewardsQuery.isPlaceholderData ? String(index) : '') } | ||
item={ item } | ||
isLoading={ rewardsQuery.isPlaceholderData } | ||
/> | ||
)) } | ||
</Show> | ||
</> | ||
) : null; | ||
|
||
const actionBar = rewardsQuery.pagination.isVisible ? ( | ||
<ActionBar mt={ -6 }> | ||
<Pagination ml="auto" { ...rewardsQuery.pagination }/> | ||
</ActionBar> | ||
) : null; | ||
|
||
return ( | ||
<DataListDisplay | ||
isError={ rewardsQuery.isError } | ||
items={ rewardsQuery.data?.items } | ||
emptyText="There are no epoch rewards for this address." | ||
content={ content } | ||
actionBar={ actionBar } | ||
/> | ||
); | ||
}; | ||
|
||
export default AddressEpochRewards; |
Binary file added
BIN
+36.1 KB
...dress/__screenshots__/AddressEpochRewards.pw.tsx_default_base-view-mobile-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.4 KB
...ddress/__screenshots__/AddressEpochRewards.pw.tsx_mobile_base-view-mobile-1.png
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Skeleton } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import type { AddressEpochRewardsItem } from 'types/api/address'; | ||
|
||
import getCurrencyValue from 'lib/getCurrencyValue'; | ||
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; | ||
import BlockEntity from 'ui/shared/entities/block/BlockEntity'; | ||
import TokenEntity from 'ui/shared/entities/token/TokenEntity'; | ||
import EpochRewardTypeTag from 'ui/shared/EpochRewardTypeTag'; | ||
import ListItemMobileGrid from 'ui/shared/ListItemMobile/ListItemMobileGrid'; | ||
|
||
type Props = { | ||
item: AddressEpochRewardsItem; | ||
isLoading?: boolean; | ||
}; | ||
|
||
const AddressEpochRewardsListItem = ({ item, isLoading }: Props) => { | ||
const { valueStr } = getCurrencyValue({ value: item.amount, accuracy: 2, decimals: item.token.decimals }); | ||
return ( | ||
<ListItemMobileGrid.Container gridTemplateColumns="100px auto"> | ||
|
||
<ListItemMobileGrid.Label isLoading={ isLoading }>Block</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
<BlockEntity | ||
number={ Number(item.block_number) } | ||
isLoading={ isLoading } | ||
noIcon | ||
/> | ||
</ListItemMobileGrid.Value> | ||
|
||
<ListItemMobileGrid.Label isLoading={ isLoading }>Epoch #</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
{ item.epoch_number } | ||
</ListItemMobileGrid.Value> | ||
|
||
{ /* <ListItemMobileGrid.Label isLoading={ isLoading }>Age</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
<TimeAgoWithTooltip | ||
timestamp={ item.timestamp } | ||
isLoading={ isLoading } | ||
color="text_secondary" | ||
display="inline-block" | ||
/> | ||
</ListItemMobileGrid.Value> */ } | ||
|
||
<ListItemMobileGrid.Label isLoading={ isLoading }>Reward type</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
<EpochRewardTypeTag type={ item.type } isLoading={ isLoading }/> | ||
</ListItemMobileGrid.Value> | ||
|
||
<ListItemMobileGrid.Label isLoading={ isLoading }>Associated address</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
<AddressEntity | ||
address={ item.associated_account } | ||
isLoading={ isLoading } | ||
/> | ||
</ListItemMobileGrid.Value> | ||
|
||
<ListItemMobileGrid.Label isLoading={ isLoading }>Value</ListItemMobileGrid.Label> | ||
<ListItemMobileGrid.Value> | ||
<Skeleton isLoaded={ !isLoading } display="flex" alignItems="center" gap={ 2 }> | ||
{ valueStr } | ||
<TokenEntity token={ item.token } isLoading={ isLoading } onlySymbol width="auto" noCopy/> | ||
</Skeleton> | ||
</ListItemMobileGrid.Value> | ||
|
||
</ListItemMobileGrid.Container> | ||
); | ||
}; | ||
|
||
export default AddressEpochRewardsListItem; |
Oops, something went wrong.