From ef51f887ca8bc6bfb4d5743b41326f9bf9c9186b Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 11 Apr 2024 12:04:46 +0100 Subject: [PATCH 1/3] feat: expose full message details to listeners --- src/controllers/AVMWebClient.test.ts | 95 ++++++++++++++++----- src/controllers/AVMWebClient.ts | 36 ++++++-- src/controllers/AVMWebProvider.test.ts | 52 +++++++---- src/controllers/AVMWebProvider.ts | 6 +- src/types/IAVMWebClientListenerOptions.ts | 18 ++++ src/types/IAVMWebProviderListenerOptions.ts | 13 +++ src/types/TAVMWebClientListener.ts | 7 +- src/types/TAVMWebProviderListener.ts | 5 +- src/types/index.ts | 2 + 9 files changed, 178 insertions(+), 56 deletions(-) create mode 100644 src/types/IAVMWebClientListenerOptions.ts create mode 100644 src/types/IAVMWebProviderListenerOptions.ts diff --git a/src/controllers/AVMWebClient.test.ts b/src/controllers/AVMWebClient.test.ts index 871e74e..3e67d20 100644 --- a/src/controllers/AVMWebClient.test.ts +++ b/src/controllers/AVMWebClient.test.ts @@ -79,10 +79,11 @@ describe(AVMWebClient.name, () => { client = AVMWebClient.init(); provider.onDisable(async () => await Promise.reject(expectedError)); - client.onDisable((result, error) => { + client.onDisable(({ error, method, result }) => { // assert - expect(result).toBeNull(); + expect(method).toEqual(ARC0027MethodEnum.Disable); expect(error).toEqual(expectedError); + expect(result).toBeNull(); done(); }); @@ -105,14 +106,21 @@ describe(AVMWebClient.name, () => { providerId, sessionIds, }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onDisable(() => expectedResult); - client.onDisable((result, error) => { + provider.onDisable(({ id }) => { + actualRequestId = id; + + return expectedResult; + }); + client.onDisable(({ error, method, result, requestId }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.Disable); expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); expect(result).toBeDefined(); expect(result).toEqual(expectedResult); @@ -149,14 +157,21 @@ describe(AVMWebClient.name, () => { ], providerId, }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onDiscover(() => expectedResult); - client.onDiscover((result, error) => { + provider.onDiscover(({ id }) => { + actualRequestId = id; + + return expectedResult; + }); + client.onDiscover(({ error, method, result, requestId }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.Discover); expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); expect(result).toBeDefined(); expect(result).toEqual(expectedResult); @@ -181,8 +196,9 @@ describe(AVMWebClient.name, () => { client = AVMWebClient.init(); provider.onEnable(async () => await Promise.reject(expectedError)); - client.onEnable((result, error) => { + client.onEnable(({ error, method, result }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.Enable); expect(result).toBeNull(); expect(error).toEqual(expectedError); @@ -212,14 +228,21 @@ describe(AVMWebClient.name, () => { genesisId: 'jest-test-v1.0', providerId, }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onEnable(() => expectedResult); - client.onEnable((result, error) => { + provider.onEnable(({ id }) => { + actualRequestId = id; + + return expectedResult; + }); + client.onEnable(({ error, method, result, requestId }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.Enable); expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); expect(result).toBeDefined(); expect(result).toEqual(expectedResult); @@ -246,8 +269,9 @@ describe(AVMWebClient.name, () => { provider.onPostTransactions( async () => await Promise.reject(expectedError) ); - client.onPostTransactions((result, error) => { + client.onPostTransactions(({ error, method, result }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.PostTransactions); expect(result).toBeNull(); expect(error).toEqual(expectedError); @@ -267,14 +291,21 @@ describe(AVMWebClient.name, () => { providerId, txnIDs: ['OKU6A2Q...'], }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onPostTransactions(() => expectedResult); - client.onPostTransactions((result, error) => { + provider.onPostTransactions(({ id }) => { + actualRequestId = id; + + return expectedResult; + }); + client.onPostTransactions(({ error, method, result, requestId }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.PostTransactions); expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); expect(result).toBeDefined(); expect(result).toEqual(expectedResult); @@ -304,8 +335,9 @@ describe(AVMWebClient.name, () => { provider.onSignAndPostTransactions( async () => await Promise.reject(expectedError) ); - client.onSignAndPostTransactions((result, error) => { + client.onSignAndPostTransactions(({ error, method, result }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.SignAndPostTransactions); expect(result).toBeNull(); expect(error).toEqual(expectedError); @@ -333,19 +365,28 @@ describe(AVMWebClient.name, () => { providerId, txnIDs: ['OKU6A2Q...'], }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onSignAndPostTransactions(() => expectedResult); - client.onSignAndPostTransactions((result, error) => { - // assert - expect(error).toBeNull(); - expect(result).toBeDefined(); - expect(result).toEqual(expectedResult); + provider.onSignAndPostTransactions(({ id }) => { + actualRequestId = id; - done(); + return expectedResult; }); + client.onSignAndPostTransactions( + ({ error, method, result, requestId }) => { + // assert + expect(method).toEqual(ARC0027MethodEnum.SignAndPostTransactions); + expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); + expect(result).toBeDefined(); + expect(result).toEqual(expectedResult); + + done(); + } + ); // act client.signAndPostTransactions({ @@ -378,8 +419,9 @@ describe(AVMWebClient.name, () => { provider.onSignTransactions( async () => await Promise.reject(expectedError) ); - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, method, result }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.SignTransactions); expect(result).toBeNull(); expect(error).toEqual(expectedError); @@ -407,14 +449,21 @@ describe(AVMWebClient.name, () => { providerId, stxns: ['gqNzaWfEQ...', null], }; + let actualRequestId: string; provider = AVMWebProvider.init(providerId); client = AVMWebClient.init(); - provider.onSignTransactions(() => expectedResult); - client.onSignTransactions((result, error) => { + provider.onSignTransactions(({ id }) => { + actualRequestId = id; + + return expectedResult; + }); + client.onSignTransactions(({ error, method, result, requestId }) => { // assert + expect(method).toEqual(ARC0027MethodEnum.SignTransactions); expect(error).toBeNull(); + expect(requestId).toBe(actualRequestId); expect(result).toBeDefined(); expect(result).toEqual(expectedResult); diff --git a/src/controllers/AVMWebClient.ts b/src/controllers/AVMWebClient.ts index 475e19f..458a74e 100644 --- a/src/controllers/AVMWebClient.ts +++ b/src/controllers/AVMWebClient.ts @@ -112,27 +112,47 @@ export default class AVMWebClient extends BaseController { const _functionName: string = 'onMessage'; const listener: TAVMWebClientListener | null = this.listeners.get(message.data.reference) || null; + let method: ARC0027MethodEnum | null = null; // ensure we have a listener for the response and the request id is known if (listener && this.requestIds.includes(message.data.requestId)) { switch (message.data.reference) { case `${createMessageReference(ARC0027MethodEnum.Disable, ARC0027MessageTypeEnum.Response)}`: + method = ARC0027MethodEnum.Disable; + break; case `${createMessageReference(ARC0027MethodEnum.Discover, ARC0027MessageTypeEnum.Response)}`: + method = ARC0027MethodEnum.Discover; + break; case `${createMessageReference(ARC0027MethodEnum.Enable, ARC0027MessageTypeEnum.Response)}`: + method = ARC0027MethodEnum.Enable; + break; case `${createMessageReference(ARC0027MethodEnum.PostTransactions, ARC0027MessageTypeEnum.Response)}`: + method = ARC0027MethodEnum.PostTransactions; + break; case `${createMessageReference(ARC0027MethodEnum.SignAndPostTransactions, ARC0027MessageTypeEnum.Response)}`: + method = ARC0027MethodEnum.SignAndPostTransactions; + break; case `${createMessageReference(ARC0027MethodEnum.SignTransactions, ARC0027MessageTypeEnum.Response)}`: - this.logger.debug( - `${AVMWebClient.name}#${_functionName}: received response message "${JSON.stringify(message.data)}"` - ); - - return listener( - (message.data as ResponseMessageWithResult).result || null, - (message.data as ResponseMessageWithError).error || null - ); + method = ARC0027MethodEnum.SignTransactions; + break; default: break; } + + // if we recognize the message, emit the listener + if (method) { + this.logger.debug( + `${AVMWebClient.name}#${_functionName}: received response message "${JSON.stringify(message.data)}"` + ); + + return listener({ + error: (message.data as ResponseMessageWithError).error || null, + id: message.data.id, + method, + requestId: message.data.requestId, + result: (message.data as ResponseMessageWithResult).result || null, + }); + } } } diff --git a/src/controllers/AVMWebProvider.test.ts b/src/controllers/AVMWebProvider.test.ts index 7c58877..5c338e4 100644 --- a/src/controllers/AVMWebProvider.test.ts +++ b/src/controllers/AVMWebProvider.test.ts @@ -4,13 +4,11 @@ import { randomBytes } from 'crypto'; import AVMWebClient from './AVMWebClient'; import AVMWebProvider from './AVMWebProvider'; +// enums +import { ARC0027MethodEnum } from '@app/enums'; + // types -import type { - IARC0001Transaction, - IAVMWebProviderConfig, - IPostTransactionsParams, - ISignTransactionsParams, -} from '@app/types'; +import type { IARC0001Transaction, IAVMWebProviderConfig } from '@app/types'; describe(AVMWebProvider.name, () => { const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; @@ -66,7 +64,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onDisable(done); + provider.onDisable(({ method }) => { + expect(method).toBe(ARC0027MethodEnum.Disable); + + return done(); + }); // act client.disable(); @@ -80,7 +82,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onDiscover(done); + provider.onDiscover(({ method }) => { + expect(method).toBe(ARC0027MethodEnum.Discover); + + return done(); + }); // act client.discover(); @@ -94,7 +100,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onEnable(done); + provider.onEnable(({ method }) => { + expect(method).toBe(ARC0027MethodEnum.Enable); + + return done(); + }); // act client.enable(); @@ -110,9 +120,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onPostTransactions((params: IPostTransactionsParams) => { - expect(params.providerId).toBe(providerId); - expect(params.stxns).toEqual(stxns); + provider.onPostTransactions(({ method, params }) => { + expect(method).toBe(ARC0027MethodEnum.PostTransactions); + expect(params).toBeDefined(); + expect(params?.providerId).toBe(providerId); + expect(params?.stxns).toEqual(stxns); return done(); }); @@ -142,9 +154,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onSignAndPostTransactions((params: ISignTransactionsParams) => { - expect(params.providerId).toBe(providerId); - expect(params.txns).toEqual(txns); + provider.onSignAndPostTransactions(({ method, params }) => { + expect(method).toBe(ARC0027MethodEnum.SignAndPostTransactions); + expect(params).toBeDefined(); + expect(params?.providerId).toBe(providerId); + expect(params?.txns).toEqual(txns); return done(); }); @@ -174,9 +188,11 @@ describe(AVMWebProvider.name, () => { client = AVMWebClient.init(); // assert - provider.onSignTransactions((params: ISignTransactionsParams) => { - expect(params.providerId).toBe(providerId); - expect(params.txns).toEqual(txns); + provider.onSignTransactions(({ method, params }) => { + expect(method).toBe(ARC0027MethodEnum.SignTransactions); + expect(params).toBeDefined(); + expect(params?.providerId).toBe(providerId); + expect(params?.txns).toEqual(txns); return done(); }); diff --git a/src/controllers/AVMWebProvider.ts b/src/controllers/AVMWebProvider.ts index a0061ab..9774987 100644 --- a/src/controllers/AVMWebProvider.ts +++ b/src/controllers/AVMWebProvider.ts @@ -77,7 +77,11 @@ export default class AVMWebProvider extends BaseController { + error: BaseARC0027Error | null; + id: string; + method: ARC0027MethodEnum; + result: Result | null; + requestId: string; +} + +export default IAVMWebClientListenerOptions; diff --git a/src/types/IAVMWebProviderListenerOptions.ts b/src/types/IAVMWebProviderListenerOptions.ts new file mode 100644 index 0000000..e4acbc6 --- /dev/null +++ b/src/types/IAVMWebProviderListenerOptions.ts @@ -0,0 +1,13 @@ +// enums +import { ARC0027MethodEnum } from '@app/enums'; + +// types +import type TRequestParams from './TRequestParams'; + +interface IAVMWebProviderListenerOptions { + id: string; + method: ARC0027MethodEnum; + params?: Params; +} + +export default IAVMWebProviderListenerOptions; diff --git a/src/types/TAVMWebClientListener.ts b/src/types/TAVMWebClientListener.ts index 0a6d529..9d538e9 100644 --- a/src/types/TAVMWebClientListener.ts +++ b/src/types/TAVMWebClientListener.ts @@ -1,12 +1,9 @@ -// errors -import { BaseARC0027Error } from '@app/errors'; - // types +import type IAVMWebClientListenerOptions from './IAVMWebClientListenerOptions'; import type TResponseResults from './TResponseResults'; type TAVMWebClientListener = ( - result: Result | null, - error: BaseARC0027Error | null + options: IAVMWebClientListenerOptions ) => void | Promise; export default TAVMWebClientListener; diff --git a/src/types/TAVMWebProviderListener.ts b/src/types/TAVMWebProviderListener.ts index 247162f..9d71a4c 100644 --- a/src/types/TAVMWebProviderListener.ts +++ b/src/types/TAVMWebProviderListener.ts @@ -1,10 +1,13 @@ // types +import type IAVMWebProviderListenerOptions from './IAVMWebProviderListenerOptions'; import type TRequestParams from './TRequestParams'; import type TResponseResults from './TResponseResults'; type TAVMWebProviderListener< Params = TRequestParams, Result = TResponseResults, -> = (params?: Params) => Result | Promise; +> = ( + options: IAVMWebProviderListenerOptions +) => Result | Promise; export default TAVMWebProviderListener; diff --git a/src/types/index.ts b/src/types/index.ts index 7d6b0b3..5c611d8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,8 +2,10 @@ export type { default as IAccount } from './IAccount'; export type { default as IARC0001Transaction } from './IARC0001Transaction'; export type { default as IAVMWebClientConfig } from './IAVMWebClientConfig'; export type { default as IAVMWebClientInitOptions } from './IAVMWebClientInitOptions'; +export type { default as IAVMWebClientListenerOptions } from './IAVMWebClientListenerOptions'; export type { default as IAVMWebProviderConfig } from './IAVMWebProviderConfig'; export type { default as IAVMWebProviderInitOptions } from './IAVMWebProviderInitOptions'; +export type { default as IAVMWebProviderListenerOptions } from './IAVMWebProviderListenerOptions'; export type { default as IBaseConfig } from './IBaseConfig'; export type { default as IBaseResponseMessage } from './IBaseResponseMessage'; export type { default as IDisableParams } from './IDisableParams'; From 6f96e838fc0ff9b87d981d90b7ac408085c1c462 Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 11 Apr 2024 12:05:30 +0100 Subject: [PATCH 2/3] feat: expose error entities --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index f6bec64..c2eeacd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export * from './constants'; export * from './controllers'; export * from './enums'; +export * from './errors'; export * from './messages'; export * from './types'; export * from './utils'; From 8f0274c4c5452dbf1cff4d7665e41b96cf768ccd Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 11 Apr 2024 12:54:30 +0100 Subject: [PATCH 3/3] docs: update docs to reflect new listners --- docs/api-reference/avm-web-client.mdx | 36 ++++++++-------- docs/api-reference/avm-web-provider.mdx | 36 ++++++++-------- docs/api-reference/types.mdx | 17 ++++++++ docs/clients/disabling-a-client.mdx | 18 ++++---- docs/clients/discover-providers.mdx | 12 +++--- docs/clients/enabling-a-client.mdx | 18 ++++---- docs/clients/posting-transactions.mdx | 6 +-- .../signing-and-posting-transactions.mdx | 6 +-- docs/clients/signing-transactions.mdx | 42 +++++++++---------- .../responding-to-disable-requests.mdx | 18 ++++---- .../responding-to-discover-requests.mdx | 12 +++--- .../responding-to-enable-requests.mdx | 12 +++--- ...sponding-to-post-transactions-requests.mdx | 6 +-- ...to-sign-and-post-transactions-requests.mdx | 6 +-- ...sponding-to-sign-transactions-requests.mdx | 6 +-- docusaurus.config.js | 20 ++++++--- 16 files changed, 148 insertions(+), 123 deletions(-) diff --git a/docs/api-reference/avm-web-client.mdx b/docs/api-reference/avm-web-client.mdx index 22c09a0..eef0f54 100644 --- a/docs/api-reference/avm-web-client.mdx +++ b/docs/api-reference/avm-web-client.mdx @@ -92,9 +92,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`IDisableResult`](types#idisableresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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. | ### `onDiscover(listener)` @@ -103,9 +103,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`IDiscoverResult`](types#idiscoverresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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 @@ -119,9 +119,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`IEnableResult`](types#ienableresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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 @@ -135,9 +135,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`IPostTransactionsResult`](types#iposttransactionsresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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 @@ -151,9 +151,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`IPostTransactionsResult`](types#iposttransactionsresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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. | ### `onSignTransactions(listener)` @@ -161,9 +161,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| listener | (`result`?: [`ISignTransactionsResult`](types#isigntransactionsresult) \| `null`, `error`?: [`IBaseError`](types#ibaseerror) \| `null`) => (`void` \| `Promise`) \| `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. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebClientListenerOptions`](types#iavmwebclientlisteneroptions)) => (`void` \| `Promise`) \| `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 diff --git a/docs/api-reference/avm-web-provider.mdx b/docs/api-reference/avm-web-provider.mdx index 2fe4d31..31b0ad4 100644 --- a/docs/api-reference/avm-web-provider.mdx +++ b/docs/api-reference/avm-web-provider.mdx @@ -44,9 +44,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`IDisableParams`](types#idisableparams)) => ([`IDisableResult`](types#idisableresult) \| [`Promise`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IDisableResult`](types#idisableresult) \| [`Promise`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns @@ -60,9 +60,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`IDiscoverParams`](types#idiscoverparams)) => ([`IDiscoverResult`](types#idiscoverresult) \| [`Promise`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IDiscoverResult`](types#idiscoverresult) \| [`Promise`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns @@ -76,9 +76,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`IEnableParams`](types#ienableparams)) => ([`IEnableResult`](types#ienableresult) \| [`Promise`](types#ienableresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IEnableResult`](types#ienableresult) \| [`Promise`](types#ienableresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns @@ -92,9 +92,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`IPostTransactionsParams`](types#iposttransactionsparams)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns @@ -108,9 +108,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`ISignTransactionsParams`](types#isigntransactionsparams)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns @@ -124,9 +124,9 @@ import TOCInline from '@theme/TOCInline'; #### Parameters -| Name | Type | Required | Default | Description | -|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| -| listener | (`params`?: [`ISignTransactionsParams`](types#isigntransactionsparams)) => ([`ISignTransactionsResult`](types#isigntransactionsresult) \| [`Promise`](types#isigntransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | +| Name | Type | Required | Default | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------| +| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`ISignTransactionsResult`](types#isigntransactionsresult) \| [`Promise`](types#isigntransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. | #### Returns diff --git a/docs/api-reference/types.mdx b/docs/api-reference/types.mdx index 4f0c512..2b4e910 100644 --- a/docs/api-reference/types.mdx +++ b/docs/api-reference/types.mdx @@ -29,6 +29,15 @@ import TOCInline from '@theme/TOCInline'; |-------|-----------|----------|---------|-------------------------------------------| | debug | `boolean` | no | `false` | Outputs debug information to the console. | +### `IAVMWebClientListenerOptions` + +| Name | Type | Required | Default | Description | +|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------| +| error | [`IBaseError`](#ibaseerror) \| `null` | yes | - | If an error occured (defined as one of the [errors](errors)), this will be defined. If a request was successful, this will be `null`. | +| id | `string` | yes | - | A unique identifier for the response message. | +| method | `disable` \| `discover` \| `enable` \| `post_transactions` \| `sign_and_post_transactions` \| `sign_transactions` | yes | - | An enum that represents the method of the message. | +| result | [`IDisableResult`](#idisableresult) \| [`IDiscoverResult`](#idiscoverresult) \| [`IEnableResult`](#ienableresult) \| [`IPostTransactionsResult`](#iposttransactionsresult) \| [`ISignTransactionsResult`](#isigntransactionsresult) \| `null` | yes | - | If a request was successful, this will contain the details of the result, otherwise, if an error occurred, this will be `null`. | + ### `IAVMWebProviderConfig` | Name | Type | Required | Default | Description | @@ -42,6 +51,14 @@ import TOCInline from '@theme/TOCInline'; |-------|-----------|----------|---------|-------------------------------------------| | debug | `boolean` | no | `false` | Outputs debug information to the console. | +### `IAVMWebProviderListenerOptions` + +| Name | Type | Required | Default | Description | +|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------| +| id | `string` | yes | - | A unique identifier for the request message. | +| method | `disable` \| `discover` \| `enable` \| `post_transactions` \| `sign_and_post_transactions` \| `sign_transactions` | yes | - | An enum that represents the method of the message. | +| params | [`IDisableParams`](#idisableparams) \| [`IDiscoverParams`](#idiscoverparams) \| [`IEnableParams`](#ienableparams) \| [`IPostTransactionsParams`](#iposttransactionsparams) \| [`ISignTransactionsParams`](#isigntransactionsparams) | no | - | Parameters that were sent by the request. | + ### `IBaseError` | Name | Type | Required | Default | Description | diff --git a/docs/clients/disabling-a-client.mdx b/docs/clients/disabling-a-client.mdx index 76e9f93..8a312af 100644 --- a/docs/clients/disabling-a-client.mdx +++ b/docs/clients/disabling-a-client.mdx @@ -29,7 +29,7 @@ Assuming a client has been [enabled](enabling-a-client) with one or all provider ```js // initialized client -client.onDisable((result, error) => { +client.onDisable(({ error, result }) => { if (error) { console.error('error:', error); @@ -54,10 +54,10 @@ client.disable(); ```typescript -import { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized client -client.onDisable((result: IDisableResult: null, error: BaseARC0027Error | null) => { +client.onDisable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -101,7 +101,7 @@ If you want to target a specific provider and network, you can simply pass the I ```js // initialized client -client.onDisable((result, error) => { +client.onDisable(({ error, result }) => { if (error) { console.error('error:', error); @@ -128,12 +128,12 @@ client.disable({ ```typescript -import { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized client -client.onEnable((result: IDisableResult: null, error: BaseARC0027Error | null) => { +client.onEnable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -180,7 +180,7 @@ If you want to remove a specific session, you can provide the session ID(s) in t ```js // initialized client -client.onDisable((result, error) => { +client.onDisable(({ error, result }) => { if (error) { console.error('error:', error); @@ -208,10 +208,10 @@ client.disable({ ```typescript -import { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized client -client.onEnable((result: IDisableResult: null, error: BaseARC0027Error | null) => { +client.onEnable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/clients/discover-providers.mdx b/docs/clients/discover-providers.mdx index 39b1f04..3781f1b 100644 --- a/docs/clients/discover-providers.mdx +++ b/docs/clients/discover-providers.mdx @@ -27,7 +27,7 @@ The first thing we want to do, after [initialization](getting-started), is start ```js // initialized client -client.onDiscover((result, error) => { +client.onDiscover(({ error, result }) => { if (error) { console.error('error:', error); @@ -76,10 +76,10 @@ client.discover(); ```typescript -import { BaseARC0027Error, IDiscoverResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized client -client.onDiscover((result: IDiscoverResult: null, error: BaseARC0027Error | null) => { +client.onDiscover(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -145,7 +145,7 @@ As before, let's first add a listener and then broadcast, but this time we will const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized client -client.onDiscover((result, error) => { +client.onDiscover(({ error, result }) => { if (error) { console.error('error:', error); @@ -194,12 +194,12 @@ client.discover({ providerId }); ```typescript -import { BaseARC0027Error, IDiscoverResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized client -client.onDiscover((result: IDiscoverResult: null, error: BaseARC0027Error | null) => { +client.onDiscover(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/clients/enabling-a-client.mdx b/docs/clients/enabling-a-client.mdx index 9a7928d..c0f5600 100644 --- a/docs/clients/enabling-a-client.mdx +++ b/docs/clients/enabling-a-client.mdx @@ -42,7 +42,7 @@ After [initialization](getting-started), you can simply call: ```js // initialized client -client.onEnable((result, error) => { +client.onEnable(({ error, result }) => { if (error) { console.error('error:', error); @@ -78,10 +78,10 @@ client.enable(); ```typescript -import { BaseARC0027Error, IEnableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized client -client.onEnable((result: IEnableResult: null, error: BaseARC0027Error | null) => { +client.onEnable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -138,7 +138,7 @@ If you want to target a specific provider, you can simply pass the ID of the pro const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized client -client.onEnable((result, error) => { +client.onEnable(({ error, result }) => { if (error) { console.error('error:', error); @@ -174,12 +174,12 @@ client.enable({ providerId }); ```typescript -import { BaseARC0027Error, IEnableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized client -client.onEnable((result: IEnableResult: null, error: BaseARC0027Error | null) => { +client.onEnable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -230,7 +230,7 @@ If you want to target a specific network, and any providers support it, you can const genesisHash = 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI='; // initialized client -client.onEnable((result, error) => { +client.onEnable(({ error, result }) => { if (error) { console.error('error:', error); @@ -266,12 +266,12 @@ client.enable({ genesisHash }); ```typescript -import { BaseARC0027Error, IEnableResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; const genesisHash: string = 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI='; // initialized client -client.onEnable((result: IEnableResult: null, error: BaseARC0027Error | null) => { +client.onEnable(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/clients/posting-transactions.mdx b/docs/clients/posting-transactions.mdx index 0688724..fa6083d 100644 --- a/docs/clients/posting-transactions.mdx +++ b/docs/clients/posting-transactions.mdx @@ -31,7 +31,7 @@ Posting transactions requires the ID of the provider. ```js // initialized client -client.onPostTransactions((result, error) => { +client.onPostTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -62,10 +62,10 @@ client.postTransactions({ ```typescript -import { BaseARC0027Error, IPostTransactionsResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized client -client.onPostTransactions((result: IPostTransactionsResult: null, error: BaseARC0027Error | null) => { +client.onPostTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/clients/signing-and-posting-transactions.mdx b/docs/clients/signing-and-posting-transactions.mdx index e9d196e..cbe83ae 100644 --- a/docs/clients/signing-and-posting-transactions.mdx +++ b/docs/clients/signing-and-posting-transactions.mdx @@ -54,7 +54,7 @@ try { } // initialized client -client.onSignAndPostTransactions((result, error) => { +client.onSignAndPostTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -94,7 +94,7 @@ import { SuggestedParams, Transaction, } from 'algosdk'; -import { BaseARC0027Error, IPostTransactionsResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -118,7 +118,7 @@ try { } // initialized client -client.onSignAndPostTransactions((result: IPostTransactionsResult: null, error: BaseARC0027Error | null) => { +client.onSignAndPostTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/clients/signing-transactions.mdx b/docs/clients/signing-transactions.mdx index 3335fcf..3f4938a 100644 --- a/docs/clients/signing-transactions.mdx +++ b/docs/clients/signing-transactions.mdx @@ -49,7 +49,7 @@ try { } // initialized client -client.onSignTransactions((result, error) => { +client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -89,7 +89,7 @@ import { SuggestedParams, Transaction, } from 'algosdk'; -import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; +import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -113,7 +113,7 @@ try { } // initialized client -client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { +client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -201,7 +201,7 @@ When sending atomic transactions, all transactions, regardless of whether the wa } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -246,7 +246,7 @@ When sending atomic transactions, all transactions, regardless of whether the wa SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -284,7 +284,7 @@ When sending atomic transactions, all transactions, regardless of whether the wa } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -372,7 +372,7 @@ For example: } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -417,7 +417,7 @@ For example: SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -449,7 +449,7 @@ For example: } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -528,7 +528,7 @@ As you can see from the above example, when the provider skips signing the trans } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -574,7 +574,7 @@ As you can see from the above example, when the provider skips signing the trans SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -606,7 +606,7 @@ As you can see from the above example, when the provider skips signing the trans } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -698,7 +698,7 @@ The provider may not support multisig accounts, in which case a [`MethodNotSuppo } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -741,7 +741,7 @@ The provider may not support multisig accounts, in which case a [`MethodNotSuppo SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -775,7 +775,7 @@ The provider may not support multisig accounts, in which case a [`MethodNotSuppo } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -854,7 +854,7 @@ If you want to only use one address, you can use the `signers` list to instruct } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -900,7 +900,7 @@ If you want to only use one address, you can use the `signers` list to instruct SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -934,7 +934,7 @@ If you want to only use one address, you can use the `signers` list to instruct } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); @@ -1020,7 +1020,7 @@ The provider may not support re-keyed accounts, in which case a [`MethodNotSuppo } // initialized client - client.onSignTransactions((result, error) => { + client.onSignTransactions(({ error, result }) => { if (error) { console.error('error:', error); @@ -1061,7 +1061,7 @@ The provider may not support re-keyed accounts, in which case a [`MethodNotSuppo SuggestedParams, Transaction, } from 'algosdk'; - import { BaseARC0027Error, ISignTransactionsResult } from '@agoralabs-sh/avm-web-provider'; + import { IAVMWebClientListenerOptions } from '@agoralabs-sh/avm-web-provider'; // create a transaction try { @@ -1085,7 +1085,7 @@ The provider may not support re-keyed accounts, in which case a [`MethodNotSuppo } // initialized client - client.onSignTransactions((result: ISignTransactionsResult: null, error: BaseARC0027Error | null) => { + client.onSignTransactions(({ error, result }: IAVMWebClientListenerOptions) => { if (error) { console.error('error:', error); diff --git a/docs/providers/responding-to-disable-requests.mdx b/docs/providers/responding-to-disable-requests.mdx index dfd2b73..b382cca 100644 --- a/docs/providers/responding-to-disable-requests.mdx +++ b/docs/providers/responding-to-disable-requests.mdx @@ -27,7 +27,7 @@ For clients that have not specified a provider, it means the client would like t ```js // initialized provider -provider.onDisable((params) => { +provider.onDisable(({ params }) => { if (!params || !params.providerId) { // ... remove all sessions @@ -44,10 +44,10 @@ provider.onDisable((params) => { ```typescript -import type { IDisableParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized provider -provider.onEnable((params?: IDisableParams) => { +provider.onEnable(({ params }: IAVMWebProviderListenerOptions) => { if (!params || !params.providerId) { // ... remove all sessions @@ -94,7 +94,7 @@ const genesisHash = 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI='; const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onDisable((params) => { +provider.onDisable(({ params }) => { if (!params || params.providerId === providerId) { // if the genesis hash has been defined, it is recommended that you throw and error if (param.genesisHash && param.genesisHash !== genesisHash) { @@ -119,13 +119,13 @@ provider.onDisable((params) => { ```typescript -import type { ARC0027NetworkNotSupportedError, IDisableParams } from '@agoralabs-sh/avm-web-provider'; +import type { ARC0027NetworkNotSupportedError, IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const genesisHash = 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI='; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onDisable((params?: IDisableParams) => { +provider.onDisable(({ params }: IAVMWebProviderListenerOptions) => { if (!params || params.providerId === providerId) { // if the genesis hash has been defined, it is recommended that you throw and error if (param.genesisHash && param.genesisHash !== genesisHash) { @@ -172,7 +172,7 @@ const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; const sessionId = '2802dff6-930e-4f79-8f67-ba9d41e88cf8'; // initialized provider -provider.onDisable((params) => { +provider.onDisable(({ params }) => { if (params && params.sessionIds.indexOf(sessionId) >= 0) { // ... remove sessions specified in the session ids list @@ -190,13 +190,13 @@ provider.onDisable((params) => { ```typescript -import type { IDisableParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; const sessionId: string = '2802dff6-930e-4f79-8f67-ba9d41e88cf8'; // initialized provider -provider.onDisable((params?: IDisableParams) => { +provider.onDisable(({ params }: IAVMWebProviderListenerOptions) => { if (params && params.sessionIds.includes(sessionId)) { // ... remove sessions specified in the session ids list diff --git a/docs/providers/responding-to-discover-requests.mdx b/docs/providers/responding-to-discover-requests.mdx index 89d2a9d..59f9b64 100644 --- a/docs/providers/responding-to-discover-requests.mdx +++ b/docs/providers/responding-to-discover-requests.mdx @@ -27,7 +27,7 @@ For clients that have not specified a provider, it means the client would like t ```js // initialized provider - provider.onDiscover((params) => { + provider.onDiscover(({ params }) => { if (!params || !params.providerId) { return { host: 'https://awesome-wallet.com', @@ -66,10 +66,10 @@ For clients that have not specified a provider, it means the client would like t ```typescript - import type { IDiscoverParams } from '@agoralabs-sh/avm-web-provider'; + import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized provider - provider.onDiscover((params?: IDiscoverParams) => { + provider.onDiscover(({ params }: IAVMWebProviderListenerOptions) => { if (!params?.providerId) { return { host: 'https://awesome-wallet.com', @@ -123,7 +123,7 @@ The `discover` request allow the client to specify the provider. This is denoted const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider - provider.onDiscover((params) => { + provider.onDiscover(({ params }) => { if (!params || params.providerId === providerId) { return { host: 'https://awesome-wallet.com', @@ -162,12 +162,12 @@ The `discover` request allow the client to specify the provider. This is denoted ```typescript - import type { IDiscoverParams } from '@agoralabs-sh/avm-web-provider'; + import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider - provider.onDiscover((params?: IDiscoverParams) => { + provider.onDiscover(({ params }: IAVMWebProviderListenerOptions) => { if (!params || params.providerId === providerId) { return { host: 'https://awesome-wallet.com', diff --git a/docs/providers/responding-to-enable-requests.mdx b/docs/providers/responding-to-enable-requests.mdx index b2a25b8..3d482d5 100644 --- a/docs/providers/responding-to-enable-requests.mdx +++ b/docs/providers/responding-to-enable-requests.mdx @@ -27,7 +27,7 @@ For clients that have not specified a provider, it means the client would like t ```js // initialized provider -provider.onEnable((params) => { +provider.onEnable(({ params }) => { if (!params || !params.providerId) { return { accounts: [ @@ -52,10 +52,10 @@ provider.onEnable((params) => { ```typescript -import type { IEnableParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; // initialized provider -provider.onEnable((params?: IEnableParams) => { +provider.onEnable(({ params }: IAVMWebProviderListenerOptions) => { if (!params || !params.providerId) { return { accounts: [ @@ -101,7 +101,7 @@ The `enable` request allows the client to specify the provider. This is denoted const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onEnable((params) => { +provider.onEnable(({ params }) => { if (!params || params.providerId === providerId) { return { accounts: [ @@ -126,12 +126,12 @@ provider.onEnable((params) => { ```typescript -import type { IEnableParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onEnable((params?: IEnableParams) => { +provider.onEnable(({ params }: IAVMWebProviderListenerOptions) => { if (!params || params.providerId === providerId) { return { accounts: [ diff --git a/docs/providers/responding-to-post-transactions-requests.mdx b/docs/providers/responding-to-post-transactions-requests.mdx index 08d8fa1..664bc76 100644 --- a/docs/providers/responding-to-post-transactions-requests.mdx +++ b/docs/providers/responding-to-post-transactions-requests.mdx @@ -29,7 +29,7 @@ Once our provider object has been initialized, we can simply listen to events an const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onPostTransactions((params) => { +provider.onPostTransactions(({ params }) => { if (params.providerId === providerId) { // ... using the `params.stxns` parameter, the provider posts the transactions to the network and returns the transaction ids @@ -47,12 +47,12 @@ provider.onPostTransactions((params) => { ```typescript -import type { IPostTransactionsParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onPostTransactions((params: IPostTransactionsParams) => { +provider.onPostTransactions(({ params }: IAVMWebProviderListenerOptions) => { if (params.providerId === providerId) { // ... using the `params.stxns` parameter, the provider posts the transactions to the network and returns the transaction ids diff --git a/docs/providers/responding-to-sign-and-post-transactions-requests.mdx b/docs/providers/responding-to-sign-and-post-transactions-requests.mdx index 906da26..aebf8ee 100644 --- a/docs/providers/responding-to-sign-and-post-transactions-requests.mdx +++ b/docs/providers/responding-to-sign-and-post-transactions-requests.mdx @@ -29,7 +29,7 @@ Once our provider object has been initialized, we can simply listen to events an const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onSignAndPostTransactions((params) => { +provider.onSignAndPostTransactions(({ params }) => { if (params.providerId === providerId) { // ... using the `params.txns` parameter, the provider signs and posts the transactions to the network and returns the transaction ids @@ -47,12 +47,12 @@ provider.onSignAndPostTransactions((params) => { ```typescript -import type { ISignTransactionsParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onSignAndPostTransactions((params: ISignTransactionsParams) => { +provider.onSignAndPostTransactions(({ params }: IAVMWebProviderListenerOptions) => { if (params.providerId === providerId) { // ... using the `params.txns` parameter, the provider signs and posts the transactions to the network and returns the transaction ids diff --git a/docs/providers/responding-to-sign-transactions-requests.mdx b/docs/providers/responding-to-sign-transactions-requests.mdx index 411364d..e269aa8 100644 --- a/docs/providers/responding-to-sign-transactions-requests.mdx +++ b/docs/providers/responding-to-sign-transactions-requests.mdx @@ -25,7 +25,7 @@ Once our provider object has been initialized, we can simply listen to events an const providerId = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onSignTransactions((params) => { +provider.onSignTransactions(({ params }) => { if (params.providerId === providerId) { // ... using the `params.txns` parameter, the provider signs the transactions and returns the base64 encoded signed transactions @@ -43,12 +43,12 @@ provider.onSignTransactions((params) => { ```typescript -import type { ISignTransactionsParams } from '@agoralabs-sh/avm-web-provider'; +import type { IAVMWebProviderListenerOptions } from '@agoralabs-sh/avm-web-provider'; const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; // initialized provider -provider.onSignTransactions((params: ISignTransactionsParams) => { +provider.onSignTransactions(({ params }: IAVMWebProviderListenerOptions) => { if (params.providerId === providerId) { // ... using the `params.txns` parameter, the provider signs the transactions and returns the base64 encoded signed transactions diff --git a/docusaurus.config.js b/docusaurus.config.js index dfe080e..7d276b1 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -81,7 +81,7 @@ const config = { metadata: [ { name: 'keywords', - content: 'algorand, algosdk, arc0027, avm, blockchain', + content: 'algorand, algosdk, arc0027, avm, blockchain voi', }, ], navbar: { @@ -130,16 +130,24 @@ const config = { items: [ { label: 'Overview', - to: 'overview', - }, - { - label: 'API Reference', - to: 'api-reference/index', + to: '/', }, { label: 'Terminology', to: 'terminology', }, + { + label: 'Clients', + to: 'clients/index', + }, + { + label: 'Providers', + to: 'providers/index', + }, + { + label: 'API Reference', + to: 'api-reference/index', + }, ], }, {