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: apply initial condition to my stored codes upload button #346

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

### Features

- [#346](https://github.com/alleslabs/celatone-frontend/pull/346) Apply initial condition to my stored codes upload button
- [#327](https://github.com/alleslabs/celatone-frontend/pull/327) Update logic to enable upload wasm code
- [#317](https://github.com/alleslabs/celatone-frontend/pull/317) Add amplitude for proposal list page and pagination

Expand Down
51 changes: 32 additions & 19 deletions src/lib/pages/codes/components/MyStoredCodesSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Box, Heading, HStack } from "@chakra-ui/react";
import { useWallet } from "@cosmos-kit/react";

import { MyStoredCodesTable } from "lib/components/table";
import type { CodeInfo } from "lib/types";
import { useUploadAccessParams } from "lib/services/proposalService";
import type { Addr, CodeInfo } from "lib/types";
import { AccessConfigPermission } from "lib/types";

import { UploadButton } from "./UploadButton";

Expand All @@ -19,21 +22,31 @@ export const MyStoredCodesSection = ({
onRowSelect,
disconnectedMessage,
isSearching,
}: MyStoredCodesSectionProps) => (
<Box mb={8}>
<HStack alignItems="center" justifyContent="space-between" mb="18px">
<Heading as="h6" variant="h6">
My Stored Codes
</Heading>
<UploadButton />
</HStack>
<MyStoredCodesTable
codes={codes}
isLoading={isLoading}
onRowSelect={onRowSelect}
emptyMessage="Your uploaded Wasm files will display as My Stored Codes."
disconnectedMessage={disconnectedMessage}
isSearching={isSearching}
/>
</Box>
);
}: MyStoredCodesSectionProps) => {
const { data } = useUploadAccessParams();
const { address } = useWallet();
const isAllowed = Boolean(data?.addresses?.includes(address as Addr));

const isPermissionedNetwork =
data?.permission !== AccessConfigPermission.EVERYBODY;

return (
<Box mb={8}>
<HStack alignItems="center" justifyContent="space-between" mb="18px">
<Heading as="h6" variant="h6">
My Stored Codes
</Heading>
{/* TODO: overwrite this logic when merging proposal feature */}
<UploadButton isAllowed={!isPermissionedNetwork || isAllowed} />
</HStack>
<MyStoredCodesTable
codes={codes}
isLoading={isLoading}
onRowSelect={onRowSelect}
emptyMessage="Your uploaded Wasm files will display as My Stored Codes."
disconnectedMessage={disconnectedMessage}
isSearching={isSearching}
/>
</Box>
);
};
23 changes: 17 additions & 6 deletions src/lib/pages/codes/components/UploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import { Button } from "@chakra-ui/react";

import { useInternalNavigate } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";
import { Tooltip } from "lib/components/Tooltip";

export const UploadButton = () => {
interface UploadButtonProps {
isAllowed: boolean;
}
export const UploadButton = ({ isAllowed }: UploadButtonProps) => {
const navigate = useInternalNavigate();

return (
<Button
onClick={() => navigate({ pathname: "/upload" })}
leftIcon={<CustomIcon name="plus" boxSize="12px" />}
<Tooltip
label="Only allowed address can upload Wasm file without opening proposal"
isDisabled={isAllowed}
>
Upload New Code
</Button>
<Button
disabled={!isAllowed}
onClick={() => navigate({ pathname: "/upload" })}
rightIcon={<CustomIcon name="upload" boxSize="12px" />}
>
Upload New Code
</Button>
</Tooltip>
);
};