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

[CFE-381]: Feature - bonded changes transaction #831

Merged
merged 25 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb930e3
refactor(types): update zod validation schema to apply with new api spec
Poafs1 Mar 18, 2024
bbd8b7a
feat: update changelog
Poafs1 Mar 18, 2024
ca5bc6c
feat(components): add bonded token changes delegation related transac…
Poafs1 Mar 19, 2024
0a0ae17
feat: update changelog
Poafs1 Mar 19, 2024
3d0fc9b
feat(components): delegation related transactions mobile card view
Poafs1 Mar 19, 2024
3fe2429
feat(components): update related transactions table fraction
Poafs1 Mar 19, 2024
11e764d
Merge pull request #832 from alleslabs/feature/cfe-52-bonded-transact…
evilpeach Mar 19, 2024
e29fde0
refactor(components): bonded token change add link to transactions tab
Poafs1 Mar 19, 2024
468a047
feat: update changelog
Poafs1 Mar 19, 2024
3b02540
feat(components): fix pr comments
Poafs1 Mar 20, 2024
40bb9c4
feat(components): fix acceptance test ui
Poafs1 Mar 20, 2024
c8c2ada
feat(components): change button to ghost variant
Poafs1 Mar 20, 2024
184e8f0
feat(components): use button size md instead of sm
Poafs1 Mar 20, 2024
f401814
Merge branch 'feature/cfe-35-voting-power-overview' into feature/cfe-…
Poafs1 Mar 20, 2024
24945a2
feat(components): fix pr comments
Poafs1 Mar 20, 2024
bcc03e7
feat(components): fix pr comments
Poafs1 Mar 21, 2024
cc23206
Merge branch 'feature/cfe-35-voting-power-overview' into feature/cfe-…
Poafs1 Mar 21, 2024
492ee23
feat(components): fix pr comments
Poafs1 Mar 21, 2024
32231dc
feat(components): fix pr comments
Poafs1 Mar 21, 2024
715999c
feat(components): fix pr comments
Poafs1 Mar 21, 2024
4a680e3
refactor(utils): totoken function test case
Poafs1 Mar 21, 2024
b1b2da4
feat(components): fix coin icon layout
Poafs1 Mar 21, 2024
ae64d18
Merge branch 'feature/cfe-35-voting-power-overview' into feature/cfe-…
Poafs1 Mar 21, 2024
10947c7
Merge pull request #833 from alleslabs/feature/cfe-37-current-bonded-…
evilpeach Mar 21, 2024
baa08bc
feat(components): fix related transaction table props
Poafs1 Mar 21, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#832](https://github.com/alleslabs/celatone-frontend/pull/832) Add bonded token changes delegation related transactions
- [#831](https://github.com/alleslabs/celatone-frontend/pull/831) Update zod schema to apply with new validator delegation related txs api spec
- [#828](https://github.com/alleslabs/celatone-frontend/pull/828) Add validator detail voting power overview section with data from APIs
- [#819](https://github.com/alleslabs/celatone-frontend/pull/819) Add validator detail overview section with data from APIs
- [#821](https://github.com/alleslabs/celatone-frontend/pull/821) Add Validator's proposed blocks table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Flex } from "@chakra-ui/react";
import { Box, Flex } from "@chakra-ui/react";

import { RelatedTransactionTable } from "../tables/RelatedTransactionsTable";
import {
RelatedTransactionsMobileCard,
RelatedTransactionTable,
} from "../tables";
import { useMobile } from "lib/app-provider";
import { Pagination } from "lib/components/pagination";
import { usePaginator } from "lib/components/pagination/usePaginator";
import { TableTitle } from "lib/components/table";
import { useValidatorDelegationRelatedTxs } from "lib/services/validatorService";
import type { AssetInfos, Option, ValidatorAddr } from "lib/types";

import { VotingPowerChart } from "./VotingPowerChart";
Expand All @@ -15,13 +23,82 @@ export const BondedTokenChanges = ({
validatorAddress,
singleStakingDenom,
assetInfos,
}: BondedTokenChangesProps) => (
<Flex direction="column" gap={{ base: 4, md: 8 }} pt={6}>
<VotingPowerChart
validatorAddress={validatorAddress}
singleStakingDenom={singleStakingDenom}
assetInfos={assetInfos}
/>
<RelatedTransactionTable />
</Flex>
);
}: BondedTokenChangesProps) => {
const isMobile = useMobile();

const {
pagesQuantity,
setTotalData,
currentPage,
setCurrentPage,
pageSize,
setPageSize,
offset,
} = usePaginator({
initialState: {
pageSize: 10,
currentPage: 1,
isDisabled: false,
},
});

const { data, isLoading } = useValidatorDelegationRelatedTxs(
validatorAddress,
pageSize,
offset,
{
onSuccess: ({ total }) => setTotalData(total),
}
);

const tableHeaderId = "relatedTransactionTableHeader";

return (
<Flex direction="column" gap={{ base: 4, md: 8 }} pt={6}>
<VotingPowerChart
validatorAddress={validatorAddress}
singleStakingDenom={singleStakingDenom}
assetInfos={assetInfos}
/>
<Box>
{isMobile ? (
<RelatedTransactionsMobileCard
delegationRelatedTxs={data?.items}
isLoading={isLoading}
assetInfos={assetInfos}
/>
) : (
<>
<TableTitle
title="Delegation-Related Transactions"
count={data?.total ?? 0}
id={tableHeaderId}
helperText="Shows transactions relevant to changes in delegated tokens, excluding any token reduction due to slashing."
/>
<RelatedTransactionTable
delegationRelatedTxs={data?.items}
isLoading={isLoading}
assetInfos={assetInfos}
/>
</>
)}
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
{!!data?.total && data.total > 10 && (
<Pagination
currentPage={currentPage}
pagesQuantity={pagesQuantity}
offset={offset}
totalData={data.total}
scrollComponentId={tableHeaderId}
pageSize={pageSize}
onPageChange={setCurrentPage}
onPageSizeChange={(e) => {
const size = Number(e.target.value);
setPageSize(size);
setCurrentPage(1);
}}
/>
)}
</Box>
</Flex>
);
};

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/pages/validator-details/components/tables/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./ProposedBlocksTable";
export * from "./RelatedTransactionsTable";
export * from "./related-transactions";
export * from "./VotedProposalsTable";
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Box, Flex, Text } from "@chakra-ui/react";
import type { BigSource } from "big.js";

import { TokenImageRender } from "lib/components/token";
import { getUndefinedTokenIcon } from "lib/pages/pools/utils";
import type { AssetInfos, Coin, Option, USD } from "lib/types";
import {
coinToTokenWithValue,
formatPrice,
formatUTokenWithPrecision,
} from "lib/utils";

interface RelatedTransactionsBondedTokenChangesProps {
txHash: string;
token: Coin;
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
assetInfos: Option<AssetInfos>;
}

export const RelatedTransactionsBondedTokenChanges = ({
txHash,
token,
assetInfos,
}: RelatedTransactionsBondedTokenChangesProps) => {
const tokenWithValue = coinToTokenWithValue(
token?.denom,
token?.amount,
assetInfos
);
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved

const formattedAmount = formatUTokenWithPrecision(
tokenWithValue.amount,
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
tokenWithValue.precision ?? 0,
false,
2,
true
);

const isPositiveAmount = tokenWithValue.amount.gte(0);

return (
<Flex
gap={2}
key={`${txHash}-${token.denom}`}
w="100%"
justifyContent={{ base: "start", md: "end" }}
alignItems="center"
>
<Box textAlign={{ base: "left", md: "right" }}>
<Text>
<Text
as="span"
fontWeight={700}
color={isPositiveAmount ? "success.main" : "error.main"}
>
{formattedAmount}
</Text>{" "}
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
{tokenWithValue.symbol}
</Text>
<Text variant="body3" color="text.dark">
({formatPrice(tokenWithValue.value?.abs() as USD<BigSource>)})
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
</Text>
</Box>
<TokenImageRender
boxSize={6}
logo={
tokenWithValue.logo ?? getUndefinedTokenIcon(tokenWithValue.denom)
}
/>
</Flex>
);
};
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Badge, Box, Flex, Grid, GridItem, Text } from "@chakra-ui/react";

