Skip to content

Commit

Permalink
Merge branch 'develop' into component/migrate-step1
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp committed Jan 27, 2023
2 parents 2b1cd8e + c4f6c8a commit a0c5fec
Show file tree
Hide file tree
Showing 28 changed files with 516 additions and 126 deletions.
2 changes: 2 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

- [#108](https://github.com/alleslabs/celatone-frontend/pull/108) Add migrate options on migrate page and upload new code for migration
- [#113](https://github.com/alleslabs/celatone-frontend/pull/113) Update admin page ui and wireup
- [#98](https://github.com/alleslabs/celatone-frontend/pull/98) Add migrate, update admin, clear admin menu on contract list and detail
- [#121](https://github.com/alleslabs/celatone-frontend/pull/121) Fix code snippet for query axios
- [#102](https://github.com/alleslabs/celatone-frontend/pull/102) Add quick menu in overview and add highlighted in left sidebar
Expand Down Expand Up @@ -109,6 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#124](https://github.com/alleslabs/celatone-frontend/pull/124) Fix public project query, display project image in contract details page
- [#125](https://github.com/alleslabs/celatone-frontend/pull/125) Fix incorrect CosmJS execute snippet
- [#117](https://github.com/alleslabs/celatone-frontend/pull/117) Fix native token label formatting
- [#121](https://github.com/alleslabs/celatone-frontend/pull/121) Fix code snippet for query axios
Expand Down
10 changes: 1 addition & 9 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MsgType } from "lib/types";
import type { ContractAddr, ChainGasPrice, Token, U } from "lib/types";
import type { CelatoneConstants, CelatoneContractAddress } from "types";

Expand Down Expand Up @@ -49,16 +48,9 @@ export const FALLBACK_LCD_ENDPOINT: Record<string, string> = {

export const MAX_FILE_SIZE = 800_000;

export const MSG_TYPE_URL = {
[MsgType.STORE_CODE]: "/cosmwasm.wasm.v1.MsgStoreCode",
[MsgType.INSTANTIATE]: "/cosmwasm.wasm.v1.MsgInstantiateContract",
[MsgType.EXECUTE]: "/cosmwasm.wasm.v1.MsgExecuteContract",
};

export const CELATONE_CONSTANTS: CelatoneConstants = {
gasAdjustment: 1.6,
maxFileSize: MAX_FILE_SIZE,
msgTypeUrl: MSG_TYPE_URL,
};

export const DUMMY_MNEMONIC = process.env.NEXT_PUBLIC_DUMMY_MNEMONIC;
Expand All @@ -83,7 +75,7 @@ export const getChainApiPath = (chainName: string) => {
export const getMainnetApiPath = (chainId: string) => {
switch (chainId) {
case "osmo-test-4":
case "osmosis":
case "osmosis-1":
return "osmosis-1";
default:
return undefined;
Expand Down
74 changes: 74 additions & 0 deletions src/lib/app-fns/tx/updateAdmin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Icon } from "@chakra-ui/react";
import type {
ExecuteResult,
SigningCosmWasmClient,
} from "@cosmjs/cosmwasm-stargate";
import type { StdFee } from "@cosmjs/stargate";
import { pipe } from "@rx-stream/pipe";
import { MdCheckCircle } from "react-icons/md";
import type { Observable } from "rxjs";

import { ExplorerLink } from "lib/components/ExplorerLink";
import type { ContractAddr, HumanAddr, TxResultRendering } from "lib/types";
import { TxStreamPhase } from "lib/types";
import { formatUFee } from "lib/utils";

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

interface UpdateAdminTxParams {
address: HumanAddr;
contractAddress: ContractAddr;
newAdmin: HumanAddr | ContractAddr;
fee: StdFee;
client: SigningCosmWasmClient;
onTxSucceed?: () => void;
onTxFailed?: () => void;
}

export const updateAdminTx = ({
address,
contractAddress,
newAdmin,
fee,
client,
onTxSucceed,
onTxFailed,
}: UpdateAdminTxParams): Observable<TxResultRendering> => {
return pipe(
sendingTx(fee),
postTx<ExecuteResult>({
postFn: () =>
client.updateAdmin(address, contractAddress, newAdmin, fee, undefined),
}),
({ value: txInfo }) => {
onTxSucceed?.();
return {
value: null,
phase: TxStreamPhase.SUCCEED,
receipts: [
{
title: "Tx Hash",
value: txInfo.transactionHash,
html: (
<ExplorerLink type="tx_hash" value={txInfo.transactionHash} />
),
},
{
title: "Tx Fee",
value: `${formatUFee(
txInfo.events.find((e) => e.type === "tx")?.attributes[0].value ??
"0u"
)}`,
},
],
receiptInfo: {
header: "Update Admin Complete",
headerIcon: (
<Icon as={MdCheckCircle} color="success.main" boxSize={6} />
),
},
actionVariant: "update-admin",
} as TxResultRendering;
}
)().pipe(catchTxError(onTxFailed));
};
5 changes: 3 additions & 2 deletions src/lib/app-provider/tx/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./upload";
export * from "./resend";
export * from "./clearAdmin";
export * from "./execute";
export * from "./instantiate";
export * from "./resend";
export * from "./updateAdmin";
export * from "./clearAdmin";
44 changes: 44 additions & 0 deletions src/lib/app-provider/tx/updateAdmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { StdFee } from "@cosmjs/stargate";
import { useWallet } from "@cosmos-kit/react";
import { useCallback } from "react";

import { updateAdminTx } from "lib/app-fns/tx/updateAdmin";
import type { ContractAddr, HumanAddr, Option } from "lib/types";

export interface UpdateAdminStreamParams {
contractAddress: ContractAddr;
newAdmin: HumanAddr | ContractAddr;
estimatedFee: Option<StdFee>;
onTxSucceed?: () => void;
onTxFailed?: () => void;
}

export const useUpdateAdminTx = () => {
const { address, getCosmWasmClient } = useWallet();

return useCallback(
async ({
contractAddress,
newAdmin,
estimatedFee,
onTxSucceed,
onTxFailed,
}: UpdateAdminStreamParams) => {
const client = await getCosmWasmClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;

return updateAdminTx({
address: address as HumanAddr,
contractAddress,
newAdmin,
fee: estimatedFee,
client,
onTxSucceed,
onTxFailed,
});
},
[address, getCosmWasmClient]
);
};
21 changes: 21 additions & 0 deletions src/lib/components/ErrorMessageRender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { FlexProps } from "@chakra-ui/react";
import { Flex, Icon, Text } from "@chakra-ui/react";
import { IoIosWarning } from "react-icons/io";

interface ErrorMessageRenderProps extends FlexProps {
error: string;
}

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>
);
};
2 changes: 1 addition & 1 deletion src/lib/components/forms/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const TextInput = ({
maxLength={maxLength}
/>
<InputRightElement h="full">
{status && getStatusIcon(status.state)}
{status && getStatusIcon(status.state, "20px")}
</InputRightElement>
</InputGroup>

Expand Down
19 changes: 19 additions & 0 deletions src/lib/components/modal/tx/ButtonSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ export const ButtonSection = ({
Proceed to Migrate
</Button>
);
case "update-admin":
return (
<>
<Button variant="ghost-primary" onClick={openExplorer}>
See Transaction
</Button>
<Button
variant="primary"
rightIcon={
<Icon as={FiChevronRight} color="gray.900" fontSize="18px" />
}
onClick={() =>
navigate({ pathname: `/contract/${router.query.contract}` })
}
>
View Contract Details
</Button>
</>
);
case "rejected":
case "resend":
return (
Expand Down
1 change: 1 addition & 0 deletions src/lib/data/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const typeUrlDict = {
[MsgType.STORE_CODE]: "/cosmwasm.wasm.v1.MsgStoreCode",
[MsgType.INSTANTIATE]: "/cosmwasm.wasm.v1.MsgInstantiateContract",
[MsgType.EXECUTE]: "/cosmwasm.wasm.v1.MsgExecuteContract",
[MsgType.UPDATE_ADMIN]: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
};

export const DEFAULT_RPC_ERROR = "Invalid format, or Something went wrong";
35 changes: 19 additions & 16 deletions src/lib/model/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { useCelatoneApp } from "lib/app-provider";
import { INSTANTIATED_LIST_NAME } from "lib/data";
import { useCodeStore, useContractStore, useLCDEndpoint } from "lib/hooks";
import { useAssetInfos } from "lib/services/assetService";
import type { InstantiateInfo, PublicInfo } from "lib/services/contract";
import type { InstantiateInfo } from "lib/services/contract";
import {
queryPublicInfo,
queryContractBalances,
queryInstantiateInfo,
} from "lib/services/contract";
Expand All @@ -20,13 +19,19 @@ import {
useTxsCountByContractAddress,
useRelatedProposalsCountByContractAddress,
} from "lib/services/contractService";
import {
usePublicProjectByContractAddress,
usePublicProjectBySlug,
} from "lib/services/publicProjectService";
import type { CodeLocalInfo } from "lib/stores/code";
import type { ContractLocalInfo, ContractListInfo } from "lib/stores/contract";
import type {
BalanceWithAssetInfo,
ContractAddr,
Detail,
HumanAddr,
Option,
PublicInfo,
} from "lib/types";
import { formatSlugName } from "lib/utils";

Expand All @@ -35,7 +40,10 @@ export interface ContractData {
codeInfo: Option<CodeLocalInfo>;
contractLocalInfo: Option<ContractLocalInfo>;
instantiateInfo: Option<InstantiateInfo>;
publicInfo: Option<PublicInfo>;
publicProject: {
publicInfo: Option<PublicInfo>;
publicDetail: Option<Detail>;
};
balances: Option<BalanceWithAssetInfo[]>;
initMsg: string;
initTxHash: Option<string>;
Expand Down Expand Up @@ -87,13 +95,16 @@ export const useInstantiatedMockInfoByMe = (): ContractListInfo => {

export const useContractData = (
contractAddress: ContractAddr
): ContractData | undefined => {
): Option<ContractData> => {
const { indexerGraphClient } = useCelatoneApp();
const { currentChainRecord } = useWallet();
const { getCodeLocalInfo } = useCodeStore();
const { getContractLocalInfo } = useContractStore();
const endpoint = useLCDEndpoint();
const assetInfos = useAssetInfos();
const { data: publicInfo } =
usePublicProjectByContractAddress(contractAddress);
const { data: publicInfoBySlug } = usePublicProjectBySlug(publicInfo?.slug);

const { data: instantiateInfo } = useQuery(
["query", "instantiateInfo", endpoint, contractAddress],
Expand Down Expand Up @@ -126,17 +137,6 @@ export const useContractData = (
return -1;
});

const { data: publicInfo } = useQuery(
["query", "publicInfo", contractAddress],
async () =>
queryPublicInfo(
currentChainRecord?.name,
currentChainRecord?.chain.chain_id,
contractAddress
),
{ enabled: !!currentChainRecord }
);

const codeInfo = instantiateInfo
? getCodeLocalInfo(Number(instantiateInfo.codeId))
: undefined;
Expand All @@ -155,7 +155,10 @@ export const useContractData = (
codeInfo,
contractLocalInfo,
instantiateInfo,
publicInfo,
publicProject: {
publicInfo,
publicDetail: publicInfoBySlug?.details,
},
balances: contractBalancesWithAssetInfos,
initMsg: instantiateDetail.initMsg,
initTxHash: instantiateDetail.initTxHash,
Expand Down
Loading

0 comments on commit a0c5fec

Please sign in to comment.