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

Issue/241 #260

Merged
merged 2 commits into from
Jan 11, 2025
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
2 changes: 1 addition & 1 deletion pkgs/frontend/app/routes/$treeId_.splits.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const SplitterNew: FC = () => {
const availableName = useMemo(() => {
if (!splitterName) return false;

return addresses?.[0]?.length === 0;
return addresses[0].length === 0;
}, [splitterName, addresses]);

const { createSplits, previewSplits, isLoading } = useSplitsCreator(
Expand Down
13 changes: 13 additions & 0 deletions pkgs/frontend/app/routes/api.namestone.$action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const action: ActionFunction = async ({ request, params }) => {
switch (action) {
case "set-name": {
const { name, address, text_records } = await request.json();

// Check if name is already taken
const existingNames = await ns.searchNames({
domain,
name,
exact_match: true,
});

// If name exists and is owned by a different address, throw error
if (existingNames.length > 0) {
throw data({ message: "Name is already taken" }, 409);
}

await ns.setName({ domain, name, address, text_records });
return { message: "OK" };
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/frontend/app/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Login: FC = () => {
}, [wallet, navigate, fetchNames]);

return (
<Grid gridTemplateRows="1fr auto" h="100vh">
<Grid gridTemplateRows="1fr auto" h="calc(100vh - 72px)">
<Flex justifyContent="center" alignItems="center" flexWrap="wrap">
<Box>
<Box width="160px">
Expand Down
53 changes: 32 additions & 21 deletions pkgs/frontend/app/routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAddressesByNames, useSetName } from "hooks/useENS";
import { useUploadImageFileToIpfs } from "hooks/useIpfs";
import { useActiveWallet } from "hooks/useWallet";
import type { TextRecords } from "namestone-sdk";
import { type FC, useMemo, useState } from "react";
import { type FC, useCallback, useMemo, useState } from "react";
import { BasicButton } from "~/components/BasicButton";
import { CommonInput } from "~/components/common/CommonInput";
import { UserIcon } from "~/components/icon/UserIcon";
Expand All @@ -30,34 +30,45 @@ const Login: FC = () => {
const availableName = useMemo(() => {
if (!userName) return false;

return addresses?.[0]?.length === 0;
return addresses[0].length === 0;
}, [userName, addresses]);

const handleSubmit = async () => {
const handleSubmit = useCallback(async () => {
if (!wallet || !availableName) return;

const params: {
name: string;
address: string;
text_records: TextRecords;
} = {
name: userName,
address: wallet.account?.address,
text_records: {},
};
try {
const params: {
name: string;
address: string;
text_records: TextRecords;
} = {
name: userName,
address: wallet.account?.address,
text_records: {},
};

if (imageFile) {
const res = await uploadImageFileToIpfs();
if (res) params.text_records.avatar = res.ipfsUri;
}

await setName(params);
if (imageFile) {
const res = await uploadImageFileToIpfs();
if (res) params.text_records.avatar = res.ipfsUri;
}

window.location.href = "/workspace";
};
await setName(params);
} catch (error) {
console.error(error);
} finally {
window.location.href = "/workspace";
}
}, [
availableName,
imageFile,
setName,
uploadImageFileToIpfs,
userName,
wallet,
]);

return (
<Grid gridTemplateRows="1fr auto" h="100vh">
<Grid gridTemplateRows="1fr auto" h="calc(100vh - 72px)">
<Flex justifyContent="center" alignItems="center" flexWrap="wrap">
<Box w="100%">
<Flex
Expand Down
Loading