@foreverrbum/ethsign
Version:
This package will allow you to electronically sign documents within your application
73 lines (69 loc) • 2.71 kB
JavaScript
import { store } from 'react-notifications-component';
export const handleNewTrustedParty = async (contract, ethAccount, web3, data, handleSubmitButton, documentKey, close, handleData, formatMessage) => {
// Call smart contract to verify if document exists
const { fromAscii } = web3.utils;
const {
newAuthorizedPartyProposal,
} = contract.methods;
const proposalComment = fromAscii(data.comment);
// Send transaction
try {
await newAuthorizedPartyProposal(
documentKey,
data.trustedParty,
proposalComment
).call({ from: ethAccount });
newAuthorizedPartyProposal(
documentKey,
data.trustedParty,
proposalComment
)
.send({ from: ethAccount })
.once('transactionHash', (txHash) => {
store.addNotification({
title: 'Transaction information',
message: `The network has accepted your new trusted party proposal transaction. TxHash ${txHash}`,
type: 'info',
insert: 'top',
container: 'bottom-right',
animationIn: ['animated', 'fadeIn'],
animationOut: ['animated', 'fadeOut'],
dismiss: {
duration: 10000,
onScreen: true,
},
});
handleData(documentKey);
})
.once('confirmation', (_, receipt) => {
// store.addNotification({
// title: 'Transaction success',
// message:
// 'Your new trusted party proposal 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: "SUBMIT"}))
return;
}
}
export default { handleNewTrustedParty }