Skip to content

Commit

Permalink
Merge pull request #338 from pshenmic/feat/transaction-page-data
Browse files Browse the repository at this point in the history
Improve transaction page
  • Loading branch information
pshenmic authored Dec 26, 2024
2 parents 26835f2 + 1bfd5d6 commit 531917c
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 67 deletions.
35 changes: 33 additions & 2 deletions packages/frontend/src/app/transaction/[hash]/TransactionData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StateTransitionEnum } from '../../../enums/state.transition.type'
import { ValueCard } from '../../../components/cards'
import { Identifier, InfoLine, CreditsBlock } from '../../../components/data'
import { Identifier, InfoLine, CreditsBlock, VoteChoice } from '../../../components/data'
import { TransitionCard, PublicKeyCard } from '../../../components/transactions'

function TransactionData ({ data, type, loading, rate }) {
Expand All @@ -14,7 +14,7 @@ function TransactionData ({ data, type, loading, rate }) {
value={(
<ValueCard>
<Identifier copyButton={true} ellipsis={true} styles={['highlight-both']}>
{data?.proTxHash}
{data?.proTxHash}
</Identifier>
</ValueCard>
)}
Expand Down Expand Up @@ -47,6 +47,37 @@ function TransactionData ({ data, type, loading, rate }) {
loading={loading}
error={!data?.ownerId}
/>

<InfoLine
className={'TransactionPage__InfoLine'}
title={'Choice'}
value={<VoteChoice choiceStr={data?.choice}/>}
loading={loading}
error={!data?.choice}
/>

<InfoLine
className={'TransactionPage__InfoLine'}
title={'Document Type'}
value={(
<ValueCard className={'TransactionPage__DocumentType'}>
{data?.documentTypeName}
</ValueCard>
)}
loading={loading}
error={!data?.documentTypeName}
/>
<InfoLine
className={'TransactionPage__InfoLine'}
title={'Index Name'}
value={(
<ValueCard className={'TransactionPage__IndexName'}>
{data?.indexName}
</ValueCard>
)}
loading={loading}
error={!data?.indexName}
/>
</>)
}

Expand Down
17 changes: 2 additions & 15 deletions packages/frontend/src/app/transaction/[hash]/TransactionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { useState, useEffect, useCallback } from 'react'
import { fetchHandlerSuccess, fetchHandlerError } from '../../../util'
import { CreditsBlock, InfoLine, DateBlock, Identifier } from '../../../components/data'
import TransactionData from './TransactionData'
import { CheckCircleIcon, WarningTwoIcon } from '@chakra-ui/icons'
import { ValueContainer, PageDataContainer } from '../../../components/ui/containers'
import { ValueCard } from '../../../components/cards'
import { HorisontalSeparator } from '../../../components/ui/separators'
import { CopyButton } from '../../../components/ui/Buttons'
import { Badge } from '@chakra-ui/react'
import { TypeBadge, FeeMultiplier } from '../../../components/transactions'
import { TypeBadge, FeeMultiplier, TransactionStatusBadge } from '../../../components/transactions'
import { ErrorMessageBlock } from '../../../components/Errors'
import { networks } from '../../../constants/networks'
import { useBreadcrumbs } from '../../../contexts/BreadcrumbsContext'
Expand Down Expand Up @@ -57,10 +55,6 @@ function Transaction ({ hash }) {

useEffect(fetchData, [hash, decodeTx])

const StatusIcon = transaction.data?.status === 'SUCCESS'
? <CheckCircleIcon color={'green.default'} mr={'5px'}/>
: <WarningTwoIcon color={'red.default'} mr={'5px'}/>

return (
<PageDataContainer
className={'TransactionPage'}
Expand Down Expand Up @@ -126,14 +120,7 @@ function Transaction ({ hash }) {
title={'Status'}
value={(
<div className={'TransactionPage__StatusContainer'}>
<Badge
className={'TransactionPage__StatusBadge'}
lineHeight={'20px'}
colorScheme={transaction.data?.status === 'SUCCESS' ? 'green' : 'red'}
>
{StatusIcon}
{transaction.data?.status}
</Badge>
<TransactionStatusBadge status={transaction.data?.status} />
{transaction.data?.error &&
<ValueContainer className={'TransactionPage__ErrorContainer'}>
{transaction.data.error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@

&__RawTransaction {
align-items: flex-start;
max-width: 510px;
overflow-wrap: break-word;
word-break: break-word;

Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/components/cards/ValueCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const Wrapper = (props) => {
export default function ValueCard ({ link, loading, colorScheme = 'default', size = 'default', children, className }) {
const colorClasses = {
default: '',
transparent: 'ValueCard--BgTransparent'
transparent: 'ValueCard--BgTransparent',
green: 'ValueCard--Green'
}

const sizeClasses = {
Expand Down
22 changes: 22 additions & 0 deletions packages/frontend/src/components/cards/ValueCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@
background: transparent;
}

&--Green {
color: var(--chakra-colors-green-default);
background: rgba(var(--chakra-colors-green-default-rgb), .2);
border-color: rgba(var(--chakra-colors-green-default-rgb), 0.4);

.CopyButton {
svg {
color: rgba(255, 255, 255, .85);
}

&:hover {
svg {
color: #fff;
}
}
}

&.ValueCard--Clickable:hover {
background: rgba(var(--chakra-colors-green-default-rgb), .3);
}
}

&--Clickable {
@media (hover: hover) and (pointer: fine) {
&:hover {
Expand Down
32 changes: 32 additions & 0 deletions packages/frontend/src/components/data/PrefundedBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RateTooltip } from '../ui/Tooltips'
import { ValueCard } from '../cards'
import { ValueContainer } from '../ui/containers'
import { Flex } from '@chakra-ui/react'
import './PrefundedBalance.scss'

function PrefundedBalance ({ prefundedBalance, rate }) {
const elements = []

for (const [title, value] of Object.entries(prefundedBalance)) {
elements.push(
<ValueCard className={'PrefundedBalance'}>
<ValueContainer className={'PrefundedBalance__Title'}>
{title}
</ValueContainer>
<ValueContainer className={'PrefundedBalance__Value'} colorScheme={'green'}>
<RateTooltip credits={Number(value)} rate={rate?.data}>
<span>{value} Credits</span>
</RateTooltip>
</ValueContainer>
</ValueCard>
)
}

return elements?.length > 1
? <Flex gap={'8px'} flexDirection={'column'}>
{elements.map((element, i) => <div key={i}>{element}</div>)}
</Flex>
: elements[0]
}

export default PrefundedBalance
11 changes: 11 additions & 0 deletions packages/frontend/src/components/data/PrefundedBalance.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PrefundedBalance {
max-width: max-content;
display: flex;
flex-wrap: wrap;
gap: 8px;

&__Title, &__Value {
padding: 3px 10px;
border-radius: 4px;
}
}
52 changes: 52 additions & 0 deletions packages/frontend/src/components/data/VoteChoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import ValueContainer from '../ui/containers/ValueContainer'
import Identifier from './Identifier'
import { ValueCard } from '../cards'
import './VoteChoice.scss'

function transformTypeString (input) {
if (typeof input !== 'string') return null
return input?.trim()?.replace(/ /g, '_')?.toUpperCase()
}

function VoteChoice ({ choiceStr }) {
if (typeof choiceStr !== 'string') return 'n/a'
const [choice, parameter] = choiceStr.split(/[()]/)
const type = transformTypeString(choice)
const colorScheme = {
TOWARDSIDENTITY: 'green',
LOCK: 'red',
ABSTAIN: 'orange'
}

if (parameter) {
return (
<ValueContainer
className={'VoteChoice VoteChoice--TowardsIdentity'}
colorScheme={colorScheme?.[type] || 'grey'}
>
<span>{choice}:</span>
<ValueCard
link={`/identity/${parameter}`}
className={'VoteChoice__Parameter'}
colorScheme={colorScheme?.[type] || 'grey'}
>
<Identifier avatar={true} copyButton={true} ellipsis={true} styles={['highlight-both']}>
{parameter}
</Identifier>
</ValueCard>
</ValueContainer>
)
}

return (
<ValueContainer
className={'VoteChoice'}
colorScheme={colorScheme?.[type] || 'grey'}
size={'sm'}
>
{choice}
</ValueContainer>
)
}

export default VoteChoice
24 changes: 24 additions & 0 deletions packages/frontend/src/components/data/VoteChoice.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.VoteChoice {
max-width: max-content;
padding: 0.375rem 0.75rem;

&--TowardsIdentity {
.ValueContainer__Value {
display: flex;
align-items: center;
gap: 8px;
}
}

&--TowardsIdentity & {
&__Parameter {
background: rgba(var(--chakra-colors-green-default-rgb), .1);
}
}

&__Parameter {
max-width: 100%;
overflow: hidden;
padding: 0.125rem 0.625rem;
}
}
6 changes: 5 additions & 1 deletion packages/frontend/src/components/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import IpAddress from './IpAddress'
import InfoLine from './InfoLine'
import Alias from './Alias'
import AliasesList from './AliasesList'
import VoteChoice from './VoteChoice'
import PrefundedBalance from './PrefundedBalance'

export {
Identifier,
Expand All @@ -17,5 +19,7 @@ export {
IpAddress,
InfoLine,
Alias,
AliasesList
AliasesList,
VoteChoice,
PrefundedBalance
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@use '../../styles/mixins.scss';
@use './variables' as txs;
@import '../../styles/variables.scss';

.PublicKeyCard {
padding: 40px;
@include txs.CardPaddings(padding);

&__InfoLine {
justify-content: flex-start;
Expand All @@ -23,8 +24,6 @@
}

@media screen and (max-width: $breakpoint-md) {
padding: 32px;

&__InfoLine {
.InfoLine {
.InfoLine__Value {
Expand All @@ -35,8 +34,6 @@
}

@media screen and (max-width: $breakpoint-sm) {
padding: 16px;

&__InfoLine {
flex-wrap: wrap;
justify-content: space-between;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Badge } from '@chakra-ui/react'
import { ErrorCircleIcon, CheckmarkIcon } from '../ui/icons'
import './TransactionStatusBadge.scss'

function TransactionStatusBadge ({ status }) {
const StatusIcon = status === 'SUCCESS'
? <CheckmarkIcon w={'12px'} h={'12px'} mr={'5px'}/>
: <ErrorCircleIcon w={'12px'} h={'12px'} mr={'5px'}/>

return (
<Badge
className={'TransactionStatusBadge'}
lineHeight={'20px'}
colorScheme={status === 'SUCCESS' ? 'green' : 'red'}
>
{StatusIcon}
{status}
</Badge>
)
}

export default TransactionStatusBadge
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@use '../../styles/mixins.scss';
@import '../../styles/variables.scss';

.TransactionStatusBadge {
padding: 0 12px 0 6px !important;
}
Loading

0 comments on commit 531917c

Please sign in to comment.