-
Notifications
You must be signed in to change notification settings - Fork 19
Package/avail wallet #106
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
manish2910
wants to merge
3
commits into
feat/wallet-sdk
Choose a base branch
from
package/avail-wallet
base: feat/wallet-sdk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Package/avail wallet #106
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}) | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "", | ||
"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" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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