Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: missed pagination from the page of transactions, referring cells and deployed cells. #113

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/components/Pagination/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export const PaginationPanel = styled.div`
justify-content: center;
border-radius: 0 0 6px 6px;
box-shadow: 0 2px 6px 0 rgb(0 0 0 / 12%);

@media (max-width: 750px) {
margin-bottom: 30px;
}
`

export const PaginationLeftItem = styled.div`
Expand Down Expand Up @@ -205,6 +201,7 @@ export const PaginationRightItem = styled.div`

@media (max-width: 750px) {
margin-left: 10px;
margin-right: 10px;
font-size: 12px;
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/pages/Script/ScriptsComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TransactionCellScript from '../Transaction/TransactionCellScript'
import { shannonToCkb, toCamelcase } from '../../utils/util'
import { localeNumberString } from '../../utils/number'
import DecimalCapacity from '../../components/DecimalCapacity'
import { CellInScript, CkbTransactionInScript } from './types'
import { CellInScript, CkbTransactionInScript, PageInfo } from './types'
import styles from './styles.module.scss'
import { QueryResult } from '../../components/QueryResult'
import AddressText from '../../components/AddressText'
Expand All @@ -28,7 +28,7 @@ export const ScriptTransactions = ({ page, size }: { page: number; size: number
const { codeHash, hashType } = useParams<{ codeHash: string; hashType: string }>()

const transactionsQuery = useQuery(['scripts_ckb_transactions', codeHash, hashType, page, size], async () => {
const { data, meta } = await explorerService.api.requesterV2
const { data } = await explorerService.api.requesterV2
.get(`scripts/ckb_transactions`, {
params: {
code_hash: codeHash,
Expand All @@ -38,14 +38,14 @@ export const ScriptTransactions = ({ page, size }: { page: number; size: number
},
})
.then((res: AxiosResponse) =>
toCamelcase<Response.Response<{ ckbTransactions: CkbTransactionInScript[] }>>(res.data),
toCamelcase<Response.Response<{ ckbTransactions: CkbTransactionInScript[]; meta: PageInfo }>>(res.data),
WhiteMinds marked this conversation as resolved.
Show resolved Hide resolved
)

if (data == null || data.ckbTransactions == null || data.ckbTransactions.length === 0) {
throw new Error('Transactions empty')
}
return {
total: meta?.total ?? 0,
total: data.meta.total,
ckbTransactions: data.ckbTransactions,
}
})
Expand Down Expand Up @@ -124,7 +124,7 @@ export const ScriptCells = ({
const { codeHash, hashType } = useParams<{ codeHash: string; hashType: string }>()

const cellsQuery = useQuery([`scripts_${cellType}`, codeHash, hashType, page, size], async () => {
const { data, meta } = await explorerService.api.requesterV2
const { data } = await explorerService.api.requesterV2
.get(`scripts/${cellType}`, {
params: {
code_hash: codeHash,
Expand All @@ -134,7 +134,9 @@ export const ScriptCells = ({
},
})
.then((res: AxiosResponse) =>
toCamelcase<Response.Response<{ deployedCells?: CellInScript[]; referringCells?: CellInScript[] }>>(res.data),
toCamelcase<
Response.Response<{ deployedCells?: CellInScript[]; referringCells?: CellInScript[]; meta: PageInfo }>
>(res.data),
)
const camelCellType = camelcase(cellType) as 'deployedCells' | 'referringCells'
if (data == null) {
Expand All @@ -145,7 +147,7 @@ export const ScriptCells = ({
throw new Error('Cells empty')
}
return {
total: meta?.total ?? 0,
total: data.meta.total ?? 0,
cells,
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Script/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/* stylelint-disable-next-line selector-class-pattern */
.ant-tabs-nav-list {
margin-left: 40px;
padding-left: 40px;
}

/* stylelint-disable-next-line selector-class-pattern */
Expand Down Expand Up @@ -168,7 +168,7 @@

@media screen and (width <= 750px) {
.codeHash {
width: 600px;
width: 270px;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Script/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface ScriptInfo {

export type ScriptTabType = 'transactions' | 'deployed_cells' | 'referring_cells' | undefined

export type PageInfo = {
total: number
pageSize: number
}

export interface CkbTransactionInScript {
id: number
txHash: string
Expand Down