@foreverrbum/ethsign
Version:
This package will allow you to electronically sign documents within your application
808 lines (667 loc) • 39.7 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _webviewer = _interopRequireDefault(require("@pdftron/webviewer"));
var _reactRouterDom = require("react-router-dom");
var _sign = require("../helpers/sign");
var _reactIntl = require("react-intl");
var _download = require("../helpers/download");
var _pdf = require("../helpers/pdf");
var _SignatureFinder = _interopRequireDefault(require("./PDF/SignatureFinder"));
var _Alert = _interopRequireDefault(require("./Alert"));
var _ProgressBarIndicator = _interopRequireDefault(require("./Dashboard/ProgressBarIndicator"));
var _TitleBar = _interopRequireDefault(require("./Sign/TitleBar"));
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var Sign = function Sign(props) {
var _useState = (0, _react.useState)(null),
_useState2 = _slicedToArray(_useState, 2),
instance = _useState2[0],
setInstance = _useState2[1];
var _useState3 = (0, _react.useState)(null),
_useState4 = _slicedToArray(_useState3, 2),
fileArr = _useState4[0],
handleFileArr = _useState4[1];
var _useState5 = (0, _react.useState)(null),
_useState6 = _slicedToArray(_useState5, 2),
mySigFields = _useState6[0],
handleMySigFields = _useState6[1]; // all fields
var _useState7 = (0, _react.useState)(null),
_useState8 = _slicedToArray(_useState7, 2),
doc = _useState8[0],
handleDoc = _useState8[1];
var newDocument = props.newDocument,
allFieldsRequiredBeforeSave = props.allFieldsRequiredBeforeSave,
callback = props.callback,
errorCallback = props.errorCallback,
bar = props.bar,
initialSigners = props.initialSigners,
handleActivePage = props.handleActivePage,
provider = props.provider,
contract = props.contract,
location = props.location,
ethAlias = props.ethAlias,
ethAccount = props.ethAccount,
ethAvatar = props.ethAvatar,
handleData = props.handleData,
networkId = props.networkId,
reloadContractDetails = props.reloadContractDetails;
var viewer = (0, _react.useRef)(null);
var _useState9 = (0, _react.useState)(false),
_useState10 = _slicedToArray(_useState9, 2),
loaded = _useState10[0],
handleLoaded = _useState10[1];
var _useState11 = (0, _react.useState)(false),
_useState12 = _slicedToArray(_useState11, 2),
updatedSignatures = _useState12[0],
handleUpdatedSignatures = _useState12[1];
var _useState13 = (0, _react.useState)(null),
_useState14 = _slicedToArray(_useState13, 2),
signed = _useState14[0],
handleSigned = _useState14[1];
var _useState15 = (0, _react.useState)(false),
_useState16 = _slicedToArray(_useState15, 2),
saving = _useState16[0],
handleSaving = _useState16[1];
var _useState17 = (0, _react.useState)(false),
_useState18 = _slicedToArray(_useState17, 2),
signing = _useState18[0],
handleSigning = _useState18[1];
var _useState19 = (0, _react.useState)(null),
_useState20 = _slicedToArray(_useState19, 2),
signer = _useState20[0],
handleSigner = _useState20[1];
var _useState21 = (0, _react.useState)(null),
_useState22 = _slicedToArray(_useState21, 2),
idx = _useState22[0],
handleIdx = _useState22[1];
var _useState23 = (0, _react.useState)(1),
_useState24 = _slicedToArray(_useState23, 2),
docPage = _useState24[0],
handleDocPage = _useState24[1];
var _useState25 = (0, _react.useState)(null),
_useState26 = _slicedToArray(_useState25, 2),
saveStatus = _useState26[0],
handleSaveStatus = _useState26[1];
var _useState27 = (0, _react.useState)([]),
_useState28 = _slicedToArray(_useState27, 2),
savedAnnotations = _useState28[0],
handleSavedAnnotations = _useState28[1];
var _useState29 = (0, _react.useState)(false),
_useState30 = _slicedToArray(_useState29, 2),
newChanges = _useState30[0],
handleNewChanges = _useState30[1];
var _useState31 = (0, _react.useState)(false),
_useState32 = _slicedToArray(_useState31, 2),
fieldChanges = _useState32[0],
handleFieldChanges = _useState32[1];
var _useState33 = (0, _react.useState)(false),
_useState34 = _slicedToArray(_useState33, 2),
allFieldsFilled = _useState34[0],
handleAllFieldsFilled = _useState34[1];
var _useState35 = (0, _react.useState)(0),
_useState36 = _slicedToArray(_useState35, 2),
signProgress = _useState36[0],
handleSignProgress = _useState36[1];
var _useState37 = (0, _react.useState)(''),
_useState38 = _slicedToArray(_useState37, 2),
password = _useState38[0],
handlePassword = _useState38[1];
var _useState39 = (0, _react.useState)(null),
_useState40 = _slicedToArray(_useState39, 2),
fieldsByPage = _useState40[0],
handleFieldsByPage = _useState40[1];
var _useState41 = (0, _react.useState)(0),
_useState42 = _slicedToArray(_useState41, 2),
numOfSigned = _useState42[0],
handleNumOfSigned = _useState42[1];
var _useIntl = (0, _reactIntl.useIntl)(),
formatMessage = _useIntl.formatMessage,
locale = _useIntl.locale;
var signContract = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
var annotManager, signaturesToSave, user;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!(!saving && (newChanges || fieldChanges))) {
_context2.next = 16;
break;
}
handleSaving(true);
annotManager = instance.annotManager;
signaturesToSave = annotManager.getAnnotationsList().filter(function (annot) {
return annot.Subject == "Widget" && annot.annot != null && annot.annot.getCustomData('Signer') == '';
});
handleSigning(signaturesToSave.length > 0);
user = ethAlias ? ethAlias : ethAccount;
handleSignProgress(0);
if (!newDocument) {
_context2.next = 12;
break;
}
_context2.next = 10;
return (0, _sign.createAndSign)(provider, ethAccount, instance, signaturesToSave, formatMessage, contract, handleSaveStatus, password, doc.name, initialSigners, bar, handleSignProgress, user, networkId, callback, errorCallback, handleSavedAnnotations, handleNewChanges);
case 10:
_context2.next = 14;
break;
case 12:
_context2.next = 14;
return (0, _sign.signAndSaveComments)(annotManager, signaturesToSave, provider, ethAccount, contract, doc, password, user, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return handleData(doc.documentKey, idx, 1);
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
})), null, formatMessage, handleSaveStatus, handleSavedAnnotations, handleNewChanges, signProgress, handleSignProgress);
case 14:
handleSaving(false);
if (reloadContractDetails) {
reloadContractDetails(doc.documentKey, idx);
}
case 16:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function signContract() {
return _ref.apply(this, arguments);
};
}();
(0, _react.useEffect)(function () {
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
var temp_doc, temp_password, index;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
if (handleActivePage) {
handleActivePage('sign');
}
if (!newDocument && location.state !== undefined && location.state.doc && location.state.idx != null && location.state.fileArr) {
temp_doc = location.state.doc;
temp_password = location.state.password;
handleDoc(temp_doc);
handleIdx(location.state.idx);
handleFileArr(location.state.fileArr);
} else if (!newDocument) {
props.history.push({
pathname: '/contracts'
});
} // set signed and signer
(0, _webviewer.default)({
initialDoc: newDocument ? newDocument.url : '',
licenseKey: 'Buildblock Tech Pte. Ltd.:OEM:EthSign::B+:AMS(20220926):60A5E4AD0457F80A7360B13AC982537860615F858748CDEA9BF51DE6240C48AE4AB4B6F5C7',
path: '/webviewer/lib',
disabledElements: ['header', 'toolsHeader']
}, viewer.current).then(function (instance) {
if (locale == "zh") {
instance.setLanguage('zh_cn');
}
setInstance(instance);
var docViewer = instance.docViewer,
annotManager = instance.annotManager,
Annotations = instance.Annotations;
instance.openElements(['notesPanel']);
annotManager.setCurrentUser(ethAlias ? ethAlias : ethAccount);
var SigFieldTxtAnnotation = /*#__PURE__*/function (_Annotations$CustomAn) {
_inherits(SigFieldTxtAnnotation, _Annotations$CustomAn);
var _super = _createSuper(SigFieldTxtAnnotation);
function SigFieldTxtAnnotation() {
var _this;
_classCallCheck(this, SigFieldTxtAnnotation);
_this = _super.call(this, 'SigFieldTxt'); // provide the custom XFDF element name
var page_idx = docViewer.getCurrentPage();
var rotation = docViewer.getCompleteRotation(page_idx) * -90;
_this.PageRotation = rotation;
_this.Subject = "SignatureField";
_this.Listable = false;
return _this;
}
_createClass(SigFieldTxtAnnotation, [{
key: "isSigned",
get: function get() {
return this.Signed;
},
set: function set(signed) {
this.Signed = signed;
}
}, {
key: "serialize",
value: function serialize(element, pageMatrix) {
var el = _get(_getPrototypeOf(SigFieldTxtAnnotation.prototype), "serialize", this).call(this, element, pageMatrix); // create an attribute to save the vertices list
el.setAttribute('Signer', JSON.stringify(this.Signer));
el.setAttribute('Index', this.Index);
el.setAttribute('Address', this.Address);
el.setAttribute('Signed', this.Signed);
return el;
}
}, {
key: "deserialize",
value: function deserialize(element, pageMatrix) {
_get(_getPrototypeOf(SigFieldTxtAnnotation.prototype), "deserialize", this).call(this, element, pageMatrix);
this.Signer = JSON.parse(element.getAttribute('Signer'));
this.Index = element.getAttribute('Index');
this.Address = element.getAttribute('Address');
this.Signed = element.getAttribute('Signed');
}
}, {
key: "draw",
value: function draw(ctx, pageMatrix) {
// the setStyles function is a function on markup annotations that sets up
// certain properties for us on the canvas for the annotation's stroke thickness.
this.setStyles(ctx, pageMatrix); // first we need to translate to the annotation's x/y coordinates so that it's
// drawn in the correct location
ctx.translate(this.X, this.Y);
ctx.beginPath();
ctx.setLineDash([5, 3]);
ctx.rect(0, 0, this.Width, this.Height);
ctx.stroke();
ctx.fillStyle = "black";
var zoom = docViewer.getZoom();
var textAnnot = this.Address + " Signs Here"; // context.translate(newx, newy);
ctx.save();
ctx.textBaseline = 'middle';
ctx.textAlign = 'center';
ctx.rotate(this.PageRotation / 180 * Math.PI);
if (this.PageRotation == -90 || this.PageRotation == -270) {
var textHeight = this.Height / 11;
ctx.font = "".concat(textHeight, "px san-serif");
if (this.PageRotation == -90) {
ctx.fillText(textAnnot, this.Height / 2 - this.Height, this.Width / 2);
} else {
ctx.fillText(textAnnot, this.Height / 2, this.Width / 2 - this.Width);
}
} else {
var _textHeight = this.Width / 11;
ctx.font = "".concat(_textHeight, "px san-serif");
if (this.PageRotation == -180) {
ctx.fillText(textAnnot, this.Width / 2 - this.Width, this.Height / 2 - this.Height);
} else {
ctx.fillText(textAnnot, this.Width / 2, this.Height / 2);
}
}
ctx.stroke();
}
}]);
return SigFieldTxtAnnotation;
}(Annotations.CustomAnnotation); // this is necessary to set the elementName before instantiation
SigFieldTxtAnnotation.prototype.elementName = 'SigFieldTxt';
SigFieldTxtAnnotation.SerializationType = Annotations.CustomAnnotation.SerializationTypes.CUSTOM; // register the annotation type so that it can be saved to XFDF files
annotManager.registerAnnotationType(SigFieldTxtAnnotation.prototype.elementName, SigFieldTxtAnnotation); // not show signatures in notesPanel
// instance.setCustomNoteFilter(annot => (!(annot instanceof instance.Annotations.FreeHandAnnotation) ))
if (allFieldsRequiredBeforeSave) {
handleAllFieldsFilled((0, _pdf.areAllFieldsFilled)(annotManager));
}
if (newDocument) {
var _getShortenedName = (0, _pdf.getShortenedName)(newDocument),
name = _getShortenedName.name,
ext = _getShortenedName.ext;
handleDoc({
name: name + ext
});
docViewer.on('annotationsLoaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
var annotationList, fieldManager, widgetAnnots, signatureWidgetAnnots;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
annotationList = annotManager.getAnnotationsList();
fieldManager = annotManager.getFieldManager();
widgetAnnots = annotationList.filter(function (a) {
return a instanceof Annotations.WidgetAnnotation;
});
signatureWidgetAnnots = widgetAnnots.filter(function (annot) {
return annot instanceof Annotations.SignatureWidgetAnnotation;
}); // customize look of Sign Here field
_context3.next = 6;
return (0, _pdf.redrawSignHereWidget)(signatureWidgetAnnots, instance, ethAccount, ethAlias, ethAvatar);
case 6:
annotManager.deleteAnnotations(signatureWidgetAnnots); // _.pull(annotationList, signatureWidgetAnnots)
// customize look of the rest of the fields
// TODO: style fields with #366DCC strokeColor and FDF4ED bg
// await styleWidgets(instance, widgetAnnots)
(0, _pdf.handleDocChanges)(instance, handleFieldsByPage, handleNumOfSigned, handleNewChanges, savedAnnotations, handleFieldChanges, handleAllFieldsFilled, ethAccount);
case 8:
case "end":
return _context3.stop();
}
}
}, _callee3);
})));
} else {
docViewer.on('annotationsLoaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return Promise.all([new Promise( /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(resolve, reject) {
var xfdf;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
if (!location.state.sigArr) {
_context5.next = 7;
break;
}
_context5.next = 3;
return (0, _pdf.getStringFromDecryptedArr)(location.state.sigArr, formatMessage);
case 3:
xfdf = _context5.sent;
annotManager.importAnnotations(xfdf).then( /*#__PURE__*/function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(sigfields) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _pdf.applyFields)(sigfields, instance, ethAccount, location.state.doc.signatureData);
case 2:
handleMySigFields(sigfields);
resolve();
case 4:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
return function (_x3) {
return _ref7.apply(this, arguments);
};
}());
_context5.next = 8;
break;
case 7:
resolve();
case 8:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
return function (_x, _x2) {
return _ref6.apply(this, arguments);
};
}()), new Promise( /*#__PURE__*/function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(resolve, reject) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return (0, _download.getCommentArrs)(location.state.commentData, temp_password, formatMessage).then( /*#__PURE__*/function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(data) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return loadComments(data, instance);
case 2:
resolve();
case 3:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
return function (_x6) {
return _ref9.apply(this, arguments);
};
}());
case 2:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
return function (_x4, _x5) {
return _ref8.apply(this, arguments);
};
}())]);
case 2:
// TODO: loading state
// here, the loading state should be set to false and the user will now be allowed to edit the document
(0, _pdf.updateSignatureFinder)(annotManager, handleFieldsByPage, handleNumOfSigned, ethAccount);
(0, _pdf.handleDocChanges)(instance, handleFieldsByPage, handleNumOfSigned, handleNewChanges, savedAnnotations, handleFieldChanges, handleAllFieldsFilled, ethAccount);
case 4:
case "end":
return _context8.stop();
}
}
}, _callee8);
})));
}
docViewer.on('pageNumberUpdated', function (pageNumber) {
handleDocPage(pageNumber);
});
});
if (temp_doc) {
index = _lodash.default.findIndex(temp_doc.signers, {
address: ethAccount
});
if (index > -1) {
handleSigner(true);
handleSigned(temp_doc.signers[index].fullySigned);
} else {
handleSigner(false);
}
}
handleLoaded(true);
case 5:
case "end":
return _context9.stop();
}
}
}, _callee9);
}))();
}, []);
(0, _react.useEffect)(function () {
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
var blob;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
if (!newDocument && fileArr != null && fileArr != false && instance != null) {
blob = new Blob([fileArr], {
type: 'application/pdf'
});
instance.loadDocument(blob, {
filename: doc.name
});
}
case 1:
case "end":
return _context10.stop();
}
}
}, _callee10);
}))();
}, [fileArr, instance]);
var loadComments = /*#__PURE__*/function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(commentArrs, instance) {
var annotManager, allImportedAnnots;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
annotManager = instance.annotManager;
allImportedAnnots = [];
_context13.t0 = Promise;
_context13.next = 5;
return commentArrs.map( /*#__PURE__*/function () {
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(commentArr, id) {
var xfdf;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return (0, _pdf.getStringFromDecryptedArr)(commentArr, formatMessage);
case 2:
xfdf = _context12.sent;
annotManager.importAnnotations(xfdf).then( /*#__PURE__*/function () {
var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(importedAnnotations) {
var signatures;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
signatures = importedAnnotations.filter(function (annot) {
return annot.Subject == "Signature";
});
(0, _sign.makeSignaturesReadOnly)(signatures);
if (signatures.length > 0) {
handleUpdatedSignatures(!updatedSignatures);
}
allImportedAnnots.push(importedAnnotations);
case 4:
case "end":
return _context11.stop();
}
}
}, _callee11);
}));
return function (_x11) {
return _ref13.apply(this, arguments);
};
}());
case 4:
case "end":
return _context12.stop();
}
}
}, _callee12);
}));
return function (_x9, _x10) {
return _ref12.apply(this, arguments);
};
}());
case 5:
_context13.t1 = _context13.sent;
_context13.next = 8;
return _context13.t0.all.call(_context13.t0, _context13.t1);
case 8:
handleSavedAnnotations(allImportedAnnots);
return _context13.abrupt("return", true);
case 10:
case "end":
return _context13.stop();
}
}
}, _callee13);
}));
return function loadComments(_x7, _x8) {
return _ref11.apply(this, arguments);
};
}();
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, saveStatus && /*#__PURE__*/_react.default.createElement(_Alert.default, {
title: "Saving Document",
message: saveStatus,
type: "bottom-right",
customComponent: /*#__PURE__*/_react.default.createElement(_ProgressBarIndicator.default, {
signStyle: true,
value: signProgress,
max: newDocument ? 4 : signing ? 2 : 1
})
}), !newDocument && /*#__PURE__*/_react.default.createElement(_TitleBar.default, {
newChanges: newChanges,
doc: doc,
saving: saving,
allFieldsFilled: allFieldsFilled,
fieldChanges: fieldChanges,
allFieldsRequiredBeforeSave: allFieldsRequiredBeforeSave,
bar: {
button1: formatMessage({
id: "BACK"
}),
button1Action: function button1Action() {
props.history.push({
pathname: '/contracts'
});
},
button2: formatMessage({
id: "SAVE"
}),
button2Action: function button2Action() {
signContract();
}
}
}), /*#__PURE__*/_react.default.createElement("div", {
className: "bg-gray-400 flex-grow flex flex-col"
}, /*#__PURE__*/_react.default.createElement("div", {
className: "mx-auto flex-grow flex flex h-full w-full text-gray-300 text-15"
}, /*#__PURE__*/_react.default.createElement(_SignatureFinder.default, {
mySigFields: mySigFields,
fieldsByPage: fieldsByPage,
numOfSigned: numOfSigned,
instance: instance,
docPage: docPage,
updatedSignatures: updatedSignatures
}), /*#__PURE__*/_react.default.createElement("div", {
className: "flex-grow",
ref: viewer
}))), newDocument && /*#__PURE__*/_react.default.createElement(_TitleBar.default, {
newChanges: newChanges,
newDocument: newDocument,
doc: doc,
saving: saving,
allFieldsFilled: allFieldsFilled,
fieldChanges: fieldChanges,
allFieldsRequiredBeforeSave: allFieldsRequiredBeforeSave,
bar: {
button1: bar.button1,
button1Action: bar.button1Action,
button2: bar.button2,
button2Action: function button2Action() {
signContract();
}
}
}));
};
var _default = (0, _reactRouterDom.withRouter)(Sign);
exports.default = _default;