From e84036c1207a208e46ae6490674bb70f16887daf Mon Sep 17 00:00:00 2001 From: Agustin Pane Date: Fri, 28 Aug 2020 08:59:53 -0300 Subject: [PATCH] (Feature) - Update decoded value types (#1285) * Renames decodedData to dataDecoded * Renames DecodedValue to ValueDecoded * Updates operation types * Remove unnecesary keyof typepo Co-authored-by: Mikhail Mikheev --- .../safe/store/models/types/transactions.d.ts | 12 ++++++------ .../TxDescription/CustomDescription.tsx | 4 ++-- .../utils/multiSendDecodedDetails.ts | 16 ++++++++-------- .../transactions/utils/newTransactionHelpers.ts | 2 +- .../safe/store/models/types/transactions.d.ts | 13 +++++++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/logic/safe/store/models/types/transactions.d.ts b/src/logic/safe/store/models/types/transactions.d.ts index c1f88e77..a9fcc709 100644 --- a/src/logic/safe/store/models/types/transactions.d.ts +++ b/src/logic/safe/store/models/types/transactions.d.ts @@ -4,9 +4,9 @@ export enum TxConstants { } export enum Operation { - CALL = 'CALL', - DELEGATE_CALL = 'DELEGATE_CALL', - CREATE = 'CREATE', + CALL, + DELEGATE_CALL, + CREATE, } // types comes from: https://github.com/gnosis/safe-client-gateway/blob/752e76b6d1d475791dbd7917b174bb41d2d9d8be/src/utils.rs @@ -35,12 +35,12 @@ export enum SettingsChangeMethods { // note: this extends SAFE_METHODS_NAMES in /logic/contracts/methodIds.ts, we need to figure out which one we are going to use export type DataDecodedMethod = TransferMethods | SettingsChangeMethods | string -export interface DecodedValue { +export interface ValueDecoded { operation: Operation to: string value: number data: string - decodedData: DataDecoded + dataDecoded: DataDecoded } export interface SingleTransactionMethodParameter { @@ -50,7 +50,7 @@ export interface SingleTransactionMethodParameter { } export interface MultiSendMethodParameter extends SingleTransactionMethodParameter { - decodedValue: DecodedValue[] + valueDecoded: ValueDecoded[] } export type Parameter = MultiSendMethodParameter | SingleTransactionMethodParameter diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/CustomDescription.tsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/CustomDescription.tsx index ae6281e8..a4a8199c 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/CustomDescription.tsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/CustomDescription.tsx @@ -8,7 +8,7 @@ import Value from './Value' import Block from 'src/components/layout/Block' import { - extractMultiSendDecodedData, + extractMultiSendDataDecoded, MultiSendDetails, } from 'src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails' import Bold from 'src/components/layout/Bold' @@ -198,7 +198,7 @@ interface CustomDescriptionProps { } const CustomDescription = ({ amount, data, recipient, storedTx }: CustomDescriptionProps): React.ReactElement => { - const txDetails = (storedTx.multiSendTx && extractMultiSendDecodedData(storedTx).txDetails) ?? undefined + const txDetails = (storedTx.multiSendTx && extractMultiSendDataDecoded(storedTx).txDetails) ?? undefined return txDetails ? ( diff --git a/src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails.ts b/src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails.ts index 076b97ac..461051c4 100644 --- a/src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails.ts +++ b/src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails.ts @@ -17,13 +17,13 @@ import { isMultiSendParameter } from './newTransactionHelpers' import { Transaction } from 'src/logic/safe/store/models/types/transaction' export type MultiSendDetails = { - operation: keyof typeof Operation + operation: Operation to: string data: DataDecoded | null value: number } -export type MultiSendDecodedData = { +export type MultiSendDataDecoded = { txDetails?: MultiSendDetails[] transfersDetails?: TransferDetails[] } @@ -43,18 +43,18 @@ export const extractTransferDetails = (transfer: Transfer): TransferDetails => { export const extractMultiSendDetails = (parameter: Parameter): MultiSendDetails[] | undefined => { if (isMultiSendParameter(parameter)) { - return parameter.decodedValue.map((decodedValue) => { + return parameter.valueDecoded.map((valueDecoded) => { return { - operation: decodedValue.operation, - to: decodedValue.to, - value: decodedValue.value, - data: decodedValue?.decodedData ?? null, + operation: valueDecoded.operation, + to: valueDecoded.to, + value: valueDecoded.value, + data: valueDecoded?.dataDecoded ?? null, } }) } } -export const extractMultiSendDecodedData = (tx: Transaction): MultiSendDecodedData => { +export const extractMultiSendDataDecoded = (tx: Transaction): MultiSendDataDecoded => { const transfersDetails = tx.transfers?.map(extractTransferDetails) const txDetails = extractMultiSendDetails(tx.dataDecoded?.parameters[0]) diff --git a/src/routes/safe/store/actions/transactions/utils/newTransactionHelpers.ts b/src/routes/safe/store/actions/transactions/utils/newTransactionHelpers.ts index d10f801a..0b1ddeab 100644 --- a/src/routes/safe/store/actions/transactions/utils/newTransactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/newTransactionHelpers.ts @@ -21,5 +21,5 @@ export const isEthereumTx = (tx: Transaction): tx is EthereumTransaction => { } export const isMultiSendParameter = (parameter: Parameter): parameter is MultiSendMethodParameter => { - return !!(parameter as MultiSendMethodParameter)?.decodedValue + return !!(parameter as MultiSendMethodParameter)?.valueDecoded } diff --git a/src/routes/safe/store/models/types/transactions.d.ts b/src/routes/safe/store/models/types/transactions.d.ts index c1f88e77..0ee07282 100644 --- a/src/routes/safe/store/models/types/transactions.d.ts +++ b/src/routes/safe/store/models/types/transactions.d.ts @@ -1,12 +1,13 @@ +// TODO this file is duplicated with src/logic/safe/store/model/types/transaction.d.ts, we should remove it export enum TxConstants { MULTI_SEND = 'multiSend', UNKNOWN = 'UNKNOWN', } export enum Operation { - CALL = 'CALL', - DELEGATE_CALL = 'DELEGATE_CALL', - CREATE = 'CREATE', + CALL, + DELEGATE_CALL, + CREATE, } // types comes from: https://github.com/gnosis/safe-client-gateway/blob/752e76b6d1d475791dbd7917b174bb41d2d9d8be/src/utils.rs @@ -35,12 +36,12 @@ export enum SettingsChangeMethods { // note: this extends SAFE_METHODS_NAMES in /logic/contracts/methodIds.ts, we need to figure out which one we are going to use export type DataDecodedMethod = TransferMethods | SettingsChangeMethods | string -export interface DecodedValue { +export interface ValueDecoded { operation: Operation to: string value: number data: string - decodedData: DataDecoded + dataDecoded: DataDecoded } export interface SingleTransactionMethodParameter { @@ -50,7 +51,7 @@ export interface SingleTransactionMethodParameter { } export interface MultiSendMethodParameter extends SingleTransactionMethodParameter { - decodedValue: DecodedValue[] + valueDecoded: ValueDecoded[] } export type Parameter = MultiSendMethodParameter | SingleTransactionMethodParameter