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

Bulk bugfix #106

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions src/components/Accounts/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const AccountDetail = () => {
if (!organization) return null

const id = organization.address
const transfersCount = organization.transfersCount
const feesCount = organization.feesCount
const transfersCount = organization.transfersCount ?? 0
const feesCount = organization.feesCount ?? 0

return (
<>
Expand Down Expand Up @@ -73,7 +73,7 @@ const AccountDetail = () => {
<AccountTransfers org={organization} txCount={transfersCount} />
</TabPanel>
<TabPanel>
<AccountFees org={organization} />
<AccountFees org={organization} feesCount={feesCount} />
selankon marked this conversation as resolved.
Show resolved Hide resolved
</TabPanel>
<TabPanel>
<RawContentBox obj={organization} />
Expand Down
10 changes: 4 additions & 6 deletions src/components/Accounts/Details/Elections.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex, Text } from '@chakra-ui/react'
import { AccountData } from '@vocdoni/sdk'
import { Trans } from 'react-i18next'
import { Trans, useTranslation } from 'react-i18next'
import { LoadingCards } from '~components/Layout/Loading'
import { RoutedPagination } from '~components/Pagination/Pagination'
import { RoutedPaginationProvider, useRoutedPagination } from '~components/Pagination/PaginationProvider'
Expand All @@ -14,12 +14,10 @@ interface OrgComponentProps {
}

const AccountElections = ({ org }: OrgComponentProps) => {
const { t } = useTranslation()

if (org.electionIndex === 0) {
return (
<Text>
<Trans i18nKey={'account.no_elections'}>No elections yet!</Trans>
</Text>
)
return <NoResultsError msg={t('account.no_elections', { defaultValue: 'No elections yet!' })} />
}

return (
Expand Down
15 changes: 12 additions & 3 deletions src/components/Accounts/Details/Fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import { TransactionTypeBadge } from '~components/Transactions/TransactionCard'
import { generatePath, Link as RouterLink } from 'react-router-dom'
import { RoutePath } from '~constants'
import { ContentError, NoResultsError } from '~components/Layout/ContentError'
import { useOrganization } from '@vocdoni/react-providers'

const AccountFees = (org: { org: AccountData }) => {
interface AccountFeessProps {
feesCount: number
org: AccountData
}

const AccountFees = (org: AccountFeessProps) => {
return (
<PaginationProvider>
<AccountFeesTable {...org} />
</PaginationProvider>
)
}

const AccountFeesTable = ({ org }: { org: AccountData }) => {
const AccountFeesTable = ({ org, feesCount }: AccountFeessProps) => {
const { page } = usePagination()
const { formatDistance } = useDateFns()

Expand All @@ -28,13 +34,16 @@ const AccountFeesTable = ({ org }: { org: AccountData }) => {
accountId: org.address,
page,
},
options: {
enabled: feesCount > 0,
},
})

if (isLoading) {
return <LoadingCards />
}

if (data?.pagination.totalItems === 0) {
if (data?.pagination.totalItems === 0 || feesCount === 0) {
return <NoResultsError />
}

Expand Down
11 changes: 4 additions & 7 deletions src/components/Accounts/Details/Transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const FromToIcon = ({ isIncoming, ...rest }: { isIncoming: boolean } & IconProps
}

interface AccountTransfersProps {
txCount: number | undefined
txCount: number
org: AccountData
}

Expand All @@ -64,6 +64,7 @@ const AccountTransfers = (txProps: AccountTransfersProps) => {
const AccountTransfersTable = ({ txCount, org }: AccountTransfersProps) => {
const { page } = usePagination()
const { formatDistance } = useDateFns()
const { t } = useTranslation()

const { data, isLoading, isError, error } = useAccountTransfers({
address: org.address,
Expand All @@ -73,12 +74,8 @@ const AccountTransfersTable = ({ txCount, org }: AccountTransfersProps) => {
},
})

if (txCount && !(txCount > 0)) {
return (
<Text>
<Trans i18nKey={'account.transfers.no_transfers'}>No transfers yet!</Trans>
</Text>
)
if (txCount === 0) {
return <NoResultsError msg={t('account.transfers.no_transfers', { defaultValue: 'No transfers yet!' })} />
}

if (!txCount || isLoading) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Layout/ContentError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Trans, useTranslation } from 'react-i18next'

export const NoResultsError = ({ msg }: { msg?: string }) => {
const { t } = useTranslation()
return <Text>{msg ?? t('errors.no_results', { defaultValue: 'Looks like there are no results to show.' })}</Text>
return (
<Alert status='info'>
<AlertIcon />
{msg ?? t('errors.no_results', { defaultValue: 'Looks like there are nothing to show.' })}
selankon marked this conversation as resolved.
Show resolved Hide resolved
</Alert>
)
}

export type ContentErrorType = Error | undefined | null | string
Expand Down
18 changes: 17 additions & 1 deletion src/components/Process/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ElectionCardSkeleton = (rest: CardProps) => {

if (!election) return null
if (election instanceof InvalidElectionType) {
return <InvalidElection />
return <InvalidElectionCard election={election} {...rest} />
}

return (
Expand Down Expand Up @@ -68,3 +68,19 @@ const ElectionCardSkeleton = (rest: CardProps) => {
</LinkCard>
)
}

const InvalidElectionCard = ({ election, ...rest }: { election: InvalidElectionType } & CardProps) => {
return (
<LinkCard
direction={'row'}
alignItems='center'
pl={4}
to={generatePath(RoutePath.Process, { pid: election.id, tab: null })}
{...rest}
>
<CardBody>
<InvalidElection />
</CardBody>
</LinkCard>
)
}
13 changes: 4 additions & 9 deletions src/components/Process/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { FallbackHeaderImg, RoutePath } from '~constants'
import { useElectionKeys, useElectionVotesList } from '~queries/processes'
import { ucfirst } from '~utils/strings'
import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { NoResultsError } from '~components/Layout/ContentError'

const Detail = () => {
const { election } = useElection()
Expand Down Expand Up @@ -161,10 +162,7 @@ const Detail = () => {
{election.description?.default ? (
<ElectionDescription />
) : (
<Alert status='warning'>
<AlertIcon />
<Trans i18nKey={'process.no_description'}>No description set!</Trans>
</Alert>
<NoResultsError msg={t('process.no_description', { defaultValue: 'No description set!' })} />
)}
</TabPanel>
<TabPanel>
Expand Down Expand Up @@ -221,13 +219,10 @@ const ElectionKeys = ({ electionId }: { electionId: string }) => {
const EnvelopeExplorer = () => {
const { election: e } = useElection()
const election = e as PublishedElection
const { t } = useTranslation()

if (!election || election.voteCount === 0) {
return (
<Text>
<Trans i18nKey={'election.no_votes_yet'}>No votes yet!</Trans>
</Text>
)
return <NoResultsError msg={t('election.no_votes_yet', { defaultValue: 'No votes yet!' })} />
}

return (
Expand Down
7 changes: 2 additions & 5 deletions src/components/Transactions/TransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ const TransactionsListCards = ({
error: Error | null
height?: number
}) => {
const { t } = useTranslation()
if (!data || (data && data.transactions.length <= 0)) {
return (
<Text>
<Trans i18nKey={'blocks.no_txs_on_block'}>There are no transactions.</Trans>
</Text>
)
return <NoResultsError msg={t('blocks.no_txs_on_block', { defaultValue: 'There are no transactions' })} />
}

if (isLoading) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Transactions/TxDetails/SpecificTxDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SmallAccountCard } from '~components/Accounts/Card'
import { RoutePath } from '~constants'
import { b64ToHex } from '~utils/objects'
import { VotePackage } from '~components/Envelope/Detail'
import { VotePackageType } from '@vocdoni/chakra-components'

export const processIdGridItem = (processId: string, t: TFunction): GridItemProps => {
return {
Expand Down Expand Up @@ -60,12 +61,14 @@ const organizationIdGridItem = (orgId: string, t: TFunction): GridItemProps => {

const VoteTxDetails = ({ rawTx, votePackage, processId }: { rawTx: any } & VoteEnvelope) => {
const { t } = useTranslation()
let showVoteSense = false
if (votePackage) {
// Decode the vote package from base64
votePackage = atob(votePackage)
// And copy it alsow to rawTx
try {
rawTx['tx']['vote']['votePackage'] = JSON.parse(votePackage)
showVoteSense = true
} catch (e) {
// If vote package cannot be parsed as JSON, it may be encrypted
const msg = t('transactions.error_parsing_vote_package', { defaultValue: 'Vote package may be encrypted' })
Expand All @@ -85,7 +88,7 @@ const VoteTxDetails = ({ rawTx, votePackage, processId }: { rawTx: any } & VoteE
},
]
: []),
...(votePackage
...(showVoteSense
? [
{
label: t('transactions.vote_sense', { defaultValue: 'Vote sense' }),
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"errors": {
"content_error": "Sembla que el contingut al qual intentaves accedir ha generat un error.",
"no_results": "Sembla que no hi ha resultats per mostrar."
"no_results": "Sembla que no hi ha res a mostrar."
},
"featured": {
"a_cutting_edge_voting_protocol": "Un protocol de votació avançat",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"errors": {
"content_error": "Looks like the content you were accessing threw an error.",
"no_results": "Looks like there are no results to show."
"no_results": "Looks like there are nothing to show."
},
"featured": {
"a_cutting_edge_voting_protocol": "A cutting edge voting protocol",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"errors": {
"content_error": "Parece que el contenido al que accediste arrojó un error.",
"no_results": "Parece que no hay resultados para mostrar."
"no_results": "Parece que no hay nada para mostrar."
},
"featured": {
"a_cutting_edge_voting_protocol": "Un protocolo de votación de vanguardia",
Expand Down
Loading