Skip to content

Commit 2a5db04

Browse files
authored
Merge pull request #203 from Apillon/staging
Staging
2 parents 02e9722 + 3aae3b5 commit 2a5db04

File tree

1 file changed

+95
-22
lines changed

1 file changed

+95
-22
lines changed

build/12-embedded-wallets-integration.md

+95-22
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,50 @@ A Vite plugin is required for running and building Vite apps with Embedded Walle
2222
npm install -D vite-plugin-node-polyfills
2323
```
2424

25+
HTTPS needs to be configured even for localhost, so that authentication can work accross multiple domains.
26+
This can be achieved with vite-plugin-mkcert Vite plugin.
27+
28+
```sh
29+
npm i vite-plugin-mkcert -D
30+
```
31+
2532
```ts
2633
// vite.config.ts
2734
import { defineConfig } from "vite";
2835
import { nodePolyfills } from "vite-plugin-node-polyfills";
36+
import mkcert from "vite-plugin-mkcert";
2937

3038
export default defineConfig({
31-
plugins: [nodePolyfills() /* ... */],
39+
plugins: [nodePolyfills(), mkcert() /* ... */],
3240
});
3341
```
3442

3543
### Next.js
3644

37-
To use the Embedded wallet UI, your Next app has to be in `app router` mode. When in `pages routing` mode, global CSS file imports throw an error. [Github Discussion](https://github.com/vercel/next.js/discussions/27953).
45+
To use the Embedded wallet UI, your Next app has to be in `app router` mode. When in `pages routing` mode, global CSS file imports throw an error. [Github Discussion](https://github.com/vercel/next.js/discussions/27953)
46+
47+
Embedded wallet relies on browser APIs and it doesn't make sense to run it server-side.
48+
To avoid errors, the component including `<WalletWidget />` should be marked with `'use client';`
49+
50+
HTTPS needs to be configured even for localhost, so that authentication can work accross multiple domains.
51+
In Next.js you can do this by adding `--experimental-https` to dev command.
52+
53+
```sh
54+
next dev --experimental-https
55+
```
3856

3957
### Nuxt
4058

4159
When using Vite as the build tool, a Vite plugin is required for running and building Nuxt apps with Embedded Wallet. This plugin enables Node API in the browser (eg. buffer, crypto).
4260

43-
::: warning
44-
The Embedded wallet integration includes a style (CSS) file imported through JavaScript.
45-
Nuxt fails to resolve this import by default.
46-
To avoid errors, the Embedded wallet dependency needs to be added to the [build.transpile](https://nuxt.com/docs/api/nuxt-config#transpile) setting.
47-
:::
48-
4961
```sh
5062
npm i -D vite-plugin-node-polyfills
5163
```
5264

65+
The Embedded wallet integration includes a style (CSS) file imported through JavaScript.
66+
Nuxt fails to resolve this import by default.
67+
To avoid errors, the Embedded wallet dependency needs to be added to the [build.transpile](https://nuxt.com/docs/api/nuxt-config#transpile) setting.
68+
5369
```ts
5470
// nuxt.config.ts
5571
import { nodePolyfills } from "vite-plugin-node-polyfills";
@@ -59,12 +75,47 @@ export default defineNuxtConfig({
5975
plugins: [nodePolyfills() /* ... */],
6076
},
6177
build: {
62-
transpile: ["@apillon/wallet-vue"],
78+
transpile: [/@apillon[\\/]wallet-vue/],
6379
},
6480
/* ... */
6581
});
6682
```
6783

84+
Embedded wallet relies on browser APIs and it doesn't make sense to run it server-side.
85+
To avoid errors, wrap the wallet with `<ClientOnly />`.
86+
87+
```vue
88+
<template>
89+
<ClientOnly>
90+
<WalletWidget clientId="..." />
91+
</ClientOnly>
92+
</template>
93+
```
94+
95+
HTTPS needs to be configured even for localhost, so that authentication can work accross multiple domains.
96+
In Nuxt.js you can do this by:
97+
98+
- add `--https` to dev command
99+
100+
- install [mkcert](https://github.com/FiloSottile/mkcert)
101+
102+
- make a localhost certificate in project folder: `mkcert localhost`
103+
104+
- edit `nuxt.config.ts` to use the certificate for the dev server
105+
106+
```ts
107+
// nuxt.config.ts
108+
export default defineNuxtConfig({
109+
// ...
110+
devServer: {
111+
https: {
112+
key: "localhost-key.pem",
113+
cert: "localhost.pem",
114+
},
115+
},
116+
});
117+
```
118+
68119
## Installation
69120

70121
<CodeGroup>
@@ -117,7 +168,7 @@ import { WalletWidget } from "@apillon/wallet-react";
117168
},
118169
/* ... */
119170
]}
120-
/>
171+
/>;
121172
```
122173

