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

refactor: structure and components #227

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

### Improvements

- [#227](https://github.com/alleslabs/celatone-frontend/pull/227) Refactor directory structure and components e.g. various tables
- [#207](https://github.com/alleslabs/celatone-frontend/pull/207) Add cta to submit public project in list page
- [#206](https://github.com/alleslabs/celatone-frontend/pull/206) Refactor copy functionality into one component

Expand Down
4 changes: 3 additions & 1 deletion src/lib/app-fns/tx/resend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ResendTxParams {
address: HumanAddr;
client: SigningCosmWasmClient;
onTxSucceed?: (txHash: string) => void;
onTxFailed?: () => void;
fee: StdFee;
messages: EncodeObject[];
}
Expand All @@ -26,6 +27,7 @@ export const resendTx = ({
address,
client,
onTxSucceed,
onTxFailed,
fee,
messages,
}: ResendTxParams): Observable<TxResultRendering> => {
Expand Down Expand Up @@ -69,5 +71,5 @@ export const resendTx = ({
actionVariant: "resend",
} as TxResultRendering;
}
)().pipe(catchTxError());
)().pipe(catchTxError(onTxFailed));
};
2 changes: 1 addition & 1 deletion src/lib/app-provider/contexts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useCodeStore,
useContractStore,
usePublicProjectStore,
} from "lib/hooks";
} from "lib/providers/store";
import type { ChainGasPrice, Token, U } from "lib/types";
import { formatUserKey } from "lib/utils";

Expand Down
17 changes: 10 additions & 7 deletions src/lib/app-provider/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export * from "./useFabricateFee";
export * from "./useSimulateFee";
export * from "./useRestrictedInput";
export * from "./useAddress";
export * from "./useAmplitude";
export * from "./useCelatoneApp";
export * from "./useQueryCmds";
export * from "./useExecuteCmds";
export * from "./useTokensInfo";
export * from "./useChainId";
export * from "./useDummyWallet";
export * from "./useFabricateFee";
export * from "./useInternalNavigate";
export * from "./useLCDEndpoint";
export * from "./useMediaQuery";
export * from "./useNetworkChange";
export * from "./useAmplitude";
export * from "./useRestrictedInput";
export * from "./useSelectChain";
export * from "./useSimulateFee";
export * from "./useTokensInfo";
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/app-provider/queries/simulateFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { useWallet } from "@cosmos-kit/react";
import { useQuery } from "@tanstack/react-query";

import { useDummyWallet } from "lib/hooks";
import { useDummyWallet } from "../hooks";
import type { ComposedMsg, Gas } from "lib/types";

interface SimulateQueryParams {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/app-provider/tx/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { HumanAddr } from "lib/types";

export interface ResendStreamParams {
onTxSucceed?: (txHash: string) => void;
onTxFailed?: () => void;
estimatedFee?: StdFee;
messages: EncodeObject[];
}
Expand All @@ -16,7 +17,12 @@ export const useResendTx = () => {
const { address, getCosmWasmClient } = useWallet();

return useCallback(
async ({ onTxSucceed, estimatedFee, messages }: ResendStreamParams) => {
async ({
onTxSucceed,
onTxFailed,
estimatedFee,
messages,
}: ResendStreamParams) => {
const client = await getCosmWasmClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
Expand All @@ -25,6 +31,7 @@ export const useResendTx = () => {
address: address as HumanAddr,
client,
onTxSucceed,
onTxFailed,
fee: estimatedFee,
messages,
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/Chakra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface ChakraProps {
children: ReactNode;
}

export const Chakra = ({ children }: ChakraProps) => {
return <ChakraProvider theme={customTheme}>{children}</ChakraProvider>;
};
export const Chakra = ({ children }: ChakraProps) => (
<ChakraProvider theme={customTheme}>{children}</ChakraProvider>
);
28 changes: 13 additions & 15 deletions src/lib/components/ContractCmdButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ interface ContractCmdButtonProps {
export const ContractCmdButton = ({
cmd,
onClickCmd,
}: ContractCmdButtonProps) => {
return (
<Button
variant="command-button"
fontSize="12px"
height="24px"
px="10px"
borderRadius="16px"
fontWeight="400"
onClick={onClickCmd}
>
{cmd}
</Button>
);
};
}: ContractCmdButtonProps) => (
<Button
variant="command-button"
fontSize="12px"
height="24px"
px="10px"
borderRadius="16px"
fontWeight="400"
onClick={onClickCmd}
>
{cmd}
</Button>
);
6 changes: 3 additions & 3 deletions src/lib/components/ContractSelectSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useEffect, useMemo } from "react";
import { useForm } from "react-hook-form";
import { MdMode, MdOutlineBookmarkBorder } from "react-icons/md";

import { useCelatoneApp } from "lib/app-provider";
import { useContractStore, useLCDEndpoint, useMobile } from "lib/hooks";
import { useCelatoneApp, useLCDEndpoint, useMobile } from "lib/app-provider";
import { useContractStore } from "lib/providers/store";
import { queryInstantiateInfo } from "lib/services/contract";
import type { ContractLocalInfo } from "lib/stores/contract";
import type { Addr, ContractAddr, Option } from "lib/types";
Expand All @@ -16,7 +16,7 @@ import { EditContractDetailsModal, SaveContractDetailsModal } from "./modal";
import {
SelectContractAdmin,
SelectContractInstantiator,
} from "./modal/select-contract";
} from "./select-contract";

interface DisplayNameProps {
notSelected: boolean;
Expand Down
18 changes: 8 additions & 10 deletions src/lib/components/ErrorMessageRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ interface ErrorMessageRenderProps extends FlexProps {
export const ErrorMessageRender = ({
error,
...restProps
}: ErrorMessageRenderProps) => {
return (
<Flex gap={2} {...restProps}>
<Icon as={IoIosWarning} boxSize={4} color="error.main" />
<Text variant="body3" color="error.main">
{error}
</Text>
</Flex>
);
};
}: ErrorMessageRenderProps) => (
<Flex gap={2} {...restProps}>
<Icon as={IoIosWarning} boxSize={4} color="error.main" />
<Text variant="body3" color="error.main">
{error}
</Text>
</Flex>
);
2 changes: 1 addition & 1 deletion src/lib/components/ExplorerLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getExplorerTxUrl,
getProposalUrl,
} from "lib/app-fns/explorer";
import type { AddressReturnType } from "lib/hooks";
import type { AddressReturnType } from "lib/app-provider";
import { AmpTrackMintscan } from "lib/services/amplitude";
import { truncate } from "lib/utils";

Expand Down
28 changes: 13 additions & 15 deletions src/lib/components/InputWithIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ const InputWithIcon = ({
value,
size,
onChange,
}: InputWithIconProps) => {
return (
<InputGroup>
<Input
placeholder={placeholder}
value={value}
onChange={onChange}
size={size}
/>
<InputRightElement h="56px" alignItems="center">
<SearchIcon color="gray.600" />
</InputRightElement>
</InputGroup>
);
};
}: InputWithIconProps) => (
<InputGroup>
<Input
placeholder={placeholder}
value={value}
onChange={onChange}
size={size}
/>
<InputRightElement h="56px" alignItems="center">
<SearchIcon color="gray.600" />
</InputRightElement>
</InputGroup>
);

