Skip to content

Commit

Permalink
Fix web3 state && reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Akim Mamedov committed Feb 23, 2024
1 parent 1d0fc23 commit 4c314bc
Show file tree
Hide file tree
Showing 94 changed files with 3,974 additions and 3,500 deletions.
5 changes: 2 additions & 3 deletions web/.github/workflows/tg-bot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: telegram message
on: [push]
jobs:

build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -14,7 +13,7 @@ jobs:
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
Repository: ${{ github.repository }}
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
1 change: 1 addition & 0 deletions web/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 10 additions & 11 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
- Landing - 1 - Route "/fluence"
- Claiming flow 1 - Route "/"
- Claiming flow 2 - Route "/wallet"
- Claiming flow 14 - Route "/proof"
- Claiming flow 8 - Route "/delegation"
- Claiming flow 9 - Route "/done"
- Claiming flow 10 - Route "/finish"
- Claiming flow 11 - Route "/not-found"
- Claiming flow 12 - Route "/claimed"


* Landing - 1 - Route "/fluence"
* Claiming flow 1 - Route "/"
* Claiming flow 2 - Route "/wallet"
* Claiming flow 14 - Route "/proof"
* Claiming flow 8 - Route "/delegation"
* Claiming flow 9 - Route "/done"
* Claiming flow 10 - Route "/finish"
* Claiming flow 11 - Route "/not-found"
* Claiming flow 12 - Route "/claimed"
#
Deploy on GH Pages - https://nsvdev.github.io/fluence/#/fluence

Deploy on GH Pages - https://nsvdev.github.io/fluence/#/fluence
22 changes: 22 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"http": "npm:stream-http@^3.2.0",
"https": "npm:https-browserify@^1.0.0",
"os": "npm:os-browserify@^0.3.0",
"prettier": "^3.2.5",
"stream": "npm:stream-browserify@^3.0.0",
"url": "^0.11.3",
"utils": "^0.3.1"
Expand Down
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
6 changes: 3 additions & 3 deletions web/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import App from './App';
import { render, screen } from "@testing-library/react";
import App from "./App";

test('renders learn react link', () => {
test("renders learn react link", () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
Expand Down
4 changes: 0 additions & 4 deletions web/src/components/App/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
.App {



}

144 changes: 74 additions & 70 deletions web/src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { memo, useEffect, useState } from 'react';
import {
Navigate,
Route,
Routes,
useLocation,
useNavigate,
} from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { memo, useEffect, useState } from "react";

import './App.css';
import 'react-toastify/dist/ReactToastify.css';
import "./App.css";
import "react-toastify/dist/ReactToastify.css";

import PageBegin from '../../pages/begin-page/begin-page';
import FirstStepPage from '../../pages/step1-page/step1-page';
import ProofPage from '../../pages/proof-page/proof-page';
import DonePage from '../../pages/done-page/done-page';
import ClaimedPage from '../../pages/claimed-page/claimed-page';
import AccountNotFound from '../../pages/not-found-account-page/not-found-account-page';
import FinishPage from '../../pages/finish-page/finish-page';
import ConnectWallet from '../ConnectWallet/ConnectWallet';
import { toast, ToastContainer } from 'react-toastify';
import { useWeb3Connection } from '../../hooks/useWeb3Connection';
import { reduxCleanup } from '../../store/actions/common';
import PageBegin from "../../pages/begin-page/begin-page";
import FirstStepPage from "../../pages/step1-page/step1-page";
import ProofPage from "../../pages/proof-page/proof-page";
import DonePage from "../../pages/done-page/done-page";
import ClaimedPage from "../../pages/claimed-page/claimed-page";
import AccountNotFound from "../../pages/not-found-account-page/not-found-account-page";
import FinishPage from "../../pages/finish-page/finish-page";
import ConnectWallet from "../ConnectWallet/ConnectWallet";
import { toast, ToastContainer } from "react-toastify";
import { useWeb3Connection } from "../../hooks/useWeb3Connection";
import { reduxCleanup } from "../../store/actions/common";
import {
ROUTE_CLAIMED,
ROUTE_CONNECT,
Expand All @@ -24,53 +30,54 @@ import {
ROUTE_INDEX,
ROUTE_NOT_FOUND,
ROUTE_PROOF,
ROUTE_WALLET
} from '../../constants/routes'
import { catchError } from '../../utils';
import { setCurrentRoute } from '../../store/actions/routes';
import { fetchCurrentAward, fetchMerkleRoot, fetchNextHalvePeriod } from '../../store/actions/distributor';
import { useVh } from '../../hooks/useVh';
ROUTE_WALLET,
} from "../../constants/routes";
import { catchError } from "../../utils";
import { setCurrentRoute } from "../../store/actions/routes";
import {
fetchCurrentAward,
fetchMerkleRoot,
fetchNextHalvePeriod,
} from "../../store/actions/distributor";
import { useVh } from "../../hooks/useVh";

function App() {
const { network, address } = useWeb3Connection()
const { network, address } = useWeb3Connection();

const dispatch = useDispatch()
const navigate = useNavigate()
const { error } = useSelector(state => state.error)
const dispatch = useDispatch();
const navigate = useNavigate();
const { error } = useSelector((state) => state.error);
const [prevAddress, setPrevAddress] = useState(null);
const { username } = useSelector(state => state.user)
const { currentRoute } = useSelector(state => state.routes)
const location = useLocation()
const [locationPut, setLocationPut] = useState(false)
const [merkleRootFetched, setMerkleRootFetched] = useState(false)
const { username } = useSelector((state) => state.user);
const { currentRoute } = useSelector((state) => state.routes);
const location = useLocation();
const [locationPut, setLocationPut] = useState(false);
const [merkleRootFetched, setMerkleRootFetched] = useState(false);

useVh()
useVh();
useEffect(() => {
if (currentRoute
&& !locationPut
&& currentRoute !== location.pathname
) {
navigate(currentRoute)
setLocationPut(true)
if (currentRoute && !locationPut && currentRoute !== location.pathname) {
navigate(currentRoute);
setLocationPut(true);
}
}, [currentRoute])
}, [currentRoute]);

useEffect(() => {
console.log("nerwork: " + network.name)
console.log("nerwork: " + network.name);
if (!merkleRootFetched && network?.name && network.name !== "unknown") {
dispatch(fetchMerkleRoot(network.name))
dispatch(fetchCurrentAward(network.name))
dispatch(fetchNextHalvePeriod(network.name))
setMerkleRootFetched(true)
}
}, [network])
dispatch(fetchMerkleRoot(network.name));
dispatch(fetchCurrentAward(network.name));
dispatch(fetchNextHalvePeriod(network.name));
setMerkleRootFetched(true);
}
}, [network]);

