From 5ee40675b9f986a9ff2e5d15a271d7de2145d0e9 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Mon, 30 Jul 2018 22:03:20 -0700 Subject: Refactor transactions list views. Add redesign components --- ui/app/helpers/transactions.util.js | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ui/app/helpers/transactions.util.js (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js new file mode 100644 index 000000000..04cef150f --- /dev/null +++ b/ui/app/helpers/transactions.util.js @@ -0,0 +1,57 @@ +import ethUtil from 'ethereumjs-util' +import MethodRegistry from 'eth-method-registry' +const registry = new MethodRegistry({ provider: global.ethereumProvider }) + +import { + TOKEN_METHOD_TRANSFER, + TOKEN_METHOD_APPROVE, + TOKEN_METHOD_TRANSFER_FROM, + SEND_ETHER_ACTION_KEY, + DEPLOY_CONTRACT_ACTION_KEY, + APPROVE_ACTION_KEY, + SEND_TOKEN_ACTION_KEY, + TRANSFER_FROM_ACTION_KEY, +} from '../constants/transactions' + +export function isConfirmDeployContract (txData = {}) { + const { txParams = {} } = txData + return !txParams.to +} + +export function getTransactionActionKey (transaction, methodData) { + const { txParams: { data } = {} } = transaction + + if (isConfirmDeployContract(transaction)) { + return DEPLOY_CONTRACT_ACTION_KEY + } + + if (data) { + const { name } = methodData + const methodName = name && name.toLowerCase() + + switch (methodName) { + case TOKEN_METHOD_TRANSFER: + return SEND_TOKEN_ACTION_KEY + case TOKEN_METHOD_APPROVE: + return APPROVE_ACTION_KEY + case TOKEN_METHOD_TRANSFER_FROM: + return TRANSFER_FROM_ACTION_KEY + default: + return name + } + } else { + return SEND_ETHER_ACTION_KEY + } +} + +export async function getMethodData (data = {}) { + const prefixedData = ethUtil.addHexPrefix(data) + const fourBytePrefix = prefixedData.slice(0, 10) + const sig = await registry.lookup(fourBytePrefix) + const parsedResult = registry.parse(sig) + + return { + name: parsedResult.name, + params: parsedResult.args, + } +} -- cgit v1.2.3 From 5ddd9b55be0d8bd778822b4b401cbd22a7b57c54 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Thu, 2 Aug 2018 20:20:15 -0700 Subject: Add retry button to TransactionListItem --- ui/app/helpers/transactions.util.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 04cef150f..68e935702 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -2,6 +2,8 @@ import ethUtil from 'ethereumjs-util' import MethodRegistry from 'eth-method-registry' const registry = new MethodRegistry({ provider: global.ethereumProvider }) +import { hexToDecimal } from './conversions.util' + import { TOKEN_METHOD_TRANSFER, TOKEN_METHOD_APPROVE, @@ -55,3 +57,22 @@ export async function getMethodData (data = {}) { params: parsedResult.args, } } + +export function getLatestSubmittedTxWithEarliestNonce (transactions = []) { + if (!transactions.length) { + return {} + } + + return transactions.reduce((acc, current) => { + const accNonce = hexToDecimal(acc.nonce) + const currentNonce = hexToDecimal(current.nonce) + + if (currentNonce < accNonce) { + return current + } else if (currentNonce === accNonce) { + return current.submittedTime > acc.submittedTime ? current : acc + } else { + return acc + } + }) +} -- cgit v1.2.3 From 33a94332e48b280fcf4c9fb23aa4d349eaa8a54d Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Sun, 5 Aug 2018 22:25:58 -0700 Subject: Show token amounts in TransactionListItem for token transfers --- ui/app/helpers/transactions.util.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 68e935702..89d2649c9 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -1,7 +1,7 @@ import ethUtil from 'ethereumjs-util' import MethodRegistry from 'eth-method-registry' -const registry = new MethodRegistry({ provider: global.ethereumProvider }) - +import abi from 'human-standard-token-abi' +import abiDecoder from 'abi-decoder' import { hexToDecimal } from './conversions.util' import { @@ -15,6 +15,26 @@ import { TRANSFER_FROM_ACTION_KEY, } from '../constants/transactions' +abiDecoder.addABI(abi) + +export function getTokenData (data = {}) { + return abiDecoder.decodeMethod(data) +} + +const registry = new MethodRegistry({ provider: global.ethereumProvider }) + +export async function getMethodData (data = {}) { + const prefixedData = ethUtil.addHexPrefix(data) + const fourBytePrefix = prefixedData.slice(0, 10) + const sig = await registry.lookup(fourBytePrefix) + const parsedResult = registry.parse(sig) + + return { + name: parsedResult.name, + params: parsedResult.args, + } +} + export function isConfirmDeployContract (txData = {}) { const { txParams = {} } = txData return !txParams.to @@ -46,18 +66,6 @@ export function getTransactionActionKey (transaction, methodData) { } } -export async function getMethodData (data = {}) { - const prefixedData = ethUtil.addHexPrefix(data) - const fourBytePrefix = prefixedData.slice(0, 10) - const sig = await registry.lookup(fourBytePrefix) - const parsedResult = registry.parse(sig) - - return { - name: parsedResult.name, - params: parsedResult.args, - } -} - export function getLatestSubmittedTxWithEarliestNonce (transactions = []) { if (!transactions.length) { return {} -- cgit v1.2.3 From 9adf0c4b60c863a820af7b20ff66a8b29f7bdbe7 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Mon, 6 Aug 2018 22:39:54 -0700 Subject: Fix integration tests --- ui/app/helpers/transactions.util.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 89d2649c9..8ded31bca 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -13,6 +13,7 @@ import { APPROVE_ACTION_KEY, SEND_TOKEN_ACTION_KEY, TRANSFER_FROM_ACTION_KEY, + SIGNATURE_REQUEST_KEY, } from '../constants/transactions' abiDecoder.addABI(abi) @@ -41,7 +42,11 @@ export function isConfirmDeployContract (txData = {}) { } export function getTransactionActionKey (transaction, methodData) { - const { txParams: { data } = {} } = transaction + const { txParams: { data } = {}, msgParams } = transaction + + if (msgParams) { + return SIGNATURE_REQUEST_KEY + } if (isConfirmDeployContract(transaction)) { return DEPLOY_CONTRACT_ACTION_KEY -- cgit v1.2.3 From 5dcd8ceb7bbaef33fef5588feceac17577679e74 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Tue, 7 Aug 2018 01:57:46 -0700 Subject: Fix e2e tests --- ui/app/helpers/transactions.util.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 8ded31bca..e890a0852 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -14,6 +14,7 @@ import { SEND_TOKEN_ACTION_KEY, TRANSFER_FROM_ACTION_KEY, SIGNATURE_REQUEST_KEY, + UNKNOWN_FUNCTION_KEY, } from '../constants/transactions' abiDecoder.addABI(abi) @@ -56,6 +57,10 @@ export function getTransactionActionKey (transaction, methodData) { const { name } = methodData const methodName = name && name.toLowerCase() + if (!methodName) { + return UNKNOWN_FUNCTION_KEY + } + switch (methodName) { case TOKEN_METHOD_TRANSFER: return SEND_TOKEN_ACTION_KEY -- cgit v1.2.3 From b48a293af059d2ad23fea0af601740888acd3f8b Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Sat, 11 Aug 2018 23:12:30 -0500 Subject: Update retry transaction logic to use network nonce --- ui/app/helpers/transactions.util.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index e890a0852..e92a22e16 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -2,7 +2,6 @@ import ethUtil from 'ethereumjs-util' import MethodRegistry from 'eth-method-registry' import abi from 'human-standard-token-abi' import abiDecoder from 'abi-decoder' -import { hexToDecimal } from './conversions.util' import { TOKEN_METHOD_TRANSFER, @@ -76,21 +75,20 @@ export function getTransactionActionKey (transaction, methodData) { } } -export function getLatestSubmittedTxWithEarliestNonce (transactions = []) { +export function getLatestSubmittedTxWithNonce (transactions = [], nonce = '0x0') { if (!transactions.length) { return {} } return transactions.reduce((acc, current) => { - const accNonce = hexToDecimal(acc.nonce) - const currentNonce = hexToDecimal(current.nonce) + const { submittedTime, txParams: { nonce: currentNonce } = {} } = current - if (currentNonce < accNonce) { - return current - } else if (currentNonce === accNonce) { - return current.submittedTime > acc.submittedTime ? current : acc + if (currentNonce === nonce) { + return acc.submittedTime + ? submittedTime > acc.submittedTime ? current : acc + : current } else { return acc } - }) + }, {}) } -- cgit v1.2.3 From 342522c6cf23670f931e69ba822eedfd2d6ee252 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Thu, 23 Aug 2018 16:44:38 -0700 Subject: Fix naming, add eth.getCode check for actions, fix translations for statuses --- ui/app/helpers/transactions.util.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index e92a22e16..54df54aa8 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -41,8 +41,8 @@ export function isConfirmDeployContract (txData = {}) { return !txParams.to } -export function getTransactionActionKey (transaction, methodData) { - const { txParams: { data } = {}, msgParams } = transaction +export async function getTransactionActionKey (transaction, methodData) { + const { txParams: { data, to } = {}, msgParams } = transaction if (msgParams) { return SIGNATURE_REQUEST_KEY @@ -53,6 +53,12 @@ export function getTransactionActionKey (transaction, methodData) { } if (data) { + const toSmartContract = await isSmartContractAddress(to) + + if (!toSmartContract) { + return SEND_ETHER_ACTION_KEY + } + const { name } = methodData const methodName = name && name.toLowerCase() @@ -92,3 +98,8 @@ export function getLatestSubmittedTxWithNonce (transactions = [], nonce = '0x0') } }, {}) } + +export async function isSmartContractAddress (address) { + const code = await global.eth.getCode(address) + return code && code !== '0x' +} -- cgit v1.2.3 From fd51ab12298e93286eeaf03c60e0b4e8d5d1bad3 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Fri, 31 Aug 2018 12:36:07 -0700 Subject: Add TransactionBreakdown component --- ui/app/helpers/transactions.util.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 54df54aa8..b88b00ac6 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -16,6 +16,8 @@ import { UNKNOWN_FUNCTION_KEY, } from '../constants/transactions' +import { addCurrencies } from '../conversion-util' + abiDecoder.addABI(abi) export function getTokenData (data = {}) { @@ -103,3 +105,13 @@ export async function isSmartContractAddress (address) { const code = await global.eth.getCode(address) return code && code !== '0x' } + +export function addHex (...args) { + const total = args.reduce((acc, base) => { + return addCurrencies(acc, base, { + toNumericBase: 'hex', + }) + }) + + return ethUtil.addHexPrefix(total) +} -- cgit v1.2.3 From f1a309e0cc110060cc56252ec5f7626ca6403fab Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Fri, 7 Sep 2018 13:59:05 -0700 Subject: Fix identicon address. Fix styling of New Contract recipient. Fix Activity Log initial ETH value. Add timestamps to Activity Log events --- ui/app/helpers/transactions.util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index b88b00ac6..0e1a6ca37 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -106,7 +106,7 @@ export async function isSmartContractAddress (address) { return code && code !== '0x' } -export function addHex (...args) { +export function sumHexes (...args) { const total = args.reduce((acc, base) => { return addCurrencies(acc, base, { toNumericBase: 'hex', -- cgit v1.2.3 From 91ee373dbe9aafd5d3f198644b12a468b5c5e363 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Tue, 18 Sep 2018 17:20:28 -0700 Subject: Fix exception thrown on getTokenData --- ui/app/helpers/transactions.util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 0e1a6ca37..54bb3bcb9 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -20,13 +20,13 @@ 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) -- cgit v1.2.3 From 5a6c333506e4000602c1a1106cee6d06fe83afa8 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Mon, 17 Sep 2018 10:34:29 -0700 Subject: Switch existing modals from using Notification to Modal. Remove Notification component. Add CancelTransaction modal --- ui/app/helpers/transactions.util.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 54bb3bcb9..8b87bb538 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -14,6 +14,7 @@ import { TRANSFER_FROM_ACTION_KEY, SIGNATURE_REQUEST_KEY, UNKNOWN_FUNCTION_KEY, + CANCEL_ATTEMPT_ACTION_KEY, } from '../constants/transactions' import { addCurrencies } from '../conversion-util' @@ -44,7 +45,11 @@ export function isConfirmDeployContract (txData = {}) { } 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 -- cgit v1.2.3 From 50d91f998d0dc228c1d5dac7966df89d6c3fe6c4 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Thu, 4 Oct 2018 19:26:41 -0700 Subject: Translate method names in the transaction list only when applicable --- ui/app/helpers/transactions.util.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index 8b87bb538..fdad63a96 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -80,8 +80,6 @@ export async function getTransactionActionKey (transaction, methodData) { return APPROVE_ACTION_KEY case TOKEN_METHOD_TRANSFER_FROM: return TRANSFER_FROM_ACTION_KEY - default: - return name } } else { return SEND_ETHER_ACTION_KEY -- cgit v1.2.3 From c474f30929e91fc2aeadba7de9faef70d4ce2e07 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Fri, 5 Oct 2018 13:02:55 -0700 Subject: Fix action translations edge cases --- ui/app/helpers/transactions.util.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ui/app/helpers/transactions.util.js') diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js index fdad63a96..f7d249e63 100644 --- a/ui/app/helpers/transactions.util.js +++ b/ui/app/helpers/transactions.util.js @@ -44,6 +44,12 @@ 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, type } = transaction @@ -80,6 +86,8 @@ export async function getTransactionActionKey (transaction, methodData) { return APPROVE_ACTION_KEY case TOKEN_METHOD_TRANSFER_FROM: return TRANSFER_FROM_ACTION_KEY + default: + return undefined } } else { return SEND_ETHER_ACTION_KEY -- cgit v1.2.3