Skip to content

Commit 184787e

Browse files
authored
Fix to fetch latest block on button click (#1)
* Fix fetching latest block on button click * Get contract address from config * Remove cache from latest block GQL query * Print error on failing invoke
1 parent 83600d2 commit 184787e

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

packages/react-app/.sample.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
REACT_APP_PROVIDER=https://rinkeby.infura.io/v3/2717afb6bf164045b5d5468031b93f87
2-
REACT_APP_CONTRACT_ADDRESS=0x7963FF0883524f8f22F9e26c8814024B85dDd391
2+
33
REACT_APP_WATCHER_URI=http://localhost:3010/graphql

packages/react-app/src/MemberCheck.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import useLazyQuery from "./hooks/useLazyQuery";
44
import LATEST_BLOCK_GRAPHQL from "./queries/latestBlock";
55
import IS_MEMBER_GRAPHQL from "./queries/isMember";
66
import TextInput from "./TextInput";
7+
import { address } from "./config.json";
78

89
export default function MemberCheck(props) {
910
const [output, setOutput] = useState("");
@@ -30,28 +31,26 @@ export default function MemberCheck(props) {
3031
export function MemberCheckButton() {
3132
// Get latest block
3233
const LATEST_BLOCK_GQL = gql(LATEST_BLOCK_GRAPHQL);
33-
const { loading, data: latestBlockData } = useQuery(LATEST_BLOCK_GQL, {
34+
const latestBlock = useLazyQuery(LATEST_BLOCK_GQL, {
3435
context: { clientName: "watcher" },
36+
fetchPolicy: "no-cache",
3537
});
3638

3739
// Check if isMember
3840
const IS_MEMBER_GQL = gql(IS_MEMBER_GRAPHQL);
3941
const isMember = useLazyQuery(IS_MEMBER_GQL, {
4042
context: { clientName: "watcher" },
4143
variables: {
42-
contractAddress: process?.env?.REACT_APP_CONTRACT_ADDRESS,
44+
contractAddress: address,
4345
},
4446
});
4547

46-
if (loading) {
47-
return <p>Loading...</p>;
48-
}
49-
5048
return (
5149
<MemberCheck
5250
checkMember={async name => {
5351
const codedName = `TWT:${name.toLowerCase()}`;
5452
try {
53+
const { data: latestBlockData } = await latestBlock();
5554
const { data } = await isMember({ blockHash: latestBlockData?.latestBlock?.hash, key0: codedName });
5655

5756
if (data?.isMember?.value) {

packages/react-app/src/MemberReport.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function SubmitBatchButton(props) {
8686
setMembers([]);
8787
} catch (err) {
8888
console.error(err);
89-
alert(`Error: ${err}`);
89+
alert(`Error: ${err.message}`);
9090
}
9191
}}
9292
>

packages/react-app/src/PhisherCheck.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import useLazyQuery from "./hooks/useLazyQuery";
44
import LATEST_BLOCK_GRAPHQL from "./queries/latestBlock";
55
import IS_PHISHER_GRAPHQL from "./queries/isPhisher";
66
import TextInput from "./TextInput";
7+
import { address } from "./config.json";
78

89
export default function PhisherCheck(props) {
910
const [output, setOutput] = useState("");
@@ -30,28 +31,26 @@ export default function PhisherCheck(props) {
3031
export function PhisherCheckButton() {
3132
// Get latest block
3233
const LATEST_BLOCK_GQL = gql(LATEST_BLOCK_GRAPHQL);
33-
const { loading, data: latestBlockData } = useQuery(LATEST_BLOCK_GQL, {
34+
const latestBlock = useLazyQuery(LATEST_BLOCK_GQL, {
3435
context: { clientName: "watcher" },
36+
fetchPolicy: "no-cache",
3537
});
3638

3739
// Check if isPhisher
3840
const IS_PHISHER_GQL = gql(IS_PHISHER_GRAPHQL);
3941
const isPhisher = useLazyQuery(IS_PHISHER_GQL, {
4042
context: { clientName: "watcher" },
4143
variables: {
42-
contractAddress: process?.env?.REACT_APP_CONTRACT_ADDRESS,
44+
contractAddress: address,
4345
},
4446
});
4547

46-
if (loading) {
47-
return <p>Loading...</p>;
48-
}
49-
5048
return (
5149
<PhisherCheck
5250
checkPhisher={async name => {
5351
const codedName = `TWT:${name.toLowerCase()}`;
5452
try {
53+
const { data: latestBlockData } = await latestBlock();
5554
const { data } = await isPhisher({ blockHash: latestBlockData?.latestBlock?.hash, key0: codedName });
5655

5756
if (data?.isPhisher?.value) {

packages/react-app/src/PhishingReport.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function SubmitBatchButton(props) {
100100
localStorage.clear();
101101
setPhishers([]);
102102
} catch (err) {
103-
alert(`Error: ${err}`);
103+
alert(`Error: ${err.message}`);
104104
}
105105
}}
106106
>

packages/server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const BASE_URI = 'https://mobymask.com/#';
2525
const fs = require('fs');
2626
const path = require('path');
2727
const configPath = path.join(__dirname, './config.json');
28-
const { privateKey, mnemonic, rpcUrl } = require('./secrets.json');
28+
const { privateKey, mnemonic, rpcUrl, baseURI = BASE_URI } = require('./secrets.json');
2929

3030
const openrpcDocument = require('./openrpc.json');
3131
const { parseOpenRPCDocument } = require("@open-rpc/schema-utils-js");
@@ -230,7 +230,7 @@ async function signDelegation () {
230230
}
231231
console.log('A SIGNED DELEGATION/INVITE LINK:');
232232
console.log(JSON.stringify(invitation, null, 2));
233-
console.log(BASE_URI + '/members?invitation=' + encodeURIComponent(JSON.stringify(invitation)));
233+
console.log(baseURI + '/members?invitation=' + encodeURIComponent(JSON.stringify(invitation)));
234234
}
235235

236236
function fromHexString (hexString: string) {

0 commit comments

Comments
 (0)