Skip to content

Commit

Permalink
Display portion of consensus hash
Browse files Browse the repository at this point in the history
To allow checking whether people are submitting the same values more
easily.
  • Loading branch information
sim31 committed Jan 5, 2023
1 parent 7081f19 commit 47d105c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"@testing-library/user-event": "^13.5.0",
"copy-to-clipboard": "^3.3.3",
"firebase": "^9.8.3",
"object-sha": "^2.0.7",
"react": "^18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
Expand Down
11 changes: 10 additions & 1 deletion src/App.js
Expand Up @@ -14,6 +14,7 @@ import Typography from "@mui/material/Typography";
// TODO: remove if you use react hooks?
import copy from "copy-to-clipboard";
import { useSearchParamsState } from 'react-use-search-params-state'
import * as objectSha from 'object-sha'

const style = {
position: "absolute",
Expand All @@ -39,6 +40,7 @@ const inputDefaults = {
}

function App(props) {
console.log("props: ", props);

const [inputs, setInputs] = useSearchParamsState(inputDefaults);
const [accountname, setAccountName] = useState("");
Expand Down Expand Up @@ -78,6 +80,14 @@ function App(props) {
};

const vote = async () => {
console.log(inputs);
const hashable = objectSha.hashable(inputs);
const inputsHash = await objectSha.digest(hashable, 'SHA-256');
const displayedId = inputsHash.substring(0, 2) + " " + inputsHash.substring(2, 4) +
" " + inputsHash.substring(4, 6) + " " + inputsHash.substring(6, 8);
console.log("hashable: ", hashable);
console.log("inputs hash: ", inputsHash);
console.log("displayed id: ", displayedId);
if (activeUser) {
// could be more elegant than if (vote6 == "")
if (inputs.vote6 == "") {
Expand Down Expand Up @@ -127,7 +137,6 @@ function App(props) {
}
} else {
let voterlist = [inputs.vote6, inputs.vote5, inputs.vote4, inputs.vote3, inputs.vote2, inputs.vote1];
console.log(voterlist);
try {
const transaction = {
actions: [
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Expand Up @@ -7338,7 +7338,7 @@ object-assign@^4.1.1:

object-hash@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-3.0.0.tgz#73f97f753e7baffc0e2cc9d6e079079744ac82e9"
integrity sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==

object-inspect@^1.12.0, object-inspect@^1.9.0:
Expand All @@ -7351,6 +7351,11 @@ object-keys@^1.1.1:
resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz"
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==

object-sha@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/object-sha/-/object-sha-2.0.7.tgz#7099fe4f235cac8ffde5eb495270e65661278839"
integrity sha512-APUZVj07TvLdWY8qYq9LVweBuLz/wqImaQJ92Wt+Pjjw79/75vr/GVZ2Q7wngvahOXY98PFt7f9WmW3cuTLk4w==

object-visit@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz"
Expand Down

0 comments on commit 47d105c

Please sign in to comment.