Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show & add Holochain Agents Info functionality #463

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project _loosely_ adheres to [Semantic Versioning](https://semver.org/spec/
## unreleased

### Added
- Add ability to get and add Holochain agent infos through launcher [PR#463](https://github.com/coasys/ad4m/pull/463)

### Changed
- Much improved ADAM Launcher setup flow [PR#440](https://github.com/coasys/ad4m/pull/440) and [PR#444](https://github.com/coasys/ad4m/pull/444):
Expand Down
88 changes: 88 additions & 0 deletions ui/src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AgentContext } from "../context/AgentContext";
import ActionButton from "./ActionButton";
import { appWindow } from "@tauri-apps/api/window";
import { open } from "@tauri-apps/api/shell";
import { writeText } from '@tauri-apps/api/clipboard'

type Props = {
did: String;
Expand Down Expand Up @@ -67,12 +68,18 @@ const Profile = (props: Props) => {

const [qrcodeModal, setQRCodeModal] = useState(false);

const [copied, setCopied] = useState(false);

const [password, setPassword] = useState("");

const [showPassword, setShowPassword] = useState(false);

const [loadingProxy, setLoadingProxy] = useState(false);

const [showAddHcAgentInfos, setShowAddHcAgentInfos] = useState(false);

const [addHcAgentInfos, setAddHcAgentInfos] = useState("");

function openLogs() {
appWindow.emit("copyLogs");
}
Expand Down Expand Up @@ -123,6 +130,26 @@ const Profile = (props: Props) => {
}
}, [url]);

const getAgentInfo = async () => {
const info = await client?.runtime.hcAgentInfos();

console.log("info", info);

await writeText(info);

setCopied(true);

setTimeout(() => {
setCopied(false);
closeSecretCodeModal();
}, 3000);
}

const addAgentInfo = async (info: string) => {
await client?.runtime.hcAddAgentInfos(info);
setShowAddHcAgentInfos(false);
}

useEffect(() => {
fetchCurrentAgentProfile();
getTrustedAgents();
Expand Down Expand Up @@ -253,6 +280,36 @@ const Profile = (props: Props) => {
</j-button>
</j-box>

{expertMode && (
<div>
<j-box px="500" my="500">
<j-button
onClick={() => {
getAgentInfo()
}}
full
variant="secondary"
>
<j-icon size="sm" slot="start" name={!copied ? "clipboard" : "clipboard-check"}></j-icon>
Copy Holochain Agent Info(s)
</j-button>
</j-box>

<j-box px="500" my="500">
<j-button
onClick={() => {
setShowAddHcAgentInfos(true)
}}
full
variant="secondary"
>
<j-icon size="sm" slot="start" name="shield-check"></j-icon>
Add Holochain Agent Info(s)
</j-button>
</j-box>
</div>
)}

<j-box px="500" my="500">
<j-button onClick={openLogs} full variant="secondary">
<j-icon size="sm" slot="start" name="clipboard"></j-icon>
Expand All @@ -271,6 +328,37 @@ const Profile = (props: Props) => {
</j-button>
</j-box>

{showAddHcAgentInfos && (
<j-modal
open={showAddHcAgentInfos}
onToggle={(e: any) => setAddHcAgentInfos(e.target.open)}
>
<j-box px="400" py="600">
<j-box pb="500">
<j-text nomargin size="600" color="black" weight="600">
Add Holochain Agents Info
</j-text>
</j-box>
<j-box pb="500">
<j-input
placeholder="Encoded Holochain AgentInfo string"
label="Input another agent's info string here.."
size="lg"
required
onInput={(e: any) => setAddHcAgentInfos(e.target.value)}
></j-input>
<j-box p="400"></j-box>
<j-button
onClick={() => addAgentInfo(addHcAgentInfos)}
full
loading={loading}>
Add Agent Info
</j-button>
</j-box>
</j-box>
</j-modal>
)}

{trustedAgentModalOpen && (
<j-modal
size="fullscreen"
Expand Down