UNPKG

@foreverrbum/ethsign

Version:

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

71 lines (64 loc) 2.52 kB
import { store } from 'react-notifications-component'; export const handleDelete = async (contract, web3, ethAccount, doc, close, handleSubmitButton, handleData, formatMessage) => { const currentBlock = await web3.eth.getBlockNumber(); if (currentBlock <= doc.expiration) { alert('The contract has not expired yet.'); return false; } const { requestClearDocument, } = contract.methods; try { await requestClearDocument(doc.documentKey).call({ from: ethAccount, }); requestClearDocument(doc.documentKey) .send({ from: ethAccount }) .once('transactionHash', (txHash) => { store.addNotification({ title: 'Transaction information', message: `The network has accepted your deletion transaction. TxHash ${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', (_, 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(); } 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: "DELETE"})) return false; } } export default { handleDelete }