Skip to content

Commit

Permalink
Merge branch 'feat/initia' of https://github.com/alleslabs/celatone-f…
Browse files Browse the repository at this point in the history
…rontend into feat/module-tx-table
  • Loading branch information
poomthiti committed Oct 18, 2023
2 parents 0ae9fb3 + 9e44981 commit 2411c9e
Show file tree
Hide file tree
Showing 35 changed files with 1,016 additions and 356 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

- [#558](https://github.com/alleslabs/celatone-frontend/pull/558) Wireup module transaction history table
- [#556](https://github.com/alleslabs/celatone-frontend/pull/556) Fully functional deploy script page
- [#550](https://github.com/alleslabs/celatone-frontend/pull/550) Add modules and resources in account detail
- [#540](https://github.com/alleslabs/celatone-frontend/pull/540) Wireup publish module tx
- [#544](https://github.com/alleslabs/celatone-frontend/pull/544) Show module source code if available
Expand Down Expand Up @@ -79,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#574](https://github.com/alleslabs/celatone-frontend/pull/574) Add min height to wasm page container to properly align footer
- [#569](https://github.com/alleslabs/celatone-frontend/pull/569) Add move config to dev shortcuts in homepage
- [#559](https://github.com/alleslabs/celatone-frontend/pull/559) Restructure and refactor responsive tables
- [#549](https://github.com/alleslabs/celatone-frontend/pull/549) Add move tx filer options
Expand Down Expand Up @@ -125,6 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#555](https://github.com/alleslabs/celatone-frontend/pull/555) Rewrite publish status resolver into an effect
- [#557](https://github.com/alleslabs/celatone-frontend/pull/557) Fix see module ux writing and policy modal
- [#554](https://github.com/alleslabs/celatone-frontend/pull/554) Fix and improve ui alignment, cta, and publish error
- [#551](https://github.com/alleslabs/celatone-frontend/pull/551) Fix various bugs on the interaction page
Expand Down
77 changes: 77 additions & 0 deletions src/lib/app-fns/tx/script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import type { EncodeObject } from "@cosmjs/proto-signing";
import type { StdFee } from "@cosmjs/stargate";
import { pipe } from "@rx-stream/pipe";
import type { Observable } from "rxjs";

import type { CatchTxError } from "lib/app-provider/tx/catchTxError";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { CustomIcon } from "lib/components/icon";
import type { HumanAddr, TxResultRendering } from "lib/types";
import { TxStreamPhase } from "lib/types";
import { formatUFee } from "lib/utils";

import { postTx, sendingTx } from "./common";

interface DeployScriptTxParams {
address: HumanAddr;
client: SigningCosmWasmClient;
onTxSucceed?: () => void;
onTxFailed?: () => void;
catchTxError: CatchTxError;
fee: StdFee;
messages: EncodeObject[];
}

export const deployScriptTx = ({
address,
client,
catchTxError,
onTxSucceed,
onTxFailed,
fee,
messages,
}: DeployScriptTxParams): Observable<TxResultRendering> => {
return pipe(
sendingTx(fee),
postTx({
postFn: () => client.signAndBroadcast(address, messages, fee),
}),
({ value: txInfo }) => {
const txFee = txInfo.events.find((e) => e.type === "tx")?.attributes[0]
.value;
onTxSucceed?.();
return {
value: null,
phase: TxStreamPhase.SUCCEED,
receipts: [
{
title: "Tx Hash",
value: txInfo.transactionHash,
html: (
<ExplorerLink
type="tx_hash"
value={txInfo.transactionHash}
openNewTab
/>
),
},
{
title: "Tx Fee",
value: txFee ? formatUFee(txFee) : "N/A",
},
],
receiptInfo: {
header: "Script Deployed!",
headerIcon: (
<CustomIcon
name="check-circle-solid"
color="success.main"
boxSize={5}
/>
),
},
} as TxResultRendering;
}
)().pipe(catchTxError(onTxFailed));
};
1 change: 1 addition & 0 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export enum CELATONE_QUERY_KEYS {
MODULE_TXS_COUNT = "CELATONE_QUERY_MODULE_TXS_COUNT",
MODULE_HISTORIES = "CELATONE_QUERY_MODULE_HISTORIES",
MODULE_HISTORIES_COUNT = "CELATONE_QUERY_MODULE_HISTORIES_COUNT",
SCRIPT_DECODE = "CELATONE_QUERY_SCRIPT_DECODE",
// RESOURCE
ACCOUNT_RESOURCES = "CELATONE_QUERY_ACCOUNT_RESOURCES",
}
50 changes: 50 additions & 0 deletions src/lib/app-provider/tx/script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { EncodeObject } from "@cosmjs/proto-signing";
import type { StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useTrack } from "lib/amplitude";
import { deployScriptTx } from "lib/app-fns/tx/script";
import type { HumanAddr } from "lib/types";

import { useCatchTxError } from "./catchTxError";

export interface DeployScriptStreamParams {
onTxSucceed?: () => void;
onTxFailed?: () => void;
estimatedFee?: StdFee;
messages: EncodeObject[];
}

export const useDeployScriptTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { trackTxSucceed } = useTrack();
const catchTxError = useCatchTxError();

return useCallback(
async ({
onTxSucceed,
onTxFailed,
estimatedFee,
messages,
}: DeployScriptStreamParams) => {
const client = await getSigningCosmWasmClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
return deployScriptTx({
address: address as HumanAddr,
client,
onTxSucceed: () => {
trackTxSucceed();
onTxSucceed?.();
},
onTxFailed,
catchTxError,
fee: estimatedFee,
messages,
});
},
[address, getSigningCosmWasmClient, trackTxSucceed, catchTxError]
);
};
10 changes: 10 additions & 0 deletions src/lib/components/ComponentLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Spinner } from "@chakra-ui/react";
import type { PropsWithChildren } from "react";

export const ComponentLoader = ({
isLoading,
children,
}: PropsWithChildren<{ isLoading: boolean }>) => {
if (isLoading) return <Spinner size="lg" mx="auto" />;
return <>{children}</>;
};
1 change: 1 addition & 0 deletions src/lib/components/WasmPageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const WasmPageContainer = ({
mx="auto"
py={12}
direction="column"
minH="inherit"
>
{children}
</Flex>
Expand Down
10 changes: 8 additions & 2 deletions src/lib/components/abi/AbiForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Flex } from "@chakra-ui/react";
import { useEffect } from "react";
import { useForm } from "react-hook-form";

import type { AbiFormData, ExposedFunction } from "lib/types";
Expand All @@ -19,14 +20,19 @@ export const AbiForm = ({
propsOnChange,
propsOnErrors,
}: AbiFormProps) => {
const { setValue, watch, getValues } = useForm<AbiFormData>({
const { setValue, watch, getValues, reset } = useForm<AbiFormData>({
defaultValues: initialData,
mode: "all",
});
const { typeArgs, args } = watch();

useEffect(() => {
reset(initialData);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(initialData), reset]);

return (
<Flex direction="column" gap={4}>
<Flex direction="column" gap={4} w="full">
{Object.keys(typeArgs).length > 0 && (
<TypesForm
genericTypeParams={fn.generic_type_params}
Expand Down
9 changes: 3 additions & 6 deletions src/lib/components/copy/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ export const CopyButton = ({
onClick={() =>
track(AmpEvent.USE_COPY_BUTTON, { section: amptrackSection })
}
leftIcon={
hasIcon ? (
// TODO config to style later
<CustomIcon name="copy" boxSize={size === "xs" ? 3 : 4} />
) : undefined
}
{...buttonProps}
borderRadius={size === "xs" ? 6 : 8}
>
{hasIcon && (
<CustomIcon name="copy" boxSize={size === "xs" ? 3 : 4} />
)}
{buttonText}
</Button>
}
Expand Down
12 changes: 8 additions & 4 deletions src/lib/components/dropzone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { DROPZONE_CONFIG } from "./config";
interface DropZoneProps extends FlexProps {
setFile: (file: File) => void;
fileType: DropzoneFileType;
error?: string;
}

export function DropZone({
setFile,
fileType,
error,
...componentProps
}: DropZoneProps) {
const wasm = useWasmConfig({ shouldRedirect: false });
Expand Down Expand Up @@ -52,11 +54,13 @@ export function DropZone({
maxSize,
});

const isError = Boolean(error || fileRejections.length > 0);

return (
<Flex direction="column">
<Flex
border="1px dashed"
borderColor={fileRejections.length > 0 ? "error.main" : "gray.700"}
borderColor={isError ? "error.main" : "gray.700"}
w="full"
p="24px 16px"
borderRadius="8px"
Expand Down Expand Up @@ -92,9 +96,9 @@ export function DropZone({
)
</Text>
</Flex>
{fileRejections.length > 0 && (
<Text variant="body3" color="error.main" mt="2px">
{fileRejections[0].errors[0].message}
{isError && (
<Text variant="body3" color="error.main" mt={1}>
{fileRejections[0]?.errors[0]?.message ?? error}
</Text>
)}
</Flex>
Expand Down
28 changes: 27 additions & 1 deletion src/lib/components/icon/CustomIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,33 @@ export const ICONS = {
),
viewBox: viewboxDefault,
},
hex: {
svg: (
<>
<path
d="M16 15C16 16.1046 15.1046 17 14 17H4C2.89543 17 2 16.1046 2 15V13.5H4V15H14V13.5H16V15Z"
fill="currentColor"
/>
<path
d="M2 2C2 0.89543 2.89543 0 4 0L14 0C15.1046 0 16 0.89543 16 2V3.5L14 3.5V2L4 2V3.5L2 3.5V2Z"
fill="currentColor"
/>
<path
d="M13.3514 6.63485C13.2409 6.63485 13.1514 6.54531 13.1514 6.43485V5.34088C13.1514 5.23043 13.2409 5.14088 13.3514 5.14088H15.7999C15.9104 5.14088 15.9999 5.23043 15.9999 5.34088V10.5C15.9999 10.6105 16.0894 10.7 16.1999 10.7H16.8C16.9105 10.7 17 10.7895 17 10.9V11.8C17 11.9104 16.9105 12 16.8 12H15.9999H14.1694H13.3514C13.2409 12 13.1514 11.9104 13.1514 11.8V10.9C13.1514 10.7895 13.2409 10.7 13.3514 10.7H13.9694C14.0799 10.7 14.1694 10.6105 14.1694 10.5V6.83485C14.1694 6.72439 14.0799 6.63485 13.9694 6.63485H13.3514Z"
fill="currentColor"
/>
<path
d="M10.6669 12C10.6042 12 10.5451 11.9706 10.5073 11.9206L9.64079 10.7737C9.55667 10.6623 9.38726 10.6692 9.31242 10.7869L8.60044 11.9073C8.56374 11.9651 8.50007 12 8.43164 12H7.02527C6.86307 12 6.76833 11.8171 6.86193 11.6846L8.44676 9.44171C8.49706 9.37054 8.49547 9.27498 8.44283 9.20552L6.8307 7.07785C6.7309 6.94613 6.82485 6.75706 6.99011 6.75706H8.46291C8.52539 6.75706 8.58428 6.78627 8.62211 6.836L9.48905 7.97607C9.57321 8.08674 9.74182 8.0799 9.81673 7.96278L10.5289 6.8493C10.5657 6.79183 10.6292 6.75706 10.6974 6.75706H12.0973C12.2608 6.75706 12.3552 6.94263 12.2589 7.07481L10.6549 9.27717C10.6029 9.34851 10.6039 9.44548 10.6572 9.51579L12.2984 11.6792C12.3983 11.8109 12.3043 12 12.139 12H10.6669Z"
fill="currentColor"
/>
<path
d="M0 8.47653C0 7.39912 0.226237 6.55034 0.678711 5.93021C1.13804 5.31007 1.87502 5 2.88966 5C3.9043 5 4.63786 5.31007 5.09033 5.93021C5.54966 6.55034 5.77933 7.39912 5.77933 8.47653C5.77933 9.56646 5.54966 10.4215 5.09033 11.0416C4.63786 11.6618 3.9043 11.9718 2.88966 11.9718C1.87502 11.9718 1.13804 11.6618 0.678711 11.0416C0.226237 10.4215 0 9.56646 0 8.47653ZM4.0517 8.47653C4.0517 7.84386 3.97629 7.3584 3.82546 7.02014C3.67464 6.67562 3.3627 6.50336 2.88966 6.50336C2.41662 6.50336 2.10469 6.67562 1.95387 7.02014C1.80304 7.3584 1.72763 7.84386 1.72763 8.47653C1.72763 8.90248 1.75505 9.2564 1.8099 9.53828C1.86474 9.81389 1.97443 10.0394 2.13897 10.2148C2.31036 10.3839 2.56059 10.4685 2.88966 10.4685C3.21874 10.4685 3.46554 10.3839 3.63008 10.2148C3.80147 10.0394 3.91459 9.81389 3.96943 9.53828C4.02428 9.2564 4.0517 8.90248 4.0517 8.47653Z"
fill="currentColor"
/>
</>
),
viewBox: "0 0 17 17",
},
home: {
svg: (
<path
Expand Down Expand Up @@ -1203,7 +1230,6 @@ export const ICONS = {
),
viewBox: viewboxDefault,
},

redo: {
svg: (
<path
Expand Down
Loading

0 comments on commit 2411c9e

Please sign in to comment.