UNPKG

@1hive/connect-core

Version:

Access and interact with Aragon Organizations and their apps.

64 lines 2.95 kB
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); }; var _installedApps, _provider; import { buildApprovePreTransactions } from '../utils/transactions'; import ForwardingPathDescription, { describePath, } from '../utils/descriptor/index'; import Transaction from './Transaction'; const normalizePreTransactions = (preTransactions) => { return preTransactions.map((preTransaction) => preTransaction instanceof Transaction ? preTransaction : new Transaction(preTransaction)); }; export default class ForwardingPath { constructor(data, installedApps, provider) { _installedApps.set(this, void 0); _provider.set(this, void 0); __classPrivateFieldSet(this, _installedApps, installedApps); __classPrivateFieldSet(this, _provider, provider); this.destination = data.destination; this.path = data.path; this.transactions = data.transactions; } // Lets consumers pass a callback to sign any number of transactions. // This is similar to calling transactions() and using a loop, but shorter. // It returns the value returned by the library, usually a transaction receipt. async sign(callback) { return Promise.all(this.transactions.map(async (tx) => await callback(tx))); } // Return a description of the forwarding path, to be rendered. async describe() { let description = []; if (this.path.length > 0) { try { description = await describePath(this.path, __classPrivateFieldGet(this, _installedApps), __classPrivateFieldGet(this, _provider)); // eslint-disable-next-line no-empty } catch (_) { } } return new ForwardingPathDescription(description, __classPrivateFieldGet(this, _installedApps)); } // Build a token allowance pre-transaction async buildApprovePreTransactions(tokenData) { return buildApprovePreTransactions(this.transactions[0], tokenData, __classPrivateFieldGet(this, _provider)); } // Apply a pretransaction to the path applyPreTransactions(preTransactions) { normalizePreTransactions(preTransactions) .reverse() .filter((preTransaction) => !!preTransaction) .forEach((preTransaction) => this.transactions.unshift(preTransaction)); } } _installedApps = new WeakMap(), _provider = new WeakMap(); //# sourceMappingURL=ForwardingPath.js.map