useEffect(() => {
if (address) {
if (prevAddress && address !== prevAddress) {
dispatch(reduxCleanup())
navigate(ROUTE_INDEX)
dispatch(setCurrentRoute(ROUTE_INDEX))
dispatch(reduxCleanup());
navigate(ROUTE_INDEX);
dispatch(setCurrentRoute(ROUTE_INDEX));
} else if (!address && username) {
navigate(ROUTE_WALLET);
} else {
Expand All @@ -80,34 +87,31 @@ function App() {
}, [address, prevAddress]);

useEffect(() => {
window.scrollTo(0, 0)
dispatch(setCurrentRoute(location.pathname))
window.scrollTo(0, 0);
dispatch(setCurrentRoute(location.pathname));
}, [location]);

useEffect(() => {
if (error) {
toast(catchError(error, true))
toast(catchError(error, true));
}
}, [error])
}, [error]);

return (
<div className="App">
<ToastContainer autoClose={false}/>
<Routes>
<Route exact path={ROUTE_INDEX} element={<PageBegin/>}/>
<Route exact path={ROUTE_WALLET} element={<FirstStepPage/>}/>
<Route exact path={ROUTE_CONNECT} element={<ConnectWallet/>}/>
<Route exact path={ROUTE_PROOF} element={<ProofPage/>}/>
<Route exact path={ROUTE_DONE} element={<DonePage/>}/>
<Route exact path={ROUTE_FINISH} element={<FinishPage/>}/>
<Route exact path={ROUTE_NOT_FOUND} element={<AccountNotFound/>}/>
<Route exact path={ROUTE_CLAIMED} element={<ClaimedPage/>}/>
<Route
path="*"
element={<Navigate to="/"/>}
/>
</Routes>
</div>
<div className="App">
<ToastContainer autoClose={false} />
<Routes>
<Route exact path={ROUTE_INDEX} element={<PageBegin />} />
<Route exact path={ROUTE_WALLET} element={<FirstStepPage />} />
<Route exact path={ROUTE_CONNECT} element={<ConnectWallet />} />
<Route exact path={ROUTE_PROOF} element={<ProofPage />} />
<Route exact path={ROUTE_DONE} element={<DonePage />} />
<Route exact path={ROUTE_FINISH} element={<FinishPage />} />
<Route exact path={ROUTE_NOT_FOUND} element={<AccountNotFound />} />
<Route exact path={ROUTE_CLAIMED} element={<ClaimedPage />} />
<Route path="*" element={<Navigate to="/" />} />
</Routes>
</div>
);
}

Expand Down
Loading

0 comments on commit 4c314bc

Please sign in to comment.