diff --git a/__tests__/helpers/helpers.test.js b/__tests__/helpers/helpers.test.js index 42b154a..481782d 100644 --- a/__tests__/helpers/helpers.test.js +++ b/__tests__/helpers/helpers.test.js @@ -1,4 +1,4 @@ -import { getBalance, getTransactions } from '../../src/app/utils/helpers' +import { getBalance, getTransactions, formatGas } from '../../src/app/utils/helpers' const account = { address: 'AbRWqwMFgf4P8zXZPdfNnWJ7aoEggKgnNf' } const network = 'TestNet' @@ -15,3 +15,13 @@ test('getTransactions gets the correct number of transactions', () => { expect(data.length).toBe(2) }) }) + +test('formatGas formats gas under 1 correctly', () => { + const formattedGas = formatGas([0, 1323242]) + expect(formattedGas).toBe('0.13232') +}) + +test('formatGas formats gas above 1 correctly', () => { + const formattedGas = formatGas([1, 1323242]) + expect(formattedGas).toBe('1.13232') +}) diff --git a/src/app/components/AccountInfo/AccountInfo.css b/src/app/components/AccountInfo/AccountInfo.css index a2584e3..b28ccef 100644 --- a/src/app/components/AccountInfo/AccountInfo.css +++ b/src/app/components/AccountInfo/AccountInfo.css @@ -45,6 +45,7 @@ display: flex; justify-content: space-around; color: #585858; + position: relative; } .accountInfoNeoAmount, diff --git a/src/app/components/Login/Login.js b/src/app/components/Login/Login.js index cdd38b3..2cd9f60 100644 --- a/src/app/components/Login/Login.js +++ b/src/app/components/Login/Login.js @@ -48,7 +48,7 @@ export class Login extends Component { errorMsg: '', }) - const { setAccount } = this.props + const { setAccount, history } = this.props wallet .decryptAsync(encryptedWif, passPhrase) @@ -58,6 +58,7 @@ export class Login extends Component { this.setState({ loading: false }) reset() setAccount(wif, account.address) + history.push('/home') }) .catch(e => { this.setState({ loading: false, errorMsg: e.message }) diff --git a/src/app/components/TransactionList/index.js b/src/app/components/TransactionList/index.js index e7b3057..b32f267 100644 --- a/src/app/components/TransactionList/index.js +++ b/src/app/components/TransactionList/index.js @@ -4,16 +4,22 @@ import PropTypes from 'prop-types' import TransactionCard from '../TransactionCard' import SecondaryButton from '../common/buttons/SecondaryButton' import FlashMessage from '../FlashMessage' + +import { formatGas } from '../../utils/helpers' + import style from './TransactionList.css' const TransactionList = ({ transactions, transactionHistoryError, getTransactions }) => { const transactionCards = transactions.map(transaction => { - const amounts = { neo: transaction.NEO, gas: transaction.GAS } + const gasArray = transaction.change.GAS.c + const gas = formatGas(gasArray) + const amounts = { neo: transaction.change.NEO.c, gas } + return ( 0 } amounts={ amounts } /> ) diff --git a/src/app/utils/helpers.js b/src/app/utils/helpers.js index d392c18..ce578f2 100644 --- a/src/app/utils/helpers.js +++ b/src/app/utils/helpers.js @@ -22,17 +22,8 @@ export const getBalance = (network, account) => { Neon.get .balance(network, account.address) .then(results => { - let gas const gasAmount = results.assets['GAS'].balance.c - - if (gasAmount.length === 1) { - gas = results.assets['GAS'].balance.c[0] / 100000000000000 - } else { - gas = - results.assets['GAS'].balance.c[1] > 0 - ? Number(results.assets['GAS'].balance.c.join('.')).toFixed(5) - : Number(results.assets['GAS'].balance.c.join('.')) - } + const gas = formatGas(gasAmount) const amounts = { neo: Number(results.assets['NEO'].balance.c[0]), @@ -53,3 +44,15 @@ export const getTransactions = (network, account) => { .catch(error => reject(error)) }) } + +export const formatGas = gasArray => { + let gas + + if (gasArray.length === 1) { + gas = gasArray[0] / 100000000000000 + } else { + gas = gasArray[1] > 0 ? Number(gasArray.join('.')).toFixed(5) : Number(gasArray.join('.')) + } + + return gas +}