Skip to content

Commit

Permalink
break out array, and truncate long param values (#1799)
Browse files Browse the repository at this point in the history
* break out array, and truncate long param values

* improved readability

* more improved readability

* more on readability

* remove spaces
  • Loading branch information
dkent600 authored Jun 4, 2020
1 parent 1f1da9d commit 4b9ee29
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alchemy-client",
"version": "0.10.9",
"version": "0.10.9-1",
"description": "An app for collaborative networks (DAOs), based on the DAO stack.",
"author": "DAOstack",
"license": "GPL-3.0",
Expand Down
15 changes: 10 additions & 5 deletions src/components/Proposal/ProposalSummary/ProposalSummary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@
color: rgba(78, 97, 118, 1);
font-weight: normal;
vertical-align: top;
}

img {
margin-left: 5px;
position: relative;
top: 1px;
}
th img,
img.copyToClipboard {
margin-left: 5px;
position: relative;
top: 1px;
}

pre .arrayItem {
margin-left: 8px;
}

td {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { IDAOState, IProposalState } from "@daostack/arc.js";
import classNames from "classnames";
import { GenericSchemeInfo } from "genericSchemeRegistry";
import { linkToEtherScan, formatTokens } from "lib/util";
import { linkToEtherScan, formatTokens, truncateWithEllipses, copyToClipboard } from "lib/util";
import * as React from "react";
import { IProfileState } from "reducers/profilesReducer";
import * as css from "./ProposalSummary.scss";
import ProposalSummaryDutchX from "./ProposalSummaryDutchX";
import ProposalSummaryStandardBounties from "./ProposalSummaryStandardBounties";
import ProposalSummaryCO2ken from "./ProposalSummaryCO2ken";
import { NotificationStatus, showNotification } from "reducers/notifications";
import { connect } from "react-redux";

interface IProps {
interface IDispatchProps {
showNotification: typeof showNotification;
}

const mapDispatchToProps = {
showNotification,
};

interface IExternalProps {
beneficiaryProfile?: IProfileState;
detailView?: boolean;
dao: IDAOState;
Expand All @@ -18,15 +28,39 @@ interface IProps {
genericSchemeInfo: GenericSchemeInfo;
}

export default class ProposalSummary extends React.Component<IProps> {
type IProps = IExternalProps & IDispatchProps;

class ProposalSummary extends React.Component<IProps> {

private copyToClipboard = (str: string) => (e: any): void => {
const { showNotification } = this.props;
copyToClipboard(str);
showNotification(NotificationStatus.Success, "Copied to clipboard!");
e.preventDefault();
}

constructor(props: IProps) {
super(props);
}

private inputHtml = (x: any) => <span key={x.name}>{x.name} {x.type}, </span>;
private callDataHtml = (value: any) => <div key={value}>{value}</div>;
private callDataHtml = (value: any, isArrayItem = false) => {
if (value?.length > 66) {

value = truncateWithEllipses(value, 66);

return <div
className={isArrayItem ? css.arrayItem : ""}
key={value}
>{value}<img className={css.copyToClipboard}
onClick={this.copyToClipboard(value)}
src="/assets/images/Icon/Copy-blue.svg" />{isArrayItem ? "," : ""}
</div>;

} else {
return <div className={isArrayItem ? css.arrayItem : ""} key={value}>{value}{isArrayItem ? "," : ""}</div>;
}
}

public render(): RenderOutput {
const { proposal, detailView, transactionModal, genericSchemeInfo } = this.props;
Expand Down Expand Up @@ -85,7 +119,20 @@ export default class ProposalSummary extends React.Component<IProps> {
<pre>{ decodedCallData.action.abi.name}
({ decodedCallData.action.abi.inputs.map(this.inputHtml) })
</pre>
with values: <pre>{ decodedCallData.values.map(this.callDataHtml)}</pre>
with values: <pre>{
decodedCallData.values.map((value: string | Array<string>) =>
{
if (value instanceof Array) {
return <>
<span>[</span>
{ value.map((value: string) => this.callDataHtml(value, true)) }
<span>]</span>
</>;
} else {
return this.callDataHtml(value);
}
})}
</pre>
on contract at:
<pre><a href={linkToEtherScan(proposal.genericScheme.contractToCall)}>{proposal.genericScheme.contractToCall}</a></pre>
sending to contract:
Expand All @@ -96,3 +143,5 @@ export default class ProposalSummary extends React.Component<IProps> {
</div>;
}
}

export default connect(null, mapDispatchToProps)(ProposalSummary);

0 comments on commit 4b9ee29

Please sign in to comment.