From c95662e8dccc4aeb5ef1d8e8807392a90d360928 Mon Sep 17 00:00:00 2001 From: Tim Pechersky Date: Wed, 10 Nov 2021 15:30:29 +0000 Subject: [PATCH] can upload and get dashboard --- frontend/src/components/NewDashboard.js | 187 ++++++++++++++++-- frontend/src/components/Sidebar.js | 2 + frontend/src/core/hooks/useDashboard.js | 35 ++++ .../core/providers/OverlayProvider/index.js | 44 ++++- .../src/core/services/dashboard.service.js | 18 ++ frontend/src/core/services/index.js | 2 + 6 files changed, 268 insertions(+), 20 deletions(-) create mode 100644 frontend/src/core/hooks/useDashboard.js create mode 100644 frontend/src/core/services/dashboard.service.js diff --git a/frontend/src/components/NewDashboard.js b/frontend/src/components/NewDashboard.js index 8445e711..5e303ae3 100644 --- a/frontend/src/components/NewDashboard.js +++ b/frontend/src/components/NewDashboard.js @@ -39,9 +39,21 @@ const NewDashboard = (props) => { subscriptions: [ { label: "", - id: null, + abi: false, + subscription_id: null, isMethods: false, isEvents: false, + generic: { + transactions: { + in: false, + out: false, + }, + value: { + in: false, + out: false, + balance: false, + }, + }, }, ], } @@ -99,20 +111,54 @@ const NewDashboard = (props) => { // borderWidth="1px" variant="simple" colorScheme="blue" - justifyContent="center" + // justifyContent="center" + textAlign="center" borderBottomRadius="xl" - alignItems="baseline" + // alignItems="baseline" h="auto" size="sm" mt={0} > - Address - ABI State - Methods - Events - + Address + + ABI + + + + Transactions + + + Value + + + + + + ABI + + + Methods + + + Events + + + In + + + Out + + + In + + + Out + + + Balance + @@ -127,7 +173,25 @@ const NewDashboard = (props) => { { const newState = { ...newDashboardForm }; - newState.subscriptions[idx] = selectedItem; + newState.subscriptions[idx] = { + label: selectedItem.label, + address: selectedItem.address, + subscription_id: selectedItem.id, + abi: selectedItem.abi, + isMethods: false, + isEvents: false, + generic: { + transactions: { + in: false, + out: false, + }, + value: { + in: false, + out: false, + balance: false, + }, + }, + }; setNewDashboardForm(newState); }} // isOpen={showSuggestions} @@ -382,7 +446,7 @@ const NewDashboard = (props) => { // )} - + {subscibedItem.abi && subscibedItem.address && ( )} @@ -404,24 +468,100 @@ const NewDashboard = (props) => { )} - + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx] = { + ...newState.subscriptions[idx], + isMethods: !newState.subscriptions[idx].isMethods, + }; + setNewDashboardForm(newState); + }} isChecked={subscibedItem.isMethods} > - + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx] = { + ...newState.subscriptions[idx], + isEvents: !newState.subscriptions[idx].isEvents, + }; + setNewDashboardForm(newState); + }} isChecked={subscibedItem.isEvents} > + + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx].generic.transactions.in = + !newState.subscriptions[idx].generic.transactions + .in; + setNewDashboardForm(newState); + }} + isChecked={subscibedItem.generic.transactions.in} + > + + + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx].generic.transactions.out = + !newState.subscriptions[idx].generic.transactions + .out; + setNewDashboardForm(newState); + }} + isChecked={subscibedItem.generic.transactions.out} + > + + + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx].generic.value.in = + !newState.subscriptions[idx].generic.value.in; + setNewDashboardForm(newState); + }} + isChecked={subscibedItem.generic.value.in} + > + + + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx].generic.value.out = + !newState.subscriptions[idx].generic.value.out; + setNewDashboardForm(newState); + }} + isChecked={subscibedItem.generic.value.out} + > + + + { + const newState = { ...newDashboardForm }; + newState.subscriptions[idx].generic.balance = + !newState.subscriptions[idx].generic.balance; + setNewDashboardForm(newState); + }} + isChecked={subscibedItem.generic.balance} + > + - + {idx > 0 && ( { @@ -456,8 +596,21 @@ const NewDashboard = (props) => { const newState = { ...newDashboardForm }; newState.subscriptions.push({ label: "", - id: null, + abi: false, + subscription_id: null, isMethods: false, + isEvents: false, + generic: { + transactions: { + in: false, + out: false, + }, + value: { + in: false, + out: false, + balance: false, + }, + }, }); setNewDashboardForm(newState); }} diff --git a/frontend/src/components/Sidebar.js b/frontend/src/components/Sidebar.js index a2f9e8aa..a1d0af37 100644 --- a/frontend/src/components/Sidebar.js +++ b/frontend/src/components/Sidebar.js @@ -21,9 +21,11 @@ import { MdSettings } from "react-icons/md"; import { HiAcademicCap } from "react-icons/hi"; import { WHITE_LOGO_W_TEXT_URL } from "../core/constants"; import { MODAL_TYPES } from "../core/providers/OverlayProvider/constants"; +import useDashboard from "../core/hooks/useDashboard"; const Sidebar = () => { const ui = useContext(UIContext); + const { dashboardsListCache } = useDashboard(); return ( { + const toast = useToast(); + const { user } = useContext(UserContext); + const createDashboard = useMutation(DashboardService.createDashboard, { + onSuccess: () => { + toast("Created new dashboard", "success"); + }, + onError: (error) => { + toast(error.error, "error", "Fail"); + }, + }); + + const dashboardsListCache = useQuery( + ["dashboards-list"], + DashboardService.getDashboardsList, + { + ...queryCacheProps, + onError: (error) => { + toast(error, "error"); + }, + enabled: !!user, + } + ); + + return { createDashboard, dashboardsListCache }; +}; + +export default useDashboard; diff --git a/frontend/src/core/providers/OverlayProvider/index.js b/frontend/src/core/providers/OverlayProvider/index.js index 621ccb23..a5059f3d 100644 --- a/frontend/src/core/providers/OverlayProvider/index.js +++ b/frontend/src/core/providers/OverlayProvider/index.js @@ -28,6 +28,7 @@ import { } from "@chakra-ui/react"; import UserContext from "../UserProvider/context"; import UIContext from "../UIProvider/context"; +import useDashboard from "../../hooks/useDashboard"; const ForgotPassword = React.lazy(() => import("../../../components/ForgotPassword") ); @@ -43,6 +44,7 @@ const NewSubscription = React.lazy(() => const UploadABI = React.lazy(() => import("../../../components/UploadABI")); const OverlayProvider = ({ children }) => { + const { createDashboard } = useDashboard(); const ui = useContext(UIContext); const { user } = useContext(UserContext); const [modal, toggleModal] = useState({ @@ -227,15 +229,51 @@ const OverlayProvider = ({ children }) => {