Skip to content
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

feat: implement enable method #8

Merged
merged 7 commits into from
Apr 6, 2024
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</p>

<p align="center">
A TypeScript implementation that allows dApps to connect and interact with web-based providers.
A TypeScript implementation that allows clients to connect and interact with web-based providers.
</p>

### Table of contents
Expand Down Expand Up @@ -127,8 +127,8 @@ This will compile the Typescript source code into a `dist/` directory.
| Command | Description |
|-----------------------|------------------------------------------------------------------------------------|
| `yarn build` | Builds the source code into the `dist/` directory. |
| `yarn run docs:build` | Builds the documentation into the `.docs/` directory. |
| `yarn run docs:serve` | Serves the built documentation from the `.docs/` directory. |
| `yarn run docs:build` | Builds the documentation into the `.docusaurus/` directory. |
| `yarn run docs:serve` | Serves the built documentation from the `.docusaurus/` directory. |
| `yarn run docs:start` | Builds and runs the documentation in a development environment with hot reloading. |
| `yarn run lint` | Runs the linter on `.js` and `.ts` files. |
| `yarn run prettier` | Runs the prettier on `.js` and `.ts` files. |
Expand Down
38 changes: 35 additions & 3 deletions docs/api-reference/avm-web-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ import TOCInline from '@theme/TOCInline';
|--------|-------------|
| `void` | - |

### `enable([params])`

> Enables to a client with providers. If the ID of the provider and/or network is specified, that provider/network is used, otherwise the default provider is enabled.

#### Parameters

