(Fix) Properly decode threshold value in tx details (#749)

* fix: Display new threshold value when changing its value

There was a typo for the `changeThreshold` action

fixes #746

* refactor: use a constant for safe methods names
This commit is contained in:
Fernando 2020-04-09 05:45:19 -03:00 committed by GitHub
parent d2f81fc0aa
commit 1ac13c63dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 12 deletions

View File

@ -39,11 +39,18 @@ import { getWeb3 } from '~/logic/wallets/getWeb3'
// { name: "getTransactionHash", id: "0xd8d11f78" } // { name: "getTransactionHash", id: "0xd8d11f78" }
// ] // ]
export const SAFE_METHODS_NAMES = {
ADD_OWNER_WITH_THRESHOLD: 'addOwnerWithThreshold',
CHANGE_THRESHOLD: 'changeThreshold',
REMOVE_OWNER: 'removeOwner',
SWAP_OWNER: 'swapOwner',
}
const METHOD_TO_ID = { const METHOD_TO_ID = {
'0xe318b52b': 'swapOwner', '0xe318b52b': SAFE_METHODS_NAMES.SWAP_OWNER,
'0x0d582f13': 'addOwnerWithThreshold', '0x0d582f13': SAFE_METHODS_NAMES.ADD_OWNER_WITH_THRESHOLD,
'0xf8dc5dd9': 'removeOwner', '0xf8dc5dd9': SAFE_METHODS_NAMES.REMOVE_OWNER,
'0x694e80c3': 'changeThreshold', '0x694e80c3': SAFE_METHODS_NAMES.CHANGE_THRESHOLD,
} }
export const decodeParamsFromSafeMethod = async (data: string) => { export const decodeParamsFromSafeMethod = async (data: string) => {

View File

@ -10,6 +10,7 @@ import Bold from '~/components/layout/Bold'
import LinkWithRef from '~/components/layout/Link' import LinkWithRef from '~/components/layout/Link'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import { getNameFromAddressBook } from '~/logic/addressBook/utils' import { getNameFromAddressBook } from '~/logic/addressBook/utils'
import { SAFE_METHODS_NAMES } from '~/logic/contracts/methodIds'
import { shortVersionOf } from '~/logic/wallets/ethAddresses' import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import OwnerAddressTableCell from '~/routes/safe/components/Settings/ManageOwners/OwnerAddressTableCell' import OwnerAddressTableCell from '~/routes/safe/components/Settings/ManageOwners/OwnerAddressTableCell'
import { getTxAmount } from '~/routes/safe/components/Transactions/TxsTable/columns' import { getTxAmount } from '~/routes/safe/components/Transactions/TxsTable/columns'
@ -120,7 +121,7 @@ const NewThreshold = ({ newThreshold }: { newThreshold: string }) => (
) )
const SettingsDescription = ({ action, addedOwner, newThreshold, removedOwner }: DescriptionDescProps) => { const SettingsDescription = ({ action, addedOwner, newThreshold, removedOwner }: DescriptionDescProps) => {
if (action === 'removeOwner' && removedOwner && newThreshold) { if (action === SAFE_METHODS_NAMES.REMOVE_OWNER && removedOwner && newThreshold) {
return ( return (
<> <>
<RemovedOwner removedOwner={removedOwner} /> <RemovedOwner removedOwner={removedOwner} />
@ -129,11 +130,11 @@ const SettingsDescription = ({ action, addedOwner, newThreshold, removedOwner }:
) )
} }
if (action === 'changedThreshold' && newThreshold) { if (action === SAFE_METHODS_NAMES.CHANGE_THRESHOLD && newThreshold) {
return <NewThreshold newThreshold={newThreshold} /> return <NewThreshold newThreshold={newThreshold} />
} }
if (action === 'addOwnerWithThreshold' && addedOwner && newThreshold) { if (action === SAFE_METHODS_NAMES.ADD_OWNER_WITH_THRESHOLD && addedOwner && newThreshold) {
return ( return (
<> <>
<AddedOwner addedOwner={addedOwner} /> <AddedOwner addedOwner={addedOwner} />
@ -142,7 +143,7 @@ const SettingsDescription = ({ action, addedOwner, newThreshold, removedOwner }:
) )
} }
if (action === 'swapOwner' && removedOwner && addedOwner) { if (action === SAFE_METHODS_NAMES.SWAP_OWNER && removedOwner && addedOwner) {
return ( return (
<> <>
<RemovedOwner removedOwner={removedOwner} /> <RemovedOwner removedOwner={removedOwner} />

View File

@ -1,4 +1,5 @@
// @flow // @flow
import { SAFE_METHODS_NAMES } from '~/logic/contracts/methodIds'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type Transaction } from '~/routes/safe/store/models/transaction' import { type Transaction } from '~/routes/safe/store/models/transaction'
@ -51,15 +52,15 @@ export const getTxData = (tx: Transaction): DecodedTxData => {
if (tx.decodedParams) { if (tx.decodedParams) {
txData.action = tx.decodedParams.methodName txData.action = tx.decodedParams.methodName
if (txData.action === 'removeOwner') { if (txData.action === SAFE_METHODS_NAMES.REMOVE_OWNER) {
txData.removedOwner = tx.decodedParams.args[1] txData.removedOwner = tx.decodedParams.args[1]
txData.newThreshold = tx.decodedParams.args[2] txData.newThreshold = tx.decodedParams.args[2]
} else if (txData.action === 'changeThreshold') { } else if (txData.action === SAFE_METHODS_NAMES.CHANGE_THRESHOLD) {
txData.newThreshold = tx.decodedParams.args[0] txData.newThreshold = tx.decodedParams.args[0]
} else if (txData.action === 'addOwnerWithThreshold') { } else if (txData.action === SAFE_METHODS_NAMES.ADD_OWNER_WITH_THRESHOLD) {
txData.addedOwner = tx.decodedParams.args[0] txData.addedOwner = tx.decodedParams.args[0]
txData.newThreshold = tx.decodedParams.args[1] txData.newThreshold = tx.decodedParams.args[1]
} else if (txData.action === 'swapOwner') { } else if (txData.action === SAFE_METHODS_NAMES.SWAP_OWNER) {
txData.removedOwner = tx.decodedParams.args[1] txData.removedOwner = tx.decodedParams.args[1]
txData.addedOwner = tx.decodedParams.args[2] txData.addedOwner = tx.decodedParams.args[2]
} }