123174
</CodeGroupItem>
@@ -158,7 +209,7 @@ EmbeddedWalletUI("#wallet", {
158209
explorerUrl: "https://moonbase.moonscan.io",
159210
},
160211
/* ... */
161-
]
212+
],
162213
});
163214
```
164215

@@ -167,14 +218,14 @@ EmbeddedWalletUI("#wallet", {
167218

168219
### Parameters
169220

170-
| Field | Type | Required | Description |
171-
| ---------------------------- | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
172-
| clientId | `string` | Yes | UUID of the integration that you obtain when creating it on the [Apillon embedded wallet dashboard](https://app.apillon.io/dashboard/service/embedded-wallet). |
173-
| defaultNetworkId | `number` | No | Chain ID set as default when opening wallet. |
174-
| networks | `Network[]` | No | Array of network specifications |
175-
| broadcastAfterSign | `boolean` | No | Automatically broadcast with SDK after confirming a transaction. |
176-
| disableDefaultActivatorStyle | `boolean` | No | Remove styles from "open wallet" button |
177-
| authFormPlaceholder | `string` | No | Placeholder displayed in input for username/email |
221+
| Field | Type | Required | Description |
222+
| ---------------------------- | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
223+
| clientId | `string` | Yes | UUID of the integration that you obtain when creating it on the [Apillon embedded wallet dashboard](https://app.apillon.io/dashboard/service/embedded-wallet). |
224+
| defaultNetworkId | `number` | No | Chain ID set as default when opening wallet. |
225+
| networks | `Network[]` | No | Array of network specifications |
226+
| broadcastAfterSign | `boolean` | No | Automatically broadcast with SDK after confirming a transaction. |
227+
| disableDefaultActivatorStyle | `boolean` | No | Remove styles from "open wallet" button |
228+
| authFormPlaceholder | `string` | No | Placeholder displayed in input for username/email |
178229

179230
#### Network Object
180231

@@ -185,13 +236,23 @@ To find the information for your desired network, visit [chainlist.org](https://
185236
:::
186237

187238
| Field | Type | Description |
188-
| ----------- | -------- | ----------------------------------------|
239+
| ----------- | -------- | --------------------------------------- |
189240
| name | `string` | The name of the network |
190241
| id | `number` | The unique Chain ID of the network |
191242
| rpcUrl | `string` | The URL to the network's RPC server |
192243
| explorerUrl | `string` | The URL to the network's block explorer |
193244

245+
### Button style
194246

247+
You can style the activator button by targeting `#oaw-wallet-widget-btn` css ID.
248+
Use `disableDefaultActivatorStyle` option to make the button unstyled.
249+
250+
You can also hide the activator button (`display: none;`) and open the wallet programmatically, eg. from a menu item or your own button.
251+
252+
```ts
253+
// const wallet = getEmbeddedWallet();
254+
wallet.events.emit("open", true);
255+
```
195256

196257
## Use wallet
197258

@@ -204,7 +265,7 @@ To access wallet signer and wallet information we provide core imports (hooks/co
204265
import { useAccount, useContract, useWallet } from "@apillon/wallet-react";
205266

206267
export default function Component() {
207-
const { username, address, getBalance } = useAccount();
268+
const { info, getBalance } = useAccount();
208269
const { wallet, signMessage, sendTransaction } = useWallet();
209270

210271
const { read, write } = useContract({
@@ -222,8 +283,14 @@ export default function Component() {
222283
return wallet.userExists(username);
223284
};
224285

286+
// get account info
287+
const getAccountInfo() = async () => {
288+
console.log(info.address);
289+
console.log(await getBalance());
290+
}
291+
225292
// sign a message
226-
const onSignMessage = await (msg: string) => {
293+
const onSignMessage = async (msg: string) => {
227294
await signMessage(msg);
228295
};
229296

@@ -266,6 +333,12 @@ function getWalletUserExists(username: string) {
266333
return wallet.value.userExists(username);
267334
}
268335
336+
// get account info
337+
async function getAccountInfo() {
338+
console.log(info.address);
339+
console.log(await getBalance());
340+
}
341+
269342
// sign a message
270343
async function onSignMessage(msg: string) {
271344
await signMessage(msg);

0 commit comments

Comments
 (0)