From 7cda208066897625a74736ba9e9d67c96e0e1ea1 Mon Sep 17 00:00:00 2001 From: mmv Date: Thu, 11 Jul 2019 14:13:26 +0400 Subject: [PATCH] decoding params from settings txs --- .eslintrc | 23 +++++---- src/logic/contracts/methodIds.js | 50 +++++++++++++------ .../safe/store/actions/fetchTransactions.js | 8 ++- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/.eslintrc b/.eslintrc index c45adf39..b565138c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,5 @@ { - "extends": [ - "airbnb", - "plugin:flowtype/recommended" - ], + "extends": ["airbnb", "plugin:flowtype/recommended"], "parser": "babel-eslint", "plugins": ["jest", "flowtype"], "rules": { @@ -27,19 +24,23 @@ "import/extensions": 0, "import/prefer-default-export": 0, "jsx-a11y/label-has-for": 0, - "indent": ["error", 2], + "indent": ["error", 2, { "SwitchCase": 1 }], "no-console": ["error", { "allow": ["warn", "error"] }], "flowtype/require-valid-file-annotation": [ 2, - "always", { + "always", + { "annotationStyle": "line" } ], - "jsx-a11y/anchor-is-valid": [ "error", { - "components": [ "Link" ], - "specialLink": [ "to", "hrefLeft", "hrefRight" ], - "aspects": [ "noHref", "invalidHref", "preferButton" ] - }], + "jsx-a11y/anchor-is-valid": [ + "error", + { + "components": ["Link"], + "specialLink": ["to", "hrefLeft", "hrefRight"], + "aspects": ["noHref", "invalidHref", "preferButton"] + } + ], "react/require-default-props": 0, "react/no-array-index-key": 0 }, diff --git a/src/logic/contracts/methodIds.js b/src/logic/contracts/methodIds.js index 59206f1d..b79b6973 100644 --- a/src/logic/contracts/methodIds.js +++ b/src/logic/contracts/methodIds.js @@ -3,6 +3,7 @@ import { getWeb3 } from '~/logic/wallets/getWeb3' // SAFE METHODS TO ITS ID // https://github.com/gnosis/safe-contracts/blob/development/test/safeMethodNaming.js +// https://github.com/gnosis/safe-contracts/blob/development/contracts/GnosisSafe.sol // [ // { name: "addOwnerWithThreshold", id: "0x0d582f13" }, // { name: "DOMAIN_SEPARATOR_TYPEHASH", id: "0x1db61b54" }, @@ -38,26 +39,47 @@ import { getWeb3 } from '~/logic/wallets/getWeb3' // { name: "getTransactionHash", id: "0xd8d11f78" } // ] -export const decodeParamsFromSafeMethod = async (data) => { - const web3 = await getWeb3() +const METHOD_TO_ID = { + '0xe318b52b': 'swapOwner', + '0x0d582f13': 'addOwnerWithThreshold', + '0xf8dc5dd9': 'removeOwner', + '0x694e80c3': 'changeThreshold', +} - switch (data.slice(0, 10)) { - // swapOwner - case '0xe318b52b': - return +export const decodeParamsFromSafeMethod = async (data: string) => { + const web3 = await getWeb3() + const [methodId, params] = [data.slice(0, 10), data.slice(10)] + + switch (methodId) { + // swapOwner + case '0xe318b52b': + return { + methodName: METHOD_TO_ID[methodId], + args: web3.eth.abi.decodeParameters(['address', 'address', 'address'], params), + } // addOwnerWithThreshold - case '0x0d582f13': - return + case '0x0d582f13': + return { + methodName: METHOD_TO_ID[methodId], + args: web3.eth.abi.decodeParameters(['address', 'uint'], params), + } // removeOwner - case '0xf8dc5dd9': - return + case '0xf8dc5dd9': + return { + methodName: METHOD_TO_ID[methodId], + args: web3.eth.abi.decodeParameters(['address', 'address', 'uint'], params), + } - case '0x694e80c3': - return + // changeThreshold + case '0x694e80c3': + return { + methodName: METHOD_TO_ID[methodId], + args: web3.eth.abi.decodeParameters(['uint'], params), + } - default: - return {} + default: + return {} } } diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index a0e5031a..6ae17ecb 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -15,6 +15,7 @@ import { addTransactions } from './addTransactions' import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens' import { isAddressAToken } from '~/logic/tokens/utils/tokenHelpers' import { TX_TYPE_EXECUTION, TX_TYPE_CONFIRMATION } from '~/logic/safe/transactions/send' +import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds' let web3 @@ -51,6 +52,7 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf }) }), ) + const modifySettingsTx = tx.to === safeAddress const isTokenTransfer = await isAddressAToken(tx.to) const creationTxHash = confirmations.findLast(conf => conf.type === TX_TYPE_CONFIRMATION).hash @@ -73,6 +75,10 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf recipient: params[0], value: params[1], } + } else if ( + modifySettingsTx && tx.data + ) { + decodedParams = await decodeParamsFromSafeMethod(tx.data) } return makeTransaction({ @@ -90,7 +96,7 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf creationTxHash, isTokenTransfer, decodedParams, - modifySettingsTx: tx.to === safeAddress, + modifySettingsTx, }) }