aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-10-21 11:48:10 +0800
committerGitHub <noreply@github.com>2018-10-21 11:48:10 +0800
commit3b46478024f87bd237b507e5fb18068febf02de9 (patch)
tree1b70c2e7f431e7e3eb638c7630a2d220fa3dd030 /ui/app/helpers
parent600f755dbf8d4cfdc152e3d521b537ee9a046a35 (diff)
parentba3617b685b9dcd8a62e0009ee2015c5997fead3 (diff)
downloadtangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.gz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.zst
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.zip
Merge branch 'develop' into develop
Diffstat (limited to 'ui/app/helpers')
-rw-r--r--ui/app/helpers/conversions.util.js19
-rw-r--r--ui/app/helpers/tests/transactions.util.test.js35
-rw-r--r--ui/app/helpers/transactions.util.js18
3 files changed, 72 insertions, 0 deletions
diff --git a/ui/app/helpers/conversions.util.js b/ui/app/helpers/conversions.util.js
index 20ef9e35b..777537e1e 100644
--- a/ui/app/helpers/conversions.util.js
+++ b/ui/app/helpers/conversions.util.js
@@ -61,3 +61,22 @@ export function getValueFromWeiHex ({
conversionRate,
})
}
+
+export function getWeiHexFromDecimalValue ({
+ value,
+ fromCurrency,
+ conversionRate,
+ fromDenomination,
+ invertConversionRate,
+}) {
+ return conversionUtil(value, {
+ fromNumericBase: 'dec',
+ toNumericBase: 'hex',
+ toCurrency: ETH,
+ fromCurrency,
+ conversionRate,
+ invertConversionRate,
+ fromDenomination,
+ toDenomination: WEI,
+ })
+}
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 b2c617384..9be77e14f 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
+}