Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serenity #355

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 66 additions & 66 deletions src/logic/safe/store/actions/fetchTransactionDetails.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
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'
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'
const updateTransactionDetails = createAction<TransactionDetailsPayload>(UPDATE_TRANSACTION_DETAILS)

export const fetchTransactionDetailsById =
({ transactionId, auraTxId }: { transactionId?: string; auraTxId?: string }) =>
async (dispatch: Dispatch, getState: () => AppReduxState): Promise<Transaction['txDetails']> => {
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<Transaction['txDetails']> => {
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: {
Expand All @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion src/pages/Transactions/components/TxDetail/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function TxMsg({ tx, txDetail, token, onImport }) {
</div>
))}
<div>
{msg[0]?.value?.funds.length > 0 ? <div className="function-name">Transaction funds:</div> : <></>}
{msg[0]?.value?.funds.length > 0 ? <strong>Transaction funds:</strong> : <></>}
{msg[0]?.value?.funds?.map((fund, index) => {
const foundToken = tokenList.find((token) => token.cosmosDenom === fund.denom || token.denom === fund.denom)
if (foundToken) {
Expand Down
7 changes: 0 additions & 7 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -371,12 +370,6 @@ export const getProposals = async () => {
.then((res) => res.data)
}

export async function getProposalDetail(
internalChainId: number | string,
proposalId: number | string,
): Promise<IResponse<IProposal>> {
return axios.get(`${baseUrl}/gov/${internalChainId}/proposals/${proposalId}`).then((res) => res.data)
}
export async function getContract(contractAddress: string): Promise<IResponse<any>> {
const chainInfo = getChainInfo() as any
return axios
Expand Down
5 changes: 1 addition & 4 deletions src/types/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,4 @@ export interface IProposal {
depositEndTime: Date
turnout: Turnout
requestAmount: Amount
}
export interface IProposalRes {
proposals: IProposal[]
}
}