aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers/transactions.util.js
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-10-17 02:01:54 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-10-17 02:01:54 +0800
commit13820b6cc1801a420f39cdfecd7ccb5309dc597b (patch)
treec79832d7077ab03e0afe0c322cb32b204865d8b5 /ui/app/helpers/transactions.util.js
parenteeecee01540fbad50c4c463a3b1a54142a63f168 (diff)
parent07ab613d4c647e3fe554bc06eab8cfb833315a88 (diff)
downloadtangerine-wallet-browser-13820b6cc1801a420f39cdfecd7ccb5309dc597b.tar.gz
tangerine-wallet-browser-13820b6cc1801a420f39cdfecd7ccb5309dc597b.tar.zst
tangerine-wallet-browser-13820b6cc1801a420f39cdfecd7ccb5309dc597b.zip
fix conflicts
Diffstat (limited to 'ui/app/helpers/transactions.util.js')
-rw-r--r--ui/app/helpers/transactions.util.js49
1 files changed, 45 insertions, 4 deletions
diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js
index 54df54aa8..e50196196 100644
--- a/ui/app/helpers/transactions.util.js
+++ b/ui/app/helpers/transactions.util.js
@@ -14,17 +14,20 @@ import {
TRANSFER_FROM_ACTION_KEY,
SIGNATURE_REQUEST_KEY,
UNKNOWN_FUNCTION_KEY,
+ CANCEL_ATTEMPT_ACTION_KEY,
} from '../constants/transactions'
+import { addCurrencies } from '../conversion-util'
+
abiDecoder.addABI(abi)
-export function getTokenData (data = {}) {
+export function getTokenData (data = '') {
return abiDecoder.decodeMethod(data)
}
const registry = new MethodRegistry({ provider: global.ethereumProvider })
-export async function getMethodData (data = {}) {
+export async function getMethodData (data = '') {
const prefixedData = ethUtil.addHexPrefix(data)
const fourBytePrefix = prefixedData.slice(0, 10)
const sig = await registry.lookup(fourBytePrefix)
@@ -41,8 +44,18 @@ export function isConfirmDeployContract (txData = {}) {
return !txParams.to
}
+/**
+ * Returns the action of a transaction as a key to be passed into the translator.
+ * @param {Object} transaction - txData object
+ * @param {Object} methodData - Data returned from eth-method-registry
+ * @returns {string|undefined}
+ */
export async function getTransactionActionKey (transaction, methodData) {
- const { txParams: { data, to } = {}, msgParams } = transaction
+ const { txParams: { data, to } = {}, msgParams, type } = transaction
+
+ if (type === 'cancel') {
+ return CANCEL_ATTEMPT_ACTION_KEY
+ }
if (msgParams) {
return SIGNATURE_REQUEST_KEY
@@ -74,7 +87,7 @@ export async function getTransactionActionKey (transaction, methodData) {
case TOKEN_METHOD_TRANSFER_FROM:
return TRANSFER_FROM_ACTION_KEY
default:
- return name
+ return undefined
}
} else {
return SEND_ETHER_ACTION_KEY
@@ -103,3 +116,31 @@ export async function isSmartContractAddress (address) {
const code = await global.eth.getCode(address)
return code && code !== '0x'
}
+
+export function sumHexes (...args) {
+ const total = args.reduce((acc, base) => {
+ return addCurrencies(acc, base, {
+ toNumericBase: 'hex',
+ })
+ })
+
+ 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
+}