decentraland / decentraland-eth

DEPRECATED - Ethereum common helpers for Decentraland
https://decentraland.github.io/decentraland-eth/
Apache License 2.0
15 stars 9 forks source link

fix: check for null tx #19

Closed cazala closed 6 years ago

cazala commented 6 years ago

The following code throws many times:

const tx = await getTransaction(txId)

if (!isPending(tx) && tx.recepeit) {

Because when we get a transaction like this:

const tx = await getTransaction(txId)

The value of tx can be null because:

export async function getTransaction(txId: string): Promise<{ recepeit: TxReceipt } & TxStatus> {
  const [tx, recepeit] = await Promise.all([
    eth.wallet.getTransactionStatus(txId),
    eth.wallet.getTransactionReceipt(txId)
  ])

  return tx ? { ...tx, recepeit } : null
}

And then when we do:

!isPending(tx) && tx.recepeit

isPending returns null:

export function isPending(tx) {
  return tx && (tx.blockNumber === null || tx.status === TRANSACTION_STATUS.pending)
}

Then !isPending(tx) evaluates to true and the following expression evaluated is tx.recepeit which throws Cannot read property 'recepeit' of null šŸ’„šŸ’„šŸ’„

This PR fixes that.

Also, is it okay that the property is called recepeit and not receipt ? I searched it and it's like that all over the library...