Skip to content

Commit

Permalink
docs: updates (#19)
Browse files Browse the repository at this point in the history
* docs: updates

* ci: update workflow
  • Loading branch information
tmm authored Jan 2, 2022
1 parent 32b4d8b commit 7bc1c47
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 35 deletions.
7 changes: 7 additions & 0 deletions .changeset/hip-dolls-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'wagmi-private': patch
'wagmi': patch
'wagmi-testing': patch
---

remove console log from walletlink connector
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Main

on: [push, pull_request]
on:
pull_request:
push:
branches: [main]

jobs:
build:
Expand Down
4 changes: 1 addition & 3 deletions docs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
WalletLinkConnector,
chain,
defaultChains,
defaultL2Chains,
} from 'wagmi'

import 'nextra-theme-docs/style.css'
Expand All @@ -21,8 +20,7 @@ import 'degen/styles'
/* eslint-enable import/no-unresolved */

const infuraId = process.env.NEXT_PUBLIC_INFURA_ID as string

const chains = [...defaultChains, ...defaultL2Chains]
const chains = defaultChains

type Config = { chainId?: number }
const connectors = ({ chainId }: Config) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/connectors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Callout from 'nextra-theme-docs/callout'

# Connectors

**Connectors** allow users to securly connect their wallet to your app. When using wagmi, you configure whatever connectors you want to use and wagmi handles the rest!
Connectors allow users to securly connect their wallet to your app. When using wagmi, you configure whatever connectors you want to use and wagmi handles the rest!

## Built-in Connectors

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/constants.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Constants

wagmi exposes some helpful **constants** to standardize frequently used values and objects.
wagmi exposes some helpful constants to standardize frequently used values and objects.

## Networks/Chains

Expand Down
12 changes: 6 additions & 6 deletions docs/pages/docs/hooks/useBalance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useBalance } from 'wagmi'