import { ExplorerLink } from "lib/components/ExplorerLink";
import { Loading } from "lib/components/Loading";
import { MobileCardTemplate, MobileTableContainer } from "lib/components/table";
import type { ValidatorDelegationRelatedTxsResponseItem } from "lib/services/validator";
import type { AssetInfos, Option } from "lib/types";
import { dateFromNow, extractMsgType, formatUTC } from "lib/utils";

import { RelatedTransactionsBondedTokenChanges } from "./RelatedTransactionsBondedTokenChanges";

interface RelatedTransactionsMobileCardProps {
delegationRelatedTxs: Option<ValidatorDelegationRelatedTxsResponseItem[]>;
isLoading: boolean;
assetInfos: Option<AssetInfos>;
}

export const RelatedTransactionsMobileCard = ({
delegationRelatedTxs,
isLoading,
assetInfos,
}: RelatedTransactionsMobileCardProps) => {
if (isLoading) return <Loading />;

return (
<MobileTableContainer>
{delegationRelatedTxs?.map((delegationRelatedTx) => (
<MobileCardTemplate
topContent={
<Flex w="100%" flexDirection="column" gap={2}>
<Grid templateColumns="1fr 1fr" gap={2}>
<GridItem>
<Text variant="body3" color="text.dark" fontWeight={600}>
Transaction Hash
</Text>
<ExplorerLink
value={delegationRelatedTx.txHash.toLocaleUpperCase()}
type="tx_hash"
showCopyOnHover
/>
{delegationRelatedTx.messages.length > 1 && (
<Badge variant="secondary" ml={2}>
{delegationRelatedTx.messages.length}
</Badge>
)}
</GridItem>
<GridItem>
<Text variant="body3" color="text.dark" fontWeight={600}>
Sender
</Text>
<ExplorerLink
value={delegationRelatedTx.sender}
type="user_address"
showCopyOnHover
/>
</GridItem>
</Grid>
<Box>
<Text variant="body3" color="text.dark" fontWeight={600}>
Action
</Text>
<Text variant="body2" color="white">
{delegationRelatedTx.messages.length > 1
? `${delegationRelatedTx.messages.length} Messages`
: extractMsgType(delegationRelatedTx.messages[0].type)}
</Text>
</Box>
<Box>
<Text variant="body3" color="text.dark" fontWeight={600}>
Bonded Token Changes
</Text>
{delegationRelatedTx.tokens.map((token) => (
<RelatedTransactionsBondedTokenChanges
txHash={delegationRelatedTx.txHash}
token={token}
assetInfos={assetInfos}
/>
))}
</Box>
</Flex>
}
bottomContent={
<Box>
<Text variant="body2" color="text.dark">
{formatUTC(delegationRelatedTx.timestamp)}
</Text>
<Text variant="body3" color="text.disabled">
{`(${dateFromNow(delegationRelatedTx.timestamp)})`}
</Text>
</Box>
}
/>
))}
</MobileTableContainer>
);
};
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Loading } from "lib/components/Loading";
import { TableContainer } from "lib/components/table";
import type { ValidatorDelegationRelatedTxsResponseItem } from "lib/services/validator";
import type { AssetInfos, Option } from "lib/types";

