UNPKG

@1hive/connect-core

Version:

Access and interact with Aragon Organizations and their apps.

56 lines 2.43 kB
import * as radspec from '@1hive/radspec'; import { addressesEqual } from '../address'; import { findAppMethodFromData } from '../app'; import { filterAndDecodeAppUpgradeIntents } from '../intent'; /** * Attempt to describe intent via radspec. */ export async function tryEvaluatingRadspec(intent, installedApps, provider // Decorated intent with description, if one could be made ) { const app = installedApps.find((app) => addressesEqual(app.address, intent.to)); // If the intent matches an installed app, use only that app to search for a // method match, otherwise fallback to searching all installed apps const appsToSearch = app ? [app] : installedApps; const method = appsToSearch.reduce((found, app) => { if (found) { return found; } const method = findAppMethodFromData(app, intent.data); if (method) return method; }, undefined); let evaluatedNotice; if (method && method.notice) { try { evaluatedNotice = await radspec.evaluate(method.notice, { abi: app === null || app === void 0 ? void 0 : app.abi, transaction: intent, }, { provider: provider }); } catch (err) { console.error(`Could not evaluate a description for given transaction data: ${intent.data}`, err); } } return { ...intent, description: evaluatedNotice }; } /** * Attempt to describe a setApp() intent. Only describes the APP_BASE namespace. * * @param {Object} intent transaction intent * @param {Object} wrapper * @return {Promise<Object>} Decorated intent with description, if one could be made */ export async function tryDescribingUpdateAppIntent(intent, installedApps) { const upgradeIntentParams = filterAndDecodeAppUpgradeIntents([intent], installedApps)[0]; if (Array.isArray(upgradeIntentParams) && upgradeIntentParams.length === 0) return undefined; const { appId, appAddress } = upgradeIntentParams; const app = installedApps.find((app) => app.address === appAddress); const repo = await (app === null || app === void 0 ? void 0 : app.repo()); return { ...intent, description: `Upgrade ${appId} app instances to v${repo === null || repo === void 0 ? void 0 : repo.lastVersion}`, }; } export { postprocessRadspecDescription } from './postprocess'; //# sourceMappingURL=index.js.map