Skip to content

Commit

Permalink
Merge pull request #1801 from CityOfZion/feature/remove-fees-from-pen…
Browse files Browse the repository at this point in the history
…ding-tx

chore: fixes issues related to pending transactions UX
  • Loading branch information
comountainclimber committed Feb 21, 2019
2 parents 7f26b5b + 356c2db commit 4c88ddc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
2 changes: 2 additions & 0 deletions app/actions/dashboardActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import balancesActions from './balancesActions'
import claimsActions from './claimsActions'
import pricesActions from './pricesActions'
import priceHistoryActions from './priceHistoryActions'
import { getPendingTransactionInfo } from './pendingTransactionActions'

export const ID = 'dashboard'

Expand All @@ -13,4 +14,5 @@ export default createBatchActions(ID, {
claims: claimsActions,
prices: pricesActions,
priceHistory: priceHistoryActions,
getPendingTransactionInfo,
})
26 changes: 17 additions & 9 deletions app/actions/pendingTransactionActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { createActions } from 'spunky'
import Neon from '@cityofzion/neon-js'
import { isEmpty } from 'lodash-es'
import { isEmpty, cloneDeep } from 'lodash-es'

import { toBigNumber } from '../core/math'
import { getStorage, setStorage } from '../core/storage'
Expand All @@ -13,7 +13,7 @@ import {

export const ID = 'pendingTransactions'
const STORAGE_KEY = 'pendingTransactions'
const MINIMUM_CONFIRMATIONS = 10
const MINIMUM_CONFIRMATIONS = 2
const INVALID_TX_ERROR_MESSAGE = 'Unknown transaction'

export const parseContractTransaction = async (
Expand All @@ -22,17 +22,23 @@ export const parseContractTransaction = async (
): Promise<Array<ParsedPendingTransaction>> => {
const parsedData = []
// eslint-disable-next-line camelcase
const { confirmations, txid, net_fee, blocktime = 0 } = transaction
transaction.vout.pop()
for (const send of transaction.vout) {
const {
confirmations,
txid,
net_fee, // eslint-disable-line camelcase
blocktime = 0,
sendEntries,
} = transaction

for (const send of sendEntries) {
parsedData.push({
confirmations,
txid: txid.substring(2),
net_fee,
blocktime,
amount: toBigNumber(send.value).toString(),
amount: toBigNumber(send.amount).toString(),
to: send.address,
asset: await findAndReturnTokenInfo(send.asset, net),
asset: await findAndReturnTokenInfo('', net, send.symbol),
})
}
return parsedData
Expand Down Expand Up @@ -170,8 +176,10 @@ export const addPendingTransaction = createActions(
Array<ParsedPendingTransaction>,
> => {
const transactions = await getPendingTransactions()

if (Array.isArray(transactions[address])) {
if (
Array.isArray(transactions[address]) &&
!transactions[address].find(pendingTx => pendingTx.hash === tx.hash)
) {
transactions[address].push(tx)
} else {
transactions[address] = [tx]
Expand Down
28 changes: 16 additions & 12 deletions app/util/findAndReturnTokenInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ export const getImageBySymbol = (symbol: string) => imageMap[symbol]
export const findAndReturnTokenInfo = async (
scriptHash: string,
net: string,
symbol?: string,
): Promise<any> => {
const NEO = {
symbol: ASSETS.NEO,
image: getImageBySymbol(ASSETS.NEO),
}
const GAS = {
symbol: ASSETS.GAS,
image: getImageBySymbol(ASSETS.GAS),
}

if (symbol === ASSETS.NEO || scriptHash.includes(NEO_ID)) return NEO
if (symbol === ASSETS.GAS || scriptHash.includes(GAS_ID)) return GAS

const tokens = await getDefaultTokens()
// if token is found in our list return it
const token = tokens.find(token => token.scriptHash.includes(scriptHash))
if (token) return token
if (scriptHash.includes(NEO_ID)) {
return {
symbol: ASSETS.NEO,
image: getImageBySymbol(ASSETS.NEO),
}
}
if (scriptHash.includes(GAS_ID)) {
return {
symbol: ASSETS.GAS,
image: getImageBySymbol(ASSETS.GAS),
}
}

// if token is unknown to application query neoscan
const endpoint = await getRPCEndpoint(net)
const tokenInfo = await api.nep5.getToken(endpoint, scriptHash).catch(e => {
console.error(e)
Expand Down

0 comments on commit 4c88ddc

Please sign in to comment.