import { RelatedTransactionsTableHeader } from "./RelatedTransactionsTableHeader";
import { RelatedTransactionsTableRow } from "./RelatedTransactionsTableRow";

interface RelatedTransactionTableProps {
delegationRelatedTxs: Option<ValidatorDelegationRelatedTxsResponseItem[]>;
isLoading: boolean;
assetInfos: Option<AssetInfos>;
}

export const RelatedTransactionTable = ({
delegationRelatedTxs = [],
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved
isLoading,
assetInfos,
}: RelatedTransactionTableProps) => {
if (isLoading) return <Loading />;
Poafs1 marked this conversation as resolved.
Show resolved Hide resolved

const templateColumns = "max(180px) max(180px) max(180px) 1fr max(280px)";

return (
<TableContainer>
<RelatedTransactionsTableHeader templateColumns={templateColumns} />
{delegationRelatedTxs.map((delegationRelatedTx) => (
<RelatedTransactionsTableRow
key={delegationRelatedTx.txHash}
templateColumns={templateColumns}
delegationRelatedTx={delegationRelatedTx}
assetInfos={assetInfos}
/>
))}
</TableContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Grid } from "@chakra-ui/react";

import { TableHeader } from "lib/components/table";

interface RelatedTransactionsTableHeaderProps {
templateColumns: string;
}

export const RelatedTransactionsTableHeader = ({
templateColumns,
}: RelatedTransactionsTableHeaderProps) => (
<Grid templateColumns={templateColumns} minW="min-content">
<TableHeader>Transaction Hash</TableHeader>
<TableHeader>Sender</TableHeader>
<TableHeader>Action</TableHeader>
<TableHeader w="100%" textAlign="end">
Bonded Token Changes
</TableHeader>
<TableHeader>Timestamp</TableHeader>
</Grid>
);
Loading