Skip to content

Commit

Permalink
Fix formatNumber bug and accounts grid mobile sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Mar 30, 2024
1 parent f63f3ed commit ab8c3d2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/dashboard/insights.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,21 @@ const Insights = ({ setRoute }) => {
</div>
),
},
{ width: isMobile ? 110 : 200, field: 'average', type: 'number', valueFormatter: formatDecimal, headerName: 'Average', cellClassName: getColourClassForValue },
{ width: isMobile ? 65 : 150, field: 'transactions', type: 'number', valueFormatter: formatNumber, headerName: isMobile ? 'Tx' : 'Transactions' },
{
width: isMobile ? 110 : 200,
field: 'average',
type: 'number',
valueFormatter: formatDecimal,
headerName: 'Average',
cellClassName: getColourClassForValue,
},
{
width: isMobile ? 65 : 150,
field: 'transactions',
type: 'number',
valueFormatter: formatNumber,
headerName: isMobile ? 'Tx' : 'Transactions',
},
];

const handleDoubleClick = ({ row }) => {
Expand Down
36 changes: 25 additions & 11 deletions src/settings/accounts-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ const GridBox = styled.div`
margin-bottom: ${props => props.isMobile ? '.5rem' : '1rem' };
`;

const IssuerChip = styled(Chip)`
const ChipInternal = styled(Chip)`
border-radius: .5rem;
height: fit-content;
font-size: .875rem;
line-height: initial;
margin: .6rem 0;
padding: .4rem 0;
color: #${props => props.colour};
border-color: #${props => props.colour};
`;

const IssuerChip = ({ issuer }) => (
<ChipInternal
colour={issuer.colour}
label={issuer.name}
variant="outlined"
/>
);

const FxRoot = styled.sup`
font-size: .8rem;
position: relative;
Expand Down Expand Up @@ -72,26 +85,27 @@ const AccountsGrid = ({
renderCell: ({ value }) => <Chip sx={{ borderRadius: '.5rem' }} label={value} color={colors[value]} />
},
{
field: 'issuer',
field: 'issuerId',
headerName: 'Issuer',
valueGetter: (_, row) => getIssuer(row.issuerId),
renderCell: ({ value }) => <IssuerChip colour={value.colour} label={value.name} variant="outlined" />
renderCell: ({ value }) => <IssuerChip issuer={getIssuer(value)} />,
},
{
field: 'typeAndIssuer',
headerName: 'Type + Issuer',
valueGetter: (_, row) => ({ type: row.type, issuer: getIssuer(row.issuerId) }),
renderCell: ({ value }) => (
valueGetter: (_, row) => row.type + row.issuerId,
renderCell: ({ row }) => (
<div style={{ display: 'flex', gap: '.5rem' }}>
<Chip sx={{ borderRadius: '.5rem' }} label={value.type} color={colors[value.type]} />
<IssuerChip colour={value.issuer.colour} label={value.issuer.name} variant="outlined" />
<ChipInternal label={row.type} color={colors[row.type]} />
<IssuerChip issuer={getIssuer(row.issuerId)} />
</div>
),
width: 165,
},
{
field: 'name',
headerName: 'Name',
width: isMobile ? 0 : '150',
flex: isMobile ? 1 : 0,
renderCell: ({ row }) => (
<>
{row.name}
Expand All @@ -101,16 +115,16 @@ const AccountsGrid = ({
},
{
field: 'transactions',
headerName: 'Transactions',
headerName: isMobile ? 'Tx' : 'Transactions',
type: 'number',
width: '103',
width: isMobile ? 60 : 110,
valueGetter: (_, row) => row.transactions || 0,
sortable: false,
},
];

useEffect(() => {
const vColumns = isMobile ? { id: false, type: false, issuer: false } :
const vColumns = isMobile ? { id: false, type: false, issuerId: false } :
{ typeAndIssuer: false };
setVisibleColumns(vColumns);
}, [ isMobile ]);
Expand Down
2 changes: 1 addition & 1 deletion src/util/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export const formatDecimal = (value) => processFormatDecimal(value, 0, 2);
export const formatFx = (value) => formatDecimal(value, 1, 5);
export const formatDecimalAbs = (value) => formatDecimal(Math.abs(value), null);
export const formatDecimalRaw = (number) => formatDecimal(number, null);
export const formatNumber = (number) => formatDecimal(number, 0, 0);
export const formatNumber = (number) => processFormatDecimal(number, 0, 0);
export const formatDate = (value) => !value ? '' : dayjs.utc(value).format('YYYY-MM-DD');
export const formatMonth = (value) => !value ? '' : dayjs.utc(value).format('YYYY MMM');

0 comments on commit ab8c3d2

Please sign in to comment.