Skip to content

Commit

Permalink
Feat: improve react examples for the CLI (#778)
Browse files Browse the repository at this point in the history
* improve design + funcionality react wagmi example

* improve design + funcionality react wagmi example

* improve design + funcionality react solana example

* improve design + funcionality react multichain example

* improve design + funcionality react multichain example

* improve design + funcionality react ethers5 example

* improve design + funcionality react ethers example

* add env.test
  • Loading branch information
rtomas authored Nov 21, 2024
1 parent 1eb9b1d commit c85aa03
Show file tree
Hide file tree
Showing 82 changed files with 14,376 additions and 970 deletions.
1 change: 1 addition & 0 deletions dapps/appkit/react-ethers/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_PROJECT_ID=
2 changes: 1 addition & 1 deletion dapps/appkit/react-ethers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/reown.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reown Appkit Example</title>
</head>
Expand Down
8 changes: 4 additions & 4 deletions dapps/appkit/react-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-wagmi",
"name": "react-ethers-appkit",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -10,8 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"@reown/appkit": "^1.1.0",
"@reown/appkit-adapter-ethers": "^1.1.0",
"@reown/appkit": "^1.5.0",
"@reown/appkit-adapter-ethers": "^1.5.0",
"ethers": "^6.13.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
Expand Down
154 changes: 84 additions & 70 deletions dapps/appkit/react-ethers/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dapps/appkit/react-ethers/public/reown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion dapps/appkit/react-ethers/public/vite.svg

This file was deleted.

103 changes: 75 additions & 28 deletions dapps/appkit/react-ethers/src/App.css
Original file line number Diff line number Diff line change
@@ -1,42 +1,89 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
:root {
--background: #ffffff;
--foreground: #171717;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);

html,
body {
max-width: 100vw;
overflow-x: hidden;
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}

.card {
padding: 2em;
section {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 16px;
background-color: #f9f9f9;
padding: 13px;
margin: 10px;
width:100%
}

.read-the-docs {
color: #888;
.pages {

align-items: center;
justify-items: center;
}

:root {
justify-items: center;
}

button {
padding: 10px 20px;
background-color: white;
color: black;
border: 2px solid black;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin: 20px; /* Space between buttons */
}

button:hover {
background-color: black;
color: white;
}

button:active {
background-color: #333; /* Dark gray on click */
color: white;
}

h1 {
margin: 20px;
}
44 changes: 12 additions & 32 deletions dapps/appkit/react-ethers/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import { createAppKit } from '@reown/appkit/react'
import { EthersAdapter } from '@reown/appkit-adapter-ethers'

// for custom networks visit -> https://docs.reown.com/appkit/react/core/custom-networks
import { arbitrum, mainnet, polygon, acala, chiliz, berachainTestnetbArtio, AppKitNetwork, sepolia } from '@reown/appkit/networks'
import { Hooks } from './components/hooks'
import { networks, projectId, metadata, ethersAdapter } from './config'
import { ActionButtonList } from './components/ActionButtonList'
import { InfoList } from './components/InfoList'

import "./App.css"

// 1. Get projectId from https://cloud.reown.com
const projectId = import.meta.env.VITE_PROJECT_ID
if (!projectId) {
throw new Error('VITE_PROJECT_ID is not set')
}

// 2. Create a metadata object - optional
const metadata = {
name: 'AppKit',
description: 'AppKit Example',
url: 'https://reown.com', // origin must match your domain & subdomain
icons: ['https://avatars.githubusercontent.com/u/179229932']
}

// 3. Set the networks
const networks: [AppKitNetwork, ...AppKitNetwork[]] = [arbitrum, mainnet];


// 4. Create a AppKit instance
const modal = createAppKit({
adapters: [new EthersAdapter()],
// Create a AppKit instance
createAppKit({
adapters: [ethersAdapter],
networks,
metadata,
projectId,
Expand All @@ -39,12 +19,12 @@ const modal = createAppKit({
export function App() {

return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<w3m-button />
<Hooks />
<p>
<button onClick={() => modal.adapters![0].connectionControllerClient?.disconnect()}>Disconnect JS</button>
</p>
<div className={"pages"}>
<img src="/reown.svg" alt="Reown" style={{ width: '150px', height: '150px' }} />
<h1>AppKit ethers React dApp Example</h1>
<appkit-button />
<ActionButtonList />
<InfoList />
</div>
)
}
Expand Down
15 changes: 15 additions & 0 deletions dapps/appkit/react-ethers/src/components/ActionButtonList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useDisconnect, useAppKit, useAppKitNetwork } from '@reown/appkit/react'
import { networks } from '../config'

export const ActionButtonList = () => {
const { disconnect } = useDisconnect();
const { open } = useAppKit();
const { switchNetwork } = useAppKitNetwork();
return (
<div >
<button onClick={() => open()}>Open</button>
<button onClick={() => disconnect()}>Disconnect</button>
<button onClick={() => switchNetwork(networks[1]) }>Switch</button>
</div>
)
}
59 changes: 59 additions & 0 deletions dapps/appkit/react-ethers/src/components/InfoList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useEffect } from 'react'
import {
useAppKitState,
useAppKitTheme,
useAppKitEvents,
useAppKitAccount,
useWalletInfo
} from '@reown/appkit/react'

export const InfoList = () => {
const { themeMode, themeVariables } = useAppKitTheme();
const state = useAppKitState();
const {address, caipAddress, isConnected, status} = useAppKitAccount();
const events = useAppKitEvents()
const walletInfo = useWalletInfo()

useEffect(() => {
console.log("Events: ", events);
}, [events]);

return (
<div >
<section>
<h2>useAppKit</h2>
<pre>
Address: {address}<br />
caip Address: {caipAddress}<br />
Connected: {isConnected.toString()}<br />
Status: {status}<br />
</pre>
</section>

<section>
<h2>Theme</h2>
<pre>
Theme: {themeMode}<br />
ThemeVariables: { JSON.stringify(themeVariables, null, 2)}<br />
</pre>
</section>

<section>
<h2>State</h2>
<pre>
activeChain: {state.activeChain}<br />
loading: {state.loading.toString()}<br />
open: {state.open.toString()}<br />
selectedNetworkId: {state.selectedNetworkId?.toString()}<br />
</pre>
</section>

<section>
<h2>WalletInfo</h2>
<pre>
Name: {walletInfo.walletInfo?.name?.toString()}<br />
</pre>
</section>
</div>
)
}
22 changes: 0 additions & 22 deletions dapps/appkit/react-ethers/src/components/hooks.tsx

This file was deleted.

24 changes: 24 additions & 0 deletions dapps/appkit/react-ethers/src/config/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mainnet, arbitrum } from '@reown/appkit/networks'
import type { AppKitNetwork } from '@reown/appkit/networks'
import { EthersAdapter } from '@reown/appkit-adapter-ethers'

// Get projectId from https://cloud.reown.com
export const projectId = import.meta.env.VITE_PROJECT_ID

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

// Create a metadata object - optional
export const metadata = {
name: 'AppKit',
description: 'AppKit Example',
url: 'https://reown.com', // origin must match your domain & subdomain
icons: ['https://avatars.githubusercontent.com/u/179229932']
}

// for custom networks visit -> https://docs.reown.com/appkit/react/core/custom-networks
export const networks = [mainnet, arbitrum] as [AppKitNetwork, ...AppKitNetwork[]]

// Set up Solana Adapter
export const ethersAdapter = new EthersAdapter();
Loading

0 comments on commit c85aa03

Please sign in to comment.