Skip to content
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: 0 additions & 1 deletion hyperdrive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ async fn main() {
// Create the cache_sources file with test content
let data_file_path = initfiles_dir.join("cache_sources");


#[cfg(not(feature = "simulation-mode"))]
{
// Write cache_source_vector to cache_sources as JSON
Expand Down
11 changes: 10 additions & 1 deletion hyperdrive/src/register-ui/src/components/EnterHnsName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type EnterNameProps = {
triggerNameCheck: boolean;
setTba?: React.Dispatch<React.SetStateAction<string>>;
isReset?: boolean;
readOnly?: boolean;
disabled?: boolean;
};

function EnterHnsName({
Expand All @@ -34,6 +36,8 @@ function EnterHnsName({
triggerNameCheck,
setTba,
isReset = false,
readOnly = false,
disabled = false,
}: EnterNameProps) {
const client = usePublicClient();
const debouncer = useRef<NodeJS.Timeout | null>(null);
Expand Down Expand Up @@ -118,6 +122,8 @@ function EnterHnsName({
const noSpaces = (e: any) =>
e.target.value.indexOf(" ") === -1 && setName(e.target.value);

const isLocked = readOnly || disabled;

return (
<div className="enter-hns-name">
<div className="flex">
Expand All @@ -128,7 +134,10 @@ function EnterHnsName({
required
name="hns-name"
placeholder="node-name"
className="grow rounded-r-none"
className={`grow rounded-r-none ${isLocked ? "bg-gray-200 dark:bg-slate-800 cursor-not-allowed" : ""}`}
readOnly={readOnly}
disabled={disabled}
aria-readonly={readOnly || undefined}
/>
{fixedTlz && <span
className="rounded-r-md p-2 bg-neon text-black"
Expand Down
61 changes: 60 additions & 1 deletion hyperdrive/src/register-ui/src/pages/ResetName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import EnterHnsName from "../components/EnterHnsName";
import { useAccount, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
import { useConnectModal, useAddRecentTransaction } from "@rainbow-me/rainbowkit";
import BackButton from "../components/BackButton";
import { Tooltip } from "../components/Tooltip";
import { FaSquareCheck, FaRegSquare } from "react-icons/fa6";

interface ResetProps extends PageProps { }

Expand Down Expand Up @@ -58,6 +60,8 @@ function ResetHnsName({
const [specifyRouters, setSpecifyRouters] = useState(false)
const [customRouters, setCustomRouters] = useState('')
const [routerValidationErrors, setRouterValidationErrors] = useState<string[]>([])
const [currentNodeName, setCurrentNodeName] = useState<string>("");
const [resetDifferentNodeId, setResetDifferentNodeId] = useState<boolean>(false);

// Track initial states for checkbox help text
const [initiallyDirect, setInitiallyDirect] = useState<boolean | undefined>(undefined);
Expand Down Expand Up @@ -134,6 +138,14 @@ function ResetHnsName({
res.json()
)) as UnencryptedIdentity;

if (infoData?.name) {
setCurrentNodeName(infoData.name);
setName(infoData.name);
setHnsName(infoData.name);
} else {
setResetDifferentNodeId(true);
}

const allowedRouters = Array.isArray(infoData.allowed_routers)
? infoData.allowed_routers
: undefined;
Expand Down Expand Up @@ -162,6 +174,7 @@ function ResetHnsName({
}
} catch (error) {
console.log("Could not fetch node info:", error);
setResetDifferentNodeId(true);
}
})();
}, []);
Expand Down Expand Up @@ -241,6 +254,19 @@ function ResetHnsName({
}, [isConfirmed, setReset, setDirect, direct, navigate]);


const handleResetDifferentNodeIdToggle = () => {
setResetDifferentNodeId((prev) => {
const next = !prev;
if (!next && currentNodeName) {
setName(currentNodeName);
setHnsName(currentNodeName);
}
return next;
});
};

const isNameReadOnly = !resetDifferentNodeId && !!currentNodeName;

return (
<div className="container fade-in" id="register-ui--reset-name">
<div className="section">
Expand All @@ -253,7 +279,19 @@ function ResetHnsName({
<h3 className="text-iris dark:text-neon">
Node ID to reset:
</h3>
<EnterHnsName {...{ address, name, setName, triggerNameCheck, nameValidities, setNameValidities, setTba, isReset: true }} />
<EnterHnsName
{...{
address,
name,
setName,
triggerNameCheck,
nameValidities,
setNameValidities,
setTba,
isReset: true
}}
readOnly={isNameReadOnly}
/>
<p className="text-sm text-gray-500">
Nodes use an onchain username in order to identify themselves to other nodes in the network.
</p>
Expand Down Expand Up @@ -306,6 +344,27 @@ function ResetHnsName({
)}
</div>
)}
<div className="flex gap-2 items-start">
<button
type="button"
className="icon mt-0.5"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleResetDifferentNodeIdToggle();
}}
aria-pressed={resetDifferentNodeId}
>
{resetDifferentNodeId ? <FaSquareCheck /> : <FaRegSquare />}
</button>
<div className="flex flex-col gap-1 min-w-0 wrap-anywhere">
<span className="text-sm">Reset different node ID.</span>
<span className="text-xs">If you are unsure, leave unchecked.</span>
</div>
<Tooltip
text={"Reset a different node ID. Only use this if you do not have access to another node that you want to reset."}
/>
</div>
</div>
</details>
<p className="text-sm text-gray-500">
Expand Down