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: migrate options and upload #108

Merged
merged 24 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ff63719
feat: migrate options and upload
songwongtp Jan 19, 2023
2921ea4
fix: changelog
songwongtp Jan 19, 2023
2b878b2
Merge branch 'develop' into component/migrate-step1
songwongtp Jan 19, 2023
1bb7d37
fix: handle not admin case
songwongtp Jan 20, 2023
ca80ab0
Merge branch 'develop' into component/migrate-step1
songwongtp Jan 22, 2023
be68a48
fix: use useForm in upload section
songwongtp Jan 22, 2023
59aaf9a
feat: migration step 2
songwongtp Jan 23, 2023
9754107
feat: add validate code id
songwongtp Jan 24, 2023
e1407c5
Merge branch 'develop' into component/migrate-step2
songwongtp Jan 25, 2023
7478f4b
fix: stop migrate button from loading
songwongtp Jan 25, 2023
3222b91
fix: text
songwongtp Jan 25, 2023
19fb156
fix: as commented
songwongtp Jan 25, 2023
066bef3
fix: navigate to contract page after migrate
songwongtp Jan 26, 2023
a577a37
fix: navigate after clicking close
songwongtp Jan 26, 2023
2b1cd8e
Merge branch 'develop' into component/migrate-step1
songwongtp Jan 26, 2023
a0c5fec
Merge branch 'develop' into component/migrate-step1
songwongtp Jan 27, 2023
65d1622
Merge branch 'component/migrate-step1' into component/migrate-step2
songwongtp Jan 27, 2023
b6261a2
Merge pull request #120 from alleslabs/component/migrate-step2
songwongtp Jan 27, 2023
a797530
fix: as comments
songwongtp Jan 30, 2023
4292ceb
fix: upload access type
songwongtp Jan 30, 2023
5f57aa9
fix: as comments
songwongtp Jan 30, 2023
a18559c
Merge branch 'develop' into component/migrate-step1
songwongtp Jan 30, 2023
36a8fc5
fix: add span
songwongtp Jan 30, 2023
d5ae6db
Merge branch 'develop' into component/migrate-step1
evilpeach Jan 30, 2023
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 @@ -39,6 +39,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
- [#94](https://github.com/alleslabs/celatone-frontend/pull/94) Add unsupported assets in contract details page
- [#72](https://github.com/alleslabs/celatone-frontend/pull/72) Fix general wording and grammar
- [#110](https://github.com/alleslabs/celatone-frontend/pull/110) Fix proposal detail rendering
Expand Down
8 changes: 5 additions & 3 deletions src/lib/app-fns/tx/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface UploadTxParams {
memo?: string;
client: SigningCosmWasmClient;
onTxSucceed?: (codeId: number) => void;
isMigrate: boolean;
}

export const uploadContractTx = ({
Expand All @@ -37,6 +38,7 @@ export const uploadContractTx = ({
memo,
client,
onTxSucceed,
isMigrate,
}: UploadTxParams): Observable<TxResultRendering> => {
return pipe(
sendingTx(fee),
Expand Down Expand Up @@ -80,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: "upload",
actionVariant: isMigrate ? "upload-migrate" : "upload",
} as TxResultRendering;
}
)().pipe(catchTxError());
Expand Down
23 changes: 15 additions & 8 deletions src/lib/app-provider/tx/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +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
) => {
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 @@ -31,8 +37,9 @@ export const useUploadContractTx = (
fee: estimatedFee,
client,
onTxSucceed,
isMigrate,
});
},
[address, getCosmWasmClient, estimatedFee, wasmCode, wasmFileName]
[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 @@ -121,7 +121,7 @@ export const ContractSelectSection = observer(
});

const { refetch } = useQuery(
["query", "instantiateInfo", contractAddress],
["query", "instantiateInfo", endpoint, contractAddress],
async () => queryInstantiateInfo(endpoint, contractAddress),
{
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/forms/FormStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Icon, Spinner, Text } from "@chakra-ui/react";
import { MdCheckCircle, MdOutlineWarning } from "react-icons/md";

type ResponseState = "init" | "loading" | "success" | "error";
export type ResponseState = "init" | "loading" | "success" | "error";

export interface FormStatus {
state: ResponseState;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modal/contract/SaveNewContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function SaveNewContract({ list, buttonProps }: SaveNewContractProps) {

// TODO: Abstract query
const { refetch } = useQuery(
["query", "instantiateInfo", contractAddressState],
["query", "instantiateInfo", endpoint, contractAddressState],
async () =>
queryInstantiateInfo(endpoint, contractAddressState as ContractAddr),
{
Expand Down
23 changes: 23 additions & 0 deletions src/lib/components/modal/tx/ButtonSection.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Button, Icon } from "@chakra-ui/react";
import { useWallet } from "@cosmos-kit/react";
import { useRouter } from "next/router";
import { useCallback } from "react";
import { FiChevronRight } from "react-icons/fi";

import { getExplorerTxUrl } from "lib/app-fns/explorer";
import { useInternalNavigate } from "lib/app-provider";
import type { ActionVariant, TxReceipt } from "lib/types";

// TODO: refactor props to pass param in txResultRendering instead of receipt
interface ButtonSectionProps {
actionVariant?: ActionVariant;
onClose?: () => void;
Expand All @@ -18,6 +20,7 @@ export const ButtonSection = ({
onClose,
receipts,
}: ButtonSectionProps) => {
const router = useRouter();
const navigate = useInternalNavigate();
const { currentChainName } = useWallet();

Expand Down Expand Up @@ -64,6 +67,26 @@ export const ButtonSection = ({
</Button>
</>
);
case "upload-migrate":
return (
<Button
variant="primary"
rightIcon={
<Icon as={FiChevronRight} color="gray.900" fontSize="18px" />
}
onClick={() => {
const codeId = receipts.find((r) => r.title === "Code ID")?.value;

navigate({
pathname: "/migrate",
query: { contract: router.query.contract, "code-id": codeId },
});
onClose?.();
}}
>
Proceed to Migrate
</Button>
);
case "rejected":
case "resend":
return (
Expand Down
11 changes: 9 additions & 2 deletions src/lib/components/stepper/StepperItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Flex, Icon, Text } from "@chakra-ui/react";
import { MdCheck } from "react-icons/md";

import type { Step } from "./types";
import type { Mode, Step } from "./types";

export const stepperText: Record<Mode, Record<number, string>> = {
deploy: { 1: "Upload or Select Code ID", 2: "Instantiate Code" },
migrate: { 1: "Migrate Options", 2: "Migrate Details" },
};

const StepLabel = ({
step,
Expand Down Expand Up @@ -33,9 +38,11 @@ const StepLabel = ({
};

export const StepperItem = ({
mode,
step,
currentStep,
}: {
mode: Mode;
step: Step;
currentStep: Step;
}) => {
Expand All @@ -61,7 +68,7 @@ export const StepperItem = ({
fontWeight={disabled ? 400 : 700}
color={disabled ? "text.disabled" : "text.main"}
>
{step === 1 ? "Upload or Select Code ID" : "Instantiate Code"}
{stepperText[mode][step]}
</Text>
</Flex>
);
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/stepper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Flex } from "@chakra-ui/react";

import { StepperItem } from "./StepperItem";
import type { Step } from "./types";
import type { Mode, Step } from "./types";

interface StepperProps {
mode: Mode;
currentStep: Step;
}

export const Stepper = ({ currentStep }: StepperProps) => {
export const Stepper = ({ mode, currentStep }: StepperProps) => {
return (
<Flex width="100%">
<StepperItem step={1} currentStep={currentStep} />
<StepperItem step={2} currentStep={currentStep} />
<StepperItem step={1} mode={mode} currentStep={currentStep} />
<StepperItem step={2} mode={mode} currentStep={currentStep} />
</Flex>
);
};
2 changes: 2 additions & 0 deletions src/lib/components/stepper/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export type Step = 1 | 2;

export type Mode = "deploy" | "migrate";
Loading