{"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { SIGNER_META_DATA_KEY } from '@common';\nimport './app/common/extensions/array';\nimport browser from 'webextension-polyfill';\nimport { v4 as uuidv4 } from 'uuid';\n//\n// Functions\n//\nfunction getSignerMetaDataVaultSnapshots() {\n  return _getSignerMetaDataVaultSnapshots.apply(this, arguments);\n}\nfunction _getSignerMetaDataVaultSnapshots() {\n  _getSignerMetaDataVaultSnapshots = _asyncToGenerator(function* () {\n    const data = yield browser.storage.local.get(SIGNER_META_DATA_KEY.vaultSnapshots);\n    return typeof data.vaultSnapshots === 'undefined' ? [] : data.vaultSnapshots.sortBy(x => x.fileName, 'desc');\n  });\n  return _getSignerMetaDataVaultSnapshots.apply(this, arguments);\n}\nfunction setSignerMetaDataVaultSnapshots(_x) {\n  return _setSignerMetaDataVaultSnapshots.apply(this, arguments);\n}\nfunction _setSignerMetaDataVaultSnapshots() {\n  _setSignerMetaDataVaultSnapshots = _asyncToGenerator(function* (vaultSnapshots) {\n    yield browser.storage.local.set({\n      vaultSnapshots\n    });\n  });\n  return _setSignerMetaDataVaultSnapshots.apply(this, arguments);\n}\nfunction rebuildSnapshotsList(snapshots) {\n  const ul = document.getElementById('snapshotsList');\n  if (!ul) {\n    return;\n  }\n  // Clear the list\n  ul.innerHTML = '';\n  for (const snapshot of snapshots) {\n    const li = document.createElement('li');\n    const test = '\"' + snapshot.fileName + '\"' + ' -> vault version: ' + snapshot.data.version + ' -> identities: ' + snapshot.data.identities.length + ' -> relays: ' + snapshot.data.relays.length + '';\n    li.innerText = test;\n    ul.appendChild(li);\n  }\n}\n//\n// Main\n//\ndocument.addEventListener('DOMContentLoaded', /*#__PURE__*/_asyncToGenerator(function* () {\n  const uploadSnapshotsButton = document.getElementById('uploadSnapshotsButton');\n  const deleteSnapshotsButton = document.getElementById('deleteSnapshotsButton');\n  const uploadSnapshotInput = document.getElementById('uploadSnapshotInput');\n  deleteSnapshotsButton?.addEventListener('click', /*#__PURE__*/_asyncToGenerator(function* () {\n    yield setSignerMetaDataVaultSnapshots([]);\n    rebuildSnapshotsList([]);\n  }));\n  uploadSnapshotsButton?.addEventListener('click', /*#__PURE__*/_asyncToGenerator(function* () {\n    uploadSnapshotInput?.click();\n  }));\n  uploadSnapshotInput?.addEventListener('change', /*#__PURE__*/function () {\n    var _ref4 = _asyncToGenerator(function* (event) {\n      const files = event.target.files;\n      if (!files) {\n        return;\n      }\n      try {\n        const existingSnapshots = yield getSignerMetaDataVaultSnapshots();\n        const newSnapshots = [];\n        for (const file of files) {\n          const text = yield file.text();\n          const vault = JSON.parse(text);\n          // Check, if the \"new\" file is already in the list (via fileName comparison)\n          if (existingSnapshots.some(x => x.fileName === file.name)) {\n            continue;\n          }\n          newSnapshots.push({\n            id: uuidv4(),\n            fileName: file.name,\n            createdAt: new Date().toISOString(),\n            data: vault,\n            identityCount: vault.identities?.length ?? 0,\n            reason: 'manual'\n          });\n        }\n        const snapshots = [...existingSnapshots, ...newSnapshots].sortBy(x => x.fileName, 'desc');\n        // Persist the new snapshots to the local storage\n        yield setSignerMetaDataVaultSnapshots(snapshots);\n        //\n        rebuildSnapshotsList(snapshots);\n      } catch (error) {\n        console.log(error);\n      }\n    });\n    return function (_x2) {\n      return _ref4.apply(this, arguments);\n    };\n  }());\n  const snapshots = yield getSignerMetaDataVaultSnapshots();\n  rebuildSnapshotsList(snapshots);\n}));","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}