import React, { useState, useEffect } from 'react';
import { withRouter } from "react-router-dom";
import ReactTooltip from "react-tooltip";
import { AccountType, Environment, Network, Role, ContractState } from '../util/enum';
import DisclaimerModal from './disclaimer';
import SsnTable from './ssn-table';
import Footer from './footer';
import WalletKeystore from './wallet-keystore';
import WalletLedger from './wallet-ledger';
import WalletZilPay from './wallet-zilpay';
import IconKeystoreLine from './icons/keystore-line';
import IconLedgerLine from './icons/ledger-line';
import IconZilPayLine from './icons/zil-pay-line';
import IconSun from './icons/sun';
import IconMoon from './icons/moon';
import ZillionLogo from '../static/zillion.svg';
import ZillionLightLogo from '../static/light/zillion.svg';
import LandingStatsTable from './landing-stats-table';
import AvelyLogo from '../static/avely.svg'
import IgniteLogo from '../static/ignite_dao.png'
import useDarkMode from '../util/use-dark-mode';
import { ToastContainer } from 'react-toastify';
import IconSearch from './icons/search';
import WarningBanner from './warning-banner';
import RewardCountdownTable from './reward-countdown-table';
import { useAppDispatch, useAppSelector } from '../store/hooks';
import { getEnvironment } from '../util/config-json-helper';
import { QUERY_AND_UPDATE_STAKING_STATS } from '../store/stakingSlice';
import { logger } from '../util/logger';
import { INIT_USER, QUERY_AND_UPDATE_USER_STATS, UPDATE_LEDGER_INDEX } from '../store/userSlice';
import { ZilSigner } from '../zilliqa-signer';
function Home(props: any) {
const dispatch = useAppDispatch();
const chainInfo = useAppSelector(state => state.blockchain);
// config.js from public folder
const env = getEnvironment();
const [isDirectDashboard, setIsDirectDashboard] = useState(false);
const [isShowAccessMethod, setShowAccessMethod] = useState(false);
const [explorerSearchAddress, setExplorerSearchAddress] = useState('');
const [role, setRole] = useState('');
const [accessMethod, setAccessMethod] = useState('');
const [selectedNetwork, setSelectedNetwork] = useState(() => {
if (env === Environment.PROD) {
return Network.MAINNET;
} else {
// default to testnet
return Network.TESTNET;
}
});
const darkMode = useDarkMode(true);
// trigger show wallets to choose
const resetWalletsClicked = () => {
setAccessMethod('');
setIsDirectDashboard(false);
}
const timeout = (delay: number) => {
return new Promise(res => setTimeout(res, delay));
}
const redirectToDashboard = async (addressBase16: string, addressBech32: string, accountType: AccountType, ledgerIndex?: number) => {
// login success
// update store and signer network
dispatch(INIT_USER({ address_base16: addressBase16, address_bech32: addressBech32, account_type: accountType, authenticated: true, selected_role: role }));
dispatch(QUERY_AND_UPDATE_USER_STATS());
await ZilSigner.changeNetwork(chainInfo.blockchain);
if (accountType === AccountType.LEDGER && typeof (ledgerIndex) !== 'undefined') {
// update ledger index to store if using ledger
dispatch(UPDATE_LEDGER_INDEX({ ledger_index: ledgerIndex }));
}
// add some delay
await timeout(1000);
logger("directing to dashboard");
props.history.push("/dashboard");
}
const handleAccessMethod = (access: string) => {
setAccessMethod(access);
}
const handleShowAccessMethod = (selectedRole: string) => {
setRole(selectedRole);
setShowAccessMethod(true);
}
const toggleDirectToDashboard = () => {
setIsDirectDashboard(true);
}
const resetView = () => {
setRole('');
setShowAccessMethod(false);
setAccessMethod('');
}
const DisplayAccessMethod = () => {
switch (accessMethod) {
case AccountType.KEYSTORE:
return
Staking with Zilliqa. Simplified!
Please refer to our Staking Viewer for more information on the nodes' statuses.
Connect your wallet to start