Skip to content

Commit

Permalink
Merge pull request #676 from alleslabs/fix/refactor-error-fetching
Browse files Browse the repository at this point in the history
feat: new error fetching image & refactor empty states
  • Loading branch information
songwongtp committed Dec 19, 2023
2 parents fc498a3 + 0df053c commit 2b5090d
Show file tree
Hide file tree
Showing 39 changed files with 71 additions and 125 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#676](https://github.com/alleslabs/celatone-frontend/pull/676) New error fetching image & refactor empty states
- [#666](https://github.com/alleslabs/celatone-frontend/pull/666) Add my published modules page
- [#671](https://github.com/alleslabs/celatone-frontend/pull/671) Add mahalo-1
- [#652](https://github.com/alleslabs/celatone-frontend/pull/652) Add amp publish module and deploy script
Expand Down
3 changes: 2 additions & 1 deletion src/config/theme/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export const DEFAULT_THEME: ThemeConfig = {
},
jsonTheme: "monokai",
illustration: {
error: "https://assets.alleslabs.dev/illustration/404.svg",
"404": "https://assets.alleslabs.dev/illustration/404.svg",
error: "https://assets.alleslabs.dev/illustration/error.svg",
searchNotFound:
"https://assets.alleslabs.dev/illustration/search-not-found.svg",
searchEmpty: "https://assets.alleslabs.dev/illustration/search-empty.svg",
Expand Down
4 changes: 3 additions & 1 deletion src/config/theme/initia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export const INITIA_THEME: ThemeConfig = {
},
jsonTheme: "monokai",
illustration: {
error:
"404":
"https://assets.alleslabs.dev/integrations/initia/illustration/404.svg",
error:
"https://assets.alleslabs.dev/integrations/initia/illustration/error.svg",
searchNotFound:
"https://assets.alleslabs.dev/integrations/initia/illustration/search-not-found.svg",
searchEmpty:
Expand Down
4 changes: 3 additions & 1 deletion src/config/theme/osmosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export const OSMOSIS_THEME: ThemeConfig = {
},
jsonTheme: "pastel_on_dark",
illustration: {
error:
"404":
"https://assets.alleslabs.dev/integrations/osmosis/illustration/404.svg",
error:
"https://assets.alleslabs.dev/integrations/osmosis/illustration/error.svg",
searchNotFound:
"https://assets.alleslabs.dev/integrations/osmosis/illustration/search-not-found.svg",
searchEmpty:
Expand Down
4 changes: 3 additions & 1 deletion src/config/theme/sei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export const SEI_THEME: ThemeConfig = {
},
jsonTheme: "one_dark",
illustration: {
error: "https://assets.alleslabs.dev/integrations/sei/illustration/404.svg",
"404": "https://assets.alleslabs.dev/integrations/sei/illustration/404.svg",
error:
"https://assets.alleslabs.dev/integrations/sei/illustration/error.svg",
searchNotFound:
"https://assets.alleslabs.dev/integrations/sei/illustration/search-not-found.svg",
searchEmpty:
Expand Down
1 change: 1 addition & 0 deletions src/config/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export type ThemeConfig = {
stepper: string;
};
illustration: {
"404": string;
error: string;
searchNotFound: string;
searchEmpty: string;
Expand Down
43 changes: 12 additions & 31 deletions src/lib/components/state/ErrorFetching.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import { Flex, Text } from "@chakra-ui/react";

import { CustomIcon } from "lib/components/icon";
import { EmptyState } from "./EmptyState";

interface ErrorFetchingProps {
message: string;
dataName: string;
withBorder?: boolean;
}

// TODO: call EmptyState here instead with a format message
export const ErrorFetching = ({ message }: ErrorFetchingProps) => (
<Flex
alignItems="center"
flexDir="column"
gap={4}
width="full"
borderY="1px solid"
py={8}
my={12}
borderColor="gray.700"
>
<CustomIcon
name="alert-circle-solid"
color="gray.600"
boxSize={20}
mr={3}
/>
<Text
color="text.dark"
textAlign="center"
whiteSpace="pre-wrap"
variant="body1"
>
{message} Please try again later.
</Text>
</Flex>
export const ErrorFetching = ({
dataName,
withBorder = false,
}: ErrorFetchingProps) => (
<EmptyState
imageVariant="error"
message={`There is an error during fetching ${dataName}. Please try again later.`}
withBorder={withBorder}
/>
);
29 changes: 9 additions & 20 deletions src/lib/components/state/InvalidState.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Flex, Heading, Text } from "@chakra-ui/react";
import { useRouter } from "next/router";
import { useEffect } from "react";

import { trackInvalidState } from "lib/amplitude";

import { StateImage } from "./StateImage";
import { EmptyState } from "./EmptyState";

interface InvalidStateProps {
title: string;
Expand All @@ -18,23 +17,13 @@ export const InvalidState = ({ title }: InvalidStateProps) => {
}, [router.isReady, title]);

return (
<Flex
direction="column"
alignItems="center"
borderY="1px solid"
borderColor="gray.700"
width="full"
my={6}
py={6}
>
<StateImage imageVariant="not-found" />
<Heading as="h5" variant="h5" my={2}>
{title}
</Heading>
<Text variant="body2" color="text.dark" textAlign="center">
Please double-check your input and make sure you have selected the
correct network.
</Text>
</Flex>
<EmptyState
heading={title}
message="Please double-check your input and make sure you have selected the
correct network."
imageVariant="not-found"
textVariant="body2"
withBorder
/>
);
};
3 changes: 2 additions & 1 deletion src/lib/components/state/StateImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Image } from "@chakra-ui/react";

import { CURR_THEME } from "env";

export type ImageVariant = "not-found" | "empty" | "disconnected";
export type ImageVariant = "error" | "not-found" | "empty" | "disconnected";

const imageSourceMap: Record<ImageVariant, string> = {
error: CURR_THEME.illustration.error,
"not-found": CURR_THEME.illustration.searchNotFound,
empty: CURR_THEME.illustration.searchEmpty,
disconnected: CURR_THEME.illustration.disconnected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export const AssetSectionContent = ({
supportedAssets,
error,
}: AssetSectionContentProps) => {
if (error)
return (
<ErrorFetching message="There is an error during fetching balances." />
);
if (error) return <ErrorFetching dataName="balances" />;

return supportedAssets.length ? (
<Grid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ export const DelegationsSection = ({
}, [onClose, router.query.accountAddress]);

if (isLoading) return <Loading />;
if (!stakingParams)
return (
<ErrorFetching message="There is an error during fetching delegation data" />
);
if (!stakingParams) return <ErrorFetching dataName="delegation data" />;

const redelegationCount = redelegations?.length ?? 0;

return (
<Flex
mt={{ base: 4, md: 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export const ModuleListsBody = ({
};

if (isLoading) return <Loading />;
if (!modules)
return (
<ErrorFetching message="There is an error during fetching modules." />
);
if (!modules) return <ErrorFetching dataName="modules" />;
if (!filteredModules?.length)
return (
<EmptyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const ResourceOverviewBody = ({
);

if (isLoading) return <Loading />;
if (!resourcesByName)
return (
<ErrorFetching message="There is an error during fetching resources." />
);
if (!resourcesByName) return <ErrorFetching dataName="resources" />;
if (!resourcesByName.length)
return (
<EmptyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ export const ResourceSectionBody = ({
}, [resourcesByOwner, selectedResource]);

if (isLoading) return <Loading />;
if (!resourcesByOwner)
return (
<ErrorFetching message="There is an error during fetching resources." />
);
if (!resourcesByOwner) return <ErrorFetching dataName="resources" />;
if (!resourcesByOwner.length)
return <EmptyState imageVariant="empty" message="No resources found" />;

return (
<>
<ResourceLeftPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const AdminContractsTable = observer(
isLoading={isLoading}
emptyState={
!contracts ? (
<ErrorFetching message="There is an error during fetching contracts." />
<ErrorFetching dataName="contracts" />
) : (
<EmptyState
message="This account does not have any admin access for any contracts."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const InstantiatedContractsTable = observer(
isLoading={isLoading}
emptyState={
!contracts ? (
<ErrorFetching message="There is an error during fetching contracts." />
<ErrorFetching dataName="contracts" />
) : (
<EmptyState
message="This account did not instantiate any contracts before."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const OpenedProposalsTable = ({
isLoading={isLoading}
emptyState={
!proposals ? (
<ErrorFetching message="There is an error during fetching proposals." />
<ErrorFetching dataName="proposals" />
) : (
<EmptyState
message="This account did not open any proposals before."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const StoredCodesTable = observer(
isLoading={isLoading}
emptyState={
!codes ? (
<ErrorFetching message="There is an error during fetching codes." />
<ErrorFetching dataName="codes" />
) : (
<EmptyState
withBorder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ const DelegationsTableBody = ({
const isMobile = useMobile();

if (isLoading) return <Loading />;
if (!delegations || !rewards)
return (
<ErrorFetching message="There is an error during fetching delegations." />
);
if (!delegations || !rewards) return <ErrorFetching dataName="delegations" />;
if (!delegations.length)
return (
<EmptyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ const UnbondingsTableBody = ({
const isMobile = useMobile();

if (isLoading) return <Loading />;
if (!unbondings)
return (
<ErrorFetching message="There is an error during fetching undelegations." />
);
if (!unbondings) return <ErrorFetching dataName="undelegations" />;
if (!unbondings.length)
return (
<EmptyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const TxsTable = ({
isLoading={isLoading || isTxCountLoading}
emptyState={
!transactions ? (
<ErrorFetching message="There is an error during fetching transactions." />
<ErrorFetching dataName="transactions" />
) : (
<EmptyState withBorder {...getEmptyStateProps(selectedFilters)} />
)
Expand Down
6 changes: 1 addition & 5 deletions src/lib/pages/blocks/components/BlocksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ export const BlocksTable = ({ isViewMore }: BlocksTableProps) => {
});

if (isLoading) return <Loading />;
if (error)
return (
<ErrorFetching message="There is an error during fetching recent blocks." />
);

if (error) return <ErrorFetching dataName="blocks" />;
if (!data?.total)
return (
<EmptyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export const ContractBalances = ({
const { supportedAssets, unsupportedAssets, isLoading, totalData, error } =
useBalanceInfos(contractAddress);

if (error)
return (
<ErrorFetching message="There is an error during fetching balances." />
);
if (error) return <ErrorFetching dataName="balances" />;

return (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const TxsTable = ({
isLoading={isLoading}
emptyState={
error ? (
<ErrorFetching message="There is an error during fetching transactions." />
<ErrorFetching dataName="transactions" />
) : (
<EmptyState
withBorder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const ModuleTxsTable = ({
isLoading={isLoading}
emptyState={
error ? (
<ErrorFetching message="There is an error during fetching transactions." />
<ErrorFetching dataName="transactions" />
) : (
<EmptyState
withBorder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const ModuleHistoryTable = ({
isLoading={isLoading}
emptyState={
!moduleId || error ? (
<ErrorFetching message="There is an error fetching module published events history." />
<ErrorFetching dataName="module published events history" />
) : (
<EmptyState
imageVariant="empty"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/modules/components/RecentModulesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const RecentModulesTable = () => {
isLoading={isLoading}
emptyState={
error ? (
<ErrorFetching message="There is an error during fetching recent modules." />
<ErrorFetching dataName="recent modules" />
) : (
<EmptyState
withBorder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,24 @@ export const MyPublishedModulesTable = () => {
}, [keyword, mappedModules]);

const emptyState = () => {
if (error)
return (
<ErrorFetching message="There is an error during fetching recent modules." />
);
if (error) return <ErrorFetching dataName="published modules" />;
if (!keyword)
return (
<EmptyState
imageVariant="empty"
message="There is currently no published modules."
withBorder
/>
);
return (
<EmptyState
withBorder
imageVariant="not-found"
message="No matching module found. Make sure you are searching with Module Name."
withBorder
/>
);
};

return (
<>
<InputWithIcon
Expand Down
Loading

2 comments on commit 2b5090d

@vercel
Copy link

@vercel vercel bot commented on 2b5090d Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2b5090d Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.