| Name | Type | Required | Default | Description |
|--------|----------------------------------------|----------|---------|------------------------------------------------------|
| params | [`IEnableParams`](types#ienableparams) | no | - | Params that specify the provider and/or the network. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |

### `getConfig()`

> Returns the configuration.
Expand All @@ -60,9 +76,25 @@ import TOCInline from '@theme/TOCInline';

#### Parameters

| Name | Type | Required | Default | Description |
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| listener | (`result`?: [`IDiscoverResult`](types#idiscoverresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise<void>`) \| `null` | yes | - | The callback is called when a response message is received, or null to remove the listener. If the reult was successful, the `error` parameter will be null. |
| Name | Type | Required | Default | Description |
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| listener | (`result`?: [`IDiscoverResult`](types#idiscoverresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise<void>`) \| `null` | yes | - | The callback is called when a response message is received, or null to remove the listener. If the result was successful, the `error` parameter will be null. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |

### `onEnable(listener)`

> Listens to enable messages sent from providers. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| listener | (`result`?: [`IEnableResult`](types#ienableresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise<void>`) \| `null` | yes | - | The callback is called when a response message is received, or null to remove the listener. If the result was successful, the `error` parameter will be null. |

#### Returns

Expand Down
16 changes: 16 additions & 0 deletions docs/api-reference/avm-web-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ import TOCInline from '@theme/TOCInline';
| Type | Description |
|--------|-------------|
| `void` | - |

### `onEnable(listener)`

> Listens to enable messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`params`?: [`IEnableParams`](types#ienableparams)) => ([`IEnableResult`](types#ienableresult) \| [`Promise<IEnableResult>`](types#ienableresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
89 changes: 56 additions & 33 deletions docs/api-reference/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,86 @@ import TOCInline from '@theme/TOCInline';

### `IAVMWebClientConfig`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |
| Name | Type | Required | Default | Description |
|-------|-----------|----------|---------|-------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |

### `IAVMWebClientInitOptions`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |
| Name | Type | Required | Default | Description |
|-------|-----------|----------|---------|-------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |

### `IAVMWebProviderConfig`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| providerId | `string` | yes | - | The ID of the provider. |
| debug | `boolean` | no | `false` | Outputs debug information to the console. |
| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|-------------------------------------------|
| providerId | `string` | yes | - | The ID of the provider. |
| debug | `boolean` | no | `false` | Outputs debug information to the console. |

### `IAVMWebProviderInitOptions`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |
| Name | Type | Required | Default | Description |
|-------|-----------|----------|---------|-------------------------------------------|
| debug | `boolean` | no | `false` | Outputs debug information to the console. |

### `IBaseError`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| code | `number` | yes | - | The code of the error. See the [error codes](errors#summary) for more information. |
| message | `string` | yes | - | A human-readable error message that can be displayed to a user. |
| providerId | `string` | no | - | The ID of the provider that threw the error. |
| Name | Type | Required | Default | Description |
|------------|----------|----------|---------|------------------------------------------------------------------------------------|
| code | `number` | yes | - | The code of the error. See the [error codes](errors#summary) for more information. |
| message | `string` | yes | - | A human-readable error message that can be displayed to a user. |
| providerId | `string` | no | - | The ID of the provider that threw the error. |

:::note

This is the basic type for an error. For specific details on errors check out the [errors](errors).

:::

### `IAccount`

| Name | Type | Required | Default | Description |
|--------|----------|----------|---------|-----------------------------------------|
| addess | `string` | yes | - | The address of the account. |
| name | `string` | no | - | A human-readable name for this account. |

### `IDiscoverParams`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| providerId | `string` | yes | - | The ID of the provider. |
| Name | Type | Required | Default | Description |
|------------|----------|----------|---------|-------------------------|
| providerId | `string` | yes | - | The ID of the provider. |

### `IDiscoverResult`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| host | `string` | no | - | The domain name of the provider. |
| icon | `string` | no | - | A URI pointing to an image. |
| name | `string` | yes | - | A human-readable canonical name of the provider. |
| networks | [`INetworkConfiguration[]`](#inetworkconfiguration) | yes | - | A list of networks available for the provider. |
| providerId | `string` | yes | - | The ID of the provider. |
| Name | Type | Required | Default | Description |
|------------|-----------------------------------------------------|----------|---------|--------------------------------------------------|
| host | `string` | no | - | The domain name of the provider. |
| icon | `string` | no | - | A URI pointing to an image. |
| name | `string` | yes | - | A human-readable canonical name of the provider. |
| networks | [`INetworkConfiguration[]`](#inetworkconfiguration) | yes | - | A list of networks available for the provider. |
| providerId | `string` | yes | - | The ID of the provider. |

### `IEnableParams`

| Name | Type | Required | Default | Description |
|-------------|----------|----------|---------|------------------------------------------------------------------------------|
| genesisHash | `string` | no | - | The unique identifier for the network that is the hash of the genesis block. |
| providerId | `string` | no | - | The ID of the provider. |

### `IEnableResult`

| Name | Type | Required | Default | Description |
|-------------|---------------------------|----------|---------|------------------------------------------------------------------------------|
| accounts | [`IAccount[]`](#iaccount) | yes | - | A list of accounts authorized accounts on the provider. |
| genesisHash | `string` | yes | - | The unique identifier for the network that is the hash of the genesis block. |
| genesisId | `string` | yes | - | A human-readable identifier for the network. |
| providerId | `string` | yes | - | The ID of the provider. |

### `INetworkConfiguration`

| Name | Type | Required | Default | Description |
|------------|-----------|----------|---------|--------------------------------------------------------------|
| genesisHash | `string` | yes | - | The unique identifier for the network that is the hash of the genesis block. |
| genesisId | `string` | yes | - | A human-readable identifier for the network. |
| methods | `string[]` | yes | - | A list of methods available from the provider for the chain. |
| Name | Type | Required | Default | Description |
|-------------|------------|----------|---------|------------------------------------------------------------------------------|
| genesisHash | `string` | yes | - | The unique identifier for the network that is the hash of the genesis block. |
| genesisId | `string` | yes | - | A human-readable identifier for the network. |
| methods | `string[]` | yes | - | A list of methods available from the provider for the chain. |
Loading