From a4068f22e146e80102cb46886def5e429c72ae68 Mon Sep 17 00:00:00 2001 From: ankushKun Date: Tue, 21 May 2024 20:54:51 +0530 Subject: [PATCH] figured out sharing encoding --- next_app/src/components/ao/blueprints.tsx | 3 +- next_app/src/components/ao/landing.tsx | 40 +++++++++++++++++++- next_app/src/components/ao/modules.tsx | 3 +- next_app/src/components/bottom-statusbar.tsx | 5 ++- next_app/src/components/top-bar.tsx | 35 +++++++++-------- next_app/src/pages/import.tsx | 6 +-- next_app/src/styles/globals.css | 4 +- 7 files changed, 71 insertions(+), 25 deletions(-) diff --git a/next_app/src/components/ao/blueprints.tsx b/next_app/src/components/ao/blueprints.tsx index 5c83f36..b3b5f9a 100644 --- a/next_app/src/components/ao/blueprints.tsx +++ b/next_app/src/components/ao/blueprints.tsx @@ -40,8 +40,9 @@ export default function Blueprints() { if (!project.process) return toast({ title: "Process id missing", description: "The active project doesnot seem to have a process id" }); setOpen(true); }}> - diff --git a/next_app/src/components/ao/landing.tsx b/next_app/src/components/ao/landing.tsx index f2fa9bf..1597011 100644 --- a/next_app/src/components/ao/landing.tsx +++ b/next_app/src/components/ao/landing.tsx @@ -1,3 +1,7 @@ +import { toast } from "@/components/ui/use-toast"; +import { Button } from "../ui/button" +import { useEffect, useState } from "react"; +import { useLocalStorage } from "usehooks-ts"; const words = [ "winston", @@ -30,18 +34,50 @@ const cat = ` ` export default function AOLanding() { + const [walletAddress, setWalletAddress] = useState(""); + const [autoconnect, setAutoconnect] = useLocalStorage("autoconnect", false, { initializeWithValue: true }); + + async function connectWallet() { + if (!window.arweaveWallet) + return toast({ + title: "No Arweave wallet found", + description: "You might want to install ArConnect extension to connect your wallet", + }); + await window.arweaveWallet.connect(["ACCESS_ADDRESS", "SIGN_TRANSACTION"]); + const addr = await window.arweaveWallet.getActiveAddress(); + const addrCropped = addr.slice(0, 9) + "..." + addr.slice(-9); + setWalletAddress(addr); + toast({ title: `Connected to ${addrCropped}` }); + setAutoconnect(true); + } + + function disconnectWallet() { + window.arweaveWallet.disconnect(); + setAutoconnect(false); + setWalletAddress(""); + } + + useEffect(() => { + if (autoconnect) connectWallet(); + else { + disconnectWallet(); + } + }, [autoconnect]); + return <> -
+

gm { words[Math.floor(Math.random() * words.length)] }

-

+

Welcome to the intuitive web IDE for building powerful actor oriented applications.

+ {!walletAddress && } +

Create a new project from the sidebar

diff --git a/next_app/src/components/ao/modules.tsx b/next_app/src/components/ao/modules.tsx index 1b59037..7683460 100644 --- a/next_app/src/components/ao/modules.tsx +++ b/next_app/src/components/ao/modules.tsx @@ -34,8 +34,9 @@ export default function Modules() { if (!project.process) return toast({ title: "Process id missing", description: "The active project doesnot seem to have a process id" }); setOpen(true); }}> - diff --git a/next_app/src/components/bottom-statusbar.tsx b/next_app/src/components/bottom-statusbar.tsx index be37a96..123b9e7 100644 --- a/next_app/src/components/bottom-statusbar.tsx +++ b/next_app/src/components/bottom-statusbar.tsx @@ -37,11 +37,14 @@ export default function BottomStatusbar() { useEffect(() => { if (autoconnect) connectWallet(); + else { + disconnectWallet(); + } }, [autoconnect]); return (
- {walletAddress.length > 0 && ( diff --git a/next_app/src/components/top-bar.tsx b/next_app/src/components/top-bar.tsx index ffb4781..0ba3679 100644 --- a/next_app/src/components/top-bar.tsx +++ b/next_app/src/components/top-bar.tsx @@ -11,6 +11,7 @@ import Blueprints from "./ao/blueprints"; import Modules from "./ao/modules"; import { useProjectManager } from "@/hooks"; import { parseOutupt, runLua } from "@/lib/ao-vars"; +import { unescape } from "querystring"; export default function TopBar() { const router = useRouter(); @@ -32,20 +33,20 @@ export default function TopBar() { delete project.ownerWallet delete project.process - const luaToRun = `_BETTERIDEA_SHARE = '${JSON.stringify(project, (k, v) => { - if (typeof v === "string") return v.replaceAll('"', '\\"').replaceAll("'", "\'").replaceAll("\n", "\\n") - return v - }).toString()}' - -Handlers.add( - "Get-Better-IDEa-Share", - Handlers.utils.hasMatchingTag("Action","Get-BetterIDEa-Share"), - function(msg) - ao.send({Target=msg.From, Action="BetterIDEa-Share-Response", Data=_BETTERIDEA_SHARE}) - return _BETTERIDEA_SHARE - end -) -` + // const stringProj = JSON.stringify(project, null, 2).replaceAll("\\n","") + const urlEncodedJson = encodeURIComponent(JSON.stringify(project)).replaceAll("'", "\\'") + + const luaToRun = `_BETTERIDEA_SHARE = '${urlEncodedJson}' + + Handlers.add( + "Get-Better-IDEa-Share", + Handlers.utils.hasMatchingTag("Action","Get-BetterIDEa-Share"), + function(msg) + ao.send({Target=msg.From, Action="BetterIDEa-Share-Response", Data=_BETTERIDEA_SHARE}) + return _BETTERIDEA_SHARE + end + ) + ` console.log(luaToRun) setSharing(true); const res = await runLua(luaToRun, processBackup, [ @@ -53,6 +54,10 @@ Handlers.add( ]); console.log(res) + if (res.Error) { + return toast({ title: "Error sharing project", description: res.Error }); + } + const url = `${window.location.origin}/import?id=${processBackup}`; navigator.clipboard.writeText(url); toast({ title: "Project URL copied", description: "The URL to the project has been copied to your clipboard" }); @@ -108,7 +113,7 @@ Handlers.add( */} { globalState.activeMode == "AO" ? globalState.setActiveMode("WARP") : globalState.setActiveMode("AO"); // checked ? router.replace(`/warp`) : router.replace(`/ao`); diff --git a/next_app/src/pages/import.tsx b/next_app/src/pages/import.tsx index 9237170..15fcd1e 100644 --- a/next_app/src/pages/import.tsx +++ b/next_app/src/pages/import.tsx @@ -25,9 +25,9 @@ export default function Import() { ] }) // console.log(r) - console.log(r.Messages[0].Data.replaceAll("\n", "\\n")) - setData(r.Messages[0].Data.replaceAll("\n", "\\n")) - const data = JSON.parse(`${r.Messages[0].Data.replaceAll("\n", "\\n")}`) + console.log(decodeURIComponent(r.Messages[0].Data)) + setData(decodeURIComponent(r.Messages[0].Data)) + const data = JSON.parse(`${decodeURIComponent(r.Messages[0].Data)}`) console.log(data) try { await window.arweaveWallet.getActiveAddress() diff --git a/next_app/src/styles/globals.css b/next_app/src/styles/globals.css index b8b4de1..19108b0 100644 --- a/next_app/src/styles/globals.css +++ b/next_app/src/styles/globals.css @@ -37,8 +37,8 @@ .dark { /* Done */ - --background: 0 0% 2%; - --foreground: 0 0% 70%; + --background: 0 0% 5%; + --foreground: 0 0% 90%; --card: 240 10% 3.9%; --card-foreground: 0 0% 98%;