From f2bed0139e01b51b9518a26d3c1d89f5b2c46a77 Mon Sep 17 00:00:00 2001 From: poomthiti Date: Fri, 6 Jan 2023 16:18:31 +0700 Subject: [PATCH 1/3] refactor: rewrite past txs link --- src/lib/components/ExplorerLink.tsx | 8 ++- .../pages/pastTxs/components/MsgDetail.tsx | 51 ++++++++++++++----- .../pages/pastTxs/components/PastTxTable.tsx | 44 ++++++++++++---- .../pages/pastTxs/components/SingleMsg.tsx | 50 +++++++++--------- 4 files changed, 100 insertions(+), 53 deletions(-) diff --git a/src/lib/components/ExplorerLink.tsx b/src/lib/components/ExplorerLink.tsx index a81af7780..9ec294aeb 100644 --- a/src/lib/components/ExplorerLink.tsx +++ b/src/lib/components/ExplorerLink.tsx @@ -11,9 +11,15 @@ import { truncate } from "lib/utils"; import { Copier } from "./Copier"; +export type LinkType = + | "tx_hash" + | "user_address" + | "contract_address" + | "code_id"; + interface ExplorerLinkProps extends BoxProps { value: string; - type?: "tx_hash" | "user_address" | "contract_address" | "code_id"; + type?: LinkType; copyValue?: string; canCopyWithHover?: boolean; isReadOnly?: boolean; diff --git a/src/lib/pages/pastTxs/components/MsgDetail.tsx b/src/lib/pages/pastTxs/components/MsgDetail.tsx index d050967cd..b36d47508 100644 --- a/src/lib/pages/pastTxs/components/MsgDetail.tsx +++ b/src/lib/pages/pastTxs/components/MsgDetail.tsx @@ -35,7 +35,7 @@ interface MsgDetailProps { success: boolean; } -const MsgDetail = ({ msg, success }: MsgDetailProps) => { +export const MsgDetail = ({ msg, success }: MsgDetailProps) => { const [button, setButton] = useState<"redo" | "resend" | "">(""); const [showButton, setShowButton] = useState(false); const { currentChainName } = useWallet(); @@ -56,14 +56,20 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { type: "Execute", tags: [Object.keys(detailExecute.msg)[0]], text2: "on", - link1: contractInfo?.name || detailExecute.contract, - link1Copy: detailExecute.contract, + link1: { + type: "contract_address", + value: contractInfo?.name || detailExecute.contract, + copyValue: detailExecute.contract, + }, } : { type: "Failed", text1: "to execute message from", - link1: contractInfo?.name || detailExecute.contract, - link1Copy: detailExecute.contract, + link1: { + type: "contract_address", + value: contractInfo?.name || detailExecute.contract, + copyValue: detailExecute.contract, + }, }; return ; } @@ -76,7 +82,10 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { ? { type: "Upload", text1: "Wasm to Code ID", - text3: msgUpload.id?.toString(), + link1: { + type: "code_id", + value: msgUpload.id?.toString(), + }, } : { type: "Failed", @@ -95,7 +104,10 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { ); } @@ -104,9 +116,16 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { ); } @@ -130,7 +149,10 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { ); } @@ -139,7 +161,10 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { type="Send" bolds={coins} text2="to" - link2={msgSend.toAddress} + link2={{ + type: "contract_address", + value: msgSend.toAddress, + }} /> ); } @@ -267,5 +292,3 @@ const MsgDetail = ({ msg, success }: MsgDetailProps) => { ); }; - -export default MsgDetail; diff --git a/src/lib/pages/pastTxs/components/PastTxTable.tsx b/src/lib/pages/pastTxs/components/PastTxTable.tsx index fa7e7a6f5..c25c418d2 100644 --- a/src/lib/pages/pastTxs/components/PastTxTable.tsx +++ b/src/lib/pages/pastTxs/components/PastTxTable.tsx @@ -46,7 +46,7 @@ import { onClickRedo, } from "lib/utils"; -import MsgDetail from "./MsgDetail"; +import { MsgDetail } from "./MsgDetail"; import type { MultipleMsgProps } from "./MultipleMsg"; import { MultipleMsg } from "./MultipleMsg"; import type { SingleMsgProps } from "./SingleMsg"; @@ -133,7 +133,10 @@ const PastTxTable = ({ element }: PastTxTableProps) => { ? { type: "Upload", text1: "Wasm to Code ID", - text3: uploadMsgs[0].id.toString(), + link1: { + type: "code_id", + value: uploadMsgs[0].id.toString(), + }, } : { type: "Failed", @@ -177,14 +180,24 @@ const PastTxTable = ({ element }: PastTxTableProps) => { ? { type: "Instantiate", text1: "contract", - link1: contractInfo?.name || instantiateMsgs[0].contractAddress, - link1Copy: instantiateMsgs[0].contractAddress, - text3: `from Code ID ${instantiateMsgs[0].codeId.toString()}`, + link1: { + type: "contract_address", + value: contractInfo?.name || instantiateMsgs[0].contractAddress, + copyValue: instantiateMsgs[0].contractAddress, + }, + text3: "from Code ID", + link2: { + type: "code_id", + value: instantiateMsgs[0].codeId.toString(), + }, } : { type: "Failed", text1: "to instantiate contract from Code ID", - text3: instantiateMsgs[0].codeId.toString(), + link1: { + type: "code_id", + value: instantiateMsgs[0].codeId.toString(), + }, }; return ; }, @@ -238,14 +251,20 @@ const PastTxTable = ({ element }: PastTxTableProps) => { tags, length: executeMsgs.length, text2: "on", - link1: contractInfo?.name || executeMsgs[0].contract, - link1Copy: executeMsgs[0].contract, + link1: { + type: "contract_address", + value: contractInfo?.name || executeMsgs[0].contract, + copyValue: executeMsgs[0].contract, + }, } : { type: "Failed", text1: "to execute message from", - link1: contractInfo?.name || executeMsgs[0].contract, - link1Copy: executeMsgs[0].contract, + link1: { + type: "contract_address", + value: contractInfo?.name || executeMsgs[0].contract, + copyValue: executeMsgs[0].contract, + }, }; return ; }, @@ -294,7 +313,10 @@ const PastTxTable = ({ element }: PastTxTableProps) => { type="Send" bolds={coins} text2="to" - link1={sendMsgs[0].toAddress} + link1={{ + type: "contract_address", + value: sendMsgs[0].toAddress, + }} /> ); }, diff --git a/src/lib/pages/pastTxs/components/SingleMsg.tsx b/src/lib/pages/pastTxs/components/SingleMsg.tsx index 6084d9d2b..7ea6541a7 100644 --- a/src/lib/pages/pastTxs/components/SingleMsg.tsx +++ b/src/lib/pages/pastTxs/components/SingleMsg.tsx @@ -1,8 +1,15 @@ import { Tag, Text, Box, Flex } from "@chakra-ui/react"; import { snakeCase } from "snake-case"; +import type { LinkType } from "lib/components/ExplorerLink"; import { ExplorerLink } from "lib/components/ExplorerLink"; +interface LinkElement { + type: LinkType; + value: string; + copyValue?: string; +} + export interface SingleMsgProps { type: string; text1?: string; @@ -10,11 +17,9 @@ export interface SingleMsgProps { tags?: Array; length?: number; text2?: string; - link1?: string; - // TODO - Change this - link1Copy?: string; + link1?: LinkElement; text3?: string; - link2?: string; + link2?: LinkElement; } export const SingleMsg = ({ @@ -25,22 +30,9 @@ export const SingleMsg = ({ length, text2, link1, - link1Copy, text3, link2, }: SingleMsgProps) => { - const linkType = (text: string) => { - if (text.length === 63) { - return "contract_address"; - } - if (text.length === 64) { - return "tx_hash"; - } - if (text.length === 43) { - return "user_address"; - } - return undefined; - }; return ( {type} {text1} @@ -66,28 +58,32 @@ export const SingleMsg = ({ )} {/* Length */} {!tags && length && {length}} - {/* Link */} + {/* Text2 */} {text2} + {/* Link */} {link1 && ( )} - {/* Text3 */} {text3} {/* Link with copy */} + {/* Text3 */} + {text3} + {/* Link2 */} {link2 && ( - )}{" "} + )} ); }; From 38eacb618de695c078a693b3cda56d2cbc4e6b0d Mon Sep 17 00:00:00 2001 From: poomthiti Date: Fri, 6 Jan 2023 16:27:55 +0700 Subject: [PATCH 2/3] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b82d0ad5f..eda20ba2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- [#68](https://github.com/alleslabs/celatone-frontend/pull/63) Refactor past txs link props and make sure navigation works - [#63](https://github.com/alleslabs/celatone-frontend/pull/63) Add code id explorer link and code table row navigation - [#60](https://github.com/alleslabs/celatone-frontend/pull/60) Add navigation to contract row - [#47](https://github.com/alleslabs/celatone-frontend/pull/47) Wireup init msg in contract details page From a03f9595744108118ea962da5f893e2cfc554dec Mon Sep 17 00:00:00 2001 From: poomthiti Date: Thu, 12 Jan 2023 10:28:03 +0700 Subject: [PATCH 3/3] fix: as commented --- src/lib/pages/pastTxs/components/SingleMsg.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/pages/pastTxs/components/SingleMsg.tsx b/src/lib/pages/pastTxs/components/SingleMsg.tsx index 7ea6541a7..d00dc66bb 100644 --- a/src/lib/pages/pastTxs/components/SingleMsg.tsx +++ b/src/lib/pages/pastTxs/components/SingleMsg.tsx @@ -68,7 +68,7 @@ export const SingleMsg = ({ type={link1.type} canCopyWithHover // Should ellipse when it is not tx hash, contract addr, user addr - textFormat={link1.type !== "code_id" ? "truncate" : "ellipsis"} + textFormat={link1.type !== "code_id" ? "truncate" : "normal"} /> )} {/* Text3 */} @@ -81,7 +81,7 @@ export const SingleMsg = ({ type={link2.type} canCopyWithHover // Should ellipse when it is not tx hash, contract addr, user addr - textFormat={link2.type !== "code_id" ? "truncate" : "ellipsis"} + textFormat={link2.type !== "code_id" ? "truncate" : "normal"} /> )}