HaveIBeenCompromised.jsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import axios from 'axios';
  2. import React, { useState, useRef } from 'react';
  3. import { InputGroup, FormControl, Form, } from 'react-bootstrap';
  4. //import { compromisedTcashAddrResponse, failedCompromisedTcashResponse } from '../../data/ihavebeencompromised';
  5. import ListOfResults from '../components/ListOfResults';
  6. export default function HaveIBeenCompromised({ tcashAddr, aliases }) {
  7. const inputEl = useRef(null);
  8. const [val, setVal] = useState('');
  9. const [numCompromised, setNumCompromised] = useState(null);
  10. const [compromisedTxns, setCompromisedTxns] = useState(null);
  11. const [invalid, setInvalid] = useState(false);
  12. const checkIfCompromised = address => {
  13. axios.get('/search/compromised?address=' + address + '&pool=' + tcashAddr).then(response => {
  14. //response = compromisedTcashAddrResponse;
  15. const { success, data } = response.data;
  16. if (!success) {
  17. setNumCompromised(null);
  18. setCompromisedTxns(null);
  19. setInvalid(true);
  20. return;
  21. }
  22. const { compromised_size, compromised } = data;
  23. setNumCompromised(compromised_size);
  24. setCompromisedTxns(compromised);
  25. setInvalid(false);
  26. })
  27. }
  28. return (
  29. <div className="row">
  30. <div className="col-12">
  31. <div className="query-info">
  32. <div className="row">
  33. <div className="col-12 panel-sub">
  34. check if your transactions have been compromised
  35. </div>
  36. <div className="col-12 panel-title">
  37. YOUR COMPROMISED TXNS IN THIS POOL
  38. </div>
  39. <InputGroup className="col-12">
  40. <FormControl className="rounded specific-result"
  41. placeholder="enter a deposit or withdrawal address used with this pool to check for compromised txs"
  42. onChange={(e) => {
  43. e.preventDefault();
  44. setVal(e.target.value);
  45. }}
  46. onKeyPress={(e) => {
  47. if (e.key !== 'Enter') {
  48. return;
  49. }
  50. checkIfCompromised(val);
  51. }}
  52. ref={inputEl}
  53. isInvalid={invalid}
  54. />
  55. <Form.Control.Feedback type='invalid'>Please input a valid deposit address.</Form.Control.Feedback>
  56. </InputGroup>
  57. {compromisedTxns && <ListOfResults
  58. sectionHeader={numCompromised !== null && <div className="results-section col-12">Total deposits compromised: {numCompromised}</div>}
  59. rowTitle='transaction'
  60. rowBadge='heuristic'
  61. results={compromisedTxns}
  62. aliases={aliases}
  63. />}
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. )
  69. }