Skip to content

Feat/add vue wagmi siwx example #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions vue/vue-wagmi-siwx/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_PROJECT_ID=your_project_id
29 changes: 29 additions & 0 deletions vue/vue-wagmi-siwx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

dist

.env
.vite
18 changes: 18 additions & 0 deletions vue/vue-wagmi-siwx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Reown AppKit Example using wagmi (Vite + Vue)

This is a [Vite](https://vitejs.dev) project together with Vue.

## Usage

1. Go to [Reown Cloud](https://cloud.reown.com) and create a new project.
2. Copy your `Project ID`
3. Rename `.env.example` to `.env` and paste your `Project ID` as the value for `VITE_PROJECT_ID`
4. Run `pnpm install` to install dependencies
5. Run `pnpm run dev` to start the development server

## Resources

- [Reown — Docs](https://docs.reown.com)
- [Vite — GitHub](https://github.com/vitejs/vite)
- [Vite — Docs](https://vitejs.dev/guide/)
- [Vue - Docs](https://vuejs.org/guide/introduction)
1 change: 1 addition & 0 deletions vue/vue-wagmi-siwx/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions vue/vue-wagmi-siwx/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AppKit Vue Example App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions vue/vue-wagmi-siwx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "appkit-vue-wagmi-example",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build --force"
},
"dependencies": {
"@reown/appkit": "1.7.1",
"@reown/appkit-adapter-wagmi": "1.7.1",
"@reown/appkit-siwx": "1.7.1",
"@tanstack/vue-query": "^5.59.16",
"@wagmi/vue": "^0.0.56",
"viem": "^2.21.39",
"vue": "^3.5.12"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/node": "^20.17.0",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vue/tsconfig": "^0.5.1",
"npm-run-all2": "^7.0.1",
"typescript": "~5.6.0",
"vite": "^6.2.0",
"vue-tsc": "^2.1.6"
}
}
Binary file added vue/vue-wagmi-siwx/public/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions vue/vue-wagmi-siwx/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.
59 changes: 59 additions & 0 deletions vue/vue-wagmi-siwx/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

<template>
<div class="pages">
<img src="/reown.svg" alt="Reown" width="150" height="150" />
<h1>AppKit wagmi SIWX vue Example</h1>

<appkit-button />
<ActionButtonList />
<div className="advice">
<p>
This projectId only works on localhost. <br/>
Go to <a href="https://cloud.reown.com" target="_blank" className="link-button" rel="Reown Cloud">Reown Cloud</a> to get your own.
</p>
</div>
<InfoList />
</div>
</template>


<script>
import {
createAppKit,
} from '@reown/appkit/vue'
import { DefaultSIWX } from "@reown/appkit-siwx";
import {wagmiAdapter , networks, projectId } from './config/index'

import ActionButtonList from "./components/ActionButton.vue";
import InfoList from "./components/InfoList.vue";

// Initialize AppKit
const appkit = createAppKit({
adapters: [wagmiAdapter],
networks,
projectId,
themeMode: 'light',
features: {
connectMethodsOrder: ['email', 'social', 'wallet'],
analytics: true, // Optional - defaults to your Cloud configuration
},
siwx: new DefaultSIWX(), // only add this line to use SIWX in appkit
metadata: {
name: 'AppKit Vue Example',
description: 'AppKit Vue Example',
url: 'https://reown.com/appkit',
icons: ['https://avatars.githubusercontent.com/u/179229932?s=200&v=4']
},
themeVariables: {
'--w3m-accent': '#000000',
}
})

export default {
name: "App",
components: {
ActionButtonList,
InfoList
},
};
</script>
109 changes: 109 additions & 0 deletions vue/vue-wagmi-siwx/src/assets/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
:root {
--background: #ffffff;
--foreground: #171717;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

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

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}

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

section {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 16px;
background-color: #f9f9f9;
padding: 13px;
margin: 10px;
width: 90%;
text-align: left;
}

.pages {
align-items: center;
justify-items: center;
text-align: center;
}

button {
padding: 10px 15px;
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: 15px; /* Space between buttons */
}

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

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

h1 {
margin: 20px;
}

pre {
white-space: pre-wrap; /* Wrap text */
word-wrap: break-word; /* Break long words */
word-break: break-all;
}


.link-button {
background-color: black;
color: white;
padding: 5px 10px;
text-decoration: none;
border-radius: 5px;
}

.link-button:hover {
background-color: #333; /* Darken the background on hover */
}

.link-button:hover {
background-color: white; /* Change background to white on hover */
color: black; /* Change text color to black on hover */
}

.advice {
text-align: 'center';
margin-bottom: 10px;
line-height: 25px;
}
39 changes: 39 additions & 0 deletions vue/vue-wagmi-siwx/src/components/ActionButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div>
<button @click="openAppKit">Open</button>
<button @click="handleDisconnect">Disconnect</button>
<button @click="switchToNetwork">Switch</button>
</div>
</template>

<script>
import { useDisconnect, useAppKit, useAppKitNetwork } from "@reown/appkit/vue";
import { networks } from "../config/index";

export default {
name: "ActionButtonList",
setup() {
const { disconnect } = useDisconnect();
const { open } = useAppKit();
const networkData = useAppKitNetwork();

const openAppKit = () => open();
const switchToNetwork = () => networkData.value.switchNetwork(networks[1]);
const handleDisconnect = async () => {
try {
await disconnect();
} catch (error) {
console.error("Error during disconnect:", error);
}
};


return {
handleDisconnect,
openAppKit,
switchToNetwork,
};
},
};
</script>

67 changes: 67 additions & 0 deletions vue/vue-wagmi-siwx/src/components/InfoList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<section>
<h2>useAppKit</h2>
<pre>
Address: {{ accountInfo.address }}
caip Address: {{ accountInfo.caipAddress }}
Connected: {{ accountInfo.isConnected }}
Status: {{ accountInfo.status }}
User Email: {{ accountInfo?.embeddedWalletInfo?.user?.email }}
</pre>
</section>

<section>
<h2>Theme</h2>
<pre>
Theme: {{ kitTheme.themeMode }}
</pre>
</section>

<section>
<h2>State</h2>
<pre>
open: {{ state.open }}
selectedNetworkId: {{ state.selectedNetworkId }}
</pre>
</section>

<section>
<h2>WalletInfo</h2>
<pre>
Name: {{ walletInfo }}<br />
</pre>
</section>
</template>

<script>
import { defineComponent, onMounted } from "vue";
import {
useAppKitState,
useAppKitTheme,
useAppKitEvents,
useAppKitAccount,
useWalletInfo,
} from "@reown/appkit/vue";

export default {
name: "InfoList",
setup() {
const kitTheme = useAppKitTheme();
const state = useAppKitState();
const accountInfo = useAppKitAccount();
const events = useAppKitEvents();
const { walletInfo } = useWalletInfo();

onMounted(() => {
console.log("Events: ", events);
});

return {
kitTheme,
state,
accountInfo,
walletInfo,
};
},
}
</script>
Loading