From eec04db79b1b16b7bd651ef4705002732c18319c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Wed, 8 Sep 2021 10:23:58 -0700 Subject: [PATCH] Using mock NFT data directly in the useNFTs hook The mock library we are using does not provide mocks in production, which is not suitable for our demo deployment. --- frontend/src/core/hooks/useNFTs.js | 553 +++++++++++++++++++++- frontend/src/core/utils/mockupRequests.js | 7 - 2 files changed, 545 insertions(+), 15 deletions(-) diff --git a/frontend/src/core/hooks/useNFTs.js b/frontend/src/core/hooks/useNFTs.js index c4f3f476..c42ce931 100644 --- a/frontend/src/core/hooks/useNFTs.js +++ b/frontend/src/core/hooks/useNFTs.js @@ -1,9 +1,545 @@ // import { useState, useEffect } from "react"; -import { useQuery } from "react-query"; +// import { useQuery } from "react-query"; import { useToast } from "."; -import { queryCacheProps } from "./hookCommon"; +// import { queryCacheProps } from "./hookCommon"; import { NFTService } from "../services"; +const mockNFTData = [ + { + blocks: { start: 13181704, end: 13181962 }, + num_transactions: "50948", + total_value: "241022031862174906387917", + nft_transfers: "2022", + nft_transfer_value: "942403059693972463051", + nft_mints: "2766", + nft_owners: "1364", + nft_minters: "1150", + crawled_at: "2021-09-08T00:55:05+00:00", + }, + { + blocks: { start: 13181446, end: 13181703 }, + num_transactions: "52954", + total_value: "207182418370549004046724", + nft_transfers: "1980", + nft_transfer_value: "877583632096386630047", + nft_mints: "2990", + nft_owners: "1391", + nft_minters: "1251", + crawled_at: "2021-09-07T23:55:05+00:00", + }, + { + blocks: { start: 13181190, end: 13181445 }, + num_transactions: "49074", + total_value: "174395680204532892975647", + nft_transfers: "1829", + nft_transfer_value: "874456919189834838083", + nft_mints: "3475", + nft_owners: "1325", + nft_minters: "1145", + crawled_at: "2021-09-07T22:55:05+00:00", + }, + { + blocks: { start: 13180923, end: 13181189 }, + num_transactions: "50347", + total_value: "101463678053631944781181", + nft_transfers: "1999", + nft_transfer_value: "1232851126852858147958", + nft_mints: "2497", + nft_owners: "1434", + nft_minters: "952", + crawled_at: "2021-09-07T21:55:05+00:00", + }, + { + blocks: { start: 13180646, end: 13180922 }, + num_transactions: "55180", + total_value: "128170830721180753067997", + nft_transfers: "2417", + nft_transfer_value: "1564323067805430522771", + nft_mints: "2835", + nft_owners: "1722", + nft_minters: "1065", + crawled_at: "2021-09-07T20:55:05+00:00", + }, + { + blocks: { start: 13180379, end: 13180645 }, + num_transactions: "76268", + total_value: "204816607425484093901108", + nft_transfers: "1899", + nft_transfer_value: "2029630831926980621045", + nft_mints: "5763", + nft_owners: "1270", + nft_minters: "2162", + crawled_at: "2021-09-07T19:55:05+00:00", + }, + { + blocks: { start: 13180106, end: 13180378 }, + num_transactions: "60472", + total_value: "220085820865741902985520", + nft_transfers: "1297", + nft_transfer_value: "649027698031354053118", + nft_mints: "2337", + nft_owners: "939", + nft_minters: "1025", + crawled_at: "2021-09-07T18:55:05+00:00", + }, + { + blocks: { start: 13179834, end: 13180105 }, + num_transactions: "55514", + total_value: "191703746402065851187032", + nft_transfers: "1042", + nft_transfer_value: "696200204921465053733", + nft_mints: "4202", + nft_owners: "780", + nft_minters: "1788", + crawled_at: "2021-09-07T17:55:05+00:00", + }, + { + blocks: { start: 13179570, end: 13179833 }, + num_transactions: "58780", + total_value: "363020196834071675848016", + nft_transfers: "1208", + nft_transfer_value: "973175193964789884943", + nft_mints: "583", + nft_owners: "856", + nft_minters: "344", + crawled_at: "2021-09-07T16:55:05+00:00", + }, + { + blocks: { start: 13179281, end: 13179569 }, + num_transactions: "60558", + total_value: "248689092172084061941093", + nft_transfers: "578", + nft_transfer_value: "507856996837230224970", + nft_mints: "195", + nft_owners: "436", + nft_minters: "111", + crawled_at: "2021-09-07T15:55:05+00:00", + }, + { + blocks: { start: 13179016, end: 13179280 }, + num_transactions: "56794", + total_value: "199084095746945845064606", + nft_transfers: "1747", + nft_transfer_value: "842049400356492801488", + nft_mints: "4891", + nft_owners: "1176", + nft_minters: "1582", + crawled_at: "2021-09-07T14:55:05+00:00", + }, + { + blocks: { start: 13178725, end: 13179015 }, + num_transactions: "58196", + total_value: "249411934752143090643459", + nft_transfers: "1972", + nft_transfer_value: "518387685815750412253", + nft_mints: "3697", + nft_owners: "1249", + nft_minters: "1273", + crawled_at: "2021-09-07T13:55:05+00:00", + }, + { + blocks: { start: 13178467, end: 13178724 }, + num_transactions: "51732", + total_value: "68101030497926832895005", + nft_transfers: "1686", + nft_transfer_value: "432588298015676190599", + nft_mints: "1883", + nft_owners: "1100", + nft_minters: "703", + crawled_at: "2021-09-07T12:55:05+00:00", + }, + { + blocks: { start: 13178226, end: 13178466 }, + num_transactions: "52010", + total_value: "108409592266730241225165", + nft_transfers: "1677", + nft_transfer_value: "339185274186028944428", + nft_mints: "2376", + nft_owners: "1059", + nft_minters: "626", + crawled_at: "2021-09-07T11:55:05+00:00", + }, + { + blocks: { start: 13177976, end: 13178225 }, + num_transactions: "52490", + total_value: "76836125679620896451649", + nft_transfers: "1845", + nft_transfer_value: "511573819789226728783", + nft_mints: "1812", + nft_owners: "1047", + nft_minters: "634", + crawled_at: "2021-09-07T10:55:05+00:00", + }, + { + blocks: { start: 13177684, end: 13177976 }, + num_transactions: "61985", + total_value: "134015615879319548574878", + nft_transfers: "2233", + nft_transfer_value: "754993233412464094210", + nft_mints: "2069", + nft_owners: "1132", + nft_minters: "704", + crawled_at: "2021-09-07T09:55:05+00:00", + }, + { + blocks: { start: 13177427, end: 13177683 }, + num_transactions: "56048", + total_value: "206644993645814861818804", + nft_transfers: "1898", + nft_transfer_value: "979828552624793924239", + nft_mints: "3112", + nft_owners: "980", + nft_minters: "895", + crawled_at: "2021-09-07T08:55:05+00:00", + }, + { + blocks: { start: 13177149, end: 13177426 }, + num_transactions: "54733", + total_value: "72658838322186948957060", + nft_transfers: "2247", + nft_transfer_value: "783495596000069563924", + nft_mints: "4037", + nft_owners: "1201", + nft_minters: "1083", + crawled_at: "2021-09-07T07:55:05+00:00", + }, + { + blocks: { start: 13176908, end: 13177149 }, + num_transactions: "46592", + total_value: "41660763354499971677552", + nft_transfers: "2752", + nft_transfer_value: "879215664596479914076", + nft_mints: "2642", + nft_owners: "1520", + nft_minters: "949", + crawled_at: "2021-09-07T06:55:05+00:00", + }, + { + blocks: { start: 13176634, end: 13176907 }, + num_transactions: "45794", + total_value: "54745591236445478514299", + nft_transfers: "3698", + nft_transfer_value: "2071984725894829840381", + nft_mints: "4755", + nft_owners: "1771", + nft_minters: "1177", + crawled_at: "2021-09-07T05:55:05+00:00", + }, + { + blocks: { start: 13176335, end: 13176634 }, + num_transactions: "48339", + total_value: "34580076943804014690670", + nft_transfers: "3161", + nft_transfer_value: "1503873586123293534429", + nft_mints: "9358", + nft_owners: "2041", + nft_minters: "1608", + crawled_at: "2021-09-07T04:55:05+00:00", + }, + { + blocks: { start: 13176082, end: 13176334 }, + num_transactions: "51624", + total_value: "100271882511661789639527", + nft_transfers: "2912", + nft_transfer_value: "1308217856525620870647", + nft_mints: "2877", + nft_owners: "1835", + nft_minters: "1038", + crawled_at: "2021-09-07T03:55:05+00:00", + }, + { + blocks: { start: 13175817, end: 13176081 }, + num_transactions: "59124", + total_value: "73954527121074510509744", + nft_transfers: "2805", + nft_transfer_value: "1059198242209308443202", + nft_mints: "2693", + nft_owners: "1840", + nft_minters: "1046", + crawled_at: "2021-09-07T02:55:05+00:00", + }, + { + blocks: { start: 13175541, end: 13175816 }, + num_transactions: "48799", + total_value: "40610370295940553790122", + nft_transfers: "3002", + nft_transfer_value: "1032200913850188423470", + nft_mints: "4663", + nft_owners: "1937", + nft_minters: "1457", + crawled_at: "2021-09-07T01:55:05+00:00", + }, + { + blocks: { start: 13175283, end: 13175540 }, + num_transactions: "44445", + total_value: "50197045829531087343346", + nft_transfers: "2783", + nft_transfer_value: "1405501547040640273950", + nft_mints: "2693", + nft_owners: "1824", + nft_minters: "1030", + crawled_at: "2021-09-07T00:55:05+00:00", + }, + { + blocks: { start: 13175019, end: 13175282 }, + num_transactions: "46659", + total_value: "157951513775031540091117", + nft_transfers: "3367", + nft_transfer_value: "1303046332608231410239", + nft_mints: "2117", + nft_owners: "2094", + nft_minters: "852", + crawled_at: "2021-09-06T23:55:05+00:00", + }, + { + blocks: { start: 13174717, end: 13175018 }, + num_transactions: "51845", + total_value: "80354960186545743025242", + nft_transfers: "3336", + nft_transfer_value: "1752203206310800762723", + nft_mints: "4151", + nft_owners: "2180", + nft_minters: "1787", + crawled_at: "2021-09-06T22:55:05+00:00", + }, + { + blocks: { start: 13174444, end: 13174716 }, + num_transactions: "49376", + total_value: "41256022243166189414614", + nft_transfers: "2878", + nft_transfer_value: "3229552818145335219691", + nft_mints: "5384", + nft_owners: "1947", + nft_minters: "1707", + crawled_at: "2021-09-06T21:55:05+00:00", + }, + { + blocks: { start: 13174183, end: 13174443 }, + num_transactions: "48701", + total_value: "38888064907905272298331", + nft_transfers: "2337", + nft_transfer_value: "2290757404339594546929", + nft_mints: "7586", + nft_owners: "1647", + nft_minters: "1980", + crawled_at: "2021-09-06T20:55:05+00:00", + }, + { + blocks: { start: 13173943, end: 13174182 }, + num_transactions: "46727", + total_value: "35493685205750738536747", + nft_transfers: "2565", + nft_transfer_value: "1360130971537358011434", + nft_mints: "4454", + nft_owners: "1718", + nft_minters: "1281", + crawled_at: "2021-09-06T19:55:05+00:00", + }, + { + blocks: { start: 13173642, end: 13173942 }, + num_transactions: "55803", + total_value: "69244938272566281474536", + nft_transfers: "2785", + nft_transfer_value: "1301211889276913431758", + nft_mints: "6163", + nft_owners: "1978", + nft_minters: "1818", + crawled_at: "2021-09-06T18:55:05+00:00", + }, + { + blocks: { start: 13173377, end: 13173641 }, + num_transactions: "48340", + total_value: "44804118263697945232838", + nft_transfers: "2712", + nft_transfer_value: "971812805048331059107", + nft_mints: "8350", + nft_owners: "1888", + nft_minters: "1863", + crawled_at: "2021-09-06T17:55:05+00:00", + }, + { + blocks: { start: 13173104, end: 13173376 }, + num_transactions: "52965", + total_value: "65797018380460297552742", + nft_transfers: "2186", + nft_transfer_value: "1020346181484062656949", + nft_mints: "12721", + nft_owners: "1463", + nft_minters: "3402", + crawled_at: "2021-09-06T16:55:05+00:00", + }, + { + blocks: { start: 13172826, end: 13173103 }, + num_transactions: "52430", + total_value: "65630614579255642458633", + nft_transfers: "2282", + nft_transfer_value: "1016712157650744442421", + nft_mints: "5613", + nft_owners: "1538", + nft_minters: "1537", + crawled_at: "2021-09-06T15:55:05+00:00", + }, + { + blocks: { start: 13172551, end: 13172826 }, + num_transactions: "50460", + total_value: "103360858446272814607170", + nft_transfers: "2009", + nft_transfer_value: "946552080764604563360", + nft_mints: "6693", + nft_owners: "1322", + nft_minters: "1515", + crawled_at: "2021-09-06T14:55:05+00:00", + }, + { + blocks: { start: 13172280, end: 13172550 }, + num_transactions: "51195", + total_value: "41652936232169143124615", + nft_transfers: "1854", + nft_transfer_value: "813398196249429235968", + nft_mints: "6766", + nft_owners: "1268", + nft_minters: "1674", + crawled_at: "2021-09-06T13:55:05+00:00", + }, + { + blocks: { start: 13172023, end: 13172279 }, + num_transactions: "51056", + total_value: "70276847687785519463508", + nft_transfers: "1495", + nft_transfer_value: "580621593869308801000", + nft_mints: "3548", + nft_owners: "1034", + nft_minters: "1296", + crawled_at: "2021-09-06T12:55:05+00:00", + }, + { + blocks: { start: 13171739, end: 13172022 }, + num_transactions: "52182", + total_value: "173469321416403061804445", + nft_transfers: "1530", + nft_transfer_value: "447873138689775653533", + nft_mints: "5674", + nft_owners: "989", + nft_minters: "1760", + crawled_at: "2021-09-06T11:55:05+00:00", + }, + { + blocks: { start: 13171485, end: 13171738 }, + num_transactions: "51548", + total_value: "54684393276514744168624", + nft_transfers: "1493", + nft_transfer_value: "456969983426604602884", + nft_mints: "4501", + nft_owners: "951", + nft_minters: "1407", + crawled_at: "2021-09-06T10:55:05+00:00", + }, + { + blocks: { start: 13171228, end: 13171484 }, + num_transactions: "56042", + total_value: "105982195987710377185268", + nft_transfers: "1591", + nft_transfer_value: "651175489188916942816", + nft_mints: "4017", + nft_owners: "1041", + nft_minters: "1390", + crawled_at: "2021-09-06T09:55:05+00:00", + }, + { + blocks: { start: 13170960, end: 13171228 }, + num_transactions: "60457", + total_value: "85426594216823296910357", + nft_transfers: "2055", + nft_transfer_value: "951273578903156304830", + nft_mints: "4505", + nft_owners: "1243", + nft_minters: "1415", + crawled_at: "2021-09-06T08:55:05+00:00", + }, + { + blocks: { start: 13170695, end: 13170959 }, + num_transactions: "51762", + total_value: "62743193024839008221594", + nft_transfers: "2059", + nft_transfer_value: "963285683137949212100", + nft_mints: "5223", + nft_owners: "1353", + nft_minters: "1667", + crawled_at: "2021-09-06T07:55:05+00:00", + }, + { + blocks: { start: 13170453, end: 13170694 }, + num_transactions: "44853", + total_value: "100051981481380571202377", + nft_transfers: "2356", + nft_transfer_value: "1054496920004418389557", + nft_mints: "4341", + nft_owners: "1453", + nft_minters: "1514", + crawled_at: "2021-09-06T06:55:05+00:00", + }, + { + blocks: { start: 13170166, end: 13170452 }, + num_transactions: "49665", + total_value: "38362697113388905603045", + nft_transfers: "2816", + nft_transfer_value: "1051917506064317130051", + nft_mints: "5809", + nft_owners: "1743", + nft_minters: "1979", + crawled_at: "2021-09-06T05:55:05+00:00", + }, + { + blocks: { start: 13169920, end: 13170165 }, + num_transactions: "46428", + total_value: "74223363921118152102274", + nft_transfers: "2499", + nft_transfer_value: "1003679401746848756030", + nft_mints: "4783", + nft_owners: "1631", + nft_minters: "1815", + crawled_at: "2021-09-06T04:55:05+00:00", + }, + { + blocks: { start: 13169645, end: 13169920 }, + num_transactions: "48961", + total_value: "90137680123315536785953", + nft_transfers: "2922", + nft_transfer_value: "1181791574401383381509", + nft_mints: "5176", + nft_owners: "1920", + nft_minters: "1945", + crawled_at: "2021-09-06T03:55:05+00:00", + }, + { + blocks: { start: 13169363, end: 13169644 }, + num_transactions: "48622", + total_value: "89695682424995800328932", + nft_transfers: "2147", + nft_transfer_value: "830598403566103512083", + nft_mints: "12984", + nft_owners: "1458", + nft_minters: "3384", + crawled_at: "2021-09-06T02:55:05+00:00", + }, + { + blocks: { start: 13169111, end: 13169362 }, + num_transactions: "43234", + total_value: "79096083842192736950337", + nft_transfers: "2815", + nft_transfer_value: "1037005383694608747671", + nft_mints: "5952", + nft_owners: "1784", + nft_minters: "1638", + crawled_at: "2021-09-06T01:55:05+00:00", + }, +]; + +const mockNFTCache = { + data: mockNFTData, + isLoading: false, +}; + const useNFTs = (query) => { const toast = useToast(); @@ -12,12 +548,13 @@ const useNFTs = (query) => { return response.data.data; }; - const nftCache = useQuery(["NFTs", query], getNFTStats, { - ...queryCacheProps, - onError: (error) => { - toast(error, "error"); - }, - }); + // const nftCache = useQuery(["NFTs", query], getNFTStats, { + // ...queryCacheProps, + // onError: (error) => { + // toast(error, "error"); + // }, + // }); + const nftCache = mockNFTCache; return { nftCache, }; diff --git a/frontend/src/core/utils/mockupRequests.js b/frontend/src/core/utils/mockupRequests.js index 38008d4b..3a61d6f5 100644 --- a/frontend/src/core/utils/mockupRequests.js +++ b/frontend/src/core/utils/mockupRequests.js @@ -1,6 +1,4 @@ import moment from "moment"; -import nftData from "./mockData"; -const MOCK_API = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL; var MockAdapter = require("axios-mock-adapter"); export const makeid = (length) => { var result = ""; @@ -98,11 +96,6 @@ export let MockSubscriptions = [ const enableMockupRequests = (axiosInstance) => { let mock = new MockAdapter(axiosInstance, { onNoMatch: "passthrough" }); - //assume all currency units are in wei - mock.onGet(`${MOCK_API}/nft`).reply(200, { - data: [...nftData], - }); - // mock.onGet(`${MOCK_API}/subscription_types/`).reply(200, { // data: [ // {