diff --git a/src/logic/safe/store/actions/fetchTransactionDetails.ts b/src/logic/safe/store/actions/fetchTransactionDetails.ts index 6d90cebdba..7e81e110a6 100644 --- a/src/logic/safe/store/actions/fetchTransactionDetails.ts +++ b/src/logic/safe/store/actions/fetchTransactionDetails.ts @@ -1,7 +1,7 @@ import { createAction } from 'redux-actions' import { AddressEx, MultisigConfirmation, TransactionStatus } from '@gnosis.pm/safe-react-gateway-sdk' -import { getInternalChainId } from 'src/config' +import { getChainInfo } from 'src/config' import { currentChainId } from 'src/logic/config/store/selectors' import { AppReduxState } from 'src/logic/safe/store' import { Dispatch } from 'src/logic/safe/store/actions/types' @@ -9,7 +9,7 @@ import { Transaction } from 'src/logic/safe/store/models/types/gateway.d' import { TransactionDetailsPayload } from 'src/logic/safe/store/reducer/gatewayTransactions' import { getTransactionByAttribute } from 'src/logic/safe/store/selectors/gatewayTransactions' import { extractSafeAddress } from 'src/routes/routes' -import { getProposalDetail, getTxDetailById } from 'src/services' +import { getProposals, getTxDetailById } from 'src/services' import { MESSAGES_CODE } from 'src/services/constant/message' export const UPDATE_TRANSACTION_DETAILS = 'UPDATE_TRANSACTION_DETAILS' @@ -17,57 +17,57 @@ const updateTransactionDetails = createAction(UPDATE_ export const fetchTransactionDetailsById = ({ transactionId, auraTxId }: { transactionId?: string; auraTxId?: string }) => - async (dispatch: Dispatch, getState: () => AppReduxState): Promise => { - const transaction = getTransactionByAttribute(getState(), { - attributeValue: transactionId ? transactionId : auraTxId, - attributeName: transactionId ? 'id' : 'auraTxId', - }) - const safeAddress = extractSafeAddress() - const chainId = currentChainId(getState()) - const internalChainId = getInternalChainId() - if (transaction?.txDetails || !safeAddress) { - return - } + async (dispatch: Dispatch, getState: () => AppReduxState): Promise => { + const transaction = getTransactionByAttribute(getState(), { + attributeValue: transactionId ? transactionId : auraTxId, + attributeName: transactionId ? 'id' : 'auraTxId', + }) + const safeAddress = extractSafeAddress() + const chainId = currentChainId(getState()) + const chainInfo = getChainInfo() as any - try { - const { Data, ErrorCode } = await getTxDetailById(safeAddress, transactionId, auraTxId) - if (ErrorCode !== MESSAGES_CODE.SUCCESSFUL.ErrorCode) { + if (transaction?.txDetails || !safeAddress) { return } - const extraDetails: any = {} - if (Data?.Messages?.[0]?.proposalId) { - const respone = await getProposalDetail(internalChainId, Data?.Messages?.[0]?.proposalId) - if (respone.Data) { + try { + const { Data, ErrorCode } = await getTxDetailById(safeAddress, transactionId, auraTxId) + if (ErrorCode !== MESSAGES_CODE.SUCCESSFUL.ErrorCode) { + return + } + const extraDetails: any = {} + const listProposals = (await getProposals()).data?.[chainInfo.environment]?.proposal + const proposal = listProposals?.find((proposal) => proposal.proposal_id === Data?.Messages?.[0]?.proposalId) + + if (proposal) { const proposalDetail = { - id: respone.Data.id, - title: respone.Data.title, - status: respone.Data.status, - votingEnd: respone.Data.votingEnd, + id: proposal.proposal_id, + title: proposal.content[0].content.title, + status: proposal.status, + votingEnd: proposal.voting_end_time, } extraDetails.proposalDetail = proposalDetail } - } - const transactionDetails: any = { - txId: Data?.MultisigTxId?.toString() || null, - auraTxId: Data?.AuraTxId?.toString() || null, - executedAt: Data.Timestamp - ? new Date(Data.Timestamp).getTime() - : Data.Executor - ? new Date(Data.Executor.updatedAt).getTime() - : null, - createAt: Data.CreatedAt ? new Date(Data.CreatedAt).getTime() : null, - txStatus: (Data.Status == '0' ? TransactionStatus.SUCCESS : Data.Status) as TransactionStatus, - txMessage: Data?.Messages?.length ? Data?.Messages : [], - rawMessage: Data?.RawMessages, - deletedBy: Data?.Deleter, - fee: Data?.Fee?.toString() || 0, - gas: Data?.Gas?.toString() || 0, - txHash: Data?.TxHash || null, - confirmationsRequired: Data.ConfirmationsRequired, - confirmations: Data?.Confirmations?.map( - (cf) => + const transactionDetails: any = { + txId: Data?.MultisigTxId?.toString() || null, + auraTxId: Data?.AuraTxId?.toString() || null, + executedAt: Data.Timestamp + ? new Date(Data.Timestamp).getTime() + : Data.Executor + ? new Date(Data.Executor.updatedAt).getTime() + : null, + createAt: Data.CreatedAt ? new Date(Data.CreatedAt).getTime() : null, + txStatus: (Data.Status == '0' ? TransactionStatus.SUCCESS : Data.Status) as TransactionStatus, + txMessage: Data?.Messages?.length ? Data?.Messages : [], + rawMessage: Data?.RawMessages, + deletedBy: Data?.Deleter, + fee: Data?.Fee?.toString() || 0, + gas: Data?.Gas?.toString() || 0, + txHash: Data?.TxHash || null, + confirmationsRequired: Data.ConfirmationsRequired, + confirmations: Data?.Confirmations?.map( + (cf) => ({ signature: cf.signature, signer: { @@ -77,31 +77,31 @@ export const fetchTransactionDetailsById = }, submittedAt: new Date(cf.createdAt).getTime(), } as MultisigConfirmation), - ), - executor: !Data?.Executor - ? null - : { + ), + executor: !Data?.Executor + ? null + : { logoUri: null, name: null, value: Data.Executor.ownerAddress, }, - rejectors: Data?.Rejectors?.map((re) => ({ logoUri: null, name: null, value: re.ownerAddress } as AddressEx)), - extraDetails, - autoClaimAmount: Data?.AutoClaimAmount, - sequence: Data?.Sequence, - logs: Data?.Logs, - txMemo: Data?.Memo, - } + rejectors: Data?.Rejectors?.map((re) => ({ logoUri: null, name: null, value: re.ownerAddress } as AddressEx)), + extraDetails, + autoClaimAmount: Data?.AutoClaimAmount, + sequence: Data?.Sequence, + logs: Data?.Logs, + txMemo: Data?.Memo, + } - dispatch( - updateTransactionDetails({ - chainId, - transactionId: transactionDetails.txId, - safeAddress, - value: transactionDetails, - }), - ) - } catch (error) { - console.error(`Failed to retrieve transaction details`, error.message) + dispatch( + updateTransactionDetails({ + chainId, + transactionId: transactionDetails.txId, + safeAddress, + value: transactionDetails, + }), + ) + } catch (error) { + console.error(`Failed to retrieve transaction details`, error.message) + } } - } diff --git a/src/pages/Transactions/components/TxDetail/Message.tsx b/src/pages/Transactions/components/TxDetail/Message.tsx index 500f859cc6..0d843c73a8 100644 --- a/src/pages/Transactions/components/TxDetail/Message.tsx +++ b/src/pages/Transactions/components/TxDetail/Message.tsx @@ -123,7 +123,7 @@ export default function TxMsg({ tx, txDetail, token, onImport }) { ))}
- {msg[0]?.value?.funds.length > 0 ?
Transaction funds:
: <>} + {msg[0]?.value?.funds.length > 0 ? Transaction funds: : <>} {msg[0]?.value?.funds?.map((fund, index) => { const foundToken = tokenList.find((token) => token.cosmosDenom === fund.denom || token.denom === fund.denom) if (foundToken) { diff --git a/src/services/index.ts b/src/services/index.ts index 1954317b72..f9d6fc0bc8 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -4,7 +4,6 @@ import { getChainInfo } from 'src/config' import { WalletKey } from 'src/logic/keplr/keplr' import { CHAIN_THEMES, THEME_DF } from 'src/services/constant/chainThemes' import { getExplorerUrl, getGatewayUrl } from 'src/services/data/environment' -import { IProposal } from 'src/types/proposal' import { ICreateSafeTransaction, ITransactionListItem, ITransactionListQuery } from 'src/types/transaction' import { IMSafeInfo, IMSafeResponse, OwnedMSafes } from '../types/safe' @@ -371,12 +370,6 @@ export const getProposals = async () => { .then((res) => res.data) } -export async function getProposalDetail( - internalChainId: number | string, - proposalId: number | string, -): Promise> { - return axios.get(`${baseUrl}/gov/${internalChainId}/proposals/${proposalId}`).then((res) => res.data) -} export async function getContract(contractAddress: string): Promise> { const chainInfo = getChainInfo() as any return axios diff --git a/src/types/proposal.ts b/src/types/proposal.ts index 768ef1c463..f2a0b801f9 100644 --- a/src/types/proposal.ts +++ b/src/types/proposal.ts @@ -54,7 +54,4 @@ export interface IProposal { depositEndTime: Date turnout: Turnout requestAmount: Amount -} -export interface IProposalRes { - proposals: IProposal[] -} +} \ No newline at end of file