diff --git a/README.md b/README.md
index b8fb07b..4040ddd 100644
--- a/README.md
+++ b/README.md
@@ -28,8 +28,9 @@ Social dapp that allows users to monetize 💰 their social activity 🫂.
## 👥 Phase 2 (Social Activity and Indexing)
-- **PunkSociety contract:** Following users, liking, commenting and sharing posts.
-- **Search**: By address or username
+- ✅ **PunkSociety contract:** Social interactions.
+- ✅ **Search**: By address or username
+- Enable following users, liking, commenting and sharing posts on frontend
- **Notification system**
- **Integrate The Graph to index activity** and save RPC calls (Reference: [Bootstrap a Full Stack Modern dapp using the Scaffold-ETH CLI and Subgraph Extension](https://siddhantk08.hashnode.dev/bootstrap-a-full-stack-modern-dapp-using-the-scaffold-eth-cli-and-subgraph-extension) | [The Graph tool for creating a subgraph](https://thegraph.com/docs/en/developing/creating-a-subgraph/))
diff --git a/packages/nextjs/app/search/Search.tsx b/packages/nextjs/app/search/Search.tsx
index 13ed36d..c430bfb 100644
--- a/packages/nextjs/app/search/Search.tsx
+++ b/packages/nextjs/app/search/Search.tsx
@@ -3,7 +3,7 @@
import { useState } from "react";
import { useRouter } from "next/navigation";
import { LoadingBars } from "../../components/punk-society/LoadingBars";
-import { AddressInput } from "~~/components/scaffold-eth";
+import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";
export const Search = () => {
const [searchQuery, setSearchQuery] = useState("");
@@ -11,47 +11,52 @@ export const Search = () => {
const [error, setError] = useState("");
const router = useRouter();
+ const { data: nameToAddress } = useScaffoldReadContract({
+ contractName: "PunkProfile",
+ functionName: "nameToAddress",
+ args: [searchQuery],
+ watch: true,
+ });
+
const handleSearch = async () => {
if (!searchQuery) {
- setError("Please enter an address.");
+ setError("Please enter an address or username.");
return;
}
setLoading(true);
setError("");
- const address = searchQuery;
-
- // If the search query is not an address, show an error
- if (!/^0x[a-fA-F0-9]{40}$/.test(searchQuery)) {
- setError("Invalid address format.");
+ try {
+ if (searchQuery.length > 17) {
+ // If the search query is longer than 17 characters, assume it's an Ethereum address
+ router.push(`/profile/${searchQuery}`);
+ } else if (nameToAddress && nameToAddress !== "0x0000000000000000000000000000000000000000") {
+ // If the search query resolves to a non-zero address, navigate to the resolved address profile
+ router.push(`/profile/${nameToAddress}`);
+ } else {
+ setError("Invalid address or username.");
+ }
+ } catch (error) {
+ setError("An error occurred while searching.");
+ } finally {
setLoading(false);
- return;
}
-
- // Redirect to the user's profile page
- router.push(`/profile/${address}`);
};
- if (loading) {
- return
{error}
} - -{error}
}