explorer: add pagination to block rewards (#14906)
This commit is contained in:
parent
0b1015f7d3
commit
ad9ea91c1d
|
@ -3,7 +3,11 @@ import { lamportsToSolString } from "utils";
|
||||||
import { ConfirmedBlock, PublicKey } from "@solana/web3.js";
|
import { ConfirmedBlock, PublicKey } from "@solana/web3.js";
|
||||||
import { Address } from "components/common/Address";
|
import { Address } from "components/common/Address";
|
||||||
|
|
||||||
|
const PAGE_SIZE = 10;
|
||||||
|
|
||||||
export function BlockRewardsCard({ block }: { block: ConfirmedBlock }) {
|
export function BlockRewardsCard({ block }: { block: ConfirmedBlock }) {
|
||||||
|
const [rewardsDisplayed, setRewardsDisplayed] = React.useState(PAGE_SIZE);
|
||||||
|
|
||||||
if (block.rewards.length < 1) {
|
if (block.rewards.length < 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +30,11 @@ export function BlockRewardsCard({ block }: { block: ConfirmedBlock }) {
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{block.rewards.map((reward) => {
|
{block.rewards.map((reward, index) => {
|
||||||
|
if (index >= rewardsDisplayed - 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let percentChange;
|
let percentChange;
|
||||||
if (reward.postBalance !== null && reward.postBalance !== 0) {
|
if (reward.postBalance !== null && reward.postBalance !== 0) {
|
||||||
percentChange = (
|
percentChange = (
|
||||||
|
@ -54,6 +62,19 @@ export function BlockRewardsCard({ block }: { block: ConfirmedBlock }) {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{block.rewards.length > rewardsDisplayed && (
|
||||||
|
<div className="card-footer">
|
||||||
|
<button
|
||||||
|
className="btn btn-primary w-100"
|
||||||
|
onClick={() =>
|
||||||
|
setRewardsDisplayed((displayed) => displayed + PAGE_SIZE)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Load More
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue