Skip to content

Commit

Permalink
Merge pull request #438 from trilitech/add-js-value-wrap
Browse files Browse the repository at this point in the history
Add JsValueWrap component
  • Loading branch information
ryutamago authored Sep 13, 2023
2 parents ea39150 + 7df8d4f commit 6717de7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import {
AccordionItem,
AccordionPanel,
Box,
Card,
CardBody,
} from "@chakra-ui/react";
import { parseRawMichelson } from "../../../../multisig/decode/decodeLambda";
import { UnrecognizedMichelsonError } from "../../../../multisig/decode/UnrecognizedMichelsonError";
import { MultisigAccount } from "../../../../types/Account";
import MultisigDecodedOperationItem from "./MultisigDecodedOperationItem";
import JsValueWrap from "../../JsValueWrap";

const MultisigDecodedOperations: React.FC<{
rawActions: string;
Expand Down Expand Up @@ -51,17 +50,7 @@ const UnrecognizedOperationAccordion: React.FC<{ unrecoginizedRawActions: string
</AccordionButton>
</h2>
<AccordionPanel pb={3} h="400px" overflowY="scroll">
<Card bg="umami.gray.700" borderRadius="5px">
<pre
style={{
whiteSpace: "pre-wrap",
fontSize: "12px",
lineHeight: "18px",
}}
>
<CardBody>{JSON.stringify(JSON.parse(unrecoginizedRawActions), null, 1)}</CardBody>
</pre>
</Card>
<JsValueWrap value={JSON.parse(unrecoginizedRawActions)} space={1} />
</AccordionPanel>
</AccordionItem>
</Accordion>
Expand Down
23 changes: 23 additions & 0 deletions src/components/AccountDrawer/JsValueWrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Card, CardBody } from "@chakra-ui/react";
import colors from "../../style/colors";

// Wrapper for any JavaScript value
const JsValueWrap: React.FC<{ value: any; space?: number }> = ({ value, space = 2 }) => {
return (
<Card bg={colors.gray[700]} borderRadius="5px">
<CardBody>
<pre
style={{
whiteSpace: "pre-wrap",
fontSize: "12px",
lineHeight: "18px",
}}
>
{JSON.stringify(value, null, space)}
</pre>
</CardBody>
</Card>
);
};

export default JsValueWrap;
15 changes: 2 additions & 13 deletions src/views/nfts/NFTDrawerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useContext } from "react";
import SendNFTForm from "../../components/SendFlow/NFT/FormPage";
import { useGetOwnedAccount } from "../../utils/hooks/accountHooks";
import { artifactUri } from "../../types/Token";
import JsValueWrap from "../../components/AccountDrawer/JsValueWrap";

const NFTDrawerCard = ({ nft, ownerPkh }: { nft: NFTBalance; ownerPkh: RawPkh }) => {
const url = getIPFSurl(artifactUri(nft));
Expand Down Expand Up @@ -97,19 +98,7 @@ const NFTDrawerCard = ({ nft, ownerPkh }: { nft: NFTBalance; ownerPkh: RawPkh })
</AccordionButton>
</h2>
<AccordionPanel>
<Card bg="umami.gray.700" borderRadius="5px">
<CardBody>
<pre
style={{
whiteSpace: "pre-wrap",
fontSize: "12px",
lineHeight: "18px",
}}
>
{JSON.stringify(nft, null, 2)}
</pre>
</CardBody>
</Card>
<JsValueWrap value={nft} />
</AccordionPanel>
</AccordionItem>
</Accordion>
Expand Down

0 comments on commit 6717de7

Please sign in to comment.