UNPKG

@foreverrbum/ethsign

Version:

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

186 lines (162 loc) 7.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleNewVote = 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 handleNewVote = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(contract, ethAccount, data, isPartyProposal, documentKey, handleSubmitButton, close, handleData, formatMessage) { var _contract$methods, voteAuthorizedPartyProposal, voteProposal, choice; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!(data.choice !== 'YES' & data.choice !== 'NO')) { _context.next = 4; break; } _reactNotificationsComponent.store.addNotification({ title: 'Error', message: 'Your vote choice is invalid. Please enter "YES" or "NO", case sensitive.', type: 'danger', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true } }); handleSubmitButton(formatMessage({ id: "SUBMIT" })); return _context.abrupt("return", false); case 4: // Call smart contract to verify if document exists _contract$methods = contract.methods, voteAuthorizedPartyProposal = _contract$methods.voteAuthorizedPartyProposal, voteProposal = _contract$methods.voteProposal; // Send transaction choice = data.choice === 'YES'; _context.prev = 6; if (!isPartyProposal) { _context.next = 13; break; } _context.next = 10; return voteAuthorizedPartyProposal(documentKey, choice).call({ from: ethAccount }); case 10: voteAuthorizedPartyProposal(documentKey, choice).send({ from: ethAccount }).once('transactionHash', function (txHash) { _reactNotificationsComponent.store.addNotification({ title: 'Transaction information', message: "The network has accepted your trusted party vote transaction. TxHash ".concat(txHash), type: 'info', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true } }); handleData(documentKey, 1); }).once('confirmation', function (_, receipt) { // store.addNotification({ // title: 'Transaction success', // message: // 'Your trusted party vote 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, // }, // }); return; }); _context.next = 16; break; case 13: _context.next = 15; return voteProposal(documentKey, choice).call({ from: ethAccount }); case 15: voteProposal(documentKey, choice).send({ from: ethAccount }).once('transactionHash', function (txHash) { _reactNotificationsComponent.store.addNotification({ title: 'Transaction information', message: "The network has accepted your vote transaction. TxHash ".concat(txHash), type: 'info', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true } }); handleData(documentKey, 1); }).once('confirmation', function (_, receipt) { // store.addNotification({ // title: 'Transaction success', // message: // 'Your vote 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, // }, // }); return; }); case 16: close(); _context.next = 24; break; case 19: _context.prev = 19; _context.t0 = _context["catch"](6); _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: "SUBMIT" })); return _context.abrupt("return", false); case 24: case "end": return _context.stop(); } } }, _callee, null, [[6, 19]]); })); return function handleNewVote(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9) { return _ref.apply(this, arguments); }; }(); exports.handleNewVote = handleNewVote; var _default = { handleNewVote: handleNewVote }; exports.default = _default;