UNPKG

@foreverrbum/ethsign

Version:

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

130 lines (124 loc) 5.18 kB
import { store } from 'react-notifications-component'; export const handleNewVote = async (contract, ethAccount, data, isPartyProposal, documentKey, handleSubmitButton, close, handleData, formatMessage) => { // Validate input if ((data.choice !== 'YES') & (data.choice !== 'NO')) { 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 false; } // Call smart contract to verify if document exists const { voteAuthorizedPartyProposal, voteProposal, } = contract.methods; // Send transaction const choice = data.choice === 'YES'; try { if (isPartyProposal) { await voteAuthorizedPartyProposal(documentKey, choice).call({ from: ethAccount, }); voteAuthorizedPartyProposal(documentKey, choice) .send({ from: ethAccount }) .once('transactionHash', (txHash) => { store.addNotification({ title: 'Transaction information', message: `The network has accepted your trusted party vote transaction. TxHash ${txHash}`, type: 'info', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true, }, }); handleData(documentKey, 1); }) .once('confirmation', (_, 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; }); } else { await voteProposal(documentKey, choice).call({ from: ethAccount, }); voteProposal(documentKey, choice) .send({ from: ethAccount }) .once('transactionHash', (txHash) => { store.addNotification({ title: 'Transaction information', message: `The network has accepted your vote transaction. TxHash ${txHash}`, type: 'info', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], dismiss: { duration: 10000, onScreen: true, }, }); handleData(documentKey, 1); }) .once('confirmation', (_, 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; }); } close(); } catch (error) { store.addNotification({ title: 'Smart contract error', message: error.toString(), type: 'danger', insert: 'top', container: 'bottom-right', animationIn: ['animated', 'fadeIn'], animationOut: ['animated', 'fadeOut'], }); handleSubmitButton(formatMessage({id: "SUBMIT"})) return false; } } export default { handleNewVote }