Skip to content

Commit

Permalink
Get data from hook
Browse files Browse the repository at this point in the history
Added timestamp and id to query.
Refactored transation link button.
  • Loading branch information
kpyszkowski committed May 15, 2024
1 parent 7ed380a commit b0b0583
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
3 changes: 3 additions & 0 deletions dapp/src/pages/DashboardPage/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BoostArrowIcon } from "#/assets/icons"
import { CurrencyBalanceWithConversion } from "#/components/shared/CurrencyBalanceWithConversion"
import { AmountType, MODAL_TYPES } from "#/types"
import { useModal } from "#/hooks"
import TransactionHistory from "./TransactionHistory"

const buttonStyles: ButtonProps = {
size: "lg",
Expand Down Expand Up @@ -96,6 +97,8 @@ export default function DashboardCard(props: DashboardCardProps) {
Withdraw
</Button>
</HStack>

<TransactionHistory />
</CardBody>
</Card>
)
Expand Down
44 changes: 26 additions & 18 deletions dapp/src/pages/DashboardPage/TransactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {
VStack,
Card,
CardBody,
IconButton,
Link,
Box,
Image,
VisuallyHidden,
} from "@chakra-ui/react"
import {
Pagination,
Expand All @@ -22,6 +21,9 @@ import emptyStateIlustration from "#/assets/images/empty-state.png"
import { ArrowUpRightAnimatedIcon } from "#/assets/icons/animated"
import { motion } from "framer-motion"
import { displayBlockTimestamp, truncateAddress } from "#/utils"
import { useActivitiesNEW as useActivities } from "#/hooks"
import { Activity } from "#/types"
import BlockExplorerLink from "#/components/shared/BlockExplorerLink"

type TransactionHistoryData = {
date: number
Expand All @@ -36,37 +38,41 @@ type TransactionHistoryProps = StackProps & {
}

export default function TransactionHistory(props: TransactionHistoryProps) {
const { data = [], ...restProps } = props
const activities = useActivities()

const completedActivities = React.useMemo(
() => activities.filter(({ status }) => status === "completed"),
[activities],
)

return (
<VStack spacing={6} w="full" {...restProps}>
<VStack spacing={6} w="full" {...props}>
<TextMd fontWeight="bold" w="full">
Transactions
</TextMd>

{data.length === 0 ? (
{completedActivities.length === 0 ? (
<VStack>
<Image src={emptyStateIlustration} alt="" opacity={0.3} />
<TextMd color="grey.400">You have no transactions yet!</TextMd>
</VStack>
) : (
<Pagination data={data} pageSize={10}>
<Pagination data={completedActivities} pageSize={10}>
<PaginationPage direction="column" spacing={2} pageSpacing={6}>
{(pageData: TransactionHistoryData) =>
// TODO: Fix type assertion of `pageData`
pageData.map(({ date, type, amount, address, url }) => (
{(pageData: Activity[]) =>
pageData.map(({ id, timestamp, type, txHash, amount }) => (
<Card
as={motion.div}
initial={false}
whileHover="animate"
key={url}
key={id}
role="group"
variant="elevated"
colorScheme="gold"
>
<CardBody as={HStack} spacing={0} p={4}>
<TextSm color="grey.500" flex={1}>
{displayBlockTimestamp(date)}
{displayBlockTimestamp(timestamp)}
</TextSm>

<HStack flexBasis="72%" spacing={0}>
Expand All @@ -82,22 +88,24 @@ export default function TransactionHistory(props: TransactionHistoryProps) {
/>
</Box>
<TextSm color="grey.500" flexBasis="50%">
{truncateAddress(address)}
{truncateAddress(txHash)}
</TextSm>
</HStack>

<IconButton
as={Link}
icon={<ArrowUpRightAnimatedIcon top={1} />}
aria-label="View transaction details"
href={url}
<BlockExplorerLink
id={txHash}
chain="bitcoin"
type="transaction"
variant="ghost"
color="grey.300"
_groupHover={{ color: "brand.400" }}
pl={6}
pr={4}
m={-4}
/>
>
<ArrowUpRightAnimatedIcon />
<VisuallyHidden>View transaction details</VisuallyHidden>
</BlockExplorerLink>
</CardBody>
</Card>
))
Expand Down
2 changes: 2 additions & 0 deletions dapp/src/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type ActivityInfo = {
}

export type Activity = {
id: string
timestamp: number
txHash: string
amount: bigint
type: "deposit" | "withdraw"
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/types/subgraphAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export type ActivityDataResponse = {
id: string
bitcoinTransactionId: string
amountToDeposit: string
events: { type: "Initialized" | "Finalized" }[]
events: { timestamp: string; type: "Initialized" | "Finalized" }[]
}
12 changes: 11 additions & 1 deletion dapp/src/utils/subgraphAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import { Activity, ActivityDataResponse } from "#/types"
const ACRE_SUBGRAPH_URL = import.meta.env.VITE_ACRE_SUBGRAPH_URL

const mapToActivity = (activityData: ActivityDataResponse): Activity => {
const { bitcoinTransactionId: txHash, amountToDeposit, events } = activityData
const {
id,
bitcoinTransactionId: txHash,
amountToDeposit,
events,
} = activityData

const status = events.some(({ type }) => type === "Finalized")
? "completed"
: "pending"

const timestamp = parseInt(events[0].timestamp, 10)

return {
id,
txHash,
timestamp,
amount: BigInt(amountToDeposit),
type: "deposit",
status,
Expand All @@ -35,6 +44,7 @@ async function fetchActivityData(account: string): Promise<Activity[]> {
id
bitcoinTransactionId
events {
timestamp
type
}
... on Deposit {
Expand Down

0 comments on commit b0b0583

Please sign in to comment.