Skip to content
Open
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
41 changes: 41 additions & 0 deletions week-05/dev/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions week-05/dev/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
22 changes: 22 additions & 0 deletions week-05/dev/frontend/app/components/BalanceCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client';

import { useAccount, useBalance } from "wagmi";

export function BalanceCard() {
const { address, isConnected } = useAccount();
const { data: balance } = useBalance({ address });

return (
<div className="rounded-2xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<p className="text-sm text-zinc-500 dark:text-zinc-400">내 잔액</p>
<p className="mt-1 text-3xl font-bold text-zinc-900 dark:text-zinc-100">
{isConnected && balance
? `${parseFloat(balance.formatted).toFixed(4)} ${balance.symbol}`
: "— ETH"}
</p>
<p className="mt-1 text-sm text-zinc-400 dark:text-zinc-500">
{isConnected && address ? address : "지갑을 연결해주세요"}
</p>
</div>
);
}
49 changes: 49 additions & 0 deletions week-05/dev/frontend/app/components/CustomConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use client";

import { ConnectButton } from "@rainbow-me/rainbowkit";
import { useDisconnect } from "wagmi";

export function CustomConnectButton() {
const { disconnect } = useDisconnect();

return (
<ConnectButton.Custom>
{({ account, chain, openConnectModal, openChainModal, mounted }) => {
const connected = mounted && account && chain;

return (
<div className="flex items-center gap-3">
{connected ? (
<>
<button
onClick={openChainModal}
className="rounded-lg bg-zinc-100 px-3 py-2 text-sm font-medium text-zinc-700 transition-colors hover:bg-zinc-200 dark:bg-zinc-800 dark:text-zinc-300 dark:hover:bg-zinc-700"
>
{chain.unsupported ? "네트워크 변경 필요" : chain.name}
</button>

<button
onClick={() => {
if (window.confirm("연결을 해제하겠습니까?")) {
disconnect();
}
}}
className="rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700"
>
{account.displayName}
</button>
</>
) : (
<button
onClick={openConnectModal}
className="rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700"
>
지갑 연결
</button>
)}
</div>
);
}}
</ConnectButton.Custom>
);
}
11 changes: 11 additions & 0 deletions week-05/dev/frontend/app/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function Footer() {
return (
<footer className="border-t border-zinc-200 dark:border-zinc-800">
<div className="mx-auto max-w-2xl px-6 py-4">
<p className="text-center text-xs text-zinc-400">
Week 5 — RainbowKit + wagmi
</p>
</div>
</footer>
);
}
14 changes: 14 additions & 0 deletions week-05/dev/frontend/app/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CustomConnectButton } from "./CustomConnectButton";

export function Header() {
return (
<header className="sticky top-0 z-10 border-b border-zinc-200 bg-white/80 backdrop-blur dark:border-zinc-800 dark:bg-zinc-900/80">
<div className="mx-auto flex max-w-2xl items-center justify-between px-6 py-4">
<h1 className="text-lg font-bold text-zinc-900 dark:text-zinc-100">
Week 5 dApp
</h1>
<CustomConnectButton />
</div>
</header>
);
}
98 changes: 98 additions & 0 deletions week-05/dev/frontend/app/components/SendEth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'use client';

import { useState } from 'react';
import { useSendTransaction, useWaitForTransactionReceipt } from 'wagmi';
import { parseEther } from 'viem';

export function SendEth() {
const [to, setTo] = useState('');
const [amount, setAmount] = useState('');

const { sendTransaction, data: hash, isPending } = useSendTransaction();

const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
sendTransaction({ to: to as `0x${string}`, value: parseEther(amount) });
};

