@1hive/connect-core
Version:
Access and interact with Aragon Organizations and their apps.
89 lines • 4.06 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _installedApps, _provider;
Object.defineProperty(exports, "__esModule", { value: true });
const transactions_1 = require("../utils/transactions");
const index_1 = __importStar(require("../utils/descriptor/index"));
const Transaction_1 = __importDefault(require("./Transaction"));
const normalizePreTransactions = (preTransactions) => {
return preTransactions.map((preTransaction) => preTransaction instanceof Transaction_1.default
? preTransaction
: new Transaction_1.default(preTransaction));
};
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 index_1.describePath(this.path, __classPrivateFieldGet(this, _installedApps), __classPrivateFieldGet(this, _provider));
// eslint-disable-next-line no-empty
}
catch (_) { }
}
return new index_1.default(description, __classPrivateFieldGet(this, _installedApps));
}
// Build a token allowance pre-transaction
async buildApprovePreTransactions(tokenData) {
return transactions_1.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));
}
}
exports.default = ForwardingPath;
_installedApps = new WeakMap(), _provider = new WeakMap();
//# sourceMappingURL=ForwardingPath.js.map