Skip to content

Commit

Permalink
feat(eth unconfirmed): use eth api v2 to determine latest pending eth tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Apr 1, 2020
1 parent 48e8591 commit eb96396
Showing 1 changed file with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../../utils/eth'
import { call, select } from 'redux-saga/effects'
import { eth } from '../../../signer'
import { EthTxType } from 'core/transactions/types'
import { FETCH_FEES_FAILURE } from '../model'
import {
identity,
Expand Down Expand Up @@ -105,38 +106,14 @@ export default ({ api }) => {
}
}

const calculateUnconfirmed = function * (type, address) {
let latestTxS =
type !== ADDRESS_TYPES.LOCKBOX
? S.kvStore.eth.getLatestTx
: S.kvStore.lockbox.getLatestTxEth
let latestTxTimestampS =
type !== ADDRESS_TYPES.LOCKBOX
? S.kvStore.eth.getLatestTxTimestamp
: S.kvStore.lockbox.getLatestTxTimestampEth

const latestTxR = yield select(latestTxS, address)
const latestTxTimestampR = yield select(latestTxTimestampS, address)
const latestTx = latestTxR.getOrElse(undefined)
const latestTxTimestamp = latestTxTimestampR.getOrElse(undefined)

if (latestTx) {
const ethOptionsR = yield select(S.walletOptions.getEthTxFuse)
const lastTxFuse = ethOptionsR.getOrElse(86400) * 1000
try {
const latestTxStatus = yield call(api.getEthTransaction, latestTx)
if (
!latestTxStatus.blockNumber &&
latestTxTimestamp + lastTxFuse > Date.now()
) {
return true
}
} catch (e) {
if (latestTxTimestamp + lastTxFuse > Date.now()) {
return true
}
}
}
const calculateUnconfirmed = function * (address: string) {
const data: {
transactions: Array<{ state: 'CONFIRMED' | 'PENDING' }>
} = yield call(api.getEthTransactionsV2, address, 0, 1)

if (data.transactions[0] && data.transactions[0].state === 'PENDING')
return true

return false
}

Expand Down Expand Up @@ -214,7 +191,7 @@ export default ({ api }) => {
address: account,
nonce
}
const unconfirmedTx = yield call(calculateUnconfirmed, type, account)
const unconfirmedTx = yield call(calculateUnconfirmed, account)

return makePayment(
mergeRight(p, { from, effectiveBalance, unconfirmedTx })
Expand Down

0 comments on commit eb96396

Please sign in to comment.