Skip to content

Commit

Permalink
Merge pull request #547 from alleslabs/fix/refetch-module
Browse files Browse the repository at this point in the history
Fix/abi form
  • Loading branch information
evilpeach committed Sep 27, 2023
2 parents 5c5d429 + 745878b commit 4d0eafe
Show file tree
Hide file tree
Showing 55 changed files with 207 additions and 155 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#547](https://github.com/alleslabs/celatone-frontend/pull/547) Fix form null and sort modules when submit an address
- [#543](https://github.com/alleslabs/celatone-frontend/pull/543) Fix Initia testnet chain config
- [#539](https://github.com/alleslabs/celatone-frontend/pull/539) Fix JSON schema upload text
- [#527](https://github.com/alleslabs/celatone-frontend/pull/527) Fix ellipsis explorer link
Expand Down
6 changes: 3 additions & 3 deletions src/lib/app-fns/tx/submitProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Observable } from "rxjs";
import type { CatchTxError } from "lib/app-provider/tx/catchTxError";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { CustomIcon } from "lib/components/icon";
import type { HumanAddr, TxResultRendering } from "lib/types";
import type { HumanAddr, Nullable, TxResultRendering } from "lib/types";
import { TxStreamPhase } from "lib/types";
import { findAttr, formatUFee } from "lib/utils";

Expand All @@ -20,7 +20,7 @@ interface SubmitWhitelistProposalTxParams {
fee: StdFee;
messages: EncodeObject[];
whitelistNumber: number;
amountToVote: string | null;
amountToVote: Nullable<string>;
catchTxError: CatchTxError;
onTxSucceed?: () => void;
onTxFailed?: () => void;
Expand Down Expand Up @@ -109,7 +109,7 @@ interface SubmitStoreCodeProposalTxParams {
chainName: string;
wasmFileName: string;
messages: EncodeObject[];
amountToVote: string | null;
amountToVote: Nullable<string>;
catchTxError: CatchTxError;
onTxSucceed?: () => void;
onTxFailed?: () => void;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/app-provider/contexts/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { useContext, createContext, useMemo } from "react";
import { usePreviousPathname } from "../hooks/usePreviousPathname";
import { StorageKeys } from "lib/data";
import { useLocalStorage } from "lib/hooks/useLocalStorage";
import type { Nullable } from "lib/types";

interface NavContextInterface {
isExpand: boolean;
prevPathname: string | null;
prevPathname: Nullable<string>;
setIsExpand: Dispatch<SetStateAction<boolean>>;
}
const NavContext = createContext<NavContextInterface>({
Expand Down
4 changes: 3 additions & 1 deletion src/lib/app-provider/hooks/usePreviousPathname.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useRouter } from "next/router";
import { useEffect, useRef } from "react";

import type { Nullable } from "lib/types";

export const usePreviousPathname = () => {
const { pathname } = useRouter();

const ref = useRef<string | null>(null);
const ref = useRef<Nullable<string>>(null);

useEffect(() => {
ref.current = pathname;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/app-provider/tx/submitProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
submitStoreCodeProposalTx,
submitWhitelistProposalTx,
} from "lib/app-fns/tx/submitProposal";
import type { HumanAddr } from "lib/types";
import type { HumanAddr, Nullable } from "lib/types";

import { useCatchTxError } from "./catchTxError";

export interface SubmitWhitelistProposalStreamParams {
estimatedFee?: StdFee;
messages: EncodeObject[];
whitelistNumber: number;
amountToVote: string | null;
amountToVote: Nullable<string>;
onTxSucceed?: () => void;
onTxFailed?: () => void;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export const useSubmitWhitelistProposalTx = () => {
interface SubmitStoreCodeProposalStreamParams {
wasmFileName: string;
messages: EncodeObject[];
amountToVote: string | null;
amountToVote: Nullable<string>;
estimatedFee?: StdFee;
onTxSucceed?: () => void;
onTxFailed?: () => void;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/ValidatorBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { useMobile } from "lib/app-provider";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { MobileLabel } from "lib/pages/account-details/components/mobile/MobileLabel";
import { useValidatorImage } from "lib/services/validatorService";
import type { ValidatorInfo } from "lib/types";
import type { Nullable, ValidatorInfo } from "lib/types";

interface ValidatorBadgeProps {
validator: ValidatorInfo | null;
validator: Nullable<ValidatorInfo>;
badgeSize?: ImageProps["boxSize"];
ampCopierSection?: string;
maxWidth?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/abi/args-form/field/ArgFieldWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Input, Textarea } from "@chakra-ui/react";
import { Select } from "chakra-react-select";
import type { ControllerRenderProps } from "react-hook-form";

import type { Option } from "lib/types";
import type { Nullable } from "lib/types";

import { UintTypes } from "./utils";

Expand All @@ -19,7 +19,7 @@ const boolOptions = [

interface ArgFieldWidgetProps {
type: string;
value: Option<string>;
value: Nullable<string>;
onChange: ControllerRenderProps["onChange"];
}

Expand All @@ -36,7 +36,7 @@ export const ArgFieldWidget = ({
return (
<Input
size="md"
placeholder={getInputPlaceholder(type, value === undefined)}
placeholder={getInputPlaceholder(type, value === null)}
value={value ?? ""}
onChange={onChange}
/>
Expand Down
9 changes: 6 additions & 3 deletions src/lib/components/abi/args-form/field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const ArgFieldTemplate = ({
const isError = isTouched && !!error;

const size = "md";
const isNull = value === undefined;
const isNull = value === null;
return (
<Box>
<FormControl
Expand Down Expand Up @@ -85,8 +85,11 @@ export const ArgFieldTemplate = ({
<Checkbox
pt="2px"
pl={2}
isChecked={value === undefined}
onChange={(e) => onChange(e.target.checked ? undefined : "")}
isChecked={isNull}
onChange={(e) => {
const newValue = e.target.checked;
onChange(newValue ? null : "");
}}
>
<Text variant="body3">Send as null</Text>
</Checkbox>
Expand Down
17 changes: 11 additions & 6 deletions src/lib/components/abi/args-form/field/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ const validateUint = (uintType: string) => (v: string) => {
: `Input must be ‘${uintType}’`;
};
const validateBool = (v: string) =>
v === "true" || v === "false" ? undefined : "Input must be ‘boolean’";
v.toLowerCase() === "true" || v.toLowerCase() === "false"
? undefined
: "Input must be ‘boolean’";

const validateAddress =
(isValidArgAddress: (input: string) => boolean) => (v: string) =>
isValidArgAddress(v) ? undefined : "invalid address";
isValidArgAddress(v) ? undefined : "Invalid address";

const validateVector = (
v: string,
Expand All @@ -44,10 +46,13 @@ const validateVector = (
// TODO: handle Vector?

let error: Option<string>;
value.split(",").forEach((elementValue) => {
const res = validateElement(elementValue);
if (res !== undefined) error = `invalid element: ${res}`;
});
value
.slice(1, -1)
.split(",")
.forEach((elementValue) => {
const res = validateElement(elementValue.trim());
if (res !== undefined) error = `Invalid element: ${res}`;
});

return error;
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/abi/args-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect } from "react";
import type { FormState } from "react-hook-form";
import { useForm } from "react-hook-form";

import type { AbiFormData, Option } from "lib/types";
import type { AbiFormData, Nullable } from "lib/types";

import { ArgFieldTemplate } from "./field";

Expand Down Expand Up @@ -33,7 +33,7 @@ export const ArgsForm = ({
control,
getValues,
formState: { errors },
} = useForm<Record<string, Option<string>>>({
} = useForm<Record<string, Nullable<string>>>({
defaultValues: initialData,
mode: "all",
});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/forms/FormStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Spinner, Text } from "@chakra-ui/react";

import { CustomIcon } from "../icon";
import type { Nullable } from "lib/types";

export type ResponseState = "init" | "loading" | "success" | "error";

export interface FormStatus {
state: ResponseState;
message?: string | null;
message?: Nullable<string>;
messageColor?: string;
}

Expand Down
10 changes: 7 additions & 3 deletions src/lib/components/json-schema/UploadTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TextInput } from "lib/components/forms";
import JsonInput from "lib/components/json/JsonInput";
import { UploadCard } from "lib/components/upload/UploadCard";
import { useSchemaStore } from "lib/providers/store";
import type { Nullable } from "lib/types";
import { jsonValidate } from "lib/utils";

enum Method {
Expand All @@ -26,7 +27,10 @@ enum Method {
FILL_MANUALLY = "fill-manually",
}

type JsonState = Record<Method, { schemaString: string; error: string | null }>;
type JsonState = Record<
Method,
{ schemaString: string; error: Nullable<string> }
>;

enum ActionType {
SET_SCHEMA = "set-schema",
Expand All @@ -38,7 +42,7 @@ type Action = {
type: ActionType;
method: Method;
schemaString?: string;
error?: string | null;
error?: Nullable<string>;
};

const initialJsonState: JsonState = {
Expand Down Expand Up @@ -68,7 +72,7 @@ const reducer = (state: JsonState, action: Action): JsonState => {
}
};

const validateSchema = (schemaString: string): string | null => {
const validateSchema = (schemaString: string): Nullable<string> => {
return (
jsonValidate(schemaString) ??
("instantiate" in JSON.parse(schemaString)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/json-schema/view/ViewSchemaPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Flex, Text } from "@chakra-ui/react";

import { CustomIcon } from "lib/components/icon";
import JsonReadOnly from "lib/components/json/JsonReadOnly";
import type { Option } from "lib/types";
import type { Nullable, Option } from "lib/types";
import { jsonPrettify } from "lib/utils";

interface ViewSchemaPanelProps {
jsonSchema: Option<object | null>;
jsonSchema: Option<Nullable<object>>;
codeId: string;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/json/JsonInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dynamic from "next/dynamic";
import { useState, useEffect, useMemo } from "react";

import { CustomIcon } from "../icon";
import type { Nullable } from "lib/types";
import { jsonLineCount, jsonPrettify, jsonValidate } from "lib/utils";

const JsonEditor = dynamic(() => import("./JsonEditor"), {
Expand All @@ -15,7 +16,7 @@ interface JsonInputProps {
minLines?: number;
maxLines?: number;
setText: (value: string) => void;
validateFn?: (value: string) => string | null;
validateFn?: (value: string) => Nullable<string>;
}

interface JsonState {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/upload/UploadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Flex, Text } from "@chakra-ui/react";
import big from "big.js";

import { CustomIcon, UploadIcon } from "lib/components/icon";
import type { Option } from "lib/types";
import type { Nullable, Option } from "lib/types";

type CardTheme = "primary" | "secondary";

Expand All @@ -13,7 +13,7 @@ interface UploadCardProps {
deleteFile: () => void;
theme?: CardTheme;
status?: Status;
statusText?: string | null;
statusText?: Nullable<string>;
}

const getTheme = (theme: CardTheme) => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/layout/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
SearchResultType,
} from "lib/services/searchService";
import { useSearchHandler } from "lib/services/searchService";
import type { Option } from "lib/types";
import type { Nullable, Option } from "lib/types";

const NOT_FOUND_MSG =
"Matches not found. Please check your spelling or make sure you have selected the correct network.";
Expand All @@ -60,7 +60,7 @@ interface ResultItemProps {

const getRouteOptions = (
type: Option<SearchResultType>
): { pathname: string; query: string } | null => {
): Nullable<{ pathname: string; query: string }> => {
switch (type) {
case "Wallet Address":
return {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/model/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
} from "lib/services/contractService";
import { useProposalsCountByWalletAddress } from "lib/services/proposalService";
import { useTxsCountByAddress } from "lib/services/txService";
import type { HumanAddr, Option } from "lib/types";
import type { HumanAddr, Nullable, Option } from "lib/types";

/**
* @remark
* Counts for stored codes, contract admin, contract instances, transactions, and opened proposals tables
*/
export const useAccountDetailsTableCounts = (
walletAddress: HumanAddr,
accountId: Option<number | null>
accountId: Option<Nullable<number>>
) => {
const { data: codesCount, refetch: refetchCodesCount } =
useCodeListCountByWalletAddress(walletAddress);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/model/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
HumanAddr,
ContractInfo,
Option,
Nullable,
} from "lib/types";
import { formatSlugName, getCurrentDate, getDefaultDate } from "lib/utils";

Expand Down Expand Up @@ -75,7 +76,7 @@ export const useInstantiatedMockInfoByMe = (): ContractListInfo => {
*/
export const useContractDetailsTableCounts = (
contractAddress: ContractAddr,
contractAccountId: Option<number | null>
contractAccountId: Option<Nullable<number>>
) => {
const { data: migrationCount, refetch: refetchMigration } =
useMigrationHistoriesCountByContractAddress(contractAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
useTxsByAddressPagination,
useTxsCountByAddress,
} from "lib/services/txService";
import type { Option, Transaction, TxFilters } from "lib/types";
import type { Nullable, Option, Transaction, TxFilters } from "lib/types";

import { TxsAlert } from "./TxsAlert";
import { TxsBody } from "./TxsBody";
import { TxsTop } from "./TxsTop";

interface TxsTableProps {
accountId: Option<number | null>;
accountId: Option<Nullable<number>>;
scrollComponentId: string;
onViewMore?: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UploadSchemaSection } from "lib/components/json-schema";
import JsonReadOnly from "lib/components/json/JsonReadOnly";
import type { Option } from "lib/types";
import type { Nullable, Option } from "lib/types";
import { jsonPrettify } from "lib/utils";

interface SchemaPanelProps {
codeId: string;
codeHash: string;
schema: Option<object | null>;
schema: Option<Nullable<object>>;
}

export const SchemaPanel = ({ codeId, codeHash, schema }: SchemaPanelProps) =>
Expand Down
Loading

1 comment on commit 4d0eafe

@vercel
Copy link

@vercel vercel bot commented on 4d0eafe Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.