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

Add data size to the details of a single transaction - Closes #2514 #2686

Merged
merged 12 commits into from
Dec 6, 2019
1 change: 1 addition & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
"Signature": "Signature",
"Signed Message": "Signed Message",
"Simply scan the QR code using the Lisk Mobile app or any other QR code reader": "Simply scan the QR code using the Lisk Mobile app or any other QR code reader",
"Size": "Size",
"Something went wrong with the registration. Please try again below!": "Something went wrong with the registration. Please try again below!",
"Sorry, this action isn’t possible": "Sorry, this action isn’t possible",
"Sorry, we couldn’t find the page you were looking for. We suggest that you return to the main dashboard.": "Sorry, we couldn’t find the page you were looking for. We suggest that you return to the main dashboard.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,38 @@
}
}

.message {
& .detailsWrapper {
flex-grow: 1;
width: 50%;
box-sizing: border-box;

&:first-child {
padding-right: 64px;
position: relative;

&::after {
background-color: var(--color-platinum);
content: '';
height: calc(100% - 13px);
position: absolute;
right: 0;
width: 1px;
top: 8px;
}
}

&:last-child {
padding-left: 64px;
}
}
}

.detailsWrapper {
flex-direction: column;
display: 100%;
text-align: left;
flex-grow: 1;

& .accountInfo {
display: flex;
Expand Down Expand Up @@ -64,11 +92,10 @@
}
}

& .message {
& .value {
@mixin contentLargest;

color: var(--color-maastricht-blue);
text-align: left;
}

& .votesContainer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { withTranslation } from 'react-i18next';
import React from 'react';
import { sizeOfString } from '../../../../../utils/helpers';
import AccountInfo from './accountInfo';
import BoxRow from '../../../../toolbox/box/row';
import TransactionTypeFigure from '../../../wallet/transactions/typeFigure/TransactionTypeFigure';
Expand Down Expand Up @@ -75,12 +76,18 @@ class TransactionDetailView extends React.Component {
}
{children}
{ transaction.type === transactionTypes.send
&& (transaction.asset && transaction.asset.data) ? (
<BoxRow>
<div className={styles.detailsWrapper}>
? (
<BoxRow className={styles.message}>
<div className={`${styles.detailsWrapper}`}>
<span className={styles.label}>{t('Message')}</span>
<div className={`${styles.message} tx-reference`}>
{transaction.asset.data}
<div className={`${styles.value} tx-reference`}>
{transaction.asset && transaction.asset.data ? transaction.asset.data : '-'}
</div>
</div>
<div className={`${styles.detailsWrapper}`}>
<span className={styles.label}>{t('Size')}</span>
<div className={`${styles.value} tx-size`}>
{`${sizeOfString(transaction.asset.data)} bytes`}
</div>
</div>
</BoxRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ describe('Transaction Detail View', () => {
expect(wrapper).toContainMatchingElements(2, '.accountInfo');
expect(wrapper.find('.accountInfo .sender-address').text()).toBe(transaction.senderId);
expect(wrapper.find('.accountInfo .receiver-address').text()).toBe(transaction.recipientId);
expect(wrapper).toContainExactlyOneMatchingElement('.message');
});

it('Should render transfer transaction without message', () => {
props.transaction.asset = {};
wrapper = mount(<TransactionDetailView {...props} />);
expect(wrapper).not.toContainMatchingElement('.message');
expect(wrapper).toContainExactlyOneMatchingElement('.tx-reference');
});
});

Expand Down
3 changes: 0 additions & 3 deletions src/components/screens/register/confirmPassphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const ConfirmPassphrase = ({
t, passphrase, prevStep, nextStep,
}) => (
<React.Fragment>
<span className={`${registerStyles.stepsLabel}`}>
{t('Step {{current}} / {{total}}', { current: 3, total: 4 })}
</span>
<div className={`${registerStyles.titleHolder} ${grid['col-xs-10']}`}>
<h1>
{t('Confirm your passphrase')}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ export const flattenArray = arr =>
(Array.isArray(item)
? [...acc, ...flattenArray(item)]
: [...acc, item]), []).filter(item => !!item);

/**
* Returns the size of a given string in bytes
* If the passed parameter is not a string, it returns 0
*
* @param {string} str - a random string
* @returns {number} - string size for strings, 0 for others
*/
export const sizeOfString = (str) => {
if (typeof str === 'string') return str.length * 2;
reyraa marked this conversation as resolved.
Show resolved Hide resolved
return 0;
};
10 changes: 10 additions & 0 deletions src/utils/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
removeUndefinedKeys,
isEmpty,
filterObjectPropsWithValue,
sizeOfString,
} from './helpers';


Expand Down Expand Up @@ -62,4 +63,13 @@ describe('helpers', () => {
}, 'unvotes')).toEqual(['genesis_15', 'genesis_16']);
});
});
describe('sizeOfString', () => {
it('should calculate the size of a string', () => {
expect(sizeOfString('random string')).toEqual(26);
});

it('should calculate the size of null', () => {
expect(sizeOfString()).toEqual(0);
});
});
});