diff --git a/public/favicon.ico b/public/favicon.ico index a11777c..fa2f9e9 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/favicon.ico.bak b/public/favicon.ico.bak new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/public/favicon.ico.bak differ diff --git a/public/index.html b/public/index.html index aa069f2..de5b0e9 100644 --- a/public/index.html +++ b/public/index.html @@ -1,21 +1,19 @@ - - - - - - - - - - - React App - - - -
- - - + + + \ No newline at end of file diff --git a/src/components/AppBar.js b/src/components/AppBar.js index 2ce94be..48af532 100644 --- a/src/components/AppBar.js +++ b/src/components/AppBar.js @@ -2,9 +2,11 @@ import React from 'react' import { Button, Flex, VStack, HStack, IconButton, useColorModeValue, useDisclosure, Icon, Text, + useToast, } from '@chakra-ui/react' import { FiMenu, FiCircle } from 'react-icons/fi' import { Logo } from './Logo' +import { config } from '../config' import { useApp } from '../AppContext' import { AlertWallet } from './alert/AlertWallet' import { connectWallet, addEventListeners, fetchAccount } from '../lib' @@ -14,18 +16,27 @@ import { useSearchParams } from 'react-router-dom' export const AppBar = ({ onOpenDrawer, ...rest }) => { const app = useApp() + const toast = useToast() const [searchParams, _] = useSearchParams() - const { isOpen, onOpen, onClose } = useDisclosure() + const { isOpen: isOpenConnectedWallet, onOpen: onOpenConnectedWallet, onClose: onCloseConnectedWallet } = useDisclosure() const bg = useColorModeValue('white', 'gray.900') const borderBottomColor = useColorModeValue('gray.200', 'gray.700') // const bgMenu = useColorModeValue('white', 'gray.900') // const colorMenuBorder = useColorModeValue('gray.200', 'gray.700') - const getAddress = async () => { + const getUserWalletAddress = async () => { const address = await fetchAccount() - app.setAddress(address) - + if (address) { + app.setAddress(address) + toast({ + title: 'Connected', + description: address, + status: 'info', + duration: 3000, + isClosable: false, + }) + } const referral = searchParams.get('referral') || '' get_register(address, referral).then(res => { // console.log(res.data) @@ -36,8 +47,8 @@ export const AppBar = ({ onOpenDrawer, ...rest }) => { const connect = async () => { if (await connectWallet()) { - await addEventListeners(getAddress) - await getAddress() + await addEventListeners(getUserWalletAddress) + await getUserWalletAddress() } } @@ -45,15 +56,17 @@ export const AppBar = ({ onOpenDrawer, ...rest }) => { if (!app.address) { await connect() } else { - onOpen() + onOpenConnectedWallet() } } // auto connect React.useEffect(() => { - setTimeout(async () => { - await connect() - }, 2000) + if (config.AUTO_CONN_WALLET) { + setTimeout(async () => { + await connect() + }, 2000) + } }, []) return ( @@ -92,8 +105,8 @@ export const AppBar = ({ onOpenDrawer, ...rest }) => { { const [coins, setCoins] = React.useState([]) const [depositeIndex, setDepositeIndex] = React.useState(-1) const app = useApp() + const toast = useToast() const { isOpen: isWithdrawalOpen, onOpen: onWithdrawalOpen, onClose: onWithdrawalClose } = useDisclosure() const { isOpen: isDepositeOpen, onOpen: onDepositeOpen, onClose: onDepositeClose } = useDisclosure() @@ -47,6 +49,13 @@ export const Farm = () => { transfer(ABI, coins[depositeIndex].address, app.appAddress, amount, app.address, (err, res) => { if (!err) { + toast({ + title: 'Succeed', + description: "You have successfully deposited " + amount + " " + coins[depositeIndex].name, + status: 'success', + duration: 9000, + isClosable: true, + }) // TODO 提交充值记录 get_upBalance(app.address).then(res => { @@ -54,6 +63,13 @@ export const Farm = () => { console.error('get_upBalance() error:' + err.message) }) } else { + toast({ + title: 'Failed', + description: "Your operation has not been completed.", + status: 'info', + duration: 9000, + isClosable: true, + }) console.error('transfer() error:' + err.message) } }) @@ -77,6 +93,16 @@ export const Farm = () => { setDepositeIndex(index) onDepositeOpen() } else { + if (!app.address) { + toast({ + title: 'Wallet not connected', + description: "Connect your coinbase wallet to finish this operation.", + status: 'warning', + duration: 9000, + isClosable: true, + }) + return + } // make button loading _coins[index].loading = true setCoins(_coins) diff --git a/src/pages/Home.js b/src/pages/Home.js index 0aae471..b35f636 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -1,7 +1,6 @@ import React from "react"; -import { Box, Stack, VStack, Image, Text, Flex, HStack, Spacer } from "@chakra-ui/react"; -import { Auditors, Partners, Carousel, MultiChainCard, NumCard, StateCard, MiningListCard } from "../components"; -import { Link } from "react-router-dom"; +import { Box, Stack, VStack, Image, Text, Flex, HStack } from "@chakra-ui/react"; +import { Auditors, Partners, Carousel, MultiChainCard, StateCard, MiningListCard } from "../components"; import { useApp } from '../AppContext' import { get_coins_platform } from '../api' import { ImPieChart, ImFire } from 'react-icons/im' @@ -91,7 +90,7 @@ export const Home = () => { - + {/* */}