3
1

2 Commity 5d64d75211 ... f046f3b8cf

Autor SHA1 Správa Dátum
  Oleksandr Korniienko f046f3b8cf Cleanup. 3 rokov pred
  Oleksandr Korniienko f7d05034be Use pako.js to decompress gzip response. 3 rokov pred
3 zmenil súbory, kde vykonal 30 pridanie a 10 odobranie
  1. 2 0
      package.json
  2. 18 10
      src/components/ValidatorReport/index.tsx
  3. 10 0
      yarn.lock

+ 2 - 0
package.json

@@ -14,6 +14,7 @@
     "d3-timeline-chart": "^1.3.0",
     "htmr": "^0.9.2",
     "interactjs": "^1.10.2",
+    "pako": "^2.0.4",
     "react": "^17.0.1",
     "react-bootstrap": "^1.4.0",
     "react-calendar-timeline": "^0.27.0",
@@ -59,6 +60,7 @@
     "@types/jest": "^26.0.15",
     "@types/node": "^12.0.0",
     "@types/node-fetch": "^2.5.7",
+    "@types/pako": "^1.0.2",
     "@types/react": "^16.9.53",
     "@types/react-bootstrap": "^0.32.25",
     "@types/react-calendar-timeline": "^0.26.3",

+ 18 - 10
src/components/ValidatorReport/index.tsx

@@ -30,6 +30,7 @@ import Alert from "@material-ui/lab/Alert";
 import Tabs from "@material-ui/core/Tabs";
 import Backdrop from "@material-ui/core/Backdrop";
 import "./index.css";
+import pako from "pako";
 import { alternativeBackendApis } from "../../config";
 
 config();
@@ -57,8 +58,8 @@ const useStyles = makeStyles((theme: Theme) =>
   })
 );
 
-const oldChainStatsLocation =
-  "https://joystreamstats.live/static/validators-old-testnet.json";
+const oldChainStatsFileName = "validators-old-testnet.json.gz";
+const oldChainStatsLocation = `https://joystreamstats.live/static/${oldChainStatsFileName}`;
 const ValidatorReport = () => {
   const dateFormat = "yyyy-MM-DD";
   const [oldChainLastDate, setOldChainLastDate] = useState(moment());
@@ -200,6 +201,7 @@ const ValidatorReport = () => {
           };
         });
         setOldChainRows(filteredStats);
+        setError(undefined);
         return;
       }
     }
@@ -209,16 +211,14 @@ const ValidatorReport = () => {
   useEffect(() => {
     setIsLoading(true);
     axios
-      .get(oldChainStatsLocation)
+      .get(oldChainStatsLocation, {
+        responseType: "arraybuffer",
+      })
       .then((response) => {
         try {
-          const oldStats = response.data;
-          setOldChainStats(oldStats as ValidatorsJSResponse);
-          setOldChainLastDate(
-            moment(
-              oldStats.eraStats[oldStats.eraStats.length - 1].timestampEnded
-            )
-          );
+          const binData = new Uint8Array(response.data);
+          const decompressedData = pako.inflate(binData);
+          updateOldChainStats(new TextDecoder().decode(decompressedData));
           setIsLoading(false);
         } catch (err) {
           setIsLoading(false);
@@ -231,6 +231,14 @@ const ValidatorReport = () => {
       });
   }, []);
 
+  const updateOldChainStats = (stringData: string) => {
+    const oldStats = JSON.parse(stringData);
+    setOldChainStats(oldStats as ValidatorsJSResponse);
+    setOldChainLastDate(
+      moment(oldStats.eraStats[oldStats.eraStats.length - 1].timestampEnded)
+    );
+  };
+
   useEffect(() => {
     updateChainState();
     const interval = setInterval(() => {

+ 10 - 0
yarn.lock

@@ -2236,6 +2236,11 @@
   resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
   integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==
 
+"@types/pako@^1.0.2":
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/@types/pako/-/pako-1.0.2.tgz#17c9b136877f33d9ecc8e73cd26944f1f6dd39a1"
+  integrity sha512-8UJl2MjkqqS6ncpLZqRZ5LmGiFBkbYxocD4e4jmBqGvfRG1RS23gKsBQbdtV9O9GvRyjFTiRHRByjSlKCLlmZw==
+
 "@types/parse-json@^4.0.0":
   version "4.0.0"
   resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
@@ -9201,6 +9206,11 @@ p-try@^2.0.0:
   resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
   integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
 
+pako@^2.0.4:
+  version "2.0.4"
+  resolved "https://registry.yarnpkg.com/pako/-/pako-2.0.4.tgz#6cebc4bbb0b6c73b0d5b8d7e8476e2b2fbea576d"
+  integrity sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==
+
 pako@~1.0.5:
   version "1.0.11"
   resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"