return (
<div className="w-full rounded-2xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<h2 className="mb-4 text-lg font-semibold text-zinc-900 dark:text-zinc-100">
ETH 전송
</h2>

<form onSubmit={handleSubmit} className="flex flex-col gap-4">
{/* 받는 주소 */}
<div>
<label
htmlFor="to"
className="mb-1 block text-sm font-medium text-zinc-700 dark:text-zinc-300"
>
받는 주소
</label>
<input
id="to"
type="text"
placeholder="0x..."
value={to}
onChange={(e) => setTo(e.target.value)}
className="w-full rounded-lg border border-zinc-300 bg-zinc-50 px-4 py-2.5 text-sm text-zinc-900 placeholder-zinc-400 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder-zinc-500"
/>
</div>

{/* 금액 */}
<div>
<label
htmlFor="amount"
className="mb-1 block text-sm font-medium text-zinc-700 dark:text-zinc-300"
>
금액 (ETH)
</label>
<input
id="amount"
type="text"
placeholder="0.01"
value={amount}
onChange={(e) => setAmount(e.target.value)}
className="w-full rounded-lg border border-zinc-300 bg-zinc-50 px-4 py-2.5 text-sm text-zinc-900 placeholder-zinc-400 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder-zinc-500"
/>
</div>

{/* 전송 버튼 */}
<button
type="submit"
disabled={!to || !amount || isPending}
className="mt-2 rounded-lg bg-blue-600 px-4 py-2.5 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-zinc-300 disabled:text-zinc-500 dark:disabled:bg-zinc-700 dark:disabled:text-zinc-500"
>
{isPending ? '전송 중...' : '전송'}
</button>
</form>

{/* 트랜잭션 상태 표시 */}
<div className="mt-4 space-y-2">
{hash && (
<div className="rounded-lg bg-zinc-50 p-3 dark:bg-zinc-800">
<p className="text-xs text-zinc-500">트랜잭션 해시</p>
<p className="mt-1 break-all font-mono text-xs text-zinc-700 dark:text-zinc-300">
{hash}
</p>
</div>
)}

{isConfirming && (
<div className="flex items-center gap-2 rounded-lg bg-yellow-50 p-3 text-sm text-yellow-700 dark:bg-yellow-900/20 dark:text-yellow-400">
트랜잭션 확인 중...
</div>
)}

{isSuccess && (
<div className="flex items-center gap-2 rounded-lg bg-green-50 p-3 text-sm text-green-700 dark:bg-green-900/20 dark:text-green-400">
트랜잭션 완료!
</div>
)}
</div>
</div>
);
}
Binary file added week-05/dev/frontend/app/favicon.ico
Binary file not shown.
26 changes: 26 additions & 0 deletions week-05/dev/frontend/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import "tailwindcss";

:root {
--background: #ffffff;
--foreground: #171717;
}

@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
35 changes: 35 additions & 0 deletions week-05/dev/frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import { Providers } from "./providers";
import "./globals.css";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata: Metadata = {
title: "Week 5 dApp",
description: "RainbowKit 지갑 연결 실습",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<Providers>{children}</Providers>
</body>
</html>
);
}
23 changes: 23 additions & 0 deletions week-05/dev/frontend/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";

import Image from "next/image";
import { Header } from "./components/Header";
import { BalanceCard } from "./components/BalanceCard";
import { SendEth } from "./components/SendEth";
import { Footer } from "./components/Footer";

export default function Home() {
return (
<div className="flex min-h-screen flex-col bg-zinc-50 font-sans dark:bg-zinc-950">
<Header />
<div className="flex justify-center">
<Image src="/Pelican.png" alt="Pelican" width={300} height={300} />
</div>
<main className="mx-auto flex w-full max-w-2xl flex-1 flex-col gap-6 px-6 py-8">
<BalanceCard />
<SendEth />
</main>
<Footer />
</div>
);
}
29 changes: 29 additions & 0 deletions week-05/dev/frontend/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import { useState, useEffect } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { WagmiProvider } from "wagmi";
import { RainbowKitProvider } from "@rainbow-me/rainbowkit";
import { config } from "@/config/wagmi";
import "@rainbow-me/rainbowkit/styles.css";

const queryClient = new QueryClient();

export function Providers({ children }: { children: React.ReactNode }) {
const [mounted, setMounted] = useState(false);

useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
setMounted(true);
}, []);

if (!mounted) return null;

return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<RainbowKitProvider>{children}</RainbowKitProvider>
</QueryClientProvider>
</WagmiProvider>
);
}
Loading