From b6d19930c74dfe466134f22748bbb1c273ad30d6 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Tue, 9 Apr 2024 17:34:48 -0700 Subject: [PATCH] wip --- .../explore-endpoints/[[...pages]]/page.tsx | 2 + src/app/(sidebar)/transaction/sign/page.tsx | 37 +++----- src/constants/signTransactionPage.ts | 94 +++++++++++++++++++ src/helpers/trim.ts | 3 + src/types/types.ts | 10 ++ src/validate/methods/xdr.ts | 17 +++- 6 files changed, 134 insertions(+), 29 deletions(-) create mode 100644 src/constants/signTransactionPage.ts create mode 100644 src/helpers/trim.ts diff --git a/src/app/(sidebar)/explore-endpoints/[[...pages]]/page.tsx b/src/app/(sidebar)/explore-endpoints/[[...pages]]/page.tsx index 122b7171e..9cfbda135 100644 --- a/src/app/(sidebar)/explore-endpoints/[[...pages]]/page.tsx +++ b/src/app/(sidebar)/explore-endpoints/[[...pages]]/page.tsx @@ -46,6 +46,8 @@ export default function ExploreEndpoints() { .find((page) => pathname.includes(page.route)) ?.nestedItems?.find((i) => i.route === pathname); + console.log("page: ", page); + const pageData = page?.form; const requiredFields = sanitizeArray( pageData?.requiredParams?.split(",") || [], diff --git a/src/app/(sidebar)/transaction/sign/page.tsx b/src/app/(sidebar)/transaction/sign/page.tsx index 3a2d7454e..b322b0087 100644 --- a/src/app/(sidebar)/transaction/sign/page.tsx +++ b/src/app/(sidebar)/transaction/sign/page.tsx @@ -3,41 +3,30 @@ import { useState } from "react"; import { Alert, Card, Icon, Text, Button } from "@stellar/design-system"; -import { useStore } from "@/store/useStore"; - -import { ExpandBox } from "@/components/ExpandBox"; -import { PubKeyPicker } from "@/components/FormElements/PubKeyPicker"; -import { MuxedAccountResult } from "@/components/MuxedAccountResult"; -import { SdsLink } from "@/components/SdsLink"; - -import { muxedAccount } from "@/helpers/muxedAccount"; - import { XdrPicker } from "@/components/FormElements/XdrPicker"; - import { validate } from "@/validate"; -import { collapseTextChangeRangesAcrossMultipleVersions } from "typescript"; -import { unescape } from "querystring"; export default function SignTransaction() { const [txInput, setTxInput] = useState(""); const [isTxValid, setIsTxValid] = useState(undefined); - - const [muxedFieldError, setMuxedFieldError] = useState(""); - const [sdkError, setSdkError] = useState(""); + const [txError, setTxError] = useState(""); const onChange = (value: string) => { + setTxError(""); setTxInput(value); - const isValid = Boolean(validate.xdr(txInput)); - - console.log("**LOG** validate.xdr(txInput): ", validate.xdr(txInput)); - console.log("**LOG** isValid: ", isValid); + if (value.length > 0) { + const validatedXDR = validate.xdr(value); - setIsTxValid(isValid); + if (validatedXDR.result === "success") { + setIsTxValid(true); + } else if (validatedXDR.result === "error") { + setIsTxValid(false); + setTxError(validatedXDR.message); + } + } }; - console.log("**LOG** txInput: ", txInput); - return (
@@ -53,13 +42,13 @@ export default function SignTransaction() { } value={txInput || ""} - error={sdkError} + error={txError} onChange={(e) => onChange(e.target.value)} />