Skip to content

Commit

Permalink
Merge pull request #260 from hackdays-io/issue/241
Browse files Browse the repository at this point in the history
Issue/241
  • Loading branch information
yu23ki14 authored Jan 11, 2025
2 parents 96ad352 + 3bad68c commit c4e8ea1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
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

0 comments on commit c4e8ea1

Please sign in to comment.