Skip to content

Commit

Permalink
Merge pull request #498 from alleslabs/fix/schema-tab-and-url
Browse files Browse the repository at this point in the history
fix: automatically switch to schema tab and show 404 not found error
  • Loading branch information
poomthiti authored Aug 25, 2023
2 parents 800f39d + 5c9491b commit 2018c76
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 223 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#498](https://github.com/alleslabs/celatone-frontend/pull/498) Automatically switch to schema tab and show 404 not found error
- [#491](https://github.com/alleslabs/celatone-frontend/pull/491) Improve scrolling into view by delaying scroll function
- [#489](https://github.com/alleslabs/celatone-frontend/pull/489) Improve jsonschema query response UI and fix jsonschema incorrect oneOf behavior
- [#484](https://github.com/alleslabs/celatone-frontend/pull/484) Fix text size consistency in txs message
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/json-schema/UploadTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export const UploadTemplate = ({
return dispatchJsonState({
type: ActionType.SET_ERROR,
method,
error: response.statusText,
error:
response.status === 404 ? "404 Not Found" : response.statusText,
});
}
schemaString = JSON.stringify(await response.json());
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/json-schema/section/SchemaInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { AttachSchemaCard } from "../AttachSchemaCard";
import { JsonSchemaForm } from "../form";
import { JsonSchemaDrawer } from "../JsonSchemaDrawer";
import { ViewSchemaButton } from "../ViewSchemaButton";
import { useSchemaStore } from "lib/providers/store";
import type { CodeSchema } from "lib/stores/schema";
import type { Option } from "lib/types";

interface SchemaSectionProps {
type: "migrate" | "instantiate";
codeHash: string;
codeId: string;
jsonSchema: Option<CodeSchema>;
initialFormData?: Record<string, unknown>;
setSchemaInput: (input: string) => void;
}
Expand All @@ -22,11 +24,10 @@ export const SchemaInputSection = observer(
type,
codeHash,
codeId,
jsonSchema,
initialFormData,
setSchemaInput,
}: SchemaSectionProps) => {
const { getSchemaByCodeHash } = useSchemaStore();
const jsonSchema = getSchemaByCodeHash(codeHash);
const { isOpen, onClose, onOpen } = useDisclosure();
const prettyType = capitalize(type);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/home/components/DevShortcut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const shortcutList: ShortcutMetadata[] = [
{
title: "Deploy",
subtitle: "Upload code or instantiate contract",
slug: "/deploy",
slug: "deploy",
icon: "add-new",
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/lib/pages/instantiate/instantiate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import JsonInput from "lib/components/json/JsonInput";
import { CodeSelectSection } from "lib/components/select-code";
import { Stepper } from "lib/components/stepper";
import WasmPageContainer from "lib/components/WasmPageContainer";
import { useSchemaStore } from "lib/providers/store";
import { useTxBroadcast } from "lib/providers/tx-broadcast";
import {
AmpEvent,
Expand Down Expand Up @@ -91,7 +92,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => {
const { broadcast } = useTxBroadcast();
const { validateUserAddress, validateContractAddress } = useValidateAddress();
const getAttachFunds = useAttachFunds();

const { getSchemaByCodeHash } = useSchemaStore();
// ------------------------------------------//
// ------------------STATES------------------//
// ------------------------------------------//
Expand Down Expand Up @@ -139,6 +140,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => {
});
const { assetsSelect, assetsJsonStr, attachFundsOption } = watchAssets();

const jsonSchema = getSchemaByCodeHash(codeHash);
const funds = getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect);
const enableInstantiate = useMemo(
() =>
Expand Down Expand Up @@ -234,6 +236,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => {
useEffect(() => {
setValue("codeHash", "");
setTab(MessageTabs.JSON_INPUT);
setValue(`msgInput.${yourSchemaInputFormKey}`, "{}");
if (codeId.length) {
setStatus({ state: "loading" });
const timer = setTimeout(() => {
Expand Down Expand Up @@ -307,6 +310,10 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => {
}
}, [codeIdQuery, msgQuery, setAssets, setValue]);

useEffect(() => {
if (jsonSchema) setTab(MessageTabs.YOUR_SCHEMA);
}, [jsonSchema]);

useEffect(() => {
if (router.isReady) AmpTrackToInstantiate(!!msgQuery, !!codeIdQuery);
}, [router.isReady, msgQuery, codeIdQuery]);
Expand Down Expand Up @@ -400,6 +407,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => {
type="instantiate"
codeHash={codeHash}
codeId={codeId}
jsonSchema={jsonSchema}
setSchemaInput={(msg: string) =>
setValue(`msgInput.${yourSchemaInputFormKey}`, msg)
}
Expand Down
Loading

0 comments on commit 2018c76

Please sign in to comment.