Skip to content

Commit

Permalink
Merge branch 'feat/show_raw_data_to_table' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
quangdz1704 committed Dec 20, 2023
2 parents 78358fd + b96686e commit 9ce8d2c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 25 deletions.
21 changes: 19 additions & 2 deletions src/components/ReactJson/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ import styles from "./ReactJson.module.scss";

const cx = cn.bind(styles);

const ValueItem = raw => {
export const formatAmountWithCurrency = inputString => {
const matches = inputString.match(/^(\d+)(.*)$/);

if (matches) {
const numberPart = matches[1];
const unitPart = matches[2];

const resultString = numberPart + " " + unitPart;

return resultString;
} else {
return inputString;
}
};

export const ValueItem = raw => {
if (typeof raw === "string") {
if (raw.match(/^https?:\/\//)) {
return (
Expand All @@ -25,7 +40,9 @@ const ValueItem = raw => {
</a>
);
}
} catch {}
} catch {
return formatAmountWithCurrency(raw);
}
}
return raw;
};
Expand Down
48 changes: 35 additions & 13 deletions src/components/Tx/TxData/TxMessage/TxMessage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useMemo, useEffect } from "react";
import { NavLink } from "react-router-dom";
import { useSelector, useDispatch } from "react-redux";
import ReactJson from "src/components/ReactJson";
import ReactJson, { ValueItem } from "src/components/ReactJson";
import PropTypes from "prop-types";
import cn from "classnames/bind";
import { Fade, Tooltip } from "@material-ui/core";
import { Fade, Tooltip, useMediaQuery, useTheme } from "@material-ui/core";
import Skeleton from "@material-ui/lab/Skeleton";
import Accordion from "@material-ui/core/Accordion";
import AccordionSummary from "@material-ui/core/AccordionSummary";
Expand Down Expand Up @@ -73,17 +73,20 @@ const tryParseMessageBinary = data => {
};

const TxMessage = ({ key, msg, data, ind }) => {
const theme = useTheme();
const isLargeScreen = useMediaQuery(theme.breakpoints.up("md"));
const dispatch = useDispatch();
const fees = useSelector(state => state.blockchain.fees);
const status = useSelector(state => state.blockchain.status);
const storageData = useSelector(state => state.contact);
const activeThemeId = useSelector(state => state.activeThemeId);
const loadMoreValue = useSelector(state => state.txs.loadMore);
const { data: storeCodeData, loading: loadingStoreCode, error: storeCodeError, fetch: fetchStoreCode } = useGithubSource();
const value = msg;

const value = msg;
let type = msg["@type"] || "";
const { memo } = data;

useEffect(() => {
if (type === txTypes.COSMOS_SDK.STORE_CODE || type === txTypes.COSMOS_SDK_NEW_VERSION.STORE_CODE) {
const loadStoreCode = async () => {
Expand Down Expand Up @@ -309,17 +312,36 @@ const TxMessage = ({ key, msg, data, ind }) => {
} catch (error) {
messageParse = [{ error: rawLog }];
} finally {
const { events } = messageParse?.[0] || [];
return (
<InfoRow label='RawLog'>
<ReactJson
style={{ backgroundColor: "transparent" }}
name={false}
theme={activeThemeId === themeIds.DARK ? "monokai" : "rjv-default"}
displayObjectSize={false}
displayDataTypes={false}
collapsed={4}
src={messageParse}
/>
{!isLargeScreen ? (
<ReactJson
style={{ backgroundColor: "transparent" }}
name={false}
theme={activeThemeId === themeIds.DARK ? "monokai" : "rjv-default"}
displayObjectSize={false}
displayDataTypes={false}
collapsed={4}
src={messageParse}
/>
) : (
events.map(event => (
<div className={cx("event")}>
<h2 className={cx("event-type")}>{event.type}</h2>
<table className={cx("event-attribute")}>
<tbody>
{event.attributes.map(attr => (
<tr>
<td>{attr.key}</td>
<td>{ValueItem(attr.value)}</td>
</tr>
))}
</tbody>
</table>
</div>
))
)}
</InfoRow>
);
}
Expand Down Expand Up @@ -927,7 +949,7 @@ const TxMessage = ({ key, msg, data, ind }) => {
/>
</>
);
}, [type, value, storageData, activeThemeId, loadingStoreCode, status, storeCodeData, storeCodeError, memo, dispatch, data, loadMoreValue]);
}, [type, value, storageData, activeThemeId, loadingStoreCode, status, storeCodeData, storeCodeError, memo, dispatch, data, loadMoreValue, isLargeScreen]);
return (
<div className={cx("card")}>
<div>{messageDetails}</div>
Expand Down
77 changes: 67 additions & 10 deletions src/components/Tx/TxData/TxMessage/TxMessage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.header-cell {
color: var(--common-headerTextColor);
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: bold;
font-size: 14px;
Expand All @@ -11,7 +11,7 @@

.address-data-cell {
color: var(--common-linkColor);
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 14px;
Expand All @@ -20,7 +20,7 @@

.amount-data-cell {
.amount {
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 14px;
Expand Down Expand Up @@ -54,7 +54,7 @@
align-items: center;
padding: 8px 16px;
border-bottom: 1px solid var(--common-borderColor);
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 16px;
Expand All @@ -81,7 +81,7 @@
.title {
display: inline-block;
color: #00fff0;
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 16px;
Expand All @@ -93,7 +93,7 @@
flex-direction: row;
justify-content: flex-start;
align-items: center;
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 16px;
Expand All @@ -120,7 +120,7 @@

.text {
color: var(--common-textColor);
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 16px;
Expand All @@ -129,7 +129,7 @@

.text-three-dots {
color: var(--common-textColor);
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 16px;
Expand Down Expand Up @@ -219,9 +219,66 @@
border: 1px solid var(--common-activeTabColor);
box-sizing: border-box;
border-radius: 4px;
font-family: 'IBM Plex Sans';
font-family: "IBM Plex Sans";
font-style: normal;
font-weight: normal;
font-size: 13px;
}
}
}

.event {
margin-bottom: 20px;

&-type {
padding: 16px;
text-align: left;
font-weight: bold;
line-height: 150%;
vertical-align: inherit;
background: var(--common-themedTable-headerBackgroundColor);
border: 1px solid var(--common-themedTable-tableBorderColor);
color: var(--common-textColor);
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
&-attribute {
width: 100%;

tr {
td {
color: var(--common-textColor);
display: table-cell;
padding: 16px;
text-align: left;
font-weight: 400;
line-height: 150%;
vertical-align: inherit;
border: 1px solid var(--common-themedTable-tableBorderColor);

&:nth-child(odd) {
background: var(--common-themedTable-oddRowBackgroundColor);
}

&:nth-child(even) {
background: var(--common-themedTable-evenRowBackgroundColor);
}

a {
color: var(--common-linkColor);
}
}

&:last-of-type {
td {
&:first-of-type {
border-bottom-left-radius: 8px;
}

&:last-of-type {
border-bottom-right-radius: 8px;
}
}
}
}
}
}

0 comments on commit 9ce8d2c

Please sign in to comment.