Browse Source

refactor: export function for poll hash generation

develop
Apostolos Fanakis 4 years ago
parent
commit
cf55e75501
Signed by: Apostolof GPG Key ID: 8600B4C4163B3269
  1. 4
      packages/concordia-app/src/components/PollCreate/index.jsx
  2. 9
      packages/concordia-app/src/utils/hashUtils.js

4
packages/concordia-app/src/components/PollCreate/index.jsx

@ -15,7 +15,7 @@ import { breeze, drizzle } from '../../redux/store';
import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../constants/TransactionStatus'; import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../constants/TransactionStatus';
import './styles.css'; import './styles.css';
import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabaseKeys'; import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabaseKeys';
import generateHash from '../../utils/hashUtils'; import generatePollHash from '../../utils/hashUtils';
const { contracts: { [VOTING_CONTRACT]: { methods: { createPoll } } } } = drizzle; const { contracts: { [VOTING_CONTRACT]: { methods: { createPoll } } } } = drizzle;
const { orbit: { stores } } = breeze; const { orbit: { stores } } = breeze;
@ -96,7 +96,7 @@ const PollCreate = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
createPoll(topicId) { createPoll(topicId) {
setCreating(true); setCreating(true);
const dataHash = generateHash(JSON.stringify({ question, optionValues })); const dataHash = generatePollHash(question, optionValues);
setCreatePollCacheSendStackId(createPoll.cacheSend( setCreatePollCacheSendStackId(createPoll.cacheSend(
...[topicId, options.length, dataHash, allowVoteChanges], { from: account }, ...[topicId, options.length, dataHash, allowVoteChanges], { from: account },
)); ));

9
packages/concordia-app/src/utils/hashUtils.js

@ -1,7 +1,8 @@
import sha256 from 'crypto-js/sha256'; import sha256 from 'crypto-js/sha256';
function generateHash(message) { const generateHash = (message) => sha256(message).toString().substring(0, 16);
return sha256(message).toString().substring(0, 16);
}
export default generateHash; const generatePollHash = (pollQuestion, pollOptions) => generateHash(JSON
.stringify({ question: pollQuestion, optionValues: pollOptions }));
export default generatePollHash;

Loading…
Cancel
Save