UNPKG

@foreverrbum/ethsign

Version:

This package will allow you to electronically sign documents within your application

117 lines (100 loc) 4.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDelete = exports.default = void 0; var _reactNotificationsComponent = require("react-notifications-component"); 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); }); }; } var handleDelete = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(contract, web3, ethAccount, doc, close, handleSubmitButton, handleData, formatMessage) { var currentBlock, requestClearDocument; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return web3.eth.getBlockNumber(); case 2: currentBlock = _context.sent; if (!(currentBlock <= doc.expiration)) { _context.next = 6; break; } alert('The contract has not expired yet.'); return _context.abrupt("return", false); case 6: requestClearDocument = contract.methods.requestClearDocument; _context.prev = 7; _context.next = 10; return requestClearDocument(doc.documentKey).call({ from: ethAccount }); case 10: requestClearDocument(doc.documentKey).send({ from: ethAccount }).once('transactionHash', function (txHash) { _reactNotificationsComponent.store.addNotification({ title: 'Transaction information', message: "The network has accepted your deletion transaction. TxHash ".concat(txHash), type: 'info', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true } }); handleData(doc.documentKey, 2); }).once('confirmation', function (_, receipt) {// store.addNotification({ // title: 'Transaction success', // message: // 'Your deletion transaction has been confirmed by the network!', // type: 'success', // insert: 'top', // container: 'bottom-right', // animationIn: ['animated', 'fadeIn'], // animationOut: ['animated', 'fadeOut'], // dismiss: { // duration: 10000, // onScreen: true, // }, // }); }); close(); _context.next = 19; break; case 14: _context.prev = 14; _context.t0 = _context["catch"](7); _reactNotificationsComponent.store.addNotification({ title: 'Smart contract error', message: _context.t0.toString(), type: 'danger', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'] }); handleSubmitButton(formatMessage({ id: "DELETE" })); return _context.abrupt("return", false); case 19: case "end": return _context.stop(); } } }, _callee, null, [[7, 14]]); })); return function handleDelete(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) { return _ref.apply(this, arguments); }; }(); exports.handleDelete = handleDelete; var _default = { handleDelete: handleDelete }; exports.default = _default;