const App = () => {
const [{ data, error, loading }, getBalance] = useBalance({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
addressOrName: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
})

if (loading) return <div>Fetching balance…</div>
Expand Down Expand Up @@ -46,7 +46,7 @@ const App = () => {

```ts
(config?: {
address: string
addressOrName: string
formatUnits?: Unit | number
token?: string
}) => Promise<
Expand All @@ -63,14 +63,14 @@ const App = () => {

### address (optional)

Fetches Ethereum balance for address.
Fetches Ethereum balance for address or ENS name.

```tsx highlight='5'
import { useBalance } from 'wagmi'

const App = () => {
const [{ data, error, loading }, getBalance] = useBalance({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
addressOrName: 'awkweb.eth'
})

return ...
Expand All @@ -79,7 +79,7 @@ const App = () => {

### formatUnits (optional)

Formats balance using [**ethers.js** units](https://docs.ethers.io/v5/api/utils/display-logic/#display-logic--units). Defaults to `ether`.
Formats balance using ethers.js [units](https://docs.ethers.io/v5/api/utils/display-logic/#display-logic--units). Defaults to `ether`.

```tsx highlight='6'
import { useBalance } from 'wagmi'
Expand Down Expand Up @@ -113,7 +113,7 @@ const App = () => {

### token (optional)

Fetches ERC-20 balance instead of Ethereum balance. For example, $UNI:
Fetches ERC-20 balance instead of Ethereum balance. For example, [$UNI](https://etherscan.io/address/0x1f9840a85d5af5bf1d1762f925bdaddc4201f984):

```tsx highlight='6'
import { useBalance } from 'wagmi'
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/hooks/useContract.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useContract

Hook for declaratively creating ethers.js [**Contract**](https://docs.ethers.io/v5/api/contract/contract).
Hook for declaratively creating ethers.js [Contract](https://docs.ethers.io/v5/api/contract/contract).

```tsx
import { useContract } from 'wagmi'
Expand Down Expand Up @@ -67,7 +67,7 @@ const App = () => {

### signerOrProvider (optional)

An [**ethers.js** Provider](https://docs.ethers.io/v5/api/providers/provider/#Provider) or [Signer](https://docs.ethers.io/v5/api/signer/#Signer).
An ethers.js [Provider](https://docs.ethers.io/v5/api/providers/provider/#Provider) or [Signer](https://docs.ethers.io/v5/api/signer/#Signer).

```tsx highlight='8'
import { useContract, useProvider } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/hooks/useProvider.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useProvider

Hook for accessing [**ethers.js** Provider](https://docs.ethers.io/v5/api/providers/provider/#Provider) from [global configuration](/docs/provider#provider-optional).
Hook for accessing ethers.js [Provider](https://docs.ethers.io/v5/api/providers/provider/#Provider) from [global configuration](/docs/provider#provider-optional).

```tsx
import { useProvider } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/hooks/useTransaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const App = () => {

### request (optional)

Object to use when creating transaction. See [**TransactionRequest**](https://docs.ethers.io/v5/api/providers/types/#providers-TransactionRequest) for more info.
Object to use when creating transaction. See [TransactionRequest](https://docs.ethers.io/v5/api/providers/types/#providers-TransactionRequest) for more info.

```tsx highlight='5'
import { useTransaction } from 'wagmi'
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/hooks/useWaitForTransaction.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useWaitForTransaction

Hook for declaratively waiting until transaction is processed. Pairs well with [**useContracWrite**](/docs/hooks/useContracWrite) and [**useTransaction**](/docs/hooks/useTransaction).
Hook for declaratively waiting until transaction is processed. Pairs well with [`useContracWrite`](/docs/hooks/useContracWrite) and [`useTransaction`](/docs/hooks/useTransaction).

```tsx
import { useWaitForTransaction } from 'wagmi'
Expand Down Expand Up @@ -116,7 +116,7 @@ const App = () => {

### wait (optional)

Function that resolves to processed transaction receipt. Works well with [**useContracWrite**](/docs/hooks/useContracWrite) and [**useTransaction**](/docs/hooks/useTransaction) results `hash` or `wait`.
Function that resolves to processed transaction receipt. Works well with [`useContracWrite`](/docs/hooks/useContracWrite) and [`useTransaction`](/docs/hooks/useTransaction) results `hash` or `wait`.

```tsx highlight='6'
import { useTransaction, useWaitForTransaction } from 'wagmi'
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/hooks/useWebSocketProvider.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useWebSocketProvider

Hook for accessing [**ethers.js** WebSocketProvider](https://docs.ethers.io/v5/api/providers/other/#WebSocketProvider) from [global configuration](/docs/provider#provider-optional).
Hook for accessing ethers.js [WebSocketProvider](https://docs.ethers.io/v5/api/providers/other/#WebSocketProvider) from [global configuration](/docs/provider#provider-optional).

```tsx
import { useWebSocketProvider } from 'wagmi'
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ WebSocket interface for connecting to network. If you provide a WebSocket provid
import { providers } from 'ethers'
import { Provider } from 'wagmi'

const provider = ({ chainId }) =>
const webSocketProvider = ({ chainId }) =>
new providers.InfuraWebSocketProvider(chainId, 'Your infura id')

const App = () => (
<Provider provider={provider}>
<Provider webSocketProvider={webSocketProvider}>
<YourRoutes />
</Provider>
)
Expand Down
1 change: 0 additions & 1 deletion packages/private/src/connectors/walletLinkConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class WalletLinkConnector extends Connector<
async connect() {
try {
const provider = this.getProvider()
console.log({ provider })
provider.on('accountsChanged', this.onAccountsChanged)
provider.on('chainChanged', this.onChainChanged)
provider.on('disconnect', this.onDisconnect)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/accounts/useBalance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('useBalance', () => {
await result.current.connect[1](mockConnector)

const res = await result.current.balance[1]({
address: wallets.ethers1.address,
addressOrName: wallets.ethers1.address,
})
expect(res).toMatchInlineSnapshot(`
{
Expand Down
28 changes: 16 additions & 12 deletions packages/react/src/hooks/accounts/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const initialState: State = {
}

export const useBalance = ({
addressOrName: address,
addressOrName,
formatUnits = 'ether',
skip,
token,
Expand All @@ -43,13 +43,17 @@ export const useBalance = ({

const getBalance = React.useCallback(
async (config?: {
address: string
addressOrName: string
formatUnits?: Config['formatUnits']
token?: Config['token']
}) => {
try {
const config_ = config ?? { address, formatUnits, token }
if (!config_.address) throw new Error('address is required')
const config_ = config ?? {
addressOrName,
formatUnits,
token,
}
if (!config_.addressOrName) throw new Error('address is required')

const formatUnits_ = config_.formatUnits ?? 'ether'

Expand All @@ -61,15 +65,15 @@ export const useBalance = ({
erc20ABI,
provider,
)
const value = await contract.balanceOf(config_.address)
const value = await contract.balanceOf(config_.addressOrName)
const symbol = await contract.symbol()
balance = {
formatted: utils.formatUnits(value, formatUnits_),
symbol,
value,
}
} else {
const value = await provider.getBalance(config_.address)
const value = await provider.getBalance(config_.addressOrName)
balance = {
formatted: utils.formatUnits(value, formatUnits_),
symbol: 'ETH',
Expand All @@ -85,30 +89,30 @@ export const useBalance = ({
return error
}
},
[address, formatUnits, provider, token],
[addressOrName, formatUnits, provider, token],
)

// Fetch balance when deps or chain changes
/* eslint-disable react-hooks/exhaustive-deps */
React.useEffect(() => {
if (skip || !address) return
if (skip || !addressOrName) return

let didCancel = false
if (didCancel) return
getBalance({ address, formatUnits, token })
getBalance({ addressOrName, formatUnits, token })

return () => {
didCancel = true
}
}, [address, cacheBuster, skip, token])
}, [addressOrName, cacheBuster, skip, token])
/* eslint-enable react-hooks/exhaustive-deps */

/* eslint-disable react-hooks/exhaustive-deps */
React.useEffect(() => {
if (!watch) return
if (!blockNumber) return
if (!address) return
getBalance({ address, formatUnits, token })
if (!addressOrName) return
getBalance({ addressOrName, formatUnits, token })
}, [blockNumber])
/* eslint-enable react-hooks/exhaustive-deps */

Expand Down

1 comment on commit 7bc1c47

@vercel
Copy link

@vercel vercel bot commented on 7bc1c47 Jan 2, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

Please sign in to comment.