From 447bc4fc1b1e53eb024ac04567bee3e1a5e382bd Mon Sep 17 00:00:00 2001 From: Chris Hatch Date: Wed, 20 Sep 2023 00:19:07 +0700 Subject: [PATCH] restore routes: /asset/ /error/not-found/ /search/ improved error messages contracts fix --- app/lib/stellar/contracts.ts | 3 +- app/routes/account.$accountId.tsx | 2 +- app/routes/asset.$assetId.tsx | 31 +++++++ app/routes/assets.tsx | 101 +------------------- app/routes/contract.$contractId.tsx | 9 +- app/routes/error.not-found.$searchStr.tsx | 12 +++ app/routes/lib/assets-base.tsx | 108 ++++++++++++++++++++++ app/routes/search.$searchStr.tsx | 10 ++ 8 files changed, 175 insertions(+), 101 deletions(-) create mode 100644 app/routes/asset.$assetId.tsx create mode 100644 app/routes/error.not-found.$searchStr.tsx create mode 100644 app/routes/lib/assets-base.tsx create mode 100644 app/routes/search.$searchStr.tsx diff --git a/app/lib/stellar/contracts.ts b/app/lib/stellar/contracts.ts index 8bf945439..bf31e329b 100644 --- a/app/lib/stellar/contracts.ts +++ b/app/lib/stellar/contracts.ts @@ -50,10 +50,9 @@ const getContractInfo = async ( console.error(error) } - if (ledgerEntries == null || ledgerEntries.entries == null) { + if (ledgerEntries == null || ledgerEntries.entries == null || ledgerEntries.entries.length == 0) { return null } - const ledgerEntry = ledgerEntries.entries[0] const codeData = xdr.LedgerEntryData.fromXDR(ledgerEntry.xdr, 'base64') .contractData() diff --git a/app/routes/account.$accountId.tsx b/app/routes/account.$accountId.tsx index fb6e587a7..f3fc3a0a5 100644 --- a/app/routes/account.$accountId.tsx +++ b/app/routes/account.$accountId.tsx @@ -177,7 +177,7 @@ export const loader = async ({ params, request }: LoaderArgs) => { if (error instanceof NotFoundError) { throw new Response(null, { status: 404, - statusText: `Account [${params.accountId}] not found on this network.`, + statusText: `Account ${params.accountId} not found on this network.`, }) } else if (error instanceof AccountTypeUnrecognizedException) { throw new Response(null, { diff --git a/app/routes/asset.$assetId.tsx b/app/routes/asset.$assetId.tsx new file mode 100644 index 000000000..abe26d2f8 --- /dev/null +++ b/app/routes/asset.$assetId.tsx @@ -0,0 +1,31 @@ +import { useEffect } from "react" +import { json } from "@remix-run/node" +import { useLoaderData } from "@remix-run/react" + +import { setTitle } from "../lib/utils" +import { Assets } from "./lib/assets-base" + +import directory from "../data/directory" + +const { assets } = directory + +export const loader = ( + { params }: { params: { assetId: string } } +) => { + const matchingAssetKeys = Object.keys(assets).filter(k => k.startsWith(params.assetId)) + return json({ matchingAssetKeys }) +} + +export default function AssetsById() { + useEffect(() => { + setTitle("Assets") + }, []) + + const { + matchingAssetKeys, + }: { + matchingAssetKeys: Array + } = useLoaderData() + + return () +} \ No newline at end of file diff --git a/app/routes/assets.tsx b/app/routes/assets.tsx index 445782bab..334bad58b 100644 --- a/app/routes/assets.tsx +++ b/app/routes/assets.tsx @@ -1,107 +1,16 @@ -import Container from "react-bootstrap/Container" -import Card from "react-bootstrap/Card" -import CardHeader from "react-bootstrap/CardHeader" -import Row from "react-bootstrap/Row" -import Table from "react-bootstrap/Table" -import { FormattedMessage, useIntl } from "react-intl" -import { Link } from "react-router-dom" +import { useEffect } from "react" +import { Assets } from "./lib/assets-base" import { setTitle } from "../lib/utils" -import AccountLink from "../components/shared/AccountLink" -import BackendResourceBadgeButton from "../components/shared/BackendResourceBadgeButton" -import ClipboardCopy from "../components/shared/ClipboardCopy" -import Logo from "../components/shared/Logo" -import NewWindowIcon from "../components/shared/NewWindowIcon" import directory from "../data/directory" -import { TitleWithJSONButton } from "~/components/shared/TitleWithJSONButton" -import { useEffect } from "react" -const { anchors, assets } = directory - -const METADATA_URI = - "https://raw.githubusercontent.com/irisli/stellarterm/master/directory/directory.json" - -interface AssetProps { - code: string - issuer: string - domain: string -} -function Asset({ code, domain, issuer }: AssetProps) { - const anchor = anchors[domain] - return ( - - - - - - - {code} - - - - - -
- {anchor.name} -
- -
- -
- - - ) -}; +const { assets } = directory -export default function Assets() { - const { formatMessage } = useIntl() +export default function AssetsAll() { useEffect(() => { setTitle("Assets") }, []) - return ( - - - - - - - - - - - - - - - - - {Object.keys(assets).sort().map((key) => { - const asset = assets[key] - return - })} - -
- - - - - - -
-
-
-
-
- ) + return () } \ No newline at end of file diff --git a/app/routes/contract.$contractId.tsx b/app/routes/contract.$contractId.tsx index 58f3a280c..f2ab18b63 100644 --- a/app/routes/contract.$contractId.tsx +++ b/app/routes/contract.$contractId.tsx @@ -1,7 +1,7 @@ import { Link } from 'react-router-dom' import { FormattedMessage, useIntl } from 'react-intl' import { LoaderArgs, json } from '@remix-run/node' -import { NavLink, Outlet, useLoaderData, useLocation } from '@remix-run/react' +import { NavLink, Outlet, useLoaderData, useLocation, useParams } from '@remix-run/react' import Container from 'react-bootstrap/Container' import Card from 'react-bootstrap/Card' @@ -63,13 +63,18 @@ export default function () { const [activeTab, setActiveTab] = useState('storage') const { pathname } = useLocation() const { contractDetails } = useLoaderData() + const { contractId } = useParams() useEffect(() => { setActiveTab(pathToTabName(pathname)) }, [pathname]) if (!contractDetails) { - return (Not Found) + return ( + + Contract {contractId} not found + + ) } const { diff --git a/app/routes/error.not-found.$searchStr.tsx b/app/routes/error.not-found.$searchStr.tsx new file mode 100644 index 000000000..ca07e7c59 --- /dev/null +++ b/app/routes/error.not-found.$searchStr.tsx @@ -0,0 +1,12 @@ +import Container from "react-bootstrap/Container" +import { useParams } from "@remix-run/react" +import { FormattedMessage } from "react-intl" + +export default function SearchNotFound() { + const { searchStr } = useParams() + return ( + + + + ) +} diff --git a/app/routes/lib/assets-base.tsx b/app/routes/lib/assets-base.tsx new file mode 100644 index 000000000..1a95ff1e4 --- /dev/null +++ b/app/routes/lib/assets-base.tsx @@ -0,0 +1,108 @@ +import { useEffect } from "react" +import Container from "react-bootstrap/Container" +import Card from "react-bootstrap/Card" +import CardHeader from "react-bootstrap/CardHeader" +import Row from "react-bootstrap/Row" +import Table from "react-bootstrap/Table" +import { FormattedMessage, useIntl } from "react-intl" +import { Link } from "react-router-dom" + +import { setTitle } from "../../lib/utils" +import AccountLink from "../../components/shared/AccountLink" +import BackendResourceBadgeButton from "../../components/shared/BackendResourceBadgeButton" +import ClipboardCopy from "../../components/shared/ClipboardCopy" +import Logo from "../../components/shared/Logo" +import NewWindowIcon from "../../components/shared/NewWindowIcon" +import { TitleWithJSONButton } from "~/components/shared/TitleWithJSONButton" + +import directory from "../../data/directory" + +const { anchors, assets } = directory + +export const METADATA_URI = + "https://raw.githubusercontent.com/irisli/stellarterm/master/directory/directory.json" + +export interface AssetProps { + code: string + issuer: string + domain: string +} + +export function Asset({ code, domain, issuer }: AssetProps) { + const anchor = anchors[domain] + return ( + + + + + + + {code} + + + + + +
+ {anchor.name} +
+ +
+ +
+ + + ) +}; + +export function Assets({ assetKeys }: { assetKeys: Array }) { + const { formatMessage } = useIntl() + useEffect(() => { + setTitle("Assets") + }, []) + + return ( + + + + + + + + + + + + + + + + + {assetKeys.sort().map((key) => { + const asset = assets[key] + return + })} + +
+ + + + + + +
+
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/routes/search.$searchStr.tsx b/app/routes/search.$searchStr.tsx new file mode 100644 index 000000000..f5e1cbe90 --- /dev/null +++ b/app/routes/search.$searchStr.tsx @@ -0,0 +1,10 @@ +import { redirect } from "@remix-run/node" +import { searchStrToPath } from "~/lib/search" + + +export const loader = async ( + { params }: { params: { searchStr: string } } +) => { + const matchPath = searchStrToPath(params.searchStr) + return redirect(matchPath as string) +}