Skip to content

Commit

Permalink
Fixed formatting tx id (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Vilensky authored Mar 25, 2020
1 parent b960d46 commit 91b5d67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/components/transactions/TransactionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { updateTransaction } from '/redux/wallet/actions';
import { chevronLeftBlack, chevronRightBlack, addContact } from '/assets/images';
import styled from 'styled-components';
import { Button } from '/basicComponents';
import { getAbbreviatedText, getFormattedTimestamp, getAddress, formatSmidge } from '/infra/utils';
import { getAbbreviatedText, formatTxId, getFormattedTimestamp, getAddress, formatSmidge } from '/infra/utils';
import { smColors } from '/vars';
import TX_STATUSES from '/vars/enums';
import type { Tx, Action } from '/types';
Expand Down Expand Up @@ -184,7 +184,7 @@ class TransactionRow extends Component<Props, State> {
{txId === 'reward' ? (
<DarkGrayText>SMESHING REWARD</DarkGrayText>
) : (
[nickname && <DarkGrayText key="nickname">{nickname.toUpperCase()}</DarkGrayText>, <Text key={txId}>{getAbbreviatedText(txId, true, 10)}</Text>]
[nickname && <DarkGrayText key="nickname">{nickname.toUpperCase()}</DarkGrayText>, <Text key={txId}>{formatTxId(txId)}</Text>]
)}
</HeaderSection>
<HeaderSection>
Expand Down Expand Up @@ -250,7 +250,7 @@ class TransactionRow extends Component<Props, State> {
<BlackText>TRANSACTION ID</BlackText>
<Dots>............</Dots>
<BoldText color={smColors.realBlack} onClick={() => this.copyAddress({ id: txId })}>
{getAbbreviatedText(txId)}
{formatTxId(txId)}
</BoldText>
</TextRow>
<TextRow>
Expand Down
16 changes: 15 additions & 1 deletion app/infra/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const createError = (message, func) => ({
const getAbbreviatedText = (address: string, addPrefix: boolean = true, tailSize: number = 4) =>
`${addPrefix && address.indexOf('0x') === -1 ? '0x' : ''}${address.substring(0, tailSize)}...${address.substring(address.length - tailSize, address.length)}`;

const formatTxId = (id) => id && id.substring(0, 6);

const formatNumber = (num) => num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');

// Internal helper - returns the value and the unit of a smidge coin amount.
Expand Down Expand Up @@ -159,4 +161,16 @@ const getFormattedTimestamp = (timestamp: string) => {

const getAddress = (key: string) => key.substring(24);

export { testGetValueAndUnit, formatSmidge, fromHexString, toHexString, createError, getAbbreviatedText, formatNumber, asyncForEach, getFormattedTimestamp, getAddress };
export {
testGetValueAndUnit,
formatSmidge,
fromHexString,
toHexString,
createError,
getAbbreviatedText,
formatNumber,
asyncForEach,
getFormattedTimestamp,
getAddress,
formatTxId
};

0 comments on commit 91b5d67

Please sign in to comment.