From 19b0e26178c8d4faa558f544ff964150af731fd1 Mon Sep 17 00:00:00 2001 From: HoangNDM Date: Tue, 5 Dec 2023 11:49:35 +0700 Subject: [PATCH] fix get proposals --- .../store/actions/fetchTransactionDetails.ts | 134 +++++++++--------- src/pages/Voting/index.tsx | 2 +- src/services/index.ts | 21 ++- src/types/proposal.ts | 2 +- 4 files changed, 88 insertions(+), 71 deletions(-) diff --git a/src/logic/safe/store/actions/fetchTransactionDetails.ts b/src/logic/safe/store/actions/fetchTransactionDetails.ts index 7e81e110a6..ad79f2d6a2 100644 --- a/src/logic/safe/store/actions/fetchTransactionDetails.ts +++ b/src/logic/safe/store/actions/fetchTransactionDetails.ts @@ -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 chainInfo = getChainInfo() as any + 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 - if (transaction?.txDetails || !safeAddress) { + if (transaction?.txDetails || !safeAddress) { + return + } + + 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) - 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: proposal.proposal_id, - title: proposal.content[0].content.title, - status: proposal.status, - votingEnd: proposal.voting_end_time, - } - extraDetails.proposalDetail = proposalDetail + if (proposal) { + const proposalDetail = { + id: proposal.proposal_id, + title: proposal.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, - } - - dispatch( - updateTransactionDetails({ - chainId, - transactionId: transactionDetails.txId, - safeAddress, - value: transactionDetails, - }), - ) - } catch (error) { - console.error(`Failed to retrieve transaction details`, error.message) + 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) } + } diff --git a/src/pages/Voting/index.tsx b/src/pages/Voting/index.tsx index e7d1ac8148..4381b0f95f 100644 --- a/src/pages/Voting/index.tsx +++ b/src/pages/Voting/index.tsx @@ -93,7 +93,7 @@ function Voting(): ReactElement { } return { id: proposal.proposal_id, - title: proposal.content.title, + title: proposal.title, proposer: proposal.proposer_address, status: proposal.status, votingStart: proposal.voting_start_time, diff --git a/src/services/index.ts b/src/services/index.ts index f9d6fc0bc8..e58bac93a9 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -350,7 +350,8 @@ export async function getNumberOfDelegator(validatorId: any): Promise chain.chainId == currentChainInfo.chainId)?.rest + `${ + chainInfo.find((chain) => chain.chainId == currentChainInfo.chainId)?.rest }/cosmos/staking/v1beta1/validators/${validatorId}/delegations?pagination.count_total=true`, ) .then((res) => res.data) @@ -363,7 +364,23 @@ export const getProposals = async () => { return axios .post(chainInfo.indexerV2, { - query: `query GetProposals {\n ${chainInfo.environment} {\n proposal(order_by: {proposal_id: desc}, limit: 10) {\n proposer_address\n content\n tally\n proposal_id\n status\n submit_time\n deposit_end_time\n total_deposit\n voting_start_time\n voting_end_time\n }\n }\n }`, + query: `query GetProposals {${chainInfo.environment} { + proposal(order_by: {proposal_id: desc}, limit: 10) + { + proposer_address + content + tally + title + proposal_id + status + submit_time + deposit_end_time + total_deposit + voting_start_time + voting_end_time + } + } + }`, variables: {}, operationName: 'GetProposals', }) diff --git a/src/types/proposal.ts b/src/types/proposal.ts index f2a0b801f9..4d8be2d64b 100644 --- a/src/types/proposal.ts +++ b/src/types/proposal.ts @@ -54,4 +54,4 @@ export interface IProposal { depositEndTime: Date turnout: Turnout requestAmount: Amount -} \ No newline at end of file +}