Skip to content

Commit

Permalink
authorize asset
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 9, 2024
1 parent b2525a8 commit 62d93ea
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 102 deletions.
103 changes: 101 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/identity": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@monaco-editor/react": "4.6.0",
"@types/react": "^18.3.5",
Expand Down
180 changes: 93 additions & 87 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
workplaceReducer,
WorkplaceDispatchContext,
WorkerContext,
ContainerContext,
getActorAliases,
getDeployedCanisters,
getShareableProject,
Expand Down Expand Up @@ -66,6 +67,17 @@ const AppContainer = styled.div<{ candidWidth: string; consoleHeight: string }>`
const worker = Comlink.wrap(
new Worker(new URL("./workers/moc.ts", import.meta.url), { type: "module" }),
);
const terminal = new Terminal({
cursorBlink: true,
fontSize: 14,
fontFamily: "monospace",
theme: {
background: "#ffffff",
foreground: "#000000",
cursor: "#000000",
},
});
const container = new Container(terminal);
const urlParams = new URLSearchParams(window.location.search);
const hasUrlParams = !!(
urlParams.get("git") ||
Expand Down Expand Up @@ -182,16 +194,6 @@ export function App() {
};

const logger = useLogging();
const terminal = new Terminal({
cursorBlink: true,
fontSize: 14,
fontFamily: "monospace",
theme: {
background: "#ffffff",
foreground: "#000000",
cursor: "#000000",
},
});

function closeProjectModal() {
setIsProjectModalOpen(false);
Expand Down Expand Up @@ -253,11 +255,10 @@ export function App() {
});
logger.log(`moc version ${MOC_VERSION}`);
logger.log(`base library version ${baseInfo.version}`);
const container = new Container(terminal);
await container.initFiles();
await container.run_cmd("npm", ["install"]);
await container.run_cmd("npm", ["run", "build"]);
await container.run_cmd("node", ["uploadAsset.js", "dist"]);
//await container.run_cmd("node", ["uploadAsset.js", "dist"]);
// fetch code after loading base library
if (hasUrlParams) {
const files = await fetchFromUrlParams(workplaceDispatch);
Expand Down Expand Up @@ -302,87 +303,92 @@ export function App() {
/>
<WorkplaceDispatchContext.Provider value={workplaceDispatch}>
<WorkerContext.Provider value={worker}>
<ProjectModal
isOpen={isProjectModalOpen}
importCode={importCode}
close={closeProjectModal}
isFirstOpen={isFirstVisit}
/>
<DeployModal
state={workplaceState}
isOpen={showDeployModal}
close={() => setShowDeployModal(false)}
onDeploy={deployWorkplace}
isDeploy={setIsDeploying}
canisters={getDeployedCanisters(workplaceState.canisters)}
ttl={TTL}
fileName={mainFile}
wasm={wasm}
candid={candidCode}
initTypes={initTypes}
logger={logger}
origin={workplaceState.origin}
/>
<AppContainer candidWidth={candidWidth} consoleHeight={consoleHeight}>
<Explorer
state={workplaceState}
ttl={TTL}
logger={logger}
deploySetter={deploySetter}
<ContainerContext.Provider value={container}>
<ProjectModal
isOpen={isProjectModalOpen}
importCode={importCode}
close={closeProjectModal}
isFirstOpen={isFirstVisit}
/>
<Editor
<DeployModal
state={workplaceState}
isOpen={showDeployModal}
close={() => setShowDeployModal(false)}
onDeploy={deployWorkplace}
isDeploy={setIsDeploying}
canisters={getDeployedCanisters(workplaceState.canisters)}
ttl={TTL}
fileName={mainFile}
wasm={wasm}
candid={candidCode}
initTypes={initTypes}
logger={logger}
terminal={terminal}
deploySetter={deploySetter}
isDeploying={isDeploying}
setConsoleHeight={setConsoleHeight}
origin={workplaceState.origin}
/>
{showCandidUI ? (
<CandidUI
setCandidWidth={setCandidWidth}
canisterId={workplaceState.canisters[
workplaceState.selectedCanister!
]?.id.toString()}
candid={
workplaceState.canisters[workplaceState.selectedCanister!]
?.candid
}
forceUpdate={forceUpdate}
onMessage={({ origin, source, message }) => {
if (!message.caller) return;
// We have to check children for all canisters in workplaceState,
// because message.caller can call other canisters to spawn new children.
const nameMap = Object.fromEntries(
Object.entries(workplaceState.canisters).map(
([name, info]) => [info.id, name],
),
);
Object.entries(workplaceState.canisters).forEach(
async ([_, info]) => {
if (!info.timestamp || info.isExternal) {
return;
}
const subtree = await backend.getSubtree(info);
subtree.reverse().forEach(([parentId, children]) => {
const parentName = nameMap[parentId];
// Assume children is sorted by timestamp
children.reverse().forEach((child, i) => {
child.name = `${parentName}_${i}`;
child.isExternal = false;
nameMap[child.id] = child.name;
workplaceDispatch({
type: "deployWorkplace",
payload: { canister: child, do_not_select: true },
<AppContainer
candidWidth={candidWidth}
consoleHeight={consoleHeight}
>
<Explorer
state={workplaceState}
ttl={TTL}
logger={logger}
deploySetter={deploySetter}
/>
<Editor
state={workplaceState}
logger={logger}
terminal={terminal}
deploySetter={deploySetter}
isDeploying={isDeploying}
setConsoleHeight={setConsoleHeight}
/>
{showCandidUI ? (
<CandidUI
setCandidWidth={setCandidWidth}
canisterId={workplaceState.canisters[
workplaceState.selectedCanister!
]?.id.toString()}
candid={
workplaceState.canisters[workplaceState.selectedCanister!]
?.candid
}
forceUpdate={forceUpdate}
onMessage={({ origin, source, message }) => {
if (!message.caller) return;
// We have to check children for all canisters in workplaceState,
// because message.caller can call other canisters to spawn new children.
const nameMap = Object.fromEntries(
Object.entries(workplaceState.canisters).map(
([name, info]) => [info.id, name],
),
);
Object.entries(workplaceState.canisters).forEach(
async ([_, info]) => {
if (!info.timestamp || info.isExternal) {
return;
}
const subtree = await backend.getSubtree(info);
subtree.reverse().forEach(([parentId, children]) => {
const parentName = nameMap[parentId];
// Assume children is sorted by timestamp
children.reverse().forEach((child, i) => {
child.name = `${parentName}_${i}`;
child.isExternal = false;
nameMap[child.id] = child.name;
workplaceDispatch({
type: "deployWorkplace",
payload: { canister: child, do_not_select: true },
});
});
});
});
},
);
}}
/>
) : null}
</AppContainer>
},
);
}}
/>
) : null}
</AppContainer>
</ContainerContext.Provider>
</WorkerContext.Provider>
</WorkplaceDispatchContext.Provider>
</main>
Expand Down
Loading

0 comments on commit 62d93ea

Please sign in to comment.