Skip to content

Commit

Permalink
Change the structure and logic for table cells
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Jan 19, 2024
1 parent af0b403 commit 6da5a2a
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 108 deletions.
27 changes: 27 additions & 0 deletions dapp/src/components/TransactionHistory/Table/Cell/Custom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react"
import { TransactionInfo } from "#/types"
import Cell from "."
import { ContentType, getCustomContent } from "./utils/content"

function CustomCell({
type,
transaction1,
transaction2,
}: {
type: ContentType
transaction1: TransactionInfo
transaction2: TransactionInfo
}) {
if (type === "date") {
return <Cell children1={getCustomContent(type, transaction1)} />
}

return (
<Cell
children1={getCustomContent(type, transaction1)}
children2={getCustomContent(type, transaction2)}
/>
)
}

export default CustomCell
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react"
import { Chain, ExplorerDataType } from "#/types"
import { BLOCK_EXPLORER } from "#/constants"
import ViewInBlockExplorer from "#/components/shared/ViewInBlockExplorer"
import SimpleText from "./SimpleText"

function BlockExplorer({ txHash, chain }: { txHash?: string; chain: Chain }) {
if (txHash) {
return (
<ViewInBlockExplorer
id={txHash}
type={ExplorerDataType.TRANSACTION}
chain={chain}
size="sm"
/>
)
}
return <SimpleText color="grey.400">{BLOCK_EXPLORER[chain].title}</SimpleText>
}

export default BlockExplorer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react"
import { TextSm } from "#/components/shared/Typography"
import { TextProps } from "@chakra-ui/react"

function SimpleText({ ...textProps }: TextProps) {
return <TextSm fontWeight="semibold" {...textProps} />
}

export default SimpleText
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import { Box, Divider, useMultiStyleConfig } from "@chakra-ui/react"

function CellWrapper({
function Cell({
children1,
children2,
}: {
Expand All @@ -24,4 +24,4 @@ function CellWrapper({
)
}

export default CellWrapper
export default Cell
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react"
import { TransactionInfo } from "#/types"
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import CurrencyIcon from "#/components/shared/CurrencyIcon"
import { displayBlockTimestamp } from "#/utils"
import BlockExplorer from "../components/BlockExplorer"
import SimpleText from "../components/SimpleText"
import Status from "../components/Status"

export type ContentType =
| "currency-balance"
| "block-explorer"
| "currency-icon"
| "date"
| "status"

export const getCustomContent = (
type: ContentType,
transaction: TransactionInfo,
) => {
switch (type) {
case "currency-balance":
return (
<CurrencyBalance
currency={transaction.asset.currency}
amount={transaction.asset.amount}
size="sm"
/>
)
case "block-explorer": {
return (
<BlockExplorer txHash={transaction.txHash} chain={transaction.chain} />
)
}
case "currency-icon": {
return <CurrencyIcon currency={transaction.asset.currency} withSymbol />
}
case "date": {
return (
<SimpleText whiteSpace="pre-line">
{displayBlockTimestamp(transaction.timestamp)}
</SimpleText>
)
}
case "status": {
return <Status status={transaction.status} />
}
default:
// eslint-disable-next-line react/jsx-no-useless-fragment
return <></>
}
}
77 changes: 0 additions & 77 deletions dapp/src/components/TransactionHistory/Table/Cells/CustomCell.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions dapp/src/components/TransactionHistory/Table/Cells/TextCell.tsx

This file was deleted.

25 changes: 17 additions & 8 deletions dapp/src/components/TransactionHistory/Table/utils/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from "react"
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
import { StakeHistory } from "#/types"
import { capitalize, truncateAddress } from "#/utils"
import TextCell from "../Cells/TextCell"
import CustomCell from "../Cells/CustomCell"
import CustomCell from "../Cell/Custom"
import Cell from "../Cell"
import SimpleText from "../Cell/components/SimpleText"

const columnHelper = createColumnHelper<StakeHistory>()
// When defining the columns for the table, columnHelper.accessor ts returns a type issue.
Expand All @@ -29,9 +30,13 @@ export const COLUMNS: ColumnDef<StakeHistory, any>[] = [
columnHelper.display({
header: "Action",
cell: ({ row: { original } }) => (
<TextCell
value1={capitalize(original.callTx.action)}
value2={capitalize(original.receiptTx.action)}
<Cell
children1={
<SimpleText>{capitalize(original.callTx.action)}</SimpleText>
}
children2={
<SimpleText>{capitalize(original.receiptTx.action)}</SimpleText>
}
/>
),
}),
Expand All @@ -58,9 +63,13 @@ export const COLUMNS: ColumnDef<StakeHistory, any>[] = [
columnHelper.display({
header: "Account",
cell: ({ row: { original } }) => (
<TextCell
value1={truncateAddress(original.callTx.account)}
value2={truncateAddress(original.receiptTx.account)}
<Cell
children1={
<SimpleText>{truncateAddress(original.callTx.account)}</SimpleText>
}
children2={
<SimpleText>{truncateAddress(original.receiptTx.account)}</SimpleText>
}
/>
),
}),
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/types/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type TransactionInfo = {
action: TransactionInfoAction
asset: Asset
account: string
txHash: string
txHash?: string
status: TransactionInfoStatus
}

Expand Down

0 comments on commit 6da5a2a

Please sign in to comment.