Skip to content

Commit

Permalink
docs: add installation and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson86tw committed May 13, 2024
1 parent 76378a6 commit b588843
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 35 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@

<img src="https://github.com/vu3th/vue-dapp/blob/main/app/public/images/overview.png" alt="Vue Dapp Overview" style="max-width:100%;" width="800">


## Getting Started

### SPA with Vite
## Installation

```bash
npm install pinia @vue-dapp/core @vue-dapp/modal
Expand All @@ -59,6 +56,18 @@ import { createPinia } from 'pinia'
app.use(createPinia())
```

### Nuxt

```bash
npm install pinia @pinia/nuxt @vue-dapp/core @vue-dapp/nuxt @vue-dapp/modal
```

```ts
modules: ['@pinia/nuxt', '@vue-dapp/nuxt']
```

## Getting Started

```vue
<script lang="ts" setup>
import { BrowserWalletConnector, useVueDapp } from '@vue-dapp/core'
Expand Down Expand Up @@ -91,29 +100,21 @@ function onClickConnectButton() {
</template>
```

### SSR with Nuxt 3

```bash
npm install pinia @pinia/nuxt @vue-dapp/core @vue-dapp/nuxt @vue-dapp/modal
```

```ts
modules: ['@pinia/nuxt', '@vue-dapp/nuxt']
```

## Examples

- [vue-dapp-starter](https://github.com/vu3th/vue-dapp-starter)
- [nuxt-dapp](https://github.com/vu3th/nuxt-dapp)

## Development

```
pnpm i
```bash
pnpm install
pnpm build
pnpm -F core watch
pnpm -F modal watch
pnpm dev
pnpm build
pnpm build:app
```


Expand Down
21 changes: 5 additions & 16 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { VueDappModal } from '@vue-dapp/modal'
import '@vue-dapp/modal/dist/style.css'
import { WalletConnectConnector } from '@vue-dapp/walletconnect'
import { CoinbaseWalletConnector } from '@vue-dapp/coinbase'
import { INFURA_ID } from './constants'
import { darkTheme, lightTheme, type GlobalThemeOverrides } from 'naive-ui'
import { useAppStore } from './stores/appStore'
Expand All @@ -23,7 +22,7 @@ useHead({
},
})
const { addConnectors, watchWalletChanged, watchDisconnect, onDisconnect, onAccountsChanged } = useVueDapp()
const { addConnectors, watchWalletChanged, watchDisconnect } = useVueDapp()
if (process.client) {
addConnectors([
new BrowserWalletConnector(),
Expand All @@ -44,26 +43,16 @@ if (process.client) {
}),
new CoinbaseWalletConnector({
appName: 'Vue Dapp',
jsonRpcUrl: `https://mainnet.infura.io/v3/${INFURA_ID}`,
jsonRpcUrl: 'https://ethereum-rpc.publicnode.com',
}),
])
}
if (process.client) {
onAccountsChanged(() => {
console.log('Disconnected')
})
}
const { setWallet, resetWallet } = useEthers()
watchWalletChanged(
async (wallet: ConnWallet) => {
setWallet(wallet.provider)
},
{
immediate: true,
},
)
watchWalletChanged(async (wallet: ConnWallet) => {
setWallet(wallet.provider)
})
watchDisconnect(() => {
resetWallet()
Expand Down
4 changes: 2 additions & 2 deletions app/components/content/Contract.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const contract = new ethers.Contract(contractAddress, iface, defaultProvider)
// ======================== Wallet ========================
const { isConnected, wallet, error: ConnectError } = useVueDapp()
const { isConnected, wallet, error: connectError } = useVueDapp()
onMounted(() => {
fetchData()
Expand Down Expand Up @@ -165,7 +165,7 @@ const isReady = computed(() => isConnected.value && !showSwitchButton.value)
</n-button>
</div>

<div class="text-red-500">{{ error || ConnectError }}</div>
<div class="text-red-500">{{ error || connectError }}</div>

<!-- Event logs -->
<div>
Expand Down
2 changes: 1 addition & 1 deletion app/content/examples/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const contract = new ethers.Contract(contractAddress, iface, defaultProvider)

// ======================== Wallet ========================

const { isConnected, wallet, error: ConnectError } = useVueDapp()
const { isConnected, wallet, error: connectError } = useVueDapp()

onMounted(() => {
fetchData()
Expand Down
71 changes: 71 additions & 0 deletions app/content/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
description: ''
head:
meta:
- name: 'keywords'
content: ''
---

# Installation

```bash
npm install pinia @vue-dapp/core @vue-dapp/modal
```

```ts [main.ts]
import { createPinia } from 'pinia'
app.use(createPinia())
```

## Nuxt

```bash
npm install pinia @pinia/nuxt @vue-dapp/core @vue-dapp/nuxt @vue-dapp/modal
```

```ts
modules: ['@pinia/nuxt', '@vue-dapp/nuxt']
```

## Add Connectors

```bash
npm install @vue-dapp/walletconnect
```

```bash
npm install @vue-dapp/coinbase
```

```ts
import { BrowserWalletConnector, useVueDapp } from '@vue-dapp/core'
import { WalletConnectConnector } from '@vue-dapp/walletconnect'
import { CoinbaseWalletConnector } from '@vue-dapp/coinbase'

const { addConnectors } = useVueDapp()

addConnectors([
new BrowserWalletConnector(),
new WalletConnectConnector({
projectId: 'd1e65611568666138126d315c0bafd7d',
chains: [1],
showQrModal: true,
qrModalOptions: {
themeMode: 'light',
themeVariables: undefined,
desktopWallets: undefined,
walletImages: undefined,
mobileWallets: undefined,
enableExplorer: true,
privacyPolicyUrl: undefined,
termsOfServiceUrl: undefined,
},
}),
new CoinbaseWalletConnector({
appName: 'Vue Dapp',
jsonRpcUrl: 'https://ethereum-rpc.publicnode.com'
}),
])
```

<!-- ## Integrate with Ethers.js -->
11 changes: 11 additions & 0 deletions app/core/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export const sidebarMenu = [
),
key: '/overview',
},
{
label: () =>
h(
NuxtLink,
{
to: '/installation',
},
{ default: () => 'Installation' },
),
key: '/installation',
},
{
label: () =>
h(
Expand Down

0 comments on commit b588843

Please sign in to comment.