Skip to content
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
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "yarn dev"
},
{
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"type": "node-terminal",
"request": "launch",
"command": "yarn dev",
"serverReadyAction": {
"pattern": "started server on .+, url: (https?://.+)",
"uriFormat": "%s",
"action": "debugWithChrome"
}
}
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"breadcrumbs.enabled": true,
"editor.cursorBlinking": "smooth",
"editor.wordWrap": "on",
"editor.bracketPairColorization.enabled": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"terminal.integrated.cursorBlinking": true,
"search.exclude": {
"**/*./node_modules": true,
"**/node_modules": false
}
}
23 changes: 23 additions & 0 deletions packages/avail-wallet/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# 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?
265 changes: 42 additions & 223 deletions packages/avail-wallet/README.md
Original file line number Diff line number Diff line change
@@ -1,235 +1,54 @@
# Avail Wallet Package
# React + TypeScript + Vite

## Overview
This package provides React components and hooks for integrating Avail wallets into your application. It includes both wallet connection functionality and styled UI components with all required fonts and assets bundled.
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

## Installation
```bash
pnpm install avail-wallet
```

## Basic Usage
Here's how to properly set up your application with this package:

### Next.js App Router Setup

```tsx
// In your app/providers.tsx
"use client";

import { AvailWalletProvider } from 'avail-wallet';
// Styles are automatically imported from the package
// No need to separately import CSS files or add fonts!

export function Providers({ children }) {
return (
<AvailWalletProvider>
{children}
</AvailWalletProvider>
);
}

// In your app/layout.tsx
import { Providers } from './providers';
import './globals.css';

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<Providers>
{children}
</Providers>
</body>
</html>
);
}
```

### Next.js Pages Router Setup

```tsx
// In your _app.tsx or root component
import { AvailWalletProvider } from 'avail-wallet';
// Styles are automatically imported from the package
import '../styles/globals.css';

function App({ Component, pageProps }) {
return (
<AvailWalletProvider>
<Component {...pageProps} />
</AvailWalletProvider>
);
}

export default App;
```

## Persistence
The wallet state is automatically persisted in your browser's localStorage. This means users will remain connected to their wallets between sessions without having to reconnect every time they visit your application.

## Components

### Wallet Components

#### AvailWalletProvider
Provides the wallet context to your application with built-in localStorage persistence.

#### AvailWalletConnect
A component for connecting to Avail wallets with a styled UI.

#### AccountSelector
Allows users to select an account from their wallet with a styled UI.

#### DisconnectWallet
Provides UI for disconnecting from a wallet.

#### WalletSelector
Allows users to select which wallet provider to connect with.

### UI Components

The package includes several UI components that are used by the wallet components but can also be used independently:

#### Button
A customizable button component with various styles and variants.

#### Badge
A customizable badge component with different style variants.

#### Dialog
A modal dialog component with header, footer, title, and description components.

## Hooks

### useAvailWallet
Access the wallet context, including connection state and API.
Currently, two official plugins are available:

### useAvailAccount
Access and manage the selected account.
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

### useApi
Access the Avail API.
## Expanding the ESLint configuration

### MetaMask Hooks
The package also includes hooks for MetaMask integration:

#### useMetaMask
Access the MetaMask wallet state.

#### useMetaMaskContext
Access the MetaMask context.

#### useRequestSnap
Request the Avail snap for MetaMask.

#### useInvokeSnap
Invoke methods on the Avail snap for MetaMask.

## Examples

### Basic Wallet Connection
```tsx
import { useAvailWallet, AvailWalletConnect } from 'avail-wallet';

function MyComponent() {
const { isConnected, api } = useAvailWallet();

return (
<div>
<AvailWalletConnect />
{isConnected ? 'Connected to wallet' : 'Not connected'}
</div>
);
}
```

### Using UI Components
```tsx
import { Button, Badge, Dialog, DialogContent, DialogHeader, DialogTitle } from 'avail-wallet';

function MyUIComponent() {
return (
<div>
<Button variant="primary" size="lg">Connect Wallet</Button>
<Badge variant="avail">Avail Network</Badge>

<Dialog>
<DialogContent>
<DialogHeader>
<DialogTitle>Select a Wallet</DialogTitle>
</DialogHeader>
{/* Dialog content here */}
</DialogContent>
</Dialog>
</div>
);
}
```

## Styling Information

### Included Assets
This package includes the following assets bundled and ready to use:

- **Fonts**: All required fonts (PP Mori and THICCCBOI variants)
- **Images**: The availsnap.png image for MetaMask integration

### Custom Styling
You can override the default styles by targeting the classes with higher specificity in your own CSS:

```css
/* In your custom CSS file */
.aw-button-primary {
background-color: #YOUR_CUSTOM_COLOR !important;
}
```

### Tailwind CSS
If you're using Tailwind CSS, ensure your content configuration includes the package components:
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

```js
// tailwind.config.js
module.exports = {
content: [
// ...your other content paths
'./node_modules/avail-wallet/**/*.{js,ts,jsx,tsx}'
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
// ...rest of your config
}
```

## TypeScript Support

The package includes TypeScript types for all components and hooks:

```tsx
import type {
UpdateMetadataParams,
WalletSelectionProps,
AccountSelectionProps,
DisconnectWalletProps,
ExtendedWalletAccount,
AvailWalletProviderProps,
AvailWalletConnectProps
} from 'avail-wallet';
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

## Utility Functions and Assets

The package provides several utility functions and asset paths:

### Utility Functions
- `updateMetadata`: Update metadata for wallet accounts
- `getInjectorMetadata`: Get metadata for wallet injectors
- `initApi`: Initialize the Avail API
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

### Asset Paths
Asset paths are exposed for advanced use cases if needed:

```tsx
import { ASSETS_PATH } from 'avail-wallet';

console.log(ASSETS_PATH.fonts.PPMoriRegular); // Path to the PP Mori Regular font
console.log(ASSETS_PATH.images.availSnap); // Path to the Avail Snap image
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```
21 changes: 21 additions & 0 deletions packages/avail-wallet/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Empty Tailwind config path could cause build issues. Should point to tailwind.config.js or similar

"css": "src/lib/index.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}
26 changes: 0 additions & 26 deletions packages/avail-wallet/dist/index.d.ts

This file was deleted.

Loading