export default InputWithIcon;
44 changes: 21 additions & 23 deletions src/lib/components/LabelText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@ export const LabelText = ({
children,
helperText1,
helperText2,
}: LabelTextProps) => {
return (
<Flex direction="column" gap={1}>
<Text variant="body2" color="text.dark" fontWeight={500}>
{label}
}: LabelTextProps) => (
<Flex direction="column" gap={1}>
<Text variant="body2" color="text.dark" fontWeight={500}>
{label}
</Text>
{typeof children === "string" ? (
<Text variant="body2">{children}</Text>
) : (
children
)}
{helperText1 && (
<Text variant="body3" color="text.dark">
{helperText1}
</Text>
{typeof children === "string" ? (
<Text variant="body2">{children}</Text>
) : (
children
)}
{helperText1 && (
<Text variant="body3" color="text.dark">
{helperText1}
</Text>
)}
{helperText2 && (
<Text variant="body3" color="text.dark">
{helperText2}
</Text>
)}
</Flex>
);
};
)}
{helperText2 && (
<Text variant="body3" color="text.dark">
{helperText2}
</Text>
)}
</Flex>
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import type { CSSProperties } from "react";
import { useState, useRef, forwardRef } from "react";
import { MdCheck, MdClose, MdAdd } from "react-icons/md";

import { CreateNewListModal } from "lib/components/modal/list";
import { useContractStore, useUserKey } from "lib/hooks";
import { useUserKey } from "lib/hooks";
import { useContractStore } from "lib/providers/store";
import type { LVPair } from "lib/types";
import { formatSlugName, mergeRefs } from "lib/utils";

import { CreateNewListModal } from "./modal/list";

export interface ListSelectionProps extends InputProps {
placeholder?: string;
result: LVPair[];
Expand Down
30 changes: 14 additions & 16 deletions src/lib/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Flex, Spinner, Text } from "@chakra-ui/react";

export const Loading = () => {
return (
<Flex
borderY="1px solid"
borderColor="pebble.700"
width="full"
py={12}
my={12}
flexDirection="column"
alignItems="center"
>
<Spinner size="xl" speed="0.65s" />
<Text mt="20px">Loading ...</Text>
</Flex>
);
};
export const Loading = () => (
<Flex
borderY="1px solid"
borderColor="pebble.700"
width="full"
py={12}
my={12}
flexDirection="column"
alignItems="center"
>
<Spinner size="xl" speed="0.65s" />
<Text mt="20px">Loading ...</Text>
</Flex>
);
38 changes: 18 additions & 20 deletions src/lib/components/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { Flex, Spinner, Text } from "@chakra-ui/react";

export const LoadingOverlay = () => {
return (
<Flex
w="100vw"
h="100vh"
justify="center"
align="center"
direction="column"
gap={3}
bgColor="background.overlay"
position="absolute"
top={0}
left={0}
zIndex="overlay"
>
<Spinner color="pebble.600" size="xl" />
<Text variant="body1">Loading ...</Text>
</Flex>
);
};
export const LoadingOverlay = () => (
<Flex
w="100vw"
h="100vh"
justify="center"
align="center"
direction="column"
gap={3}
bgColor="background.overlay"
position="absolute"
top={0}
left={0}
zIndex="overlay"
>
<Spinner color="pebble.600" size="xl" />
<Text variant="body1">Loading ...</Text>
</Flex>
);
2 changes: 1 addition & 1 deletion src/lib/components/MobileGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactNode } from "react";

import { useMobile } from "lib/hooks";
import { useMobile } from "lib/app-provider";

import { NoMobile } from "./modal";

Expand Down
Loading