decoding params from settings txs

This commit is contained in:
mmv 2019-07-11 14:13:26 +04:00
parent a2c2793788
commit 7cda208066
3 changed files with 55 additions and 26 deletions

View File

@ -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
},

View File

@ -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 {}
}
}

View File

@ -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,
})
}