Skip to content

Commit

Permalink
fix: comment
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp committed Aug 16, 2024
1 parent a100e22 commit 0e25752
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 198 deletions.
201 changes: 102 additions & 99 deletions src/lib/pages/interact-contract/components/execute-area/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Flex, TabList, Tabs } from "@chakra-ui/react";
import type { Coin } from "@cosmjs/stargate";
import { observer } from "mobx-react-lite";
import { useCallback, useEffect, useState } from "react";

import { trackUseTab } from "lib/amplitude";
Expand Down Expand Up @@ -27,108 +28,110 @@ interface ExecuteAreaProps {
codeHash: Option<string>;
}

export const ExecuteArea = ({
verifiedSchema,
localSchema,
contractAddress,
initialMsg,
initialFunds,
codeHash,
codeId,
}: ExecuteAreaProps) => {
const [tab, setTab] = useState<MessageTabs>(MessageTabs.JSON_INPUT);
export const ExecuteArea = observer(
({
verifiedSchema,
localSchema,
contractAddress,
initialMsg,
initialFunds,
codeHash,
codeId,
}: ExecuteAreaProps) => {
const [tab, setTab] = useState<MessageTabs>(MessageTabs.JSON_INPUT);

const schema = verifiedSchema ?? localSchema;
const attached = Boolean(codeHash && schema);
const schema = verifiedSchema ?? localSchema;
const hasSchema = Boolean(schema);

const handleTabChange = useCallback(
(nextTab: MessageTabs) => {
if (nextTab === tab) return;
trackUseTab(nextTab);
setTab(nextTab);
},
[tab]
);
const handleTabChange = useCallback(
(nextTab: MessageTabs) => {
if (nextTab === tab) return;
trackUseTab(nextTab);
setTab(nextTab);
},
[tab]
);

useEffect(() => {
if (!schema) setTab(MessageTabs.JSON_INPUT);
else setTab(MessageTabs.YOUR_SCHEMA);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(schema)]);
useEffect(() => {
if (!schema) setTab(MessageTabs.JSON_INPUT);
else setTab(MessageTabs.YOUR_SCHEMA);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(schema)]);

return (
<>
<ConnectWalletAlert
subtitle="You need to connect your wallet to perform this action"
mb={4}
/>
<Tabs
isLazy
lazyBehavior="keepMounted"
index={Object.values(MessageTabs).indexOf(tab)}
>
<TabList mb={8} borderBottom="1px" borderColor="gray.800">
<CustomTab onClick={() => handleTabChange(MessageTabs.JSON_INPUT)}>
JSON Input
</CustomTab>
<CustomTab
onClick={() => handleTabChange(MessageTabs.YOUR_SCHEMA)}
isDisabled={!contractAddress}
>
<Tooltip
label="Please select contract first"
hidden={Boolean(contractAddress)}
return (
<>
<ConnectWalletAlert
subtitle="You need to connect your wallet to perform this action"
mb={4}
/>
<Tabs
isLazy
lazyBehavior="keepMounted"
index={Object.values(MessageTabs).indexOf(tab)}
>
<TabList mb={8} borderBottom="1px" borderColor="gray.800">
<CustomTab onClick={() => handleTabChange(MessageTabs.JSON_INPUT)}>
JSON Input
</CustomTab>
<CustomTab
onClick={() => handleTabChange(MessageTabs.YOUR_SCHEMA)}
isDisabled={!contractAddress}
>
Your Schema
</Tooltip>
</CustomTab>
</TabList>
</Tabs>
<MessageInputContent
currentTab={tab}
jsonContent={
<JsonExecute
contractAddress={contractAddress}
initialFunds={initialFunds}
initialMsg={initialMsg}
/>
}
schemaContent={
codeId &&
codeHash && (
<>
{attached ? (
<SchemaExecute
verifiedSchema={verifiedSchema}
localSchema={localSchema}
contractAddress={contractAddress}
initialMsg={initialMsg}
initialFunds={initialFunds}
codeId={codeId}
codeHash={codeHash}
/>
) : (
<UploadSchemaSection
codeId={codeId}
codeHash={codeHash}
title={
<Flex flexDirection="column" alignItems="center">
<Flex display="inline" textAlign="center">
You haven&#39;t attached the JSON Schema for
<CustomIcon name="code" mx={1} color="gray.400" />
code {codeId}
<Tooltip
label="Please select contract first"
hidden={Boolean(contractAddress)}
>
Your Schema
</Tooltip>
</CustomTab>
</TabList>
</Tabs>
<MessageInputContent
currentTab={tab}
jsonContent={
<JsonExecute
contractAddress={contractAddress}
initialFunds={initialFunds}
initialMsg={initialMsg}
/>
}
schemaContent={
codeId &&
codeHash && (
<>
{hasSchema ? (
<SchemaExecute
verifiedSchema={verifiedSchema}
localSchema={localSchema}
contractAddress={contractAddress}
initialMsg={initialMsg}
initialFunds={initialFunds}
codeId={codeId}
codeHash={codeHash}
/>
) : (
<UploadSchemaSection
codeId={codeId}
codeHash={codeHash}
title={
<Flex flexDirection="column" alignItems="center">
<Flex display="inline" textAlign="center">
You haven&#39;t attached the JSON Schema for
<CustomIcon name="code" mx={1} color="gray.400" />
code {codeId}
</Flex>
<Flex textAlign="center">
from which this contract is instantiated yet.
</Flex>
</Flex>
<Flex textAlign="center">
from which this contract is instantiated yet.
</Flex>
</Flex>
}
/>
)}
</>
)
}
/>
</>
);
};
}
/>
)}
</>
)
}
/>
</>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const SchemaExecute = ({
<>
<Flex gap={6} mb={6}>
<InputWithIcon
placeholder="Search with Execute Message"
placeholder="Search by Execute Message"
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
size="md"
Expand Down
Loading

0 comments on commit 0e25752

Please sign in to comment.