diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-07-31 13:03:20 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-08-24 07:44:44 +0800 |
commit | 5ee40675b9f986a9ff2e5d15a271d7de2145d0e9 (patch) | |
tree | 80f4b3e0a88a5621724a05efeb320596e0bcedad /ui/app/helpers/transactions.util.js | |
parent | d733bd34fbd356bca640b3a50582208c0284be40 (diff) | |
download | tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar.gz tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar.bz2 tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar.lz tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar.xz tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.tar.zst tangerine-wallet-browser-5ee40675b9f986a9ff2e5d15a271d7de2145d0e9.zip |
Refactor transactions list views. Add redesign components
Diffstat (limited to 'ui/app/helpers/transactions.util.js')
-rw-r--r-- | ui/app/helpers/transactions.util.js | 57 |
1 files changed, 57 insertions, 0 deletions
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, + } +} |