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: implement wasm feature from config #369

Merged
merged 6 commits into from
Jun 6, 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 @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#369](https://github.com/alleslabs/celatone-frontend/pull/369) Implement Wasm feature from config
- [#359](https://github.com/alleslabs/celatone-frontend/pull/359) Remove hardcode constant (length) and use from config
- [#367](https://github.com/alleslabs/celatone-frontend/pull/367) Update osmosis testnet 5 config and use explorer url from config instead
- [#368](https://github.com/alleslabs/celatone-frontend/pull/368) Use chain name from config for Meta instead of env variable
Expand Down
8 changes: 7 additions & 1 deletion src/lib/app-provider/hooks/useWasmConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useCelatoneApp } from "../contexts";

export const useWasmConfig = () => {
import { useInternalNavigate } from "./useInternalNavigate";

export const useWasmConfig = (shouldRedirect: { shouldRedirect: boolean }) => {
const {
chainConfig: {
features: { wasm },
},
} = useCelatoneApp();
const navigate = useInternalNavigate();

if (!wasm.enabled && shouldRedirect)
navigate({ pathname: "/", replace: true });

return wasm;
};
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 @@ -14,7 +14,7 @@ export const useClearAdminTx = (contractAddress: ContractAddr) => {
const { address, getCosmWasmClient } = useWallet();
const queryClient = useQueryClient();
const fabricateFee = useFabricateFee();
const wasm = useWasmConfig();
const wasm = useWasmConfig({ shouldRedirect: false });

return useCallback(
async ({ onTxSucceed }: ClearAdminStreamParams) => {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/components/dropzone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { useCallback } from "react";
import { useDropzone } from "react-dropzone";

import { UploadIcon } from "../icon";
import { MAX_FILE_SIZE } from "lib/data";
import { useWasmConfig } from "lib/app-provider";

interface DropZoneProps
extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
setFile: (file: File) => void;
}

export function DropZone({ setFile, ...componentProps }: DropZoneProps) {
const wasm = useWasmConfig({ shouldRedirect: false });

const onDrop = useCallback(
(file: File[]) => {
setFile(file[0]);
Expand All @@ -25,7 +27,8 @@ export function DropZone({ setFile, ...componentProps }: DropZoneProps) {
accept: {
"application/wasm": [".wasm"],
},
maxSize: MAX_FILE_SIZE,
// Throwing error when wasm is disabled will cause the page to not redirect, so default value is assigned instead
maxSize: wasm.enabled ? wasm.storeCodeMaxFileSize : 0,
});

return (
Expand Down
24 changes: 0 additions & 24 deletions src/lib/data/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,3 @@ export const getNetworkByChainName = (chainName: string): Network => {

return network;
};

interface ChainConfig {
isWasm: boolean;
}

const CHAIN_CONFIG: Record<SupportedChain, ChainConfig> = {
osmosis: {
isWasm: true,
},
terra: {
isWasm: true,
},
mitosis: {
isWasm: false,
},
};

export const getChainConfig = () => {
if (!SELECTED_CHAIN)
throw new Error(`${SELECTED_CHAIN} - environment variable not found`);
if (!CHAIN_CONFIG[SELECTED_CHAIN])
throw new Error(`Chain not found in chain config`);
return CHAIN_CONFIG[SELECTED_CHAIN];
};
2 changes: 0 additions & 2 deletions src/lib/data/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export const DEFAULT_LIST: LVPair[] = [

export const DEFAULT_ADDRESS = "default-address";

export const MAX_FILE_SIZE = 800_000;

export const MICRO = 1_000_000;

export const typeUrlDict = {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useRouter } from "next/router";
import type { ReactNode } from "react";
import { useState, useEffect } from "react";

import { useMobile } from "lib/app-provider";
import { getChainConfig } from "lib/data";
import { useMobile, useWasmConfig } from "lib/app-provider";
import { scrollToTop } from "lib/utils";

import Footer from "./Footer";
Expand All @@ -19,9 +18,9 @@ type LayoutProps = {
const Layout = ({ children }: LayoutProps) => {
const router = useRouter();
const isMobile = useMobile();
const wasm = useWasmConfig({ shouldRedirect: false });

const [isExpand, setIsExpand] = useState(!isMobile);
const chainConfig = getChainConfig();

const lightMode = {
templateAreas: `"header""nav""main"`,
Expand All @@ -36,7 +35,7 @@ const Layout = ({ children }: LayoutProps) => {
navBar: <Navbar isExpand={isExpand} setIsExpand={setIsExpand} />,
};

const mode = chainConfig.isWasm ? fullMode : lightMode;
const mode = wasm.enabled ? fullMode : lightMode;

useEffect(() => {
scrollToTop();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useLCDEndpoint,
useGetAddressType,
useValidateAddress,
useWasmConfig,
} from "lib/app-provider";
import { ConnectWalletAlert } from "lib/components/ConnectWalletAlert";
import { ContractSelectSection } from "lib/components/ContractSelectSection";
Expand All @@ -34,6 +35,7 @@ import { MsgType } from "lib/types";
import { composeMsg, getFirstQueryParam } from "lib/utils";

const UpdateAdmin = () => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const { address } = useWallet();
const { validateContractAddress, validateUserAddress } = useValidateAddress();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pages/code-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { observer } from "mobx-react-lite";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { useWasmConfig } from "lib/app-provider";
import { BackButton } from "lib/components/button";
import { CopyLink } from "lib/components/CopyLink";
import { CustomIcon } from "lib/components/icon";
Expand Down Expand Up @@ -123,6 +124,7 @@ const CodeDetailsBody = observer(
);

const CodeDetails = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const codeIdParam = getFirstQueryParam(router.query.codeId);
const data = useCodeData(codeIdParam);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/codes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { ChangeEvent } from "react";
import { useEffect } from "react";
import { useForm } from "react-hook-form";

import { useInternalNavigate } from "lib/app-provider";
import { useInternalNavigate, useWasmConfig } from "lib/app-provider";
import { CustomTab } from "lib/components/CustomTab";
import { FilterByPermission } from "lib/components/forms";
import InputWithIcon from "lib/components/InputWithIcon";
Expand All @@ -30,6 +30,7 @@ interface CodeFilterState {
}

const Codes = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const onRowSelect = (codeId: number) =>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/contract-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { observer } from "mobx-react-lite";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { useValidateAddress } from "lib/app-provider";
import { useValidateAddress, useWasmConfig } from "lib/app-provider";
import { BackButton } from "lib/components/button";
import { CustomTab } from "lib/components/CustomTab";
import { Loading } from "lib/components/Loading";
Expand Down Expand Up @@ -135,6 +135,7 @@ const ContractDetailsBody = observer(
);

const ContractDetails = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const { validateContractAddress } = useValidateAddress();
const contractAddressParam = getFirstQueryParam(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/contract-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { observer } from "mobx-react-lite";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { useInternalNavigate } from "lib/app-provider";
import { useInternalNavigate, useWasmConfig } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";
import { CreateNewListModal } from "lib/components/modal";
import PageContainer from "lib/components/PageContainer";
Expand All @@ -13,6 +13,7 @@ import { useContractStore } from "lib/providers/store";
import { AmpEvent, AmpTrack } from "lib/services/amplitude";

const AllContractListsPage = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const { getContractLists } = useContractStore();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/contract-list/slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { observer } from "mobx-react-lite";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { useInternalNavigate } from "lib/app-provider";
import { useInternalNavigate, useWasmConfig } from "lib/app-provider";
import { AppLink } from "lib/components/AppLink";
import { CustomIcon } from "lib/components/icon";
import {
Expand All @@ -31,6 +31,7 @@ import type { ContractAddr } from "lib/types";
import { formatSlugName, getFirstQueryParam } from "lib/utils";

const ContractsByList = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const listSlug = getFirstQueryParam(router.query.slug);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pages/deploy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useInternalNavigate,
useSelectChain,
useCurrentNetwork,
useWasmConfig,
} from "lib/app-provider";
import { ButtonCard } from "lib/components/ButtonCard";
import { CustomIcon } from "lib/components/icon";
Expand All @@ -26,6 +27,7 @@ const Deploy = () => {
const router = useRouter();
const navigate = useInternalNavigate();
const selectChain = useSelectChain();
useWasmConfig({ shouldRedirect: true });

useEffect(() => {
if (router.isReady) AmpTrack(AmpEvent.TO_DEPLOY);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/execute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Coin } from "@cosmjs/stargate";
import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";

import { useInternalNavigate } from "lib/app-provider";
import { useInternalNavigate, useWasmConfig } from "lib/app-provider";
import { BackButton } from "lib/components/button";
import { ConnectWalletAlert } from "lib/components/ConnectWalletAlert";
import { ContractSelectSection } from "lib/components/ContractSelectSection";
Expand All @@ -23,6 +23,7 @@ import {
import { ExecuteArea } from "./components/ExecuteArea";

const Execute = () => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const [initialMsg, setInitialMsg] = useState("");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/faucet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Faucet = () => {

useEffect(() => {
if (!faucet.enabled) navigate({ pathname: "/", replace: true });
else if (router.isReady) AmpTrack(AmpEvent.TO_FAUCET);
if (router.isReady) AmpTrack(AmpEvent.TO_FAUCET);
}, [faucet, navigate, router]);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { useRouter } from "next/router";
import { useEffect } from "react";

import NetworkOverview from "../network-overview";
import { getChainConfig } from "lib/data";
import { useWasmConfig } from "lib/app-provider";
import { AmpEvent, AmpTrack } from "lib/services/amplitude";

import { QuickMenu } from "./components/QuickMenu";
import { RecentActivities } from "./components/RecentActivities";

const Home = () => {
const router = useRouter();
const chainConfig = getChainConfig();
const wasm = useWasmConfig({ shouldRedirect: false });

useEffect(() => {
if (router.isReady) AmpTrack(AmpEvent.TO_OVERVIEW);
}, [router.isReady]);

return chainConfig.isWasm ? (
return wasm.enabled ? (
<Box mx="1">
<QuickMenu />
<RecentActivities />
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pages/instantiate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { InstantiateResult } from "@cosmjs/cosmwasm-stargate";
import { useEffect, useState } from "react";

import { useWasmConfig } from "lib/app-provider";
import { scrollToTop } from "lib/utils";

import CompletedPage from "./completed";
Expand All @@ -11,6 +12,7 @@ export interface InstantiateTxInfo extends InstantiateResult {
}

const Index = () => {
useWasmConfig({ shouldRedirect: true });
const [completed, setCompleted] = useState(false);
const [txInfo, setTxInfo] = useState<InstantiateTxInfo>({
contractAddress: "",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/pages/migrate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useCelatoneApp,
useInternalNavigate,
useLCDEndpoint,
useWasmConfig,
} from "lib/app-provider";
import { ConnectWalletAlert } from "lib/components/ConnectWalletAlert";
import { ContractSelectSection } from "lib/components/ContractSelectSection";
Expand All @@ -32,6 +33,7 @@ const defaultValues: MigratePageState = {
};

const Migrate = () => {
useWasmConfig({ shouldRedirect: true });
const { indexerGraphClient } = useCelatoneApp();
const router = useRouter();
const navigate = useInternalNavigate();
Expand All @@ -43,6 +45,7 @@ const Migrate = () => {
mode: "all",
defaultValues,
});

const { migrateStep, contractAddress, admin, codeId } = watch();

const firstStep = migrateStep !== "migrate_contract";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pages/public-project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Flex, Heading } from "@chakra-ui/react";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { useWasmConfig } from "lib/app-provider";
import PageContainer from "lib/components/PageContainer";
import { AmpEvent, AmpTrack } from "lib/services/amplitude";

import { AllProject } from "./components/AllProject";

export const AllPublicProjectsPage = () => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();

useEffect(() => {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/pages/query/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type { AxiosError } from "axios";
import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";

import { useInternalNavigate, useLCDEndpoint } from "lib/app-provider";
import {
useInternalNavigate,
useLCDEndpoint,
useWasmConfig,
} from "lib/app-provider";
import { BackButton } from "lib/components/button";
import { ContractSelectSection } from "lib/components/ContractSelectSection";
import { CustomIcon } from "lib/components/icon";
Expand All @@ -23,6 +27,7 @@ import {
import { QueryArea } from "./components/QueryArea";

const Query = () => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const lcdEndpoint = useLCDEndpoint();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/recent-codes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ChangeEvent } from "react";
import { useEffect } from "react";
import { useForm } from "react-hook-form";

import { useInternalNavigate } from "lib/app-provider";
import { useInternalNavigate, useWasmConfig } from "lib/app-provider";
import { FilterByPermission } from "lib/components/forms";
import InputWithIcon from "lib/components/InputWithIcon";
import PageContainer from "lib/components/PageContainer";
Expand All @@ -22,6 +22,7 @@ interface RecentCodesState {
}

const RecentCodes = observer(() => {
useWasmConfig({ shouldRedirect: true });
const router = useRouter();
const navigate = useInternalNavigate();
const onRowSelect = (codeId: number) =>
Expand Down
Loading