Skip to content

Commit

Permalink
Merge branch 'component/migrate-step1' into component/migrate-step2
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp committed Jan 27, 2023
2 parents a577a37 + a0c5fec commit 65d1622
Show file tree
Hide file tree
Showing 70 changed files with 1,328 additions and 446 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#120](https://github.com/alleslabs/celatone-frontend/pull/120) Add simulate migrate fee and the final migration step
- [#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
- [#125](https://github.com/alleslabs/celatone-frontend/pull/125) Add connect wallet alert in instantiate page
- [#126](https://github.com/alleslabs/celatone-frontend/pull/126) Add port id copier for IBC port id
Expand Down Expand Up @@ -108,6 +111,10 @@ 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
- [#122](https://github.com/alleslabs/celatone-frontend/pull/122) Fix unknown code upload block height
- [#121](https://github.com/alleslabs/celatone-frontend/pull/121) Fix code snippet for query axios
- [#119](https://github.com/alleslabs/celatone-frontend/pull/119) Fix searching and project ordering in public projects page
Expand Down
11 changes: 1 addition & 10 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,17 +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",
[MsgType.MIGRATE]: "/cosmwasm.wasm.v1.MsgMigrateContract",
};

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 @@ -84,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
72 changes: 72 additions & 0 deletions src/lib/app-fns/tx/clearAdmin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Icon } from "@chakra-ui/react";
import type {
SigningCosmWasmClient,
ChangeAdminResult,
} 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 { TxStreamPhase } from "lib/types";
import type { TxResultRendering, ContractAddr } from "lib/types";
import { formatUFee } from "lib/utils";

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

interface ClearAdminTxParams {
address: string;
contractAddress: ContractAddr;
fee: StdFee;
memo?: string;
client: SigningCosmWasmClient;
onTxSucceed?: (txHash: string) => void;
}

export const clearAdminTx = ({
address,
contractAddress,
fee,
memo,
client,
onTxSucceed,
}: ClearAdminTxParams): Observable<TxResultRendering> => {
return pipe(
sendingTx(fee),
postTx<ChangeAdminResult>({
postFn: () => client.clearAdmin(address, contractAddress, fee, memo),
}),
({ value: txInfo }) => {
onTxSucceed?.(txInfo.transactionHash);
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: "Transaction Complete",
headerIcon: (
<Icon as={MdCheckCircle} color="success.main" boxSize={6} />
),
},
} as TxResultRendering;
}
)().pipe(catchTxError());
};
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));
};
10 changes: 5 additions & 5 deletions src/lib/app-fns/tx/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface UploadTxParams {
memo?: string;
client: SigningCosmWasmClient;
onTxSucceed?: (codeId: number) => void;
onMigrate: boolean;
isMigrate: boolean;
}

export const uploadContractTx = ({
Expand All @@ -38,7 +38,7 @@ export const uploadContractTx = ({
memo,
client,
onTxSucceed,
onMigrate,
isMigrate,
}: UploadTxParams): Observable<TxResultRendering> => {
return pipe(
sendingTx(fee),
Expand Down Expand Up @@ -82,15 +82,15 @@ export const uploadContractTx = ({
<span style={{ fontWeight: 700 }}>
{codeDesc || `${wasmFileName}(${txInfo.codeId})`}
</span>{" "}
is available on your stored code. Would you like to instantiate
your code now?
is available on your stored code. Would you like to{" "}
{isMigrate ? "migrate" : "instantiate"} your code now?
</>
),
headerIcon: (
<Icon as={MdCloudUpload} fontSize="24px" color="text.dark" />
),
},
actionVariant: onMigrate ? "upload-migrate" : "upload",
actionVariant: isMigrate ? "upload-migrate" : "upload",
} as TxResultRendering;
}
)().pipe(catchTxError());
Expand Down
34 changes: 34 additions & 0 deletions src/lib/app-provider/tx/clearAdmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useWallet } from "@cosmos-kit/react";
import { useCallback } from "react";

import { useFabricateFee } from "../hooks";
import { clearAdminTx } from "lib/app-fns/tx/clearAdmin";
import { CLEAR_ADMIN_GAS } from "lib/data";
import type { ContractAddr } from "lib/types";

export interface ClearAdminStreamParams {
onTxSucceed?: (txHash: string) => void;
}

export const useClearAdminTx = (contractAddress: ContractAddr) => {
const { address, getCosmWasmClient } = useWallet();
const fabricateFee = useFabricateFee();
const clearAdminFee = fabricateFee(CLEAR_ADMIN_GAS);

return useCallback(
async ({ onTxSucceed }: ClearAdminStreamParams) => {
const client = await getCosmWasmClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");

return clearAdminTx({
address,
contractAddress,
fee: clearAdminFee,
client,
onTxSucceed,
});
},
[address, clearAdminFee, contractAddress, getCosmWasmClient]
);
};
4 changes: 4 additions & 0 deletions src/lib/app-provider/tx/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export * from "./upload";
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]
);
};
32 changes: 15 additions & 17 deletions src/lib/app-provider/tx/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import { useWallet } from "@cosmos-kit/react";
import { useCallback } from "react";

import { uploadContractTx } from "lib/app-fns/tx/upload";
import type { Option } from "lib/types";

export interface UploadStreamParams {
onTxSucceed?: (codeId: number) => void;
wasmFileName: Option<string>;
wasmCode: Option<Promise<ArrayBuffer>>;
codeDesc: string;
estimatedFee: Option<StdFee>;
onTxSucceed?: (codeId: number) => void;
}

export const useUploadContractTx = (
wasmFileName: string | undefined,
wasmCode: Promise<ArrayBuffer> | undefined,
estimatedFee: StdFee | undefined,
onMigrate: boolean
) => {
export const useUploadContractTx = (isMigrate: boolean) => {
const { address, getCosmWasmClient } = useWallet();

return useCallback(
async ({ onTxSucceed, codeDesc }: UploadStreamParams) => {
async ({
wasmFileName,
wasmCode,
codeDesc,
estimatedFee,
onTxSucceed,
}: UploadStreamParams) => {
const client = await getCosmWasmClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
Expand All @@ -32,16 +37,9 @@ export const useUploadContractTx = (
fee: estimatedFee,
client,
onTxSucceed,
onMigrate,
isMigrate,
});
},
[
address,
getCosmWasmClient,
estimatedFee,
wasmCode,
wasmFileName,
onMigrate,
]
[address, getCosmWasmClient, isMigrate]
);
};
2 changes: 1 addition & 1 deletion src/lib/components/ContractSelectSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const ContractSelectSection = observer(
});

const { refetch } = useQuery(
["query", "instantiateInfo", contractAddress],
["query", "instantiateInfo", endpoint, contractAddress],
async () =>
queryInstantiateInfo(endpoint, indexerGraphClient, contractAddress),
{
Expand Down
Loading

0 comments on commit 65d1622

Please sign in to comment.