Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support contract from Sylvia #575

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#575](https://github.com/alleslabs/celatone-frontend/pull/575) Support message suggestion for contract from Sylvia framework
- [#564](https://github.com/alleslabs/celatone-frontend/pull/564) Update cosmjs version to latest and bump terra testnet gas price
- [#540](https://github.com/alleslabs/celatone-frontend/pull/540) Add open proposal configuration
- [#532](https://github.com/alleslabs/celatone-frontend/pull/532) Implement new Amplitude structure
Expand Down
20 changes: 15 additions & 5 deletions src/lib/hooks/useExecuteCmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ export const useExecuteCmds = (contractAddress: ContractAddr) => {
],
retry: false,
onError: (e) => {
if (e.message.includes("contract: ")) {
setExecCmds([]);
const executeCmds: string[] = [];

// Check if Sylvia framework
const sylviaRegex =
/Messages supported by this contract: (.*?): execute wasm contract failed: invalid request/;
const contentMatch = e.message?.match(sylviaRegex);

if (contentMatch && contentMatch[1]) {
const content = contentMatch[1].split(",");
content.forEach((each) => executeCmds.push(each.trim()));
} else if (e.message.includes("Error parsing into type")) {
const executeCmds: string[] = [];
Array.from(e.message?.matchAll(/`(.*?)`/g) || [])
.slice(1)
.forEach((match) => executeCmds.push(match[1]));
setExecCmds(executeCmds.map((cmd) => [cmd, `{"${cmd}": {}}`]));
} else {
}

if (executeCmds.length === 0) {
setExecCmds([["", "{}"]]);
} else {
setExecCmds(executeCmds.map((cmd) => [cmd, `{"${cmd}": {}}`]));
}
},
});
Expand Down
18 changes: 15 additions & 3 deletions src/lib/hooks/useQueryCmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ export const useQueryCmds = (contractAddress: ContractAddr) => {
refetchOnWindowFocus: false,
onError: (e: AxiosError<RpcQueryError>) => {
const cmds: string[] = [];
Array.from(e.response?.data.message?.matchAll(/`(.*?)`/g) || [])
.slice(1)
.forEach((match) => cmds.push(match[1]));
const resMsg = e.response?.data.message;

// Check if Sylvia framework
const sylviaRegex =
/Messages supported by this contract: (.*?): query wasm contract failed: invalid request/;
const contentMatch = resMsg?.match(sylviaRegex);

if (contentMatch && contentMatch[1]) {
const content = contentMatch[1].split(",");
content.forEach((each) => cmds.push(each.trim()));
} else {
Array.from(resMsg?.matchAll(/`(.*?)`/g) || [])
.slice(1)
.forEach((match) => cmds.push(match[1]));
}
setQueryCmds(cmds.map((cmd) => [cmd, `{"${cmd}": {}}`]));
},
}
Expand Down
237 changes: 113 additions & 124 deletions src/lib/layout/navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex } from "@chakra-ui/react";
import { observer } from "mobx-react-lite";
import { useMemo, type Dispatch, type SetStateAction } from "react";
import { type Dispatch, type SetStateAction } from "react";

import { AmpEvent, useTrack } from "lib/amplitude";
import {
Expand Down Expand Up @@ -32,133 +32,122 @@ const Navbar = observer(({ isExpand, setIsExpand }: NavbarProps) => {

const { address } = useCurrentChain();

const navMenu: MenuInfo[] = useMemo(
() => [
{
category: "Your Account",
slug: "your-account",
submenu: [
const navMenu: MenuInfo[] = [
{
category: "Your Account",
slug: "your-account",
submenu: [
{
name: "Past Transactions",
slug: "/past-txs",
icon: "history" as IconKeys,
},
{
name: "Your Account Details",
slug: `/accounts/${address}`,
icon: "admin" as IconKeys,
isDisable: !address,
tooltipText:
"You need to connect wallet to view your account details.",
trackEvent: () => track(AmpEvent.USE_TO_YOUR_ACCOUNT),
},
],
},
...(publicProject.enabled
? [
{
name: "Past Transactions",
slug: "/past-txs",
icon: "history" as IconKeys,
category: "Public Projects",
slug: StorageKeys.ProjectSidebar,
submenu: [
...getSavedPublicProjects().map((list) => ({
name: list.name,
slug: `/projects/${list.slug}`,
logo: list.logo as IconKeys,
})),
{
name: "View All Projects",
slug: "/projects",
icon: "public-project" as IconKeys,
},
],
},
]
: []),
...(wasm.enabled
? [
{
name: "Your Account Details",
slug: `/accounts/${address}`,
icon: "admin" as IconKeys,
isDisable: !address,
tooltipText:
"You need to connect wallet to view your account details.",
trackEvent: () => track(AmpEvent.USE_TO_YOUR_ACCOUNT),
category: "Developer Tools",
slug: StorageKeys.DevSidebar,
submenu: [
{
name: "Deploy Contract",
slug: "/deploy",
icon: "add-new" as IconKeys,
},
{
name: "Query",
slug: "/query",
icon: "query" as IconKeys,
},
{
name: "Execute",
slug: "/execute",
icon: "execute" as IconKeys,
},
{
name: "Migrate",
slug: "/migrate",
icon: "migrate" as IconKeys,
},
// {
// name: "Recent Activities",
// slug: "/",
// icon: "list" as IconKeys,
// },
],
subSection: [
{
category: "This Wallet",
submenu: [
{
name: "My Stored Codes",
slug: "/stored-codes",
icon: "code" as IconKeys,
},
{
name: INSTANTIATED_LIST_NAME,
slug: `/contract-lists/${formatSlugName(
INSTANTIATED_LIST_NAME
)}`,
icon: getListIcon(INSTANTIATED_LIST_NAME),
},
],
},
{
category: "This Device",
submenu: [
{
name: "Saved Codes",
slug: "/saved-codes",
icon: "code" as IconKeys,
},
{
name: SAVED_LIST_NAME,
slug: `/contract-lists/${formatSlugName(SAVED_LIST_NAME)}`,
icon: "contract-address" as IconKeys,
},
{
name: "View All Contract List",
slug: "/contract-lists",
icon: "more" as IconKeys,
},
],
},
],
},
],
},
...(publicProject.enabled
? [
{
category: "Public Projects",
slug: StorageKeys.ProjectSidebar,
submenu: [
...getSavedPublicProjects().map((list) => ({
name: list.name,
slug: `/projects/${list.slug}`,
logo: list.logo as IconKeys,
})),
{
name: "View All Projects",
slug: "/projects",
icon: "public-project" as IconKeys,
},
],
},
]
: []),
...(wasm.enabled
? [
{
category: "Developer Tools",
slug: StorageKeys.DevSidebar,
submenu: [
{
name: "Deploy Contract",
slug: "/deploy",
icon: "add-new" as IconKeys,
},
{
name: "Query",
slug: "/query",
icon: "query" as IconKeys,
},
{
name: "Execute",
slug: "/execute",
icon: "execute" as IconKeys,
},
{
name: "Migrate",
slug: "/migrate",
icon: "migrate" as IconKeys,
},
// {
// name: "Recent Activities",
// slug: "/",
// icon: "list" as IconKeys,
// },
],
subSection: [
{
category: "This Wallet",
submenu: [
{
name: "My Stored Codes",
slug: "/stored-codes",
icon: "code" as IconKeys,
},
{
name: INSTANTIATED_LIST_NAME,
slug: `/contract-lists/${formatSlugName(
INSTANTIATED_LIST_NAME
)}`,
icon: getListIcon(INSTANTIATED_LIST_NAME),
},
],
},
{
category: "This Device",
submenu: [
{
name: "Saved Codes",
slug: "/saved-codes",
icon: "code" as IconKeys,
},
{
name: SAVED_LIST_NAME,
slug: `/contract-lists/${formatSlugName(
SAVED_LIST_NAME
)}`,
icon: "contract-address" as IconKeys,
},
{
name: "View All Contract List",
slug: "/contract-lists",
icon: "more" as IconKeys,
},
],
},
],
},
]
: []),
],
[
address,
getSavedPublicProjects,
publicProject.enabled,
track,
wasm.enabled,
]
);
]
: []),
];

return (
<Flex direction="column" h="full" overflow="hidden" position="relative">
Expand Down
Loading
Loading