Skip to content
Merged
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
21 changes: 21 additions & 0 deletions src/components/AgentManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
const [loadingMeta, setLoadingMeta] = useState(true);
const [error, setError] = useState<string | null>(null);
const [txHash, setTxHash] = useState<Hex | undefined>();
const [successMessage, setSuccessMessage] = useState<string | null>(null);

// Edit state for URI update
const [editing, setEditing] = useState(false);
Expand Down Expand Up @@ -127,6 +128,13 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
}
}, [metadata]);

// Auto-dismiss success message after 5 seconds
useEffect(() => {
if (!successMessage) return;
const timer = setTimeout(() => setSuccessMessage(null), 5000);
return () => clearTimeout(timer);
}, [successMessage]);

const isOwner = role === "owner";
const editUri = useMemo(() => {
if (!editName.trim()) return "";
Expand All @@ -144,6 +152,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
if (!editUri) return;
try {
setError(null);
setSuccessMessage(null);
setSavingUri(true);
const hash = await writeContractAsync({
address: ERC8004_REGISTRY,
Expand All @@ -155,6 +164,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
await publicClient.waitForTransactionReceipt({ hash });
const parsed = JSON.parse(editUri);
setMetadata({ ...metadata!, ...parsed });
setSuccessMessage("Agent profile updated");
// Persist URI update to DB
fetch("/api/user/agent-update", {
method: "POST",
Expand All @@ -180,6 +190,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
async function handleUnsetWallet() {
try {
setError(null);
setSuccessMessage(null);
setUnsettingWallet(true);
const hash = await writeContractAsync({
address: ERC8004_REGISTRY,
Expand All @@ -189,6 +200,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
});
setTxHash(hash);
await publicClient.waitForTransactionReceipt({ hash });
setSuccessMessage("Agent wallet removed");
// Persist unset to DB
fetch("/api/user/agent-update", {
method: "POST",
Expand All @@ -209,6 +221,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
if (!newWalletAddr || !address) return;
try {
setError(null);
setSuccessMessage(null);
setSigningWallet(true);
const deadline = BigInt(Math.floor(Date.now() / 1000) + 300);
const signature = await signTypedDataAsync({
Expand Down Expand Up @@ -236,6 +249,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
if (!walletSignature || !walletDeadline || !newWalletAddr) return;
try {
setError(null);
setSuccessMessage(null);
setSubmittingWallet(true);
const hash = await writeContractAsync({
address: ERC8004_REGISTRY,
Expand All @@ -254,6 +268,7 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
fields: { agent_wallet: newWalletAddr.toLowerCase() },
}),
}).catch(() => {});
setSuccessMessage("Agent wallet bound successfully");
setWalletStep(null);
setChangingWallet(false);
setNewWalletAddr("");
Expand Down Expand Up @@ -305,6 +320,12 @@ export function AgentManage({ agentId, role }: AgentManageProps) {
<div className="border-error/30 text-error rounded border px-3 py-2 text-xs">{error}</div>
)}

{successMessage && (
<div className="border-accent/30 bg-accent/5 text-accent rounded border px-3 py-2 text-xs font-medium">
{successMessage}
</div>
)}

{txHash && (
<div className="border-border text-muted rounded border px-3 py-2 text-xs">
Tx:{" "}
Expand Down
Loading