Skip to content

Commit

Permalink
fixes issue with parsing of transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
comountainclimber committed Feb 12, 2019
1 parent 8549804 commit 356c2db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
21 changes: 13 additions & 8 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 = 3
const MINIMUM_CONFIRMATIONS = 2
const INVALID_TX_ERROR_MESSAGE = 'Unknown transaction'

export const parseContractTransaction = async (
Expand All @@ -22,18 +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()
console.log({ transaction })
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
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 356c2db

Please sign in to comment.