Skip to content

Commit

Permalink
Home screen optimizations (#92)
Browse files Browse the repository at this point in the history
* Make getTransacitons compatible with neoscan data structure

* Add tests for format gas
  • Loading branch information
FredrikOseberg authored and slipo committed Apr 9, 2018
1 parent a19b33f commit 81debc5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
12 changes: 11 additions & 1 deletion __tests__/helpers/helpers.test.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')
})
1 change: 1 addition & 0 deletions src/app/components/AccountInfo/AccountInfo.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
display: flex;
justify-content: space-around;
color: #585858;
position: relative;
}

.accountInfoNeoAmount,
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Login extends Component {
errorMsg: '',
})

const { setAccount } = this.props
const { setAccount, history } = this.props

wallet
.decryptAsync(encryptedWif, passPhrase)
Expand All @@ -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 })
Expand Down
10 changes: 8 additions & 2 deletions src/app/components/TransactionList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TransactionCard
key={ transaction.txid }
transactionId={ transaction.txid }
neoSent={ transaction.neo_sent }
neoSent={ amounts.neo > 0 }
amounts={ amounts }
/>
)
Expand Down
23 changes: 13 additions & 10 deletions src/app/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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
}

0 comments on commit 81debc5

Please sign in to comment.