Skip to content

Commit

Permalink
feat: start adding support for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Feb 29, 2024
1 parent 322ade6 commit 8e9ce5b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ query TransactionDetails($hash: String) {
memo: memo
rawLog: raw_log
}
message(where: {transaction: {hash: {_eq: $hash}}}) {
type
value
transaction_hash
}
}
7 changes: 6 additions & 1 deletion apps/web-namada/src/graphql/types/general_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@ export type TransactionDetailsQueryVariables = Exact<{
}>;


export type TransactionDetailsQuery = { transaction: Array<{ __typename?: 'transaction', hash: string, height: any, gasUsed?: any | null, gasWanted?: any | null, success: boolean, memo?: string | null, rawLog?: string | null, block?: { __typename?: 'block', timestamp: any } | null }> };
export type TransactionDetailsQuery = { transaction: Array<{ __typename?: 'transaction', hash: string, height: any, gasUsed?: any | null, gasWanted?: any | null, success: boolean, memo?: string | null, rawLog?: string | null, block?: { __typename?: 'block', timestamp: any } | null }>, message: Array<{ __typename?: 'message', type: string, value: any, transaction_hash: string }> };

export type TransactionsListenerSubscriptionVariables = Exact<{
limit?: InputMaybe<Scalars['Int']>;
Expand Down Expand Up @@ -2742,6 +2742,11 @@ export const TransactionDetailsDocument = gql`
memo: memo
rawLog: raw_log
}
message(where: {transaction: {hash: {_eq: $hash}}}) {
type
value
transaction_hash
}
}
`;

Expand Down
2 changes: 1 addition & 1 deletion apps/web-namada/src/screens/transaction_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const formatLogs = (data: TransactionDetailsQuery) => {
// messages
// =============================
const formatMessages = (data: TransactionDetailsQuery) => {
const messages = convertMsgsToModels(data.transaction[0]);
const messages = convertMsgsToModels(data.message);
return {
filterBy: 'none',
viewRaw: false,
Expand Down
8 changes: 7 additions & 1 deletion apps/web-namada/src/screens/transaction_details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { NextSeo } from 'next-seo';
import useAppTranslation from '@/hooks/useAppTranslation';
import Layout from '@/components/layout';
import LoadAndExist from '@/components/load_and_exist';
import Logs from '@/screens/transaction_details/components/logs';
import Messages from '@/screens/transaction_details/components/messages';
import Overview from '@/screens/transaction_details/components/overview';
import { useTransactionDetails } from '@/screens/transaction_details/hooks';
Expand All @@ -28,6 +27,13 @@ const TransactionDetails = () => {
<span className={classes.root}>
<Overview data={overview} />
</span>
<Messages
className={classes.messages}
messages={filterMessages(messages.items)}
viewRaw={messages.viewRaw}
toggleMessageDisplay={toggleMessageDisplay}
onMessageFilterCallback={onMessageFilterCallback}
/>
</LoadAndExist>
</Layout>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const DepositProposal: FC<{ message: MsgDeposit }> = (props) => {
);

const depositor = useProfileRecoil(message.depositor);
const depositorMoniker = depositor ? depositor?.name : message.depositor;
const depositorMoniker = depositor ? depositor?.name : message.voter;

return (
<Typography>
Expand Down
17 changes: 8 additions & 9 deletions packages/ui/src/components/msg/governance/vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ import { FC, useMemo } from 'react';
const Vote: FC<{ message: MsgVote }> = (props) => {
const { t } = useAppTranslation('transactions');
const { message } = props;
const vote = t(message.getOptionTranslationKey() ?? '');
const vote = t(message.getOptionTranslationKey?.() ?? '');

const voter = useProfileRecoil(message.voter);
const voterMoniker = voter ? voter?.name : message.voter;
const voterMoniker = message.value.voter;

const Proposal = useMemo(
() => (
<Link shallow href={PROPOSAL_DETAILS(message.proposalId)}>
#{message.proposalId}
<Link shallow href={PROPOSAL_DETAILS(message.value.id)}>
#{message.value.id}
</Link>
),
[message.proposalId]
[message.value.id]
);

return (
<Typography>
<AppTrans
i18nKey="message_contents:txVoteContent"
components={[<Name address={message.voter} name={voterMoniker} />, <b />, Proposal]}
components={[<Name address={message.value.voter} name={voterMoniker} />, <b />, Proposal]}
values={{
vote,
proposal: message.proposalId,
vote: message.value.vote,
proposal: message.value.id,
}}
/>
</Typography>
Expand Down
29 changes: 9 additions & 20 deletions packages/ui/src/components/msg/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const defaultTypeToModel = {
tagTheme: 'seven',
tagDisplay: 'txDepositLabel',
},
'/cosmos.gov.v1beta1.MsgVote': {
tx_vote_proposal: {
model: MODELS.MsgVote,
content: COMPONENTS.Vote,
tagTheme: 'seven',
Expand Down Expand Up @@ -482,26 +482,15 @@ export const getMessageByType = <TMessage,>(message: TMessage, viewRaw: boolean,
};
};

export const convertMsgsToModels = (
transaction?: {
messages?: Array<{
'@type': string;
}>;
logs?: Array<Log>;
} | null
) => {
export const convertMsgsToModels = (messagesRaw?: any[] | null) => {
const messages =
transaction?.messages?.map((msg: object, i: number) => {
const model = getMessageModelByType(R.pathOr<string>('', ['@type'], msg));
if (model === MODELS.MsgWithdrawDelegatorReward) {
const log = transaction?.logs?.[i];
return MODELS.MsgWithdrawDelegatorReward.fromJson(msg, log);
}
if (model === MODELS.MsgWithdrawValidatorCommission) {
const log = transaction?.logs?.[i];
return MODELS.MsgWithdrawValidatorCommission.fromJson(msg, log);
}
return model.fromJson(msg);
messagesRaw?.map((msg: object) => {
return {
value: msg.value,
type: msg.type,
json: msg.value,
transaction_hash: msg.transaction_hash,
};
}) ?? [];

return messages;
Expand Down

0 comments on commit 8e9ce5b

Please sign in to comment.