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

Bump vocdoni packages #125

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@tanstack/react-query": "^5.40.0",
"@vocdoni/chakra-components": "~0.8.1",
"@vocdoni/extended-sdk": "^0.1.3",
"@vocdoni/sdk": "https://github.com/vocdoni/vocdoni-sdk.git#main",
"@vocdoni/chakra-components": "~0.9.0",
"@vocdoni/extended-sdk": "~0.2.0",
"@vocdoni/sdk": "~0.9.0",
"date-fns": "^2.29.3",
"ethers": "^5.7.2",
"framer-motion": "^10.9.2",
Expand Down Expand Up @@ -55,6 +55,6 @@
"node": "20.x"
},
"resolutions": {
"@vocdoni/sdk": "https://github.com/vocdoni/vocdoni-sdk.git#main"
"@vocdoni/sdk": "~0.9.0"
}
}
2 changes: 1 addition & 1 deletion src/components/Accounts/Details/Transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const TransfersRow = ({
toCopy={transfer.txHash}
fontWeight={'normal'}
fontSize={'sm'}
to={generatePath(RoutePath.TransactionByHashOrHeight, { hashOrHeight: transfer.txHash })}
to={generatePath(RoutePath.TransactionByHash, { hash: transfer.txHash, tab: null })}
>
{transfer.txHash}
</ReducedTextAndCopy>
Expand Down
39 changes: 8 additions & 31 deletions src/components/Blocks/BlockCard.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import { Box, Card, CardBody, Flex, Link, HStack, Icon, Text } from '@chakra-ui/react'
import { BlockError, BlockNotFoundError } from '@vocdoni/extended-sdk'
import { IChainBlockInfoResponse } from '@vocdoni/sdk'
import { Trans, useTranslation } from 'react-i18next'
import { BiTransferAlt } from 'react-icons/bi'
import { Box, CardBody, Flex, HStack, Icon, Text } from '@chakra-ui/react'
import { IBlock } from '@vocdoni/sdk'
import { Trans } from 'react-i18next'

import { generatePath, Link as RouterLink } from 'react-router-dom'
import { generatePath } from 'react-router-dom'
import { ReducedTextAndCopy } from '~components/Layout/CopyButton'
import LinkCard from '~components/Layout/LinkCard'
import { RoutePath } from '~constants'
import { useDateFns } from '~i18n/use-date-fns'
import { Icons } from '~src/theme/components/Icons'

interface IBlockCardProps {
block: IChainBlockInfoResponse | BlockError
block: IBlock
compact?: boolean
}

export const BlockCard = ({ block, compact = false }: IBlockCardProps) => {
const { formatDistance } = useDateFns()
if (block instanceof BlockError) return <BlockErrorCard error={block} height={block.height} />

const height = block.header.height
const time = block.header.time
const proposer = block.header.proposerAddress
// Not on the SDK yet
// @ts-ignore
const height = block.height
const time = block.time
const proposer = block.proposer
const txn = block.txCount
elboletaire marked this conversation as resolved.
Show resolved Hide resolved

const date = new Date(time)
Expand Down Expand Up @@ -62,21 +57,3 @@ export const BlockCard = ({ block, compact = false }: IBlockCardProps) => {
</LinkCard>
)
}

const BlockErrorCard = ({ height, error }: { height: number; error: BlockError }) => {
const { t } = useTranslation()

let message = error.message
if (error instanceof BlockNotFoundError) {
message = t('blocks.block_not_found')
}

return (
<Card>
<CardBody>
<Text fontWeight='bold'># {height}</Text>
<Text wordBreak='break-word'>{message}</Text>
</CardBody>
</Card>
)
}
3 changes: 1 addition & 2 deletions src/components/Blocks/BlocksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { generatePath, useNavigate } from 'react-router-dom'
import { BlockCard } from '~components/Blocks/BlockCard'
import { PaginatedAsyncList } from '~components/Layout/AsyncList'
import { PopoverInputSearch } from '~components/Layout/Inputs'
import { RoutedPaginationProvider, useRoutedPagination } from '~components/Pagination/PaginationProvider'
import { PaginationItemsPerPage, RefreshIntervalBlocks, RoutePath } from '~constants'
import { useBlockList } from '~queries/blocks'
import { useChainInfo } from '~queries/stats'
import { PaginatedAsyncList } from '~components/Layout/AsyncList'

export const BlocksFilter = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -67,7 +67,6 @@ export const BlocksList = () => {
error,
} = useBlockList({
params: {
totalItems: blockCount,
page: page,
limit: PaginationItemsPerPage,
},
Expand Down
9 changes: 5 additions & 4 deletions src/components/Blocks/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { ReducedTextAndCopy } from '~components/Layout/CopyButton'
import { DetailsGrid, GridItemProps } from '~components/Layout/DetailsGrid'
import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { RawContentBox } from '~components/Layout/ShowRawButton'
import TextAndTag from '~components/Layout/TextAndTag'
import { PaginatedBlockTransactionsList } from '~components/Transactions/TransactionList'
import { RefreshIntervalBlocks, RoutePath } from '~constants'
import { useDateFns } from '~i18n/use-date-fns'
import { useBlocksHeight } from '~queries/blocks'
import TextAndTag from '~components/Layout/TextAndTag'

const HeightNavigator = ({ height }: { height: number }) => {
const { data, isLoading } = useBlocksHeight({
Expand Down Expand Up @@ -117,8 +117,6 @@ const DetailsTab = ({ block }: { block: IChainBlockInfoResponse }) => {
export const BlockDetail = ({ block }: { block: IChainBlockInfoResponse }) => {
const height = block.header.height
const date = new Date(block.header.time)
// Not on the SDK yet
// @ts-ignore
const txCount = block.txCount

const { t } = useTranslation()
Expand All @@ -142,7 +140,10 @@ export const BlockDetail = ({ block }: { block: IChainBlockInfoResponse }) => {
<Trans i18nKey={'process.tab_details'}>Details</Trans>
</Tab>
<Tab>
<TextAndTag text={t('process.tab_txs', { defaultValue: 'Transactions' })} tagLabel={txCount ?? '0'} />
<TextAndTag
text={t('process.tab_txs', { defaultValue: 'Transactions' })}
tagLabel={txCount.toString() ?? '0'}
/>
</Tab>
<Tab>
<Trans i18nKey={'raw'}>Raw</Trans>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Process/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { CardBody, CardProps, Flex, HStack } from '@chakra-ui/react'
import { ElectionSchedule, ElectionTitle } from '@vocdoni/chakra-components'
import { ElectionProvider, OrganizationProvider, useElection } from '@vocdoni/react-providers'
import { ArchivedElection, InvalidElection as InvalidElectionType, PublishedElection } from '@vocdoni/sdk'
import { InvalidElection as InvalidElectionType, PublishedElection } from '@vocdoni/sdk'
import { generatePath } from 'react-router-dom'
import { SmallAccountCard } from '~components/Accounts/Card'
import { ElectionStatusBadge } from '~components/Accounts/StatusBadge'
import LinkCard from '~components/Layout/LinkCard'
import InvalidElection from '~components/Process/InvalidElection'
import { RoutePath } from '~constants'
import { SmallAccountCard } from '~components/Accounts/Card'
import LinkCard from '~components/Layout/LinkCard'

export type ElectionCardProps = {
id?: string
election?: PublishedElection | ArchivedElection | InvalidElectionType
election?: PublishedElection | InvalidElectionType
} & CardProps

/**
Expand Down
19 changes: 5 additions & 14 deletions src/components/Process/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import {
import { useElection } from '@vocdoni/react-providers'
import { ElectionStatus, IElectionInfoResponse, InvalidElection as InvalidElectionType } from '@vocdoni/sdk'
import { Trans, useTranslation } from 'react-i18next'
import { AccountCard } from '~components/Accounts/Card'
import { ElectionStatusBadge } from '~components/Accounts/StatusBadge'
import { PaginatedEnvelopeList } from '~components/Envelope/EnvelopeList'
import { NoResultsError } from '~components/Layout/ContentError'
import { ReducedTextAndCopy } from '~components/Layout/CopyButton'
import { HeroHeaderLayout } from '~components/Layout/HeroHeaderLayout'
import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { RawContentBox } from '~components/Layout/ShowRawButton'
import { AccountCard } from '~components/Accounts/Card'
import { ElectionStatusBadge } from '~components/Accounts/StatusBadge'
import InvalidElection from '~components/Process/InvalidElection'
import { FallbackHeaderImg, RoutePath } from '~constants'
import { useElectionKeys } from '~queries/processes'
import { ucfirst } from '~utils/strings'
import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { NoResultsError } from '~components/Layout/ContentError'
import { PaginatedEnvelopeList } from '~components/Envelope/EnvelopeList'

const Detail = () => {
const { election } = useElection()
Expand All @@ -52,9 +52,6 @@ const Detail = () => {

const raw = election.raw as IElectionInfoResponse
const censusOrigin = ucfirst(raw.census.censusOrigin.replace('_', ' ').toLocaleLowerCase())
const autoStart = raw.electionMode.autoStart
? t('processes.process_mode_badge.autostart')
: t('processes.process_mode_badge.notAutostart')
const encryptedVotes = raw.voteMode.encryptedVotes
? t('processes.envelope_type_badge.encrypted_votes')
: t('processes.envelope_type_badge.not_encrypted_votes')
Expand Down Expand Up @@ -96,18 +93,12 @@ const Detail = () => {
{/*Information tags */}
<Flex wrap={'wrap'} gap={2}>
<QuestionsTypeBadge />
{election.fromArchive && (
<Tag variant={'vocdoni'}>
<Trans i18nKey={'process.badge.archive'}>From archive</Trans>
</Tag>
)}
{raw.voteMode.anonymous && (
<Tag variant={'vocdoni'}>
<Trans i18nKey={'process.badge.anonymous'}>Anonymous</Trans>
</Tag>
)}
<Tag variant={'vocdoni'}>{censusOrigin}</Tag>
<Tag variant={'vocdoni'}>{autoStart}</Tag>
<Tag variant={'vocdoni'}>{encryptedVotes}</Tag>
</Flex>
{/*Organization card and other cards*/}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Stats/LatestBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { keepPreviousData } from '@tanstack/react-query'
import { Trans } from 'react-i18next'
import { generatePath, Link as RouterLink } from 'react-router-dom'
import { BlockCard } from '~components/Blocks/BlockCard'
import { ContentError } from '~components/Layout/ContentError'
import { LoadingCards } from '~components/Layout/Loading'
import { RoutePath } from '~constants'
import { useBlockList } from '~queries/blocks'
import { useChainInfo } from '~queries/stats'
import { ContentError } from '~components/Layout/ContentError'

export const LatestBlocks = () => {
const blockListSize = 3
Expand All @@ -22,7 +22,6 @@ export const LatestBlocks = () => {
params: {
page: 0,
limit: blockListSize,
totalItems: stats?.height ?? 0,
},
enabled: !!stats?.height,
placeholderData: keepPreviousData,
Expand Down
8 changes: 4 additions & 4 deletions src/components/Transactions/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { RawContentBox } from '~components/Layout/ShowRawButton'
import { SpecificTxDetails } from '~components/Transactions/TxDetails/SpecificTxDetails'
import { TxDetailsGrid } from '~components/Transactions/TxDetails/TxDetails'
import { RoutePath } from '~constants'
import { useDateFns } from '~i18n/use-date-fns'
import { useBlockToDate } from '~queries/stats'
import { objectB64StringsToHex } from '~utils/objects'
import { RoutePath } from '~constants'

export const TransactionDetail = (tx: Tx) => {
const { data } = useBlockToDate({ height: tx.txInfo.blockHeight })
const { data } = useBlockToDate({ height: tx.txInfo.height })
const { formatDistance } = useDateFns()

let createdOn = ''
Expand All @@ -33,8 +33,8 @@ export const TransactionDetail = (tx: Tx) => {
<Flex direction={'column'} mt={'40px'} gap={6}>
<VStack align='start'>
<Heading isTruncated wordBreak='break-word' mb={0}>
<Trans i18nKey={'transactions.tx_title'} number={tx.txInfo.transactionNumber}>
Transaction #{{ number: tx.txInfo.transactionNumber }}
<Trans i18nKey={'transactions.tx_title'} number={tx.txInfo.index}>
Transaction details
</Trans>
</Heading>
{createdOn && (
Expand Down
57 changes: 37 additions & 20 deletions src/components/Transactions/TransactionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
import { Box, CardBody, Flex, Tag, Text } from '@chakra-ui/react'
import { IChainTxReference, TransactionType } from '@vocdoni/sdk'
import { Trans } from 'react-i18next'
import { Box, CardBody, Flex, Icon, Tag, Text } from '@chakra-ui/react'
import { IChainTxReference } from '@vocdoni/sdk'
import { generatePath } from 'react-router-dom'
import { ReducedTextAndCopy } from '~components/Layout/CopyButton'
import { RoutePath } from '~constants'
import LinkCard from '~components/Layout/LinkCard'
import { BlockIconLink } from '~components/Layout/IconLink'
import LinkCard from '~components/Layout/LinkCard'
import { RoutePath } from '~constants'
import { useDateFns } from '~i18n/use-date-fns'
import { useBlockToDate } from '~queries/stats'
import { Icons } from '~src/theme/components/Icons'

export const TransactionTypeBadge = ({ transactionType }: { transactionType: TransactionType }) => {
export const TransactionTypeBadge = ({ transactionType }: { transactionType: string }) => {
return (
<Tag bg={'#f3fccc'} color={'#74af07'} variant={'vocdoni'}>
{transactionType}
</Tag>
)
}

export const TransactionCard = ({
transactionIndex,
transactionType,
transactionNumber,
transactionHash,
blockHeight,
}: IChainTxReference) => {
export const TransactionCard = ({ index, hash, height, subtype, type }: IChainTxReference) => {
const { formatDistance } = useDateFns()

let _type = subtype
if (!subtype || subtype === '') _type = type

const { data } = useBlockToDate({ height })
let date: Date | undefined
if (data?.date) {
date = new Date(data.date)
}

return (
<LinkCard
to={generatePath(RoutePath.Transaction, {
block: blockHeight.toString(),
index: transactionIndex.toString(),
block: height.toString(),
index: index.toString(),
tab: null,
})}
>
<CardBody>
<Flex gap={3} direction={'column'}>
<Flex gap={2}>
<TransactionTypeBadge transactionType={transactionType} />
<BlockIconLink height={blockHeight} />
<TransactionTypeBadge transactionType={_type} />
{date && (
<Text fontWeight={100} color={'lighterText'}>
{formatDistance(date, new Date())}
</Text>
)}
</Flex>
<Text fontWeight='bold'># {transactionNumber}</Text>

<Flex align='center' gap={2}>
<Icon as={Icons.TxIcon} />
<Box>{index}</Box>
<BlockIconLink height={height} />
</Flex>

<Flex gap={2} align={'center'}>
<ReducedTextAndCopy fontSize={'sm'} color={'textAccent1'} toCopy={transactionHash}>
{transactionHash}
<ReducedTextAndCopy fontSize={'sm'} color={'textAccent1'} toCopy={hash}>
{hash}
</ReducedTextAndCopy>
</Flex>
</Flex>
Expand Down
Loading
Loading