Skip to content

Commit

Permalink
Merge pull request #702 from alleslabs/feat/cfe-102-api-v1-contract-info
Browse files Browse the repository at this point in the history
[after #697] feat: api v1 contract info
  • Loading branch information
songwongtp committed Dec 27, 2023
2 parents 8fd82b2 + 9d5f428 commit 1b98ff0
Show file tree
Hide file tree
Showing 56 changed files with 557 additions and 813 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#702](https://github.com/alleslabs/celatone-frontend/pull/702) api v1 - contract info
- [#703](https://github.com/alleslabs/celatone-frontend/pull/703) api v1 - contract's query msgs
- [#697](https://github.com/alleslabs/celatone-frontend/pull/697) api v1 - contract tables (migrations and related proposals)
- [#696](https://github.com/alleslabs/celatone-frontend/pull/696) api v1 - block details
Expand Down
4 changes: 1 addition & 3 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export enum CELATONE_QUERY_KEYS {
// CONTRACT,CODE LCD
CODE_INFO = "CELATONE_QUERY_CODE_INFO",
CONTRACT_DETAIL_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_CONTRACT_DETAIL_BY_CONTRACT_ADDRESS",
CONTRACT_CW2_INFO = "CELATONE_QUERY_CONTRACT_CW2_INFO",
CONTRACT_INFO = "CELATONE_QUERY_CONTRACT_INFO",
CONTRACT_QUERY_MSGS = "CELATONE_QUERY_CONTRACT_QUERY_MSGS",
CONTRACT_QUERY = "CELATONE_QUERY_CONTRACT_QUERY",
Expand All @@ -35,8 +34,8 @@ export enum CELATONE_QUERY_KEYS {
CODE_DATA_BY_ID = "CELATONE_QUERY_CODE_DATA_BY_ID",
// CONTRACT GQL
CONTRACTS = "CELATONE_QUERY_CONTRACTS",
CONTRACT_DATA = "CELATONE_QUERY_CONTRACT_DATA",
CONTRACTS_BY_ADMIN = "CELATONE_QUERY_CONTRACT_BY_ADMIN",
CONTRACT_INSTANTIATE_DETAIL = "CELATONE_QUERY_CONTRACT_INSTANTIATE_DETAIL",
INSTANTIATED_CONTRACTS_BY_ADDRESS = "CELATONE_QUERY_INSTANTIATED_CONTRACTS_BY_ADDRESS",
ADMIN_CONTRACTS_BY_ADDRESS = "CELATONE_QUERY_ADMIN_CONTRACTS_BY_ADDRESS",
INSTANTIATED_COUNT_BY_WALLET_ADDRESS = "CELATONE_QUERY_INSTANTIATED_COUNT_BY_WALLET_ADDRESS",
Expand Down Expand Up @@ -64,7 +63,6 @@ export enum CELATONE_QUERY_KEYS {
// PUBLIC PROJECT
PUBLIC_PROJECTS = "CELATONE_QUERY_PUBLIC_PROJECTS",
PUBLIC_PROJECT_BY_SLUG = "CELATONE_QUERY_PUBLIC_PROJECT_BY_SLUG",
PUBLIC_PROJECT_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_PUBLIC_PROJECT_BY_CONTRACT_ADDRESS",
PUBLIC_PROJECT_BY_CODE_ID = "CELATONE_QUERY_PUBLIC_PROJECT_BY_CODE_ID",
PUBLIC_PROJECT_BY_WALLET_ADDRESS = "CELATONE_QUERY_PUBLIC_PROJECT_BY_WALLET_ADDRESS",
PUBLIC_PROJECT_BY_MODULE_PATH = "CELATONE_QUERY_PUBLIC_PROJECT_BY_MODULE_PATH",
Expand Down
3 changes: 0 additions & 3 deletions src/lib/app-provider/hooks/useBaseApiRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const useBaseApiRoute = (
| "blocks"
| "contracts"
| "projects"
| "project_contracts"
| "codes"
| "legacy.accounts"
| "rest"
Expand Down Expand Up @@ -48,8 +47,6 @@ export const useBaseApiRoute = (
return `${api}/v1/${chain}/${currentChainId}/contracts`;
case "projects":
return `${api}/projects/${chain}/${currentChainId}`;
case "project_contracts":
return `${api}/contracts/${chain}/${currentChainId}`;
case "codes":
return `${api}/codes/${chain}/${currentChainId}`;
case "legacy.accounts":
Expand Down
2 changes: 1 addition & 1 deletion src/lib/app-provider/tx/clearAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useClearAdminTx = (contractAddress: ContractAddr) => {
queryKey: [CELATONE_QUERY_KEYS.ADMINS_BY_CONTRACTS],
}),
queryClient.invalidateQueries({
queryKey: [CELATONE_QUERY_KEYS.CONTRACT_INSTANTIATE_DETAIL],
queryKey: [CELATONE_QUERY_KEYS.CONTRACT_DATA],
}),
]);
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/button/AdminButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { CustomIcon } from "../icon";
import { ClearAdminModal } from "../modal/contract/ClearAdmin";
import { Tooltip } from "../Tooltip";
import { useCurrentChain, useInternalNavigate } from "lib/app-provider";
import type { Addr, ContractAddr, Option } from "lib/types";
import type { Addr, ContractAddr, Nullable } from "lib/types";

interface AdminButtonProps {
contractAddress: ContractAddr;
admin: Option<Addr>;
admin: Nullable<Addr>;
}

export const AdminButton = ({ contractAddress, admin }: AdminButtonProps) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/AttachSchemaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ViewSchemaModal } from "./view/ViewSchemaModal";

interface AttachSchemaCardProps {
attached: boolean;
codeId: string;
codeId: number;
codeHash: string;
schema: Option<CodeSchema>;
openModal: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/AttachStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConnectingLine } from "../ConnectingLine";
import { CustomIcon } from "../icon";

interface AttachStatusProps {
codeId: string;
codeId: number;
isReattach?: boolean;
}
export const AttachStatus = ({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/EditSchemaButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Tooltip } from "../Tooltip";
import { AmpEvent, track } from "lib/amplitude";

interface EditSchemaButtonsProps {
codeId: string;
codeId: number;
codeHash: string;
openModal: () => void;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/JsonSchemaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AttachStatus } from "./AttachStatus";
import { UploadTemplate } from "./UploadTemplate";

interface JsonSchemaModalProps {
codeId: string;
codeId: number;
codeHash: string;
isOpen: boolean;
isReattach?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/json-schema/UploadTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const MethodRender = ({

interface UploadTemplateInterface {
codeHash: string;
codeId: string;
codeId: number;
isReattach: boolean;
closeDrawer: () => void;
onSchemaSave?: () => void;
Expand Down Expand Up @@ -249,7 +249,7 @@ export const UploadTemplate = ({
error: schemaValidateError,
});
}
saveNewSchema(codeHash, codeId, JSON.parse(schemaString));
saveNewSchema(codeHash, codeId.toString(), JSON.parse(schemaString));
track(AmpEvent.ACTION_ATTACH_JSON, { method, isReattach });
toast({
title: `Attached JSON Schema`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { Option } from "lib/types";
interface SchemaSectionProps {
type: "migrate" | "instantiate";
codeHash: string;
codeId: string;
codeId: number;
jsonSchema: Option<CodeSchema>;
initialFormData?: Record<string, unknown>;
handleChange: (data: unknown, errors: RJSFValidationError[]) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/upload/UploadSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Option } from "lib/types";
interface UploadSchemaContentInterface {
attached: boolean;
schema: Option<CodeSchema>;
codeId: string;
codeId: number;
codeHash: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { UploadSchema } from "./UploadSchema";

interface UploadSchemaSectionProps {
schema?: Option<CodeSchema>;
codeId: string;
codeId: number;
codeHash: string;
title?: string | JSX.Element;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/json-schema/view/ViewSchemaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const StyledTabPanel = chakra(TabPanel, {
});

interface ViewSchemaModalProps {
codeId: string;
codeId: number;
jsonSchema: Option<CodeSchema>;
isIcon?: boolean;
}
Expand Down
70 changes: 34 additions & 36 deletions src/lib/components/json-schema/view/ViewSchemaPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,43 @@ import { jsonPrettify } from "lib/utils";

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

export const ViewSchemaPanel = ({
jsonSchema,
codeId,
}: ViewSchemaPanelProps) => {
return (
<>
{jsonSchema === undefined ? (
<Flex
p="24px 16px"
direction="column"
alignItems="center"
bgColor="gray.900"
borderRadius="8px"
}: ViewSchemaPanelProps) => (
<>
{jsonSchema === undefined ? (
<Flex
p="24px 16px"
direction="column"
alignItems="center"
bgColor="gray.900"
borderRadius="8px"
>
<Text variant="body1" fontWeight={700}>
You haven&#39;t attached the JSON Schema for{" "}
<CustomIcon name="code" mx={1} color="gray.400" />
code {codeId} yet
</Text>
<Text
variant="body2"
textColor="text.disabled"
fontWeight={500}
mt={2}
mb={4}
>
<Text variant="body1" fontWeight={700}>
You haven&#39;t attached the JSON Schema for{" "}
<CustomIcon name="code" mx={1} color="gray.400" />
code {codeId} yet
</Text>
<Text
variant="body2"
textColor="text.disabled"
fontWeight={500}
mt={2}
mb={4}
>
Please attach schema in Code Detail page
</Text>
</Flex>
) : (
<JsonReadOnly
text={jsonSchema ? jsonPrettify(JSON.stringify(jsonSchema)) : "null"}
canCopy
showLines={26}
/>
)}
</>
);
};
Please attach schema in Code Detail page
</Text>
</Flex>
) : (
<JsonReadOnly
text={jsonSchema ? jsonPrettify(JSON.stringify(jsonSchema)) : "null"}
canCopy
showLines={26}
/>
)}
</>
);
2 changes: 1 addition & 1 deletion src/lib/components/modal/RemoveSchemaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useSchemaStore } from "lib/providers/store";
import { ActionModal } from "./ActionModal";

interface RemoveSchemaModalProps {
codeId: string;
codeId: number;
codeHash: string;
trigger: ReactNode;
}
Expand Down
69 changes: 29 additions & 40 deletions src/lib/components/modal/code/SaveNewCode.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import type { ButtonProps } from "@chakra-ui/react";
import { Button, useToast, FormControl } from "@chakra-ui/react";
import { useQuery } from "@tanstack/react-query";
import { useEffect, useMemo, useState } from "react";

import { ActionModal } from "../ActionModal";
import { AmpEvent, track } from "lib/amplitude";
import {
CELATONE_QUERY_KEYS,
useBaseApiRoute,
useCelatoneApp,
useCurrentChain,
} from "lib/app-provider";
import { useCelatoneApp, useCurrentChain } from "lib/app-provider";
import type { FormStatus } from "lib/components/forms";
import { TextInput, NumberInput } from "lib/components/forms";
import { CustomIcon } from "lib/components/icon";
import { useGetMaxLengthError } from "lib/hooks";
import { useCodeStore } from "lib/providers/store";
import { getCodeIdInfo } from "lib/services/code";
import { useLCDCodeInfo } from "lib/services/codeService";
import type { Addr, HumanAddr } from "lib/types";
import { getNameAndDescriptionDefault, getPermissionHelper } from "lib/utils";

Expand Down Expand Up @@ -60,38 +54,33 @@ export function SaveNewCodeModal({ buttonProps }: SaveNewCodeModalProps) {
const toast = useToast();
const { isCodeIdSaved, saveNewCode, updateCodeInfo, getCodeLocalInfo } =
useCodeStore();
const lcdEndpoint = useBaseApiRoute("rest");

const { refetch, isFetching, isRefetching } = useQuery(
[CELATONE_QUERY_KEYS.CODE_INFO, lcdEndpoint, codeId],
async () => getCodeIdInfo(lcdEndpoint, codeId),
{
enabled: false,
retry: false,
cacheTime: 0,
onSuccess(data) {
const { message, messageColor } = getPermissionHelper(
address as HumanAddr,
data.code_info.instantiate_permission.permission,
data.code_info.instantiate_permission.address
? [data.code_info.instantiate_permission.address]
: data.code_info.instantiate_permission.addresses
);
setCodeIdStatus({
state: "success",
message: `${message} (${data.code_info.instantiate_permission.permission})`,
messageColor,
});
setUploader(data.code_info.creator);
setUploaderStatus({ state: "success" });
},
onError() {
setCodeIdStatus({ state: "error", message: "Invalid Code ID" });
setUploader("Not Found");
setUploaderStatus({ state: "error" });
},
}
);

const { refetch, isFetching, isRefetching } = useLCDCodeInfo(codeId, {
enabled: false,
retry: false,
cacheTime: 0,
onSuccess(data) {
const { message, messageColor } = getPermissionHelper(
address as HumanAddr,
data.code_info.instantiate_permission.permission,
data.code_info.instantiate_permission.address
? [data.code_info.instantiate_permission.address]
: data.code_info.instantiate_permission.addresses
);
setCodeIdStatus({
state: "success",
message: `${message} (${data.code_info.instantiate_permission.permission})`,
messageColor,
});
setUploader(data.code_info.creator);
setUploaderStatus({ state: "success" });
},
onError() {
setCodeIdStatus({ state: "error", message: "Invalid Code ID" });
setUploader("Not Found");
setUploaderStatus({ state: "error" });
},
});

/* CALLBACK */
const reset = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/layout/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ const getPlaceholder = ({
isPool: boolean;
isMove: boolean;
}) => {
const wasmText = isWasm ? "/ Code ID / Contract Address " : "";
const poolText = isPool ? "/ Pool ID " : "";
const moveText = isMove ? "/ Module Path " : "";
const wasmText = isWasm ? " / Code ID / Contract Address" : "";
const poolText = isPool ? " / Pool ID" : "";
const moveText = isMove ? " / Module Path" : "";

return `Search by Account Address / Tx Hash / Block${wasmText}${poolText}${moveText}`;
};
Expand Down
Loading

2 comments on commit 1b98ff0

@vercel
Copy link

@vercel vercel bot commented on 1b98ff0 Dec 27, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 1b98ff0 Dec 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.