UNPKG

@steeveproject/ngx-steem-keychain

Version:
226 lines 6.11 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { SteemKeychainError } from './errors/steem-keychain-error'; import * as i0 from "@angular/core"; export class SteemKeychainService { /** * @param {?} ngZone */ constructor(ngZone) { this.ngZone = ngZone; } /** * @return {?} */ get steemKeychainAvailable() { return ((/** @type {?} */ (window))).steem_keychain !== undefined; } /** * @return {?} */ requestHandshake() { return this.call('requestHandshake', []); } /** * @param {?} account * @param {?} encryptedMessage * @param {?} keyType * @return {?} */ requestVerifyKey(account, encryptedMessage, keyType) { return this.call('requestVerifyKey', [ account, encryptedMessage, keyType ]); } /** * @param {?} account * @param {?} message * @param {?} keyType * @return {?} */ requestSignBuffer(account, message, keyType) { return this.call('requestSignBuffer', [ account, message, keyType ]); } /** * @param {?} account * @param {?} operations * @param {?} keyType * @return {?} */ requestBroadcast(account, operations, keyType) { return this.call('requestBroadcast', [ account, operations.map(op => op.toArray()), keyType ]); } /** * @param {?} account * @param {?} method * @param {?} params * @param {?} keyType * @return {?} */ requestSignedCall(account, method, params, keyType) { return this.call('requestSignedCall', [ account, method, params, keyType ]); } /** * @param {?} parentAuthor * @param {?} parentPermlink * @param {?} author * @param {?} permlink * @param {?} title * @param {?} body * @param {?=} jsonMetadata * @param {?=} options * @return {?} */ requestPost(parentAuthor, parentPermlink, author, permlink, title, body, jsonMetadata = '', options = '') { return this.call('requestPost', [ author, title, body, parentPermlink, parentAuthor, jsonMetadata, permlink, options ]); } /** * @param {?} voter * @param {?} author * @param {?} permlink * @param {?} weight * @return {?} */ requestVote(voter, author, permlink, weight) { return this.call('requestVote', [ voter, permlink, author, weight ]); } /** * @param {?} account * @param {?} displayMessage * @param {?} id * @param {?} customJson * @param {?=} key * @return {?} */ requestCustomJson(account, displayMessage, id, customJson, key = 'Posting') { return this.call('requestCustomJson', [ account, id, ((/** @type {?} */ (key))).toLowerCase(), customJson, displayMessage ]); } /** * @param {?} from * @param {?} to * @param {?} amount * @param {?} memo * @param {?} currency * @param {?=} enforce * @return {?} */ requestTransfer(from, to, amount, memo, currency, enforce = false) { return this.call('requestTransfer', [ from, to, amount, memo, currency, enforce, ], 4); } /** * @param {?} delegator * @param {?} delegatee * @param {?} amount * @param {?} unit * @return {?} */ requestDelegation(delegator, delegatee, amount, unit) { return this.call('requestDelegation', [ delegator, delegatee, amount, unit ]); } /* * call is invoked by all other methods to call Steem Keychain. * It should not be used directly since it is not type-safe, * but it can be bandy in case there is a method not implemented yet. */ /** * @param {?} method * @param {?} args * @param {?=} callbackIndex * @return {?} */ call(method, args, callbackIndex) { return Observable.create((observer) => { // Make sure the extension is available. if (!this.steemKeychainAvailable) { observer.error(new Error('Steem Keychain not available')); observer.complete(); return; } // Push the callback to the argument list. /** @type {?} */ const cb = (res) => this.ngZone.run(() => { if (res.success) { observer.next(res); observer.complete(); } else { observer.error(new SteemKeychainError(res)); } }); if (callbackIndex) { args.splice(callbackIndex, 0, cb); } else { args.push(cb); } // Send the request. ((/** @type {?} */ (window))).steem_keychain[method](...args); }); } } SteemKeychainService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ SteemKeychainService.ctorParameters = () => [ { type: NgZone } ]; /** @nocollapse */ SteemKeychainService.ngInjectableDef = i0.defineInjectable({ factory: function SteemKeychainService_Factory() { return new SteemKeychainService(i0.inject(i0.NgZone)); }, token: SteemKeychainService, providedIn: "root" }); if (false) { /** @type {?} */ SteemKeychainService.prototype.ngZone; } //# sourceMappingURL=steem-keychain.service.js.map