diff --git a/intro/4-ipfs-code-execution/web/src/App.scss b/intro/4-ipfs-code-execution/web/src/App.scss
index 1955419..808bd03 100644
--- a/intro/4-ipfs-code-execution/web/src/App.scss
+++ b/intro/4-ipfs-code-execution/web/src/App.scss
@@ -3,7 +3,7 @@ $color2: rgb(214, 214, 214);
$accent-color: rgb(225, 30, 90);
.logo {
- height: 15vmin;
+ height: 10vmin;
pointer-events: none;
}
@@ -16,7 +16,7 @@ $accent-color: rgb(225, 30, 90);
}
header {
- margin-top: 10vmin;
+ margin-top: 3vmin;
}
header,
@@ -44,23 +44,13 @@ li {
padding: 0;
}
-.p {
- width: 550px;
+p {
+ margin: 0.5em;
+ text-align: left;
}
-.btn-clipboard {
- border: none;
- background-color: transparent;
- cursor: pointer;
-
- &:hover,
- &:focus {
- color: $accent-color;
- }
-
- &:focus {
- outline: none;
- }
+.row {
+ width: 100%;
}
.btn {
@@ -88,27 +78,49 @@ li {
}
}
-.btn-hello {
- width: 200px;
+.btn-right {
+ width: 250px;
display: inline;
float: right;
}
+.btn-inline {
+ background-color: transparent;
+ margin: 5px;
+
+ display: inline;
+ border: none;
+ font-size: inherit;
+ font-family: inherit;
+ color: $accent-color;
+ outline: none;
+
+ &:hover,
+ &:focus {
+ outline: none;
+ text-decoration: underline;
+ cursor: pointer;
+ }
+}
+
table {
text-align: right;
}
.label {
- width: 240px;
+ width: 30%;
display: inline-block;
+ text-align: right;
+ margin-right: 5px;
}
.input {
- width: 500px;
+ width: calc(70% - 15px);
height: 26px;
box-sizing: border-box;
margin: 5px;
+ padding: 0 5px;
border: 1px solid;
border-color: $color2;
@@ -125,75 +137,15 @@ table {
}
}
-.gg-clipboard {
+.input-ro {
+ display: inline;
+ width: 500px;
+ height: 26px;
box-sizing: border-box;
- position: relative;
- display: block;
- transform: scale(var(--ggs, 1));
- width: 18px;
- height: 18px;
- border: 2px solid;
- border-radius: 2px;
-}
-.gg-clipboard::after,
-.gg-clipboard::before {
- content: "";
- display: block;
- box-sizing: border-box;
- position: absolute;
- border-radius: 2px;
- width: 10px;
- left: 2px;
-}
-.gg-clipboard::before {
- border: 2px solid;
- border-bottom-left-radius: 3px;
- border-bottom-right-radius: 3px;
- top: -2px;
- height: 6px;
-}
-.gg-clipboard::after {
- height: 2px;
- background: currentColor;
- box-shadow: 0 -4px 0 0;
- bottom: 2px;
+
+ margin: 5px;
}
-.gg-trash {
- box-sizing: border-box;
- position: relative;
- display: block;
- transform: scale(var(--ggs, 1));
- width: 10px;
- height: 12px;
- border: 2px solid transparent;
- box-shadow: 0 0 0 2px, inset -2px 0 0, inset 2px 0 0;
- border-bottom-left-radius: 1px;
- border-bottom-right-radius: 1px;
- margin-top: 4px;
-}
-.gg-trash::after,
-.gg-trash::before {
- content: "";
- display: block;
- box-sizing: border-box;
- position: absolute;
-}
-.gg-trash::after {
- background: currentColor;
- border-radius: 3px;
- width: 16px;
- height: 2px;
- top: -4px;
- left: -5px;
-}
-.gg-trash::before {
- width: 10px;
- height: 4px;
- border: 2px solid;
- border-bottom: transparent;
- border-top-left-radius: 2px;
- border-top-right-radius: 2px;
- top: -7px;
- left: -2px;
+.article {
+ margin-bottom: 10px;
}
diff --git a/intro/4-ipfs-code-execution/web/src/App.tsx b/intro/4-ipfs-code-execution/web/src/App.tsx
index d8c248f..2a5e294 100644
--- a/intro/4-ipfs-code-execution/web/src/App.tsx
+++ b/intro/4-ipfs-code-execution/web/src/App.tsx
@@ -2,18 +2,25 @@ import React from "react";
import logo from "./logo.svg";
import "./App.scss";
-import { gotRpcAddrState, isConnectedState, isDeployedState } from "./state";
+import {
+ gotRpcAddrState,
+ hasResultState,
+ isConnectedState,
+ isDeployedState,
+} from "./state";
import { useRecoilValue } from "recoil";
import { ConnectedInfo } from "./Components/ConnectedInfo";
import { ConnectionForm } from "./Components/ConnectionForm";
import { IpfsForm } from "./Components/IpfsForm";
import { IpfsDeploymentInfo } from "./Components/IpfsDeploymentInfo";
import { SizeCalcForm } from "./Components/SizeCalcForm";
+import { SizeCalcResult } from "./Components/SizeCalcResult";
function App() {
const isConnected = useRecoilValue(isConnectedState);
const gotRpcAddr = useRecoilValue(gotRpcAddrState);
const isDeployed = useRecoilValue(isDeployedState);
+ const hasResult = useRecoilValue(hasResultState);
console.log(
"isConnected gotRpcAddr deployed\n",
@@ -38,6 +45,7 @@ function App() {
>
)}
+ {isDeployed && hasResult && }
);
diff --git a/intro/4-ipfs-code-execution/web/src/Components/ConnectedInfo.tsx b/intro/4-ipfs-code-execution/web/src/Components/ConnectedInfo.tsx
index bb3983e..5125a46 100644
--- a/intro/4-ipfs-code-execution/web/src/Components/ConnectedInfo.tsx
+++ b/intro/4-ipfs-code-execution/web/src/Components/ConnectedInfo.tsx
@@ -1,6 +1,6 @@
import { useRecoilValue } from "recoil";
import { clientState } from "../state";
-import { copyToClipboard } from "../util";
+import { TextWithLabel } from "./TextInput";
export const ConnectedInfo = () => {
const client = useRecoilValue(clientState);
@@ -11,34 +11,8 @@ export const ConnectedInfo = () => {
return (
<>
Connected
-
-
-
- Peer id:
- {client.selfPeerId}
-
- copyToClipboard(client.selfPeerId)}
- >
-
-
-
-
-
- Relay peer id:
- {client.relayPeerId}
-
- copyToClipboard(client.relayPeerId!)}
- >
-
-
-
-
-
-
+
+
>
);
};
diff --git a/intro/4-ipfs-code-execution/web/src/Components/IpfsDeploymentInfo.tsx b/intro/4-ipfs-code-execution/web/src/Components/IpfsDeploymentInfo.tsx
index f073cf2..d01cfae 100644
--- a/intro/4-ipfs-code-execution/web/src/Components/IpfsDeploymentInfo.tsx
+++ b/intro/4-ipfs-code-execution/web/src/Components/IpfsDeploymentInfo.tsx
@@ -1,36 +1,29 @@
import { useRecoilValue } from "recoil";
-import { serviceIdState, useRemoveServuce, wasmState } from "../state";
+import { serviceIdState, useRemoveService, wasmState } from "../state";
import { copyToClipboard } from "../util";
+import { TextWithLabel } from "./TextInput";
export const IpfsDeploymentInfo = () => {
const wasm = useRecoilValue(wasmState);
const serviceId = useRecoilValue(serviceIdState);
- const removeService = useRemoveServuce;
+ const removeService = useRemoveService();
return (
<>
- Deployed
-
-
- process_files.wasm CID:
- {wasm}
-
- copyToClipboard(wasm)}
- >
-
-
-
-
-
- ProcessFiles service ID:
- {serviceId}
-
-
-
-
-
+
+ Service deployed{" "}
+
+ remove
+
+
+
+
+ Service deployed into Fluence network. You can observe it's service ID
+ as well as the CID of the wasm file used to create the service
+
+
+
+
>
);
};
diff --git a/intro/4-ipfs-code-execution/web/src/Components/IpfsForm.tsx b/intro/4-ipfs-code-execution/web/src/Components/IpfsForm.tsx
index 82af2fe..b025c44 100644
--- a/intro/4-ipfs-code-execution/web/src/Components/IpfsForm.tsx
+++ b/intro/4-ipfs-code-execution/web/src/Components/IpfsForm.tsx
@@ -9,17 +9,19 @@ export const IpfsForm = () => {
return (
<>
- Ipfs
-
- process_files.wasm will be downloaded via IPFS to the Fluence node, and
- then a service will be dynamically created from it! After that, you will
- be able to use that service to get sizes of IPFS files!
-
- To do so, please specify IPFS RPC address to download process_files.wasm
- from
-
- And specify CID of WebAssembly module.
-
+ Deploy service from IPFS
+
+
Now we can deploy service from IPFS into Fluence network
+
+ process_files.wasm will be downloaded via IPFS to the Fluence node,
+ and then a service will be dynamically created from it! After that,
+ you will be able to use that service to get sizes of IPFS files!
+
+
+ To do so, please specify IPFS RPC address of process_files.wasm from,
+ and the CIP of WebAssembly module to use (process_files.wasm)
+
+
{
setValue={setWasm}
/>
-
+
deploy service
diff --git a/intro/4-ipfs-code-execution/web/src/Components/SizeCalcForm.tsx b/intro/4-ipfs-code-execution/web/src/Components/SizeCalcForm.tsx
index 9ab587b..09c2154 100644
--- a/intro/4-ipfs-code-execution/web/src/Components/SizeCalcForm.tsx
+++ b/intro/4-ipfs-code-execution/web/src/Components/SizeCalcForm.tsx
@@ -1,55 +1,29 @@
import { useRecoilState, useRecoilValue } from "recoil";
-import {
- fileCIDState,
- fileSizeCIDState,
- fileSizeState,
- rpcAddrState,
- useGetFileSize,
-} from "../state";
+import { fileCIDState, rpcAddrState, useGetFileSize } from "../state";
+import { TextInput } from "./TextInput";
export const SizeCalcForm = () => {
const rpcAddr = useRecoilValue(rpcAddrState);
const [fileCID, setFileCID] = useRecoilState(fileCIDState);
- const fileSize = useRecoilValue(fileSizeState);
- const fileSizeCID = useRecoilValue(fileSizeCIDState);
const getFileSize = useGetFileSize();
return (
<>
-
-
Get file size
-
+
Get file size
+
+
Upload any file to IPFS node
-
- {rpcAddr}
-
+
{rpcAddr}
paste CID here and get the size of that file via ProcessFiles service
you have just deployed
-
- IPFS CID
- setFileCID(e.target.value)}
- value={fileCID}
- />
-
-
-
- get size
-
-
+
+
- File Size:
- {fileSize}
-
-
-
- File size is uploaded to IPFS as CID:
-
- {fileSizeCID}
+
+ get size
+
>
);
diff --git a/intro/4-ipfs-code-execution/web/src/Components/SizeCalcResult.tsx b/intro/4-ipfs-code-execution/web/src/Components/SizeCalcResult.tsx
new file mode 100644
index 0000000..b8a1ad3
--- /dev/null
+++ b/intro/4-ipfs-code-execution/web/src/Components/SizeCalcResult.tsx
@@ -0,0 +1,23 @@
+import { useRecoilValue } from "recoil";
+import { fileSizeCIDState, fileSizeState } from "../state";
+import { TextWithLabel } from "./TextInput";
+
+export const SizeCalcResult = () => {
+ const fileSize = useRecoilValue(fileSizeState);
+ const fileSizeCID = useRecoilValue(fileSizeCIDState);
+
+ return (
+ <>
+
Result
+
+
+ File size has been calculated and displayed below. Also the result of
+ the calculation has been uploaded to IPFS and is available under it's
+ CID
+
+
+
+
+ >
+ );
+};
diff --git a/intro/4-ipfs-code-execution/web/src/Components/TextInput.tsx b/intro/4-ipfs-code-execution/web/src/Components/TextInput.tsx
index 1ba57fd..bf3a917 100644
--- a/intro/4-ipfs-code-execution/web/src/Components/TextInput.tsx
+++ b/intro/4-ipfs-code-execution/web/src/Components/TextInput.tsx
@@ -18,3 +18,15 @@ export const TextInput = (props: {
);
};
+
+export const TextWithLabel = (props: {
+ text: string;
+ value: string | null;
+}) => {
+ return (
+
+
{props.text}
+
{props.value || ""}
+
+ );
+};
diff --git a/intro/4-ipfs-code-execution/web/src/state.ts b/intro/4-ipfs-code-execution/web/src/state.ts
index 2a18a2d..acd41e8 100644
--- a/intro/4-ipfs-code-execution/web/src/state.ts
+++ b/intro/4-ipfs-code-execution/web/src/state.ts
@@ -38,19 +38,19 @@ export const rpcAddrState = atom({
default: null,
});
-export const fileCIDState = atom({
+export const fileCIDState = atom({
key: "fileCIDState",
- default: "",
+ default: null,
});
-export const fileSizeState = atom({
+export const fileSizeState = atom({
key: "fileSizeState",
- default: "",
+ default: null,
});
-export const fileSizeCIDState = atom({
+export const fileSizeCIDState = atom({
key: "fileSizeCIDState",
- default: "",
+ default: null,
});
export const isConnectedState = selector({
@@ -81,6 +81,14 @@ export const isDeployedState = selector({
},
});
+export const hasResultState = selector({
+ key: "hasResultState",
+ get: ({ get }) => {
+ const fileSize = get(fileSizeState);
+ return fileSize !== null;
+ },
+});
+
const getRpcAddr = async (client: FluenceClient) => {
if (client === null) {
console.log("getRpcAddr client is null");
@@ -140,8 +148,9 @@ export const useGetFileSize = () => {
const rpcAddr = useRecoilValue(rpcAddrState);
const client = useRecoilValue(clientState);
const serviceId = useRecoilValue(serviceIdState);
+ const fileCID = useRecoilValue(fileCIDState);
const setFileSize = useSetRecoilState(fileSizeState);
- const [fileCID, setFileSizeCID] = useRecoilState(fileCIDState);
+ const setFileSizeCID = useSetRecoilState(fileSizeCIDState);
return async () => {
if (client === null || serviceId === null || rpcAddr === null) {
@@ -151,7 +160,7 @@ export const useGetFileSize = () => {
var putResult = await put_file_size(
client,
client.relayPeerId!,
- fileCID,
+ fileCID!,
rpcAddr,
serviceId,
(size) => setFileSize(size.toString()),
@@ -170,9 +179,12 @@ export const useGetFileSize = () => {
};
};
-export const useRemoveServuce = () => {
+export const useRemoveService = () => {
const client = useRecoilValue(clientState);
const [serviceId, setServiceId] = useRecoilState(serviceIdState);
+ const setFileCID = useSetRecoilState(fileCIDState);
+ const setFileSize = useSetRecoilState(fileSizeState);
+ const setFileSizeCID = useSetRecoilState(fileSizeCIDState);
return async () => {
if (client === null || serviceId === null) {
@@ -183,5 +195,8 @@ export const useRemoveServuce = () => {
ttl: 10000,
});
setServiceId(null);
+ setFileCID(null);
+ setFileSize(null);
+ setFileSizeCID(null);
};
};