Skip to content

Commit

Permalink
Update TopLevelApi documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Feb 28, 2019
1 parent 486f89f commit 2661502
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/request/TopLevelApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
* A common parent class for pop-up requests.
*
* Usage:
* Inherit this class in your popup request API class:
* Inherit this class in your popup request API class and define two properties:
* ```
* class SignTransactionApi extends TopLevelApi {
* async parseRequest(request) {
* // This method receives the raw internal request and is expected to
* // return a parsed request of the same type, using the parsing methods
* // inherited from the RequestParser class.
* // Throwing an InvalidRequestError means parsing has failed.
* }
*
* // Define the onRequest method to receive the client's request object:
* onRequest(request) {
* // do something...
*
* // When done, call this.resolve() with the result object
* this.resolve(result);
* get Handler() {
* // Should return the class that should be instantiated as the request's handler
* }
*
* // Or this.reject() with an error
* this.reject(error);
* async onBeforeRun(parsedRequest) {
* // This optional method receives the parsed request just before the
* // global close button text is set and the handler is run.
* // The return value is not used.
* }
* }
*
Expand Down Expand Up @@ -104,7 +109,7 @@ class TopLevelApi extends RequestParser { // eslint-disable-line no-unused-vars

const parsedRequest = await this.parseRequest(request);

return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
this._resolve = resolve;
this._reject = reject;

Expand Down Expand Up @@ -144,7 +149,7 @@ class TopLevelApi extends RequestParser { // eslint-disable-line no-unused-vars
try {
const handler = new this.Handler(parsedRequest, this.resolve.bind(this), reject);

this.onBeforeRun(parsedRequest);
await this.onBeforeRun(parsedRequest);

this.setGlobalCloseButtonText(`${I18n.translatePhrase('back-to')} ${parsedRequest.appName}`);

Expand Down

0 comments on commit 2661502

Please sign in to comment.