Skip to content

Commit

Permalink
Merge pull request #9 from project-kardeshev/develop
Browse files Browse the repository at this point in the history
fix(readme): update readme
  • Loading branch information
atticusofsparta authored Oct 25, 2024
2 parents 63b9e88 + 7a654f6 commit 63a0a74
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn format
yarn lint
yarn lint-staged
8 changes: 7 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ public
dist
coverage
CODEOWNERS
docs
docs
.storybook
.husky
CHANGLELOG.md
LICENSE
yarn.lock
storybook-static
76 changes: 56 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
# Arweave Wallet Kit

React Hooks and Components for better interaction with Arweave wallets. Modular, can support any Arweave-based wallet.

> The Arweave Wallet Kit is in BETA. Please report bugs at the issues tab.
# AO Wallet Kit

React Hooks and Components for preconfigured and customizable interactions on AO.

<!-- toc -->

- [Supported wallets](#supported-wallets)
- [Installation](#installation)
- [Setup](#setup)
- [Config](#config)
- [App config](#app-config)
- [Available options](#available-options)
- [Custom theme](#custom-theme)
- [Available options](#available-options-1)
- [Font](#font)
- [Terminology of Arweave Wallet Kit](#terminology-of-arweave-wallet-kit)
- [Connect Button](#connect-button)
- [Usage](#usage)
- [Config](#config-1)
- [Hooks](#hooks)
- [`useConnection`](#useconnection)
- [Usage](#usage-1)
- [`useApi`](#useapi)
- [Usage](#usage-2)
- [`useProfileModal`](#useprofilemodal)
- [`useActiveAddress`](#useactiveaddress)
- [Usage](#usage-3)
- [`usePublicKey`](#usepublickey)
- [Usage](#usage-4)
- [`usePermissions`](#usepermissions)
- [Usage](#usage-5)
- [`useAddresses`](#useaddresses)
- [Usage](#usage-6)
- [`useWalletNames`](#usewalletnames)
- [Usage](#usage-7)
- [`useStrategy`](#usestrategy)
- [Usage](#usage-8)

<!-- tocstop -->

## Supported wallets

- [ArConnect](https://arconnect.io)
- [Arweave.app](https://arweave.app)
- Any extension-based Arweave wallet, that injects it's ArConnect-like API into `window.arweaveWallet`
- [Metamask](https://metamask.io/)
- [Phantom](https://phantom.app/)
- Any wallet that injects the `window.ethereum` or `window.arweaveWallet` API (wagmi is used internally)
- Allows for custom strategies to be implemented so future integrations can be added!

## Installation

```sh
yarn add arweave-wallet-kit
yarn add @project-kardeshev/ao-wallet-kit
```

or

```sh
npm i arweave-wallet-kit
npm i @project-kardeshev/ao-wallet-kit
```

## Setup
Expand All @@ -29,9 +66,9 @@ To use the library, you'll need to wrap your application with the Kit Provider.
```tsx
const App = () => {
return (
<ArweaveWalletKit>
<AOWalletKit>
<YourApp />
</ArweaveWalletKit>
</AOWalletKit>
);
};
```
Expand All @@ -42,7 +79,7 @@ The Arweave Wallet Kit can be configured with information about your application

```tsx
...
<ArweaveWalletKit
<AOWalletKit
config={{
permissions: ["ACCESS_ADDRESS"],
ensurePermissions: true,
Expand All @@ -54,13 +91,13 @@ The Arweave Wallet Kit can be configured with information about your application
}}
>
<YourApp />
</ArweaveWalletKit>
</AOWalletKit>
...
```

### App config

Using the `config` field of the `<ArweaveWalletKit>` provider component, you can define a name, a logo or the required permissions for your app.
Using the `config` field of the `<AOWalletKit>` provider component, you can define a name, a logo or the required permissions for your app.

#### Available options

Expand Down Expand Up @@ -93,7 +130,7 @@ Here's an example of how to use it:

```tsx
...
<ArweaveWalletKit
<AOWalletKit
theme={{
font: {
fontFamily: "Arial"
Expand All @@ -106,11 +143,11 @@ Here's an example of how to use it:

## Terminology of Arweave Wallet Kit

Arweave Wallet Kit supports several _strategies_. The word **strategy means an implementation of an Arweave Wallet** in the Kit. These strategies allow the user to communicate with all wallets the same way and with the same API.
Arweave Wallet Kit supports several _strategies_. The word **strategy means an implementation of a Wallet** in the Kit. These strategies allow the user to communicate with all wallets the same way and with the same API.

## Connect Button

To quickly integrate the Arweave Wallet Kit, you can use the `<ConnectButton>` component. It is a highly customizable button that supports the [ANS](https://ar.page) protocol to display information about the connected wallet.
To quickly integrate the Arweave Wallet Kit, you can use the `<ConnectButton>` component. It is a highly customizable button that supports displaying profile information about the connected wallet.

### Usage

Expand All @@ -132,12 +169,11 @@ You can configure the Connect Button through it's props.
| `accent` | `string` |  A theme color for the button |
| `showBalance` | `boolean` | Show user balance when connected |
| `showProfilePicture` | `boolean` | Show user profile picture when connected |
| `useAns` | `boolean` | Use ANS to grab profile information |
| `profileModal` | `boolean` | Show profile modal on click (if disabled, clicking the button will disconnect the user) |

## Hooks

Inside the [`<ArweaveWalletKit>`](#setup), you can use all kinds of hooks that are reactive to the different [strategies](#terminology-of-arweave-wallet-kit). Some of the hooks / api functions might not be supported by all wallets.
Inside the [`<AOWalletKit>`](#setup), you can use all kinds of hooks that are reactive to the different [strategies](#terminology-of-arweave-wallet-kit). Some of the hooks / api functions might not be supported by all wallets.

### `useConnection`

Expand Down Expand Up @@ -198,7 +234,7 @@ const address = useActiveAddress();

### `usePublicKey`

Active address hook. Requires the `ACCESS_PUBLIC_KEY` permission.
Active public key hook. Requires the `ACCESS_PUBLIC_KEY` permission.

#### Usage

Expand Down Expand Up @@ -228,7 +264,7 @@ const addresses = useAddresses();

### `useWalletNames`

All addresses hook. Returns the addresses in the connected wallet, known by Arweave Wallet Kit. Requires the `ACCESS_ALL_ADDRESSES` permission.
All addresses hook. Returns the addresses in the connected wallet, known by Arweave Wallet Kit. Requires the `ACCESS_ALL_ADDRESSES` permission. Note this is note available for Ethereum wallets.

#### Usage

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"serve-docs": "http-server storybook-static --port 8080",
"test": "echo \"Warning: no test specified\"",
"format": "prettier . --write",
"lint": "eslint src"
"lint": "eslint src",
"docs:update": "markdown-toc-gen insert README.md",
"prepare": "husky install"
},
"dependencies": {
"@ar.io/sdk": "^2.3.2",
Expand Down Expand Up @@ -117,6 +119,7 @@
"eslint-plugin-simple-import-sort": "^8.0.0",
"http-server": "^14.1.1",
"husky": "^8.0.3",
"lint-staged": "^15.2.10",
"markdown-toc-gen": "^1.0.1",
"node-stdlib-browser": "^1.2.1",
"prettier": "^2.8.8",
Expand All @@ -138,10 +141,7 @@
"react-dom": "^16.8.0 || 17.x || 18.x"
},
"lint-staged": {
"**/*.{ts,js,mjs,cjs,md,json}": [
"prettier --write ."
],
"**/README.md": [
"./README.md": [
"markdown-toc-gen insert"
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Strategy from '../strategy/Strategy';
import { Font, ThemeProvider, darkTheme, lightTheme } from '../theme';
import { rgbToString } from '../utils/arweave';

export function ArweaveWalletKit({
export function AOWalletKit({
children,
theme = defaultTheme,
config = defaultConfig,
Expand Down
40 changes: 20 additions & 20 deletions src/hooks/useAns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ import { useEffect, useState } from 'react';
import useAddress from './active_address';
import useGatewayURL from './gateway';

interface AnsProfile {
user: string;
currentLabel: string;
ownedLabels?: {
domain: string;
color: string;
subdomains: unknown[];
record: string | null;
created_at: number;
label: string;
}[];
nickname?: string;
address_color: string;
bio?: string;
avatar?: string;
links?: {
[key: string]: string;
};
}

/**
* ANS profile hook
*/
Expand Down Expand Up @@ -44,23 +64,3 @@ export default function useAns() {

return ans;
}

interface AnsProfile {
user: string;
currentLabel: string;
ownedLabels?: {
domain: string;
color: string;
subdomains: unknown[];
record: string | null;
created_at: number;
label: string;
}[];
nickname?: string;
address_color: string;
bio?: string;
avatar?: string;
links?: {
[key: string]: string;
};
}
8 changes: 4 additions & 4 deletions src/stories/ConnectButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { ComponentStory } from '@storybook/react';

import ConnectButton from '../components/ConnectButton';
import { ArweaveWalletKit } from '../components/Provider';
import { AOWalletKit } from '../components/Provider';

export default {
name: 'ConnectButton',
component: ConnectButton,
};

const Template: ComponentStory<typeof ArweaveWalletKit> = (props) => (
<ArweaveWalletKit {...props}>
const Template: ComponentStory<typeof AOWalletKit> = (props) => (
<AOWalletKit {...props}>
<ConnectButton accent={'rgb(0, 122, 255)'} />
</ArweaveWalletKit>
</AOWalletKit>
);

export const Basic = Template.bind({});
Expand Down
6 changes: 3 additions & 3 deletions src/stories/Connector.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';

import { Modal } from '../components/Modal/Modal';
import { ArweaveWalletKit } from '../components/Provider';
import { AOWalletKit } from '../components/Provider';
import useAddress from '../hooks/active_address';
import useAddresses, { useWalletNames } from '../hooks/addresses';
import useConnection from '../hooks/connection';
Expand All @@ -15,7 +15,7 @@ export default {

export const Basic = () => {
return (
<ArweaveWalletKit
<AOWalletKit
config={{
permissions: [
'ACCESS_ADDRESS',
Expand All @@ -29,7 +29,7 @@ export const Basic = () => {
}}
>
<Button />
</ArweaveWalletKit>
</AOWalletKit>
);
};

Expand Down
6 changes: 3 additions & 3 deletions src/stories/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Footer } from '../components/Modal/Footer';
import { Head } from '../components/Modal/Head';
import { Modal } from '../components/Modal/Modal';
import { Paragraph } from '../components/Paragraph';
import { ArweaveWalletKit } from '../components/Provider';
import { AOWalletKit } from '../components/Provider';
import { Title, TitleWithParagraph } from '../components/Title';
import useModal from '../hooks/modal';

Expand All @@ -19,7 +19,7 @@ export const Basic = () => {
const modal = useModal(true);

return (
<ArweaveWalletKit>
<AOWalletKit>
<Modal {...modal.bindings}>
<Head onClose={modal.bindings.onClose}>
<Title>Connect wallet</Title>
Expand All @@ -42,7 +42,7 @@ export const Basic = () => {
<Button>MORE</Button>
</Footer>
</Modal>
</ArweaveWalletKit>
</AOWalletKit>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/strategy/strategies/Othent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class OthentStrategy implements Strategy {
try {
const appInfo: OthentAppInfo = {
name: typeof location === 'undefined' ? 'UNKNOWN' : location.hostname,
version: 'ArweaveWalletKit',
version: 'AOWalletKit',
env: '',
};

Expand Down
2 changes: 1 addition & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export const { ThemeProvider, useTheme } = theming;
// the components that are outside throw the undefined error
// naturally on production use, this will never happen, as
// the users need to wrap their application with the
// <ArweaveWalletKit> component anyway
// <AOWalletKit> component anyway
export const withTheme =
theming.withTheme || ((val) => val as ThemingType<DefaultTheme>['withTheme']);
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strictNullChecks": true
"strictNullChecks": true,
"jsx": "react-jsx"
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down
Loading

0 comments on commit 63a0a74

Please sign in to comment.