Skip to content

Commit

Permalink
frontend deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 9, 2024
1 parent cd73d38 commit b2525a8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion service/pool/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
Expand Down
38 changes: 37 additions & 1 deletion src/components/DeployModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +122,7 @@ interface DeployModalProps {
candid: string;
initTypes: Array<IDL.Type>;
logger: ILoggingStore;
origin: string | undefined;
origin: Origin;
}

const MAX_CANISTERS = 3;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -576,6 +611,7 @@ actor {
Install
</MyButton>
)}
<MyButton onClick={deployFrontend}>Frontend</MyButton>
<MyButton onClick={close}>Cancel</MyButton>
</ButtonContainer>
) : null}
Expand Down

0 comments on commit b2525a8

Please sign in to comment.