Skip to content

Commit

Permalink
push to prod
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaaiden committed Jun 18, 2023
1 parent d374885 commit c83f8d1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REACT_APP_FIREBASE_API_KEY=AIzaSyDTRY5WPQm0v26OuJDvkZ-FwDiPMtoIg_U
REACT_APP_FIREBASE_AUTH_DOMAIN=indexsc-80164.firebaseapp.com
REACT_APP_FIREBASE_PROJECT_ID=indexsc-80164
REACT_APP_FIREBASE_STORAGE_BUCKET=indexsc-80164.appspot.com
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=450893406130
REACT_APP_FIREBASE_APP_ID=1:450893406130:web:5326cc19258ad6e83f8eab
REACT_APP_FIREBASE_MEASUREMENT_ID=G-NN253G450K
REACT_APP_FIREBASE_DATABASE_URL=https://indexsc-80164-default-rtdb.firebaseio.com/
45 changes: 41 additions & 4 deletions src/components/Content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Link } from "react-router-dom";
import {
doc,
getDoc,
// onSnapshot,
query,
collection,
where,
getDocs,
deleteDoc,
arrayRemove,
updateDoc,
} from "firebase/firestore";
import { db as fsDatabase } from "../firebase/config";
import { v4 as uuid4 } from "uuid";
Expand All @@ -20,18 +26,44 @@ import Tippy from "@tippyjs/react";
import "tippy.js/dist/tippy.css"; // optional for styling
import "tippy.js/themes/light-border.css";

const deleteContract = async (contractTimestamp, userId, setKey) => {
// console.log("deleteContract", contractId);
const contractRef = query(
collection(fsDatabase, "contracts"),
where("timestamp", "==", contractTimestamp)
);

const contractSnapshot = await getDocs(contractRef);
contractSnapshot.forEach(async (doc) => {
await deleteDoc(doc.ref);
});

// remove from smart_contracts array
const userRef = doc(fsDatabase, "users", userId);
await updateDoc(userRef, {
smart_contracts: arrayRemove(contractSnapshot.docs[0].id),
});
setKey(uuid4());
};

const Content = ({ userData, searchQuery }) => {
// console.log('userData', userData);
const [contracts, setContracts] = useState([]);
const [contractsLoaded, setContractsLoaded] = useState(false);
const [key, setKey] = useState(0);

// console.log('contracts', contracts);
useEffect(() => {
const fetchContracts = async () => {
if (userData === null) {
return;
}
const contractIds = userData.smart_contracts;

//refetch smart_contracts
const userRef = doc(fsDatabase, "users", userData.uid);
const userSnap = await getDoc(userRef);
const userData2 = userSnap.data();
const contractIds = userData2.smart_contracts;
// console.log('contractIds', contractIds);
const contract = contractIds.map(async (contractId) => {
const getSc = await getDoc(doc(fsDatabase, "contracts", contractId));
Expand All @@ -52,7 +84,7 @@ const Content = ({ userData, searchQuery }) => {
setContractsLoaded(true);
};
fetchContracts();
}, [userData]);
}, [userData, key]);

// filter contracts based on searchQuery on contract.name and contract.address
useEffect(() => {
Expand Down Expand Up @@ -388,8 +420,13 @@ const Content = ({ userData, searchQuery }) => {
} flex items-center w-full px-4 py-2 text-sm`}
onClick={() => {
console.log("Delete clicked");
// delete firestore item based on timestamp
deleteContract(
contract.timestamp,
userData.uid,
setKey
);
}}
disabled
>
<TrashIcon className="w-5 h-5 mr-2" />
Delete
Expand Down
22 changes: 10 additions & 12 deletions src/firebase/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getDatabase } from "firebase/database";


const firebaseConfig = {
apiKey: 'AIzaSyDTRY5WPQm0v26OuJDvkZ-FwDiPMtoIg_U',
authDomain: 'indexsc-80164.firebaseapp.com',
projectId: 'indexsc-80164',
storageBucket: 'indexsc-80164.appspot.com',
messagingSenderId: '450893406130',
appId: '1:450893406130:web:5326cc19258ad6e83f8eab',
measurementId: 'G-NN253G450K',
databaseURL: "https://indexsc-80164-default-rtdb.firebaseio.com/"
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
};

// Initialize Firebase
Expand Down
8 changes: 4 additions & 4 deletions src/pages/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export const Homepage = () => {
</h1>
{/* <br /> */}
<p className="mt-3 text-gray-500 md:text-lg">
Smoldata is Zero-ETL platform that delivers fast and simple
indexing for smart contracts. Replace time-consuming ETL processes
with direct data transfers between systems, and asynchronously
update your databases and API endpoints in real-time.
Smoldata is a platform that enables quick and easy indexing for
smart contracts, eliminating the need for time-consuming ETL
processes. It simplifies the process of ingesting smart contract
data with minimal alterations and transformations.
</p>
<form action="#" className="mt-8 sm:max-w-lg sm:w-full sm:flex">
<div className="">
Expand Down
42 changes: 38 additions & 4 deletions src/pages/smart-contracts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types"; // ES6
import { Link } from "react-router-dom";
import { doc, getDoc } from "firebase/firestore";
import {
doc,
getDoc,
query,
getDocs,
collection,
where,
updateDoc,
arrayRemove,
deleteDoc,
} from "firebase/firestore";
import { db as fsDatabase } from "../firebase/config";
import { v4 as uuid4 } from "uuid";
import { Menu, Transition } from "@headlessui/react";
Expand Down Expand Up @@ -30,6 +40,7 @@ const SmartContracts = ({ searchQuery }) => {
const [userData, setUserData] = useState(null);
const { user, loading } = useContext(AuthContext);
const [filteredContracts, setFilteredContracts] = useState(contracts);
const [key, setKey] = useState(0);

useEffect(() => {
const fetchContracts = async () => {
Expand Down Expand Up @@ -59,7 +70,7 @@ const SmartContracts = ({ searchQuery }) => {
};
fetchContracts();
setContractsLoaded(true);
}, [userData]);
}, [userData, key]);

useEffect(() => {
// console.log("searchQuery", searchQuery, contracts);
Expand All @@ -78,6 +89,25 @@ const SmartContracts = ({ searchQuery }) => {
// setContracts(filteredContracts);
}, [searchQuery, contractsLoaded]);

const deleteContract = async (contractTimestamp, userId, setKey) => {
// console.log("deleteContract", contractId);
const contractRef = query(
collection(fsDatabase, "contracts"),
where("timestamp", "==", contractTimestamp)
);

const contractSnapshot = await getDocs(contractRef);
contractSnapshot.forEach(async (doc) => {
await deleteDoc(doc.ref);
});

// remove from smart_contracts array
const userRef = doc(fsDatabase, "users", userId);
await updateDoc(userRef, {
smart_contracts: arrayRemove(contractSnapshot.docs[0].id),
});
setKey(uuid4());
};
if (loading && !user) {
// console.log('Dashboard loading', loading, user);
return (
Expand Down Expand Up @@ -239,7 +269,7 @@ const SmartContracts = ({ searchQuery }) => {
</h2>
<div className="flex gap-2 text-right">
<Link
to="addContract"
to="/dashboard/addContract"
className="link hover:!no-underline !no-underline"
>
Add new contract
Expand Down Expand Up @@ -387,7 +417,11 @@ const SmartContracts = ({ searchQuery }) => {
: "text-gray-700"
} flex items-center w-full px-4 py-2 text-sm`}
onClick={() => {
console.log("Delete clicked");
deleteContract(
contract.timestamp,
contract.id,
setKey
);
}}
>
<TrashIcon className="w-5 h-5 mr-2" />
Expand Down

1 comment on commit c83f8d1

@vercel
Copy link

@vercel vercel bot commented on c83f8d1 Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.