From 5df06250b205c6698bd729d72c0dd4c60e11a7dc Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:02:50 +0700 Subject: [PATCH 1/2] feat: internal tx --- CHANGELOG.md | 1 + src/lib/app-fns/explorer/index.ts | 17 ----------------- src/lib/components/ExplorerLink.tsx | 11 ++++------- src/lib/components/modal/tx/ButtonSection.tsx | 9 ++------- src/lib/layout/Searchbar.tsx | 4 +++- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fafc1e783..b75cd83e0 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 +- [#224](https://github.com/alleslabs/celatone-frontend/pull/224) Support search by tx and internal tx link - [#214](https://github.com/alleslabs/celatone-frontend/pull/214) Show code permission helper text in save new code modal - [#218](https://github.com/alleslabs/celatone-frontend/pull/218) Add instantiated and admin contracts of an account - [#192](https://github.com/alleslabs/celatone-frontend/pull/192) Add alternative sidebar with only icons diff --git a/src/lib/app-fns/explorer/index.ts b/src/lib/app-fns/explorer/index.ts index bb367e179..ef1d7f42d 100644 --- a/src/lib/app-fns/explorer/index.ts +++ b/src/lib/app-fns/explorer/index.ts @@ -5,23 +5,6 @@ export const explorerMap: Record = { osmosistestnet: "https://testnet.mintscan.io/osmosis-testnet", }; -export const getExplorerTxUrl = (chainName: string) => { - let pathSuffix = ""; - switch (chainName) { - case "osmosis": - case "osmosistestnet": - pathSuffix = "txs"; - break; - case "terra2": - case "terra2testnet": - pathSuffix = "tx"; - break; - default: - break; - } - return `${explorerMap[chainName]}/${pathSuffix}`; -}; - export const getExplorerBlockUrl = (chainName: string) => { let pathSuffix = ""; switch (chainName) { diff --git a/src/lib/components/ExplorerLink.tsx b/src/lib/components/ExplorerLink.tsx index b82d9c812..541f2bb5a 100644 --- a/src/lib/components/ExplorerLink.tsx +++ b/src/lib/components/ExplorerLink.tsx @@ -2,11 +2,7 @@ import type { BoxProps } from "@chakra-ui/react"; import { Box, Text } from "@chakra-ui/react"; import { useWallet } from "@cosmos-kit/react"; -import { - getExplorerBlockUrl, - getExplorerTxUrl, - getProposalUrl, -} from "lib/app-fns/explorer"; +import { getExplorerBlockUrl, getProposalUrl } from "lib/app-fns/explorer"; import type { AddressReturnType } from "lib/hooks"; import { AmpTrackMintscan } from "lib/services/amplitude"; import { truncate } from "lib/utils"; @@ -39,7 +35,7 @@ const getNavigationUrl = ( let url = ""; switch (type) { case "tx_hash": - url = getExplorerTxUrl(currentChainName); + url = "/tx"; break; case "contract_address": url = "/contract"; @@ -138,7 +134,8 @@ export const ExplorerLink = ({ const isInternal = type === "code_id" || type === "contract_address" || - type === "user_address"; + type === "user_address" || + type === "tx_hash"; const [hrefLink, textValue] = [ getNavigationUrl(type, currentChainName, copyValue || value), diff --git a/src/lib/components/modal/tx/ButtonSection.tsx b/src/lib/components/modal/tx/ButtonSection.tsx index e661260c9..64454bc7e 100644 --- a/src/lib/components/modal/tx/ButtonSection.tsx +++ b/src/lib/components/modal/tx/ButtonSection.tsx @@ -1,12 +1,9 @@ import { Button, Icon } from "@chakra-ui/react"; -import { useWallet } from "@cosmos-kit/react"; import { useRouter } from "next/router"; import { useCallback } from "react"; import { FiChevronRight } from "react-icons/fi"; -import { getExplorerTxUrl } from "lib/app-fns/explorer"; import { useInternalNavigate } from "lib/app-provider"; -import { AmpTrackMintscan } from "lib/services/amplitude"; import type { ActionVariant, TxReceipt } from "lib/types"; // TODO: refactor props to pass param in txResultRendering instead of receipt @@ -23,18 +20,16 @@ export const ButtonSection = ({ }: ButtonSectionProps) => { const router = useRouter(); const navigate = useInternalNavigate(); - const { currentChainName } = useWallet(); const openExplorer = useCallback(() => { - AmpTrackMintscan("tx_hash"); const txHash = receipts.find((r) => r.title === "Tx Hash")?.value; window.open( - `${getExplorerTxUrl(currentChainName)}/${txHash}`, + `/${router.query.network}/tx/${txHash}`, "_blank", "noopener,noreferrer" ); onClose?.(); - }, [receipts, onClose, currentChainName]); + }, [receipts, router.query.network, onClose]); switch (actionVariant) { case "sending": diff --git a/src/lib/layout/Searchbar.tsx b/src/lib/layout/Searchbar.tsx index 70dab1ef7..aa611851f 100644 --- a/src/lib/layout/Searchbar.tsx +++ b/src/lib/layout/Searchbar.tsx @@ -44,6 +44,8 @@ const getRoute = (type: SearchResultType) => { return "/contract"; case "Wallet Address": return "/account"; + case "Transaction Hash": + return "/tx"; default: return null; } @@ -124,7 +126,7 @@ const Searchbar = () => { value={keyword} h="36px" onChange={handleSearchChange} - placeholder="Search by Wallet Address / Contract Address / Code ID" + placeholder="Search by Wallet Address / Contract Address / Code ID / Tx Hash" focusBorderColor="lilac.main" onFocus={() => setDisplayResults(keyword.length > 0)} onKeyDown={handleOnKeyEnter} From 943215de4ac40bd67c35400112eb67f98c777979 Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:19:48 +0700 Subject: [PATCH 2/2] fix: comment --- src/lib/components/modal/tx/ButtonSection.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/components/modal/tx/ButtonSection.tsx b/src/lib/components/modal/tx/ButtonSection.tsx index 64454bc7e..ea93aa1bd 100644 --- a/src/lib/components/modal/tx/ButtonSection.tsx +++ b/src/lib/components/modal/tx/ButtonSection.tsx @@ -1,9 +1,11 @@ import { Button, Icon } from "@chakra-ui/react"; +import { useWallet } from "@cosmos-kit/react"; import { useRouter } from "next/router"; import { useCallback } from "react"; import { FiChevronRight } from "react-icons/fi"; import { useInternalNavigate } from "lib/app-provider"; +import { getNetworkByChainName } from "lib/data"; import type { ActionVariant, TxReceipt } from "lib/types"; // TODO: refactor props to pass param in txResultRendering instead of receipt @@ -20,16 +22,17 @@ export const ButtonSection = ({ }: ButtonSectionProps) => { const router = useRouter(); const navigate = useInternalNavigate(); + const { currentChainName } = useWallet(); const openExplorer = useCallback(() => { const txHash = receipts.find((r) => r.title === "Tx Hash")?.value; window.open( - `/${router.query.network}/tx/${txHash}`, + `/${getNetworkByChainName(currentChainName)}/tx/${txHash}`, "_blank", "noopener,noreferrer" ); onClose?.(); - }, [receipts, router.query.network, onClose]); + }, [receipts, currentChainName, onClose]); switch (actionVariant) { case "sending":