diff options
author | Alexander Tseung <alextsg@users.noreply.github.com> | 2018-10-16 06:00:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 06:00:47 +0800 |
commit | c821a8354c8eba05885ca219f39aedafbd4f8052 (patch) | |
tree | 880b60c46a0c3f0873a58f16077623211140ac0e /ui/app/helpers | |
parent | 61dec4ea464607d32a5727bdf343a7d8a9af66fc (diff) | |
download | tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar.gz tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar.bz2 tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar.lz tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar.xz tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.tar.zst tangerine-wallet-browser-c821a8354c8eba05885ca219f39aedafbd4f8052.zip |
Add txReceipt data to transaction details (#5513)
Diffstat (limited to 'ui/app/helpers')
-rw-r--r-- | ui/app/helpers/tests/transactions.util.test.js | 35 | ||||
-rw-r--r-- | ui/app/helpers/transactions.util.js | 18 |
2 files changed, 53 insertions, 0 deletions
diff --git a/ui/app/helpers/tests/transactions.util.test.js b/ui/app/helpers/tests/transactions.util.test.js index 103a84a8c..838522e35 100644 --- a/ui/app/helpers/tests/transactions.util.test.js +++ b/ui/app/helpers/tests/transactions.util.test.js @@ -19,4 +19,39 @@ describe('Transactions utils', () => { assert.doesNotThrow(() => utils.getTokenData()) }) }) + + describe('getStatusKey', () => { + it('should return the correct status', () => { + const tests = [ + { + transaction: { + status: 'confirmed', + txReceipt: { + status: '0x0', + }, + }, + expected: 'failed', + }, + { + transaction: { + status: 'confirmed', + txReceipt: { + status: '0x1', + }, + }, + expected: 'confirmed', + }, + { + transaction: { + status: 'pending', + }, + expected: 'pending', + }, + ] + + tests.forEach(({ transaction, expected }) => { + assert.equal(utils.getStatusKey(transaction), expected) + }) + }) + }) }) diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index f7d249e63..e50196196 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -126,3 +126,21 @@ export function sumHexes (...args) { return ethUtil.addHexPrefix(total) } + +/** + * Returns a status key for a transaction. Requires parsing the txMeta.txReceipt on top of + * txMeta.status because txMeta.status does not reflect on-chain errors. + * @param {Object} transaction - The txMeta object of a transaction. + * @param {Object} transaction.txReceipt - The transaction receipt. + * @returns {string} + */ +export function getStatusKey (transaction) { + const { txReceipt: { status } = {} } = transaction + + // There was an on-chain failure + if (status === '0x0') { + return 'failed' + } + + return transaction.status +} |