Skip to content

Commit

Permalink
Merge pull request #3 from HAPPYS1NGH/walletconnect
Browse files Browse the repository at this point in the history
Added complete support for Walletconnect
  • Loading branch information
HAPPYS1NGH authored Nov 3, 2024
2 parents 48013d8 + 3155313 commit 263725d
Show file tree
Hide file tree
Showing 9 changed files with 3,441 additions and 2,467 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ETH Telegram Mini App NextJS Starter Kit
# ETH Telegram Mini App NextJS Starter Kit with WalletConnect/Reown

## Getting Started

Expand All @@ -9,6 +9,7 @@ This starter kit helps you create a mini application integrated with Ethereum an
[Blog on using this Starter Kit](https://medium.com/rabble-labs/deploy-your-first-telegram-mini-app-on-ethereum-8b589f4e6411)

**For Visual Learners**

[![YouTube](http://i.ytimg.com/vi/cFLKu4sl76I/hqdefault.jpg)](https://www.youtube.com/watch?v=cFLKu4sl76I)

### Prerequisites
Expand All @@ -23,7 +24,7 @@ Ensure you have the following installed on your machine:
1. **Clone the repository or click on the "Use this template" button:**

```bash
git clone https://github.com/HAPPYS1NGH/rabble-tg-mini-app-nextjs-js
git clone https://github.com/HAPPYS1NGH/rabble-tg-mini-app-nextjs-js/tree/walletconnect
```

2. **Navigate to the project directory:**
Expand All @@ -34,7 +35,7 @@ Ensure you have the following installed on your machine:

3. **Create a `.env.local` file in the root directory and copy the contents of `.env.sample`:**

- Obtain the WalletConnect project ID from [WalletConnect](https://cloud.walletconnect.com/).
- Obtain the WalletConnect project ID from [Reown(prev Walletconnect)](https://cloud.reown.com/).

- Make sure to select the App Kit.

Expand Down
5,731 changes: 3,347 additions & 2,384 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
"@rainbow-me/rainbowkit": "^2.0.2",
"@tanstack/react-query": "^5.27.5",
"@reown/appkit": "^1.2.1",
"@reown/appkit-adapter-wagmi": "^1.2.1",
"@tanstack/react-query": "^5.59.16",
"@telegram-apps/sdk-react": "^1.1.3",
"@walletconnect/modal-core": "^2.7.0",
"@walletconnect/modal-ui": "^2.7.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"eruda": "^3.2.1",
Expand All @@ -25,8 +28,8 @@
"sonner": "^1.5.0",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"viem": "^2.8.4",
"wagmi": "^2.5.7"
"viem": "^2.21.38",
"wagmi": "^2.12.25"
},
"devDependencies": {
"autoprefixer": "^10",
Expand Down
11 changes: 7 additions & 4 deletions src/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Outfit, Be_Vietnam_Pro } from "next/font/google";
import "@rainbow-me/rainbowkit/styles.css";
import "./globals.css";
import Web3Provider from "@/providers/Web3Provider";

import { headers } from "next/headers";
import { Outfit, Be_Vietnam_Pro } from "next/font/google";
import Layout from "@/providers/Layout";
import Web3Provider from "@/providers/Web3Provider";
import { TelegramProvider } from "@/providers/TelegramProvider";

const outfit = Outfit({ subsets: ["latin"], variable: "--font-outfit" });
Expand All @@ -20,10 +21,12 @@ export const metadata = {
export default function RootLayout({
children,
}) {
const cookies = headers().get('cookie')

return (
<html lang="en" className={`${outfit.variable} ${beVietnamPro.variable}`}>
<body className={beVietnamPro.className}>
<Web3Provider>
<Web3Provider cookies={cookies}>
<TelegramProvider>
<Layout>{children}</Layout>
</TelegramProvider>
Expand Down
3 changes: 3 additions & 0 deletions src/components/shared/ConnectButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function ConnectButton() {
return <w3m-button />
}
12 changes: 5 additions & 7 deletions src/components/shared/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import React from "react";
import Link from "next/link";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import ConnectButton from "@/components/shared/ConnectButton"
import { usePathname } from "next/navigation";
import Image from "next/image";

Expand All @@ -21,19 +21,17 @@ const Navbar = () => {
<div className="flex space-x-4 ">
<Link
href="/"
className={`${
pathname == "/" ? "text-rabble" : "text-color hover:text-color/90"
} `}
className={`${pathname == "/" ? "text-rabble" : "text-color hover:text-color/90"
} `}
>
Home
</Link>
<Link
href="/contract"
className={`${
pathname == "/contract"
className={`${pathname == "/contract"
? "text-rabble"
: "text-color hover:text-color/90"
} `}
} `}
>
Contract
</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const counterAddress = "0x75b167a1628b6F239C0BEA211d731578bA90465a"
export const counterAddress = "0x0A37fC81Da775CBf75A49b45Cbda60F5F80E1a14";
76 changes: 47 additions & 29 deletions src/providers/Web3Provider.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
"use client";
import { WagmiProvider } from "wagmi";
import {
darkTheme,
lightTheme,
RainbowKitProvider,
} from "@rainbow-me/rainbowkit";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { config } from "../utils/config";

const queryClient = new QueryClient();

export default function Web3Provider({
children,
}) {
'use client'

import { wagmiAdapter, projectId } from '@/utils/config'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { createAppKit } from '@reown/appkit/react'
import { mainnet, arbitrum, sepolia } from '@reown/appkit/networks'
import React from 'react'
import { cookieToInitialState, WagmiProvider } from 'wagmi'

// Set up queryClient
const queryClient = new QueryClient()

if (!projectId) {
throw new Error('Project ID is not defined')
}


const metadata = {
name: "rabble-starter-kit",
description: "Rabble Mini App Starter Kit",
url: "https://rabble-tg-mini-app-nextjs-js-git-walletconnect-happysingh.vercel.app/", // origin must match your domain & subdomain
icons: ["https://rabble-tg-mini-app-nextjs-js-git-walletconnect-happysingh.vercel.app/butterfly.svg"]
}

// Create the modal
const modal = createAppKit({
adapters: [wagmiAdapter],
projectId,
networks: [mainnet, arbitrum, sepolia],
defaultNetwork: sepolia,
metadata: metadata,
features: {
analytics: true, // Optional - defaults to your Cloud configuration
},
themeVariables: {
'--w3m-accent': '#08F7AF',
}
})

function ContextProvider({ children, cookies }) {
const initialState = cookieToInitialState(wagmiAdapter.wagmiConfig, cookies)

return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<RainbowKitProvider
theme={darkTheme({
accentColor: "#21C896",
accentColorForeground: "white",
borderRadius: "medium",
fontStack: "system",
})}
>
{children}
</RainbowKitProvider>
</QueryClientProvider>
<WagmiProvider config={wagmiAdapter.wagmiConfig} initialState={initialState}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
);
)
}

export default ContextProvider
55 changes: 20 additions & 35 deletions src/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
import { getDefaultWallets, getDefaultConfig } from "@rainbow-me/rainbowkit"
import {
argentWallet,
trustWallet,
ledgerWallet,
} from "@rainbow-me/rainbowkit/wallets"
import {
arbitrum,
arbitrumSepolia,
localhost,
} from "wagmi/chains"
import { cookieStorage, createStorage, http } from "@wagmi/core";
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
import { arbitrum, sepolia } from "@reown/appkit/networks";

const { wallets } = getDefaultWallets()
// Get projectId from https://cloud.reown.com
export const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID;

export const WALLETCONNECT_PROJECT_ID =
process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? ""
if (!WALLETCONNECT_PROJECT_ID) {
console.warn(
"You need to provide a NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID env variable"
)
if (!projectId) {
throw new Error("Project ID is not defined");
}
export const config = getDefaultConfig({
appName: "RainbowKit demo",
projectId: WALLETCONNECT_PROJECT_ID,
wallets: [
...wallets,
{
groupName: "Other",
wallets: [argentWallet, trustWallet, ledgerWallet],
},
],
chains: [
arbitrumSepolia,
...(process.env.NEXT_PUBLIC_ENABLE_TESTNETS === "true"
? [arbitrumSepolia, arbitrum, localhost]
: []),
],

export const networks = [arbitrum, sepolia];

//Set up the Wagmi Adapter (Config)
export const wagmiAdapter = new WagmiAdapter({
storage: createStorage({
storage: cookieStorage,
}),
ssr: true,
})
projectId,
networks,
});

export const config = wagmiAdapter.wagmiConfig;

0 comments on commit 263725d

Please sign in to comment.