Skip to content

Commit

Permalink
fix: module search and abi
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp committed Nov 9, 2023
1 parent 7ca01bb commit 79099ab
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 71 deletions.
69 changes: 41 additions & 28 deletions src/lib/pages/account-details/components/modules/ModuleLists.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Flex } from "@chakra-ui/react";
import { useState } from "react";

import { useMobile } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";
import { TableTitle } from "lib/components/table";
import InputWithIcon from "lib/components/InputWithIcon";
import { TableTitle, ViewMore } from "lib/components/table";
import { type IndexedModule } from "lib/services/move/moduleService";
import type { MoveAccountAddr, Option } from "lib/types";

Expand All @@ -23,41 +25,52 @@ export const ModuleLists = ({
isLoading,
onViewMore,
}: ModuleListsProps) => {
const [keyword, setKeyword] = useState("");
const isMobile = useMobile();
const isMobileOverview = isMobile && !!onViewMore;
return (
return isMobileOverview ? (
<Flex
justify="space-between"
w="full"
bg="gray.900"
borderRadius="8px"
p={4}
onClick={onViewMore}
>
<TableTitle title="Modules" count={totalCount} mb={0} />
<CustomIcon name="chevron-right" color="gray.600" />
</Flex>
) : (
<Flex
direction="column"
mt={{ base: 4, md: 8 }}
mb={{ base: 0, md: 8 }}
width="full"
gap={6}
>
{isMobileOverview ? (
<Flex
justify="space-between"
w="full"
bg="gray.900"
borderRadius="8px"
p={4}
onClick={onViewMore}
>
<TableTitle title="Modules" count={totalCount} mb={0} />
<CustomIcon name="chevron-right" color="gray.600" />
</Flex>
) : (
<>
<TableTitle
title="Module Instances"
helperText="Modules are ‘smart contracts’ deployed by this account"
count={totalCount}
/>
<ModuleListsBody
selectedAddress={selectedAddress}
modules={modules}
isLoading={isLoading}
onViewMore={onViewMore}
/>
</>
<TableTitle
title="Module Instances"
helperText="Modules are ‘smart contracts’ deployed by this account"
count={totalCount}
mb={0}
/>
{!onViewMore && (
<InputWithIcon
placeholder="Search with Module Name..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
action="execute-message-search"
/>
)}
<ModuleListsBody
selectedAddress={selectedAddress}
keyword={keyword}
modules={modules}
isLoading={isLoading}
onViewMore={onViewMore}
/>
{onViewMore && totalCount && totalCount > 9 && (
<ViewMore onClick={onViewMore} />
)}
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import { Box, SimpleGrid } from "@chakra-ui/react";
import { useMemo, useState } from "react";
import { SimpleGrid } from "@chakra-ui/react";
import { useMemo } from "react";

import { ErrorFetching } from "../ErrorFetching";
import { useInternalNavigate } from "lib/app-provider";
import InputWithIcon from "lib/components/InputWithIcon";
import { Loading } from "lib/components/Loading";
import { ModuleCard } from "lib/components/module";
import { EmptyState } from "lib/components/state";
import { ViewMore } from "lib/components/table";
import type { IndexedModule } from "lib/services/move/moduleService";
import type { MoveAccountAddr, Option } from "lib/types";

interface ModuleListsBodyProps {
selectedAddress: MoveAccountAddr;
keyword: string;
modules: Option<IndexedModule[]>;
isLoading: boolean;
onViewMore?: () => void;
}

export const ModuleListsBody = ({
selectedAddress,
keyword,
modules,
isLoading,
onViewMore,
}: ModuleListsBodyProps) => {
const navigate = useInternalNavigate();
const [keyword, setKeyword] = useState("");

const filteredModules = useMemo(() => {
if (!keyword) return modules;
Expand Down Expand Up @@ -58,33 +57,18 @@ export const ModuleListsBody = ({
/>
);
return (
<div>
{!onViewMore && (
<Box mb={8}>
<InputWithIcon
placeholder="Search with Module Name..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
action="execute-message-search"
<SimpleGrid columns={{ sm: 1, md: 2, lg: 3 }} spacing={4}>
{(onViewMore ? filteredModules.slice(0, 9) : filteredModules).map(
(item) => (
<ModuleCard
key={item.moduleName}
selectedAddress={selectedAddress}
module={item}
selectedModule={undefined}
setSelectedModule={handleOnSelect}
/>
</Box>
)
)}
<SimpleGrid columns={{ sm: 1, md: 2, lg: 3 }} spacing={4} mb={4}>
{(onViewMore ? filteredModules.slice(0, 9) : filteredModules).map(
(item) => (
<ModuleCard
key={item.moduleName}
selectedAddress={selectedAddress}
module={item}
selectedModule={undefined}
setSelectedModule={handleOnSelect}
/>
)
)}
</SimpleGrid>
{onViewMore && filteredModules.length > 9 && (
<ViewMore onClick={onViewMore} />
)}
</div>
</SimpleGrid>
);
};
2 changes: 1 addition & 1 deletion src/lib/pages/account-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ const AccountDetailsBody = ({
</TabPanel>
<TabPanel p={0}>
<ModuleLists
selectedAddress={accountAddress}
totalCount={modulesData?.length}
selectedAddress={accountAddress}
modules={modulesData}
isLoading={isModulesLoading}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/styles/theme/components/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const errorMain = "error.main";
const labelStyles = {
top: 0,
left: 0,
zIndex: 2,
zIndex: 1,
position: "absolute",
pointerEvents: "none",
mx: 3,
Expand Down
19 changes: 9 additions & 10 deletions src/lib/utils/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ export const getAbiInitialData = (length: number) =>
// ------------------------------------------//
// -----------------MOVE ARGS----------------//
// ------------------------------------------//
export const getArgType = (argType: string) => {
if (argType === "0x1::string::String") return BCS.STRING;
if (argType.startsWith("0x1::option::Option")) return BCS.OPTION;
if (argType.startsWith("0x1::object::Object")) return BCS.OBJECT;
if (argType === "0x1::fixed_point32::FixedPoint32") return BCS.FIXED_POINT32;
if (argType === "0x1::fixed_point64::FixedPoint64") return BCS.FIXED_POINT64;
if (argType === "0x1::decimal128::Decimal128") return BCS.DECIMAL128;
if (argType === "0x1::decimal256::Decimal256") return BCS.DECIMAL256;
return argType;
};
export const getArgType = (argType: string) =>
argType
.replace("0x1::string::String", BCS.STRING)
.replace("0x1::option::Option", BCS.OPTION)
.replace("0x1::object::Object", BCS.OBJECT)
.replace("0x1::fixed_point32::FixedPoint32", BCS.FIXED_POINT32)
.replace("0x1::fixed_point64::FixedPoint64", BCS.FIXED_POINT64)
.replace("0x1::decimal128::Decimal128", BCS.DECIMAL128)
.replace("0x1::decimal256::Decimal256", BCS.DECIMAL256);

const getArgValue = ({
type,
Expand Down

0 comments on commit 79099ab

Please sign in to comment.