Skip to content

Commit

Permalink
v5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed Apr 22, 2019
1 parent d8442e3 commit 17649ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -212,7 +212,7 @@ Regardless of how you access the `web3-react` context, it will look like:
- `setConnector(connectorName: string, { suppressAndThrowErrors?: boolean, networkId?: number })`: Activates a connector by name. The optional second argument has two keys: `suppressAndThrowErrors` (`false` by default) that controls whether errors, instead of bubbling up to `context.error`, are instead thrown by this function, and `networkId`, an optional manual network id passed to the `getProvider` method of the connector.
- `setFirstValidConnector(connectorNames: string[], { suppressAndThrowErrors?: boolean, networkIds?: number[] })`: Tries to activate each connector in turn by name. The optional second argument has two keys: `suppressAndThrowErrors` (`false` by default) that controls whether errors, instead of bubbling up to `context.error`, are instead thrown by this function, and `networkIds`, optional manual network ids passed to the `getProvider` method of the connector in turn.
- `unsetConnector()`: Unsets the currently active connector.
- `setError: (error: Error, { preserveConnector?: boolean, connectorName?: string }) => void`: Sets `context.error`, optionally preserving the current connector if `preserveConnector` is `true` (default `false`), or setting a `connectorName` (note that if you're doing this, `preserveConnector` must be `false`).
- `setError: (error: Error, { preserveConnector?: boolean, connectorName?: string }) => void`: Sets `context.error`, optionally preserving the current connector if `preserveConnector` is `true` (default `true`), or setting a `connectorName` (note that if you're doing this, `preserveConnector` is ignored).

## Implementations

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "web3-react",
"version": "5.0.3",
"version": "5.0.4",
"description": "A simple, powerful framework for building modern Ethereum dApps using React.",
"author": "Noah Zinsmeister <noahwz@gmail.com>",
"keywords": [
Expand Down
15 changes: 13 additions & 2 deletions src/manager.ts
Expand Up @@ -30,6 +30,7 @@ interface SetFirstValidConnectorOptions {

interface SetErrorOptions {
preserveConnector?: boolean
connectorName?: string
}

export interface Web3ReactUpdateHandlerOptions {
Expand Down Expand Up @@ -122,6 +123,10 @@ function web3StateReducer(state: Web3State, action: any): Web3State {
return { ...initialWeb3State, error: action.payload }
case 'SET_ERROR_PRESERVE_CONNECTOR_NAME':
return { ...initialWeb3State, connectorName: state.connectorName, error: action.payload }
case 'SET_ERROR_WITH_CONNECTOR_NAME': {
const { connectorName, error } = action.payload
return { ...initialWeb3State, connectorName, error }
}
case 'RESET':
return initialWeb3State
default: {
Expand Down Expand Up @@ -151,7 +156,13 @@ export default function useWeb3Manager(connectors: Connectors): Web3Manager {
: undefined

// function to set the error state.
function setError(error: Error, { preserveConnector = true }: SetErrorOptions = {}): void {
function setError(error: Error, { preserveConnector = true, connectorName }: SetErrorOptions = {}): void {
if (connectorName) {
dispatchWeb3State({
type: 'SET_ERROR_WITH_CONNECTOR_NAME',
payload: { error, connectorName }
})
}
if (preserveConnector) {
dispatchWeb3State({
type: 'SET_ERROR_PRESERVE_CONNECTOR_NAME',
Expand Down Expand Up @@ -221,7 +232,7 @@ export default function useWeb3Manager(connectors: Connectors): Web3Manager {
if (suppressAndThrowErrors) {
throw error
} else {
setError(error)
setError(error, { connectorName })
}
}
}
Expand Down

0 comments on commit 17649ab

Please sign in to comment.