From b2525a87d22154920eb48889262883e4915b6fb7 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:33:32 -0700 Subject: [PATCH] frontend deploy --- service/pool/Main.mo | 2 +- src/components/DeployModal.tsx | 38 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/service/pool/Main.mo b/service/pool/Main.mo index e6922e40..5fa2801f 100644 --- a/service/pool/Main.mo +++ b/service/pool/Main.mo @@ -247,7 +247,7 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this { if (not validateOrigin(origin)) { throw Error.reject "Please specify a valid origin"; }; - if (pool.find info) { + if (not pool.find info) { stats := Logs.updateStats(stats, #mismatch); throw Error.reject "Cannot find canister"; }; diff --git a/src/components/DeployModal.tsx b/src/components/DeployModal.tsx index f44fa3b9..064198d0 100644 --- a/src/components/DeployModal.tsx +++ b/src/components/DeployModal.tsx @@ -16,12 +16,16 @@ import { WorkerContext, WorkplaceDispatchContext, WorkplaceState, + Origin, } from "../contexts/WorkplaceState"; import { didjs } from "../config/actor"; import { Field } from "./shared/Field"; import { Confirm } from "./shared/Confirm"; import "../assets/styles/candid.css"; +const assetWasmHash = + "3a533f511b3960b4186e76cf9abfbd8222a2c507456a66ec55671204ee70cae3"; + const ModalContainer = styled.div` display: flex; flex-direction: column; @@ -118,7 +122,7 @@ interface DeployModalProps { candid: string; initTypes: Array; logger: ILoggingStore; - origin: string | undefined; + origin: Origin; } const MAX_CANISTERS = 3; @@ -308,6 +312,37 @@ export function DeployModal({ } catch (err) {} } + async function deployFrontend() { + try { + await close(); + await isDeploy(true); + const module_hash = assetWasmHash + .match(/.{2}/g)! + .map((byte) => parseInt(byte, 16)); + const info = await deploy( + worker, + canisterName, + canisters[canisterName], + new Uint8Array(IDL.encode([], [])), + "install", + new Uint8Array(module_hash), + true, + false, + false, + logger, + origin, + ); + await isDeploy(false); + setCompileResult({ wasm: undefined }); + if (info) { + onDeploy(info); + } + } catch (err) { + await isDeploy(false); + throw err; + } + } + async function handleDeploy(mode: string) { const args = parse(); await addTags(); @@ -576,6 +611,7 @@ actor { Install )} + Frontend Cancel ) : null}