forked from blockscout/frontend
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial * feat: ⚡ Add 'aspect' tag to transaction tag * fix: ✏️ rename all rowInput to rawInput * fix: Delete redundant operations * feat: ⚡ display number of bound aspects * fix: 🐛 ts type error * fix: delete old Screenshot * fix: remove pw test file * fix: remove Txs pw file * feat: UI cleanup * remove pw test file * Adjust the maxDiffPixelRatio to 100% to pass the test. * Adjust the maxDiffPixelRatio to 100% to pass the test. * feat: Add Address Detail Page: Bound Aspects * Adjust the maxDiffPixelRatio to 100% to pass the test. * Adjust the maxDiffPixelRatio to 100% to pass the test.
- Loading branch information
Showing
9 changed files
with
244 additions
and
13 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,79 @@ | ||
import AspectABI from 'aspect/abi/aspect.json'; | ||
import { ethers } from 'ethers'; | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import chain from 'configs/app/chain'; | ||
import getQueryParamString from 'lib/router/getQueryParamString'; | ||
import { ADDRESS_COIN_BALANCE } from 'stubs/address'; | ||
import { generateListStub } from 'stubs/utils'; | ||
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages'; | ||
|
||
import AddressAspectsHistory from './aspects/AddressAspectsHistory'; | ||
|
||
export type AspectType = { | ||
aspectId?: string; | ||
version?: number; | ||
priority?: number; | ||
joinPoints?: number; | ||
}; | ||
const AddressAspects = () => { | ||
const router = useRouter(); | ||
const scrollRef = React.useRef<HTMLDivElement>(null); | ||
const [ aspectList, setAspectList ] = React.useState<Array<Array<AspectType>>>([]); | ||
const addressHash = getQueryParamString(router.query.hash); | ||
const provider = React.useMemo(() => { | ||
return new ethers.JsonRpcProvider(chain.rpcUrl); | ||
}, []); | ||
const contract = React.useMemo(() => { | ||
return new ethers.Contract(chain.aspectAddress, AspectABI, provider); | ||
}, [ provider ]); | ||
const chunkArray = (arr: Array<AspectType>, chunkSize: number) => { | ||
const result = []; | ||
|
||
for (let i = 0; i < arr.length; i += chunkSize) { | ||
result.push(arr.slice(i, i + chunkSize)); | ||
} | ||
|
||
return result; | ||
}; | ||
const getAspectsList = React.useCallback(async(addressHash: string) => { | ||
const res = await contract.aspectsOf(addressHash); | ||
const data = chunkArray(res.map((item: AspectType) => { | ||
return { | ||
aspectId: item.aspectId, | ||
version: item.version, | ||
priority: item.priority, | ||
}; | ||
}), 10); | ||
|
||
setAspectList(data); | ||
}, [ contract ]); | ||
|
||
React.useEffect(() => { | ||
getAspectsList(addressHash); | ||
}, [ addressHash, getAspectsList ]); | ||
const coinBalanceQuery = useQueryWithPages({ | ||
resourceName: 'address_coin_balance', | ||
pathParams: { hash: addressHash }, | ||
scrollRef, | ||
options: { | ||
placeholderData: generateListStub<'address_coin_balance'>( | ||
ADDRESS_COIN_BALANCE, | ||
50, | ||
{ | ||
next_page_params: { | ||
block_number: 8009880, | ||
items_count: 50, | ||
}, | ||
}, | ||
), | ||
}, | ||
}); | ||
|
||
return ( | ||
<AddressAspectsHistory query={ coinBalanceQuery } aspectList={ aspectList }/> | ||
); | ||
}; | ||
|
||
export default React.memo(AddressAspects); |
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,92 @@ | ||
import { Hide, Table, Tbody, Th, Tr } from '@chakra-ui/react'; | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import React from 'react'; | ||
|
||
import type { AddressAspectsHistoryResponse } from 'types/api/address'; | ||
import type { PaginationParams } from 'ui/shared/pagination/types'; | ||
|
||
import type { AspectType } from 'ui/address/AddressAspects'; | ||
import ActionBar from 'ui/shared/ActionBar'; | ||
import DataListDisplay from 'ui/shared/DataListDisplay'; | ||
import Pagination from 'ui/shared/pagination/Pagination'; | ||
import { default as Thead } from 'ui/shared/TheadSticky'; | ||
|
||
import AddressAspectsTableItem from './AddressAspectsTableItem'; | ||
|
||
interface Props { | ||
query: UseQueryResult<AddressAspectsHistoryResponse> & { | ||
pagination: PaginationParams; | ||
}; | ||
aspectList: Array<Array<AspectType>>; | ||
} | ||
|
||
const AddressAspectsHistory = ({ query, aspectList }: Props) => { | ||
const [ page, setPage ] = React.useState<number>(1); | ||
const onNextPageClick = | ||
React.useCallback(() => { | ||
() => { | ||
setPage(page => page + 1); | ||
}; | ||
}, [ setPage ]); | ||
|
||
const onPrevPageClick = | ||
React.useCallback(() => { | ||
() => { | ||
setPage(page => page - 1); | ||
}; | ||
}, [ setPage ]); | ||
|
||
const resetPage = | ||
React.useCallback(() => { | ||
() => { | ||
setPage(1); | ||
}; | ||
}, [ setPage ]); | ||
|
||
const content = query.data?.items ? ( | ||
<Hide below="lg" ssr={ false }> | ||
<Table variant="simple" size="sm"> | ||
<Thead top={ query.pagination.isVisible ? 80 : 0 }> | ||
<Tr> | ||
<Th width="40%">Aspect ID</Th> | ||
<Th width="20%">Join Points</Th> | ||
<Th width="20%">Version</Th> | ||
<Th width="20%">Priority</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{ aspectList[0] ? | ||
aspectList[page - 1].map((item: AspectType, index: number) => ( | ||
<AddressAspectsTableItem | ||
key={ index } | ||
{ ...item } | ||
page={ query.pagination.page } | ||
isLoading={ query.isPlaceholderData } | ||
/> | ||
)) : '' } | ||
</Tbody> | ||
</Table> | ||
</Hide> | ||
) : null; | ||
|
||
const actionBar = ( | ||
<ActionBar mt={ -6 }> | ||
<Pagination ml="auto" page={ page } isVisible={ true } hasPages={ aspectList.length > 0 } | ||
hasNextPage={ page < aspectList.length } canGoBackwards={ true } isLoading={ false } | ||
onNextPageClick={ onNextPageClick } onPrevPageClick={ onPrevPageClick } resetPage={ resetPage }/> | ||
</ActionBar> | ||
); | ||
|
||
return ( | ||
<DataListDisplay | ||
mt={ 8 } | ||
isError={ query.isError } | ||
items={ aspectList } | ||
emptyText="There is no aspect bound to this address." | ||
content={ content } | ||
actionBar={ actionBar } | ||
/> | ||
); | ||
}; | ||
|
||
export default React.memo(AddressAspectsHistory); |
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,39 @@ | ||
import { Td, Tr, Skeleton } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import type { AspectType } from 'ui/address/AddressAspects'; | ||
|
||
type Props = AspectType & { | ||
page: number; | ||
isLoading: boolean; | ||
}; | ||
|
||
const AddressAspectsTableItem = (props: Props) => { | ||
return ( | ||
<Tr> | ||
<Td> | ||
<Skeleton isLoaded={ !props.isLoading } display="inline-block"> | ||
<span>{ props.aspectId }</span> | ||
</Skeleton> | ||
</Td> | ||
<Td> | ||
<Skeleton isLoaded={ !props.isLoading } color="text_secondary" display="inline-block"> | ||
<span>{ props.joinPoints ? Number(props.joinPoints) : '' }</span> | ||
</Skeleton> | ||
</Td> | ||
<Td> | ||
<Skeleton isLoaded={ !props.isLoading } color="text_secondary" display="inline-block"> | ||
<span>{ Number(props.version) }</span> | ||
</Skeleton> | ||
</Td> | ||
<Td> | ||
<Skeleton isLoaded={ !props.isLoading } color="text_secondary" display="inline-block"> | ||
<span>{ Number(props.priority) }</span> | ||
</Skeleton> | ||
</Td> | ||
|
||
</Tr> | ||
); | ||
}; | ||
|
||
export default React.memo(AddressAspectsTableItem); |
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