diff --git a/src/components/FarmCoinCard.js b/src/components/FarmCoinCard.js index f536d5f..ce633ab 100644 --- a/src/components/FarmCoinCard.js +++ b/src/components/FarmCoinCard.js @@ -20,7 +20,7 @@ const Row = ({ children }) => { ) } -const CardRow = ({ title, value, compond = false }) => { +export const CardRow = ({ title, value, compond = false }) => { return ( diff --git a/src/components/StakingCoinCard.js b/src/components/StakingCoinCard.js index b6aa3b8..af99c53 100644 --- a/src/components/StakingCoinCard.js +++ b/src/components/StakingCoinCard.js @@ -1,13 +1,216 @@ import React from "react" import { - VStack, Image, Text, HStack, - Button, Flex, Slider, - SliderTrack, SliderFilledTrack, - useColorModeValue, Badge, + VStack, Image, Text, Stack, HStack, + Button, Tag, Box, + useColorModeValue, Badge, Divider, Icon, } from "@chakra-ui/react" +import { StateCard } from './NumCard' import { useTranslation } from 'react-i18next' +import { ModalBox } from "./alert" +import { CardRow } from './FarmCoinCard' +import { FiLock, FiUnlock } from "react-icons/fi" +import { HBetween, HFStack, VFStack } from "./base" -export const StakingCoinCard = ({ symbol, icon, index, apy, vl, assets }) => { +/** + * Special Modal Box, Why not ask who is your daddy ??? + */ +export const StakingModalStrategy = ({ isOpen, onClose, + icon, symbol, amount, percentage, address, + nodesStaked, nodesNominations, share, status }) => { + + return ( + + + {/* title */} + + + {symbol} + + {symbol} + + + + + {amount} + + + + Staked + + + + + {/* tips */} + + + Note:The pledged amount of the node includes the pledged + amount of CoinWind's entire network staking + + + + {/* body */} + + + + + + + + + + + + ) +} + +export const StakingModalCertificate = ({ isOpen, onClose, onConfirm, + icon, symbol, index, assets, apy, income, start, days, authorized }) => { + + const Row2Text = ({ row1, row2 }) => { + + return ( + + + {row1} + + + {row2} + + + ) + } + + return ( + { onConfirm(index) }} + > + + {/* title */} + + + {symbol} + + {symbol} + + + + + {'Assets ' + assets} + + + + + {/* tag */} + + Current + + + + + APY + + + + {apy} + + + + + {/* progressing */} + + + + + + + + {/* intro */} + + + + + + + + + + + + Income + {income} + + + + ) +} + +export const StakingCoinCard = ({ + symbol, icon, index, + apy, vl, assets, + onStrategy, + onCertificate, +}) => { const { t } = useTranslation() const bg = useColorModeValue('white', 'gray.900') @@ -42,14 +245,63 @@ export const StakingCoinCard = ({ symbol, icon, index, apy, vl, assets }) => { /> - {/* body */} - + {/* body */} + - - Current - - + Current + + + + + {t('apy')} + + + {apy}% + + + + + + + + + + + + + ) } \ No newline at end of file diff --git a/src/components/alert/ModalBox.js b/src/components/alert/ModalBox.js index 2011a33..4761247 100644 --- a/src/components/alert/ModalBox.js +++ b/src/components/alert/ModalBox.js @@ -1,7 +1,10 @@ import React from 'react' import { Button, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay } from '@chakra-ui/react' -export const ModalBox = ({ title, isOpen, onClose, children, onConfirm = null, focusRef = null }) => { +export const ModalBox = ({ title, isOpen, onClose, children, + showFooter = true, showCancel = true, showConfirm = true, + textCancel = 'Cancel', textConfirm = 'OK', + onConfirm = null, focusRef = null }) => { return ( - - + + - diff --git a/src/components/base/col.js b/src/components/base/col.js new file mode 100644 index 0000000..bb4da39 --- /dev/null +++ b/src/components/base/col.js @@ -0,0 +1,8 @@ +import { VStack } from "@chakra-ui/react" + + +export const VFStack = ({ children, ...rest }) => (( + + {children} + +)) \ No newline at end of file diff --git a/src/components/base/index.js b/src/components/base/index.js new file mode 100644 index 0000000..1d2cc98 --- /dev/null +++ b/src/components/base/index.js @@ -0,0 +1,2 @@ +export * from './row' +export * from './col' diff --git a/src/components/base/row.js b/src/components/base/row.js new file mode 100644 index 0000000..fb3ff89 --- /dev/null +++ b/src/components/base/row.js @@ -0,0 +1,25 @@ +import { HStack, Stack } from "@chakra-ui/react" + + +export const HFStack = ({ children, ...rest }) => (( + + {children} + +)) + +export const HBetween = ({ children, ...rest }) => (( + + {children} + +)) + +export const AutoRowCol = () => (( + + + +)) \ No newline at end of file diff --git a/src/components/index.js b/src/components/index.js index 56497dc..6c35e0d 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -10,4 +10,5 @@ export * from './StakingCoinCard' export * from './ColorModeSwitcher' export * from './Placeholder' export * from './Panel' -export * from './alert' \ No newline at end of file +export * from './alert' +export * from './base' diff --git a/src/lang/en.js b/src/lang/en.js index 5693f2f..05d409c 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -35,4 +35,9 @@ export const en = { notFound: 'Page Not Found', notFoundContent: "The page you're looking for does not seem to exist", goHome: 'Go to Home', -} + + current: 'Current', + strategy: 'Stragety', + certificate: 'Certificate', + assets: 'Assets', +} \ No newline at end of file diff --git a/src/lang/fr.js b/src/lang/fr.js index deb609b..a10c057 100644 --- a/src/lang/fr.js +++ b/src/lang/fr.js @@ -35,4 +35,9 @@ export const fr = { notFound: 'Page Not Found', notFoundContent: "The page you're looking for does not seem to exist", goHome: 'Go to Home', + + current: 'Current', + strategy: 'Stragety', + certificate: 'Certificate', + assets: 'Assets', } \ No newline at end of file diff --git a/src/lang/tw.js b/src/lang/tw.js index 2a47531..cc1ed21 100644 --- a/src/lang/tw.js +++ b/src/lang/tw.js @@ -35,4 +35,9 @@ export const tw = { notFound: 'Page Not Found', notFoundContent: "The page you're looking for does not seem to exist", goHome: 'Go to Home', + + current: 'Current', + strategy: 'Stragety', + certificate: 'Certificate', + assets: 'Assets', } \ No newline at end of file diff --git a/src/pages/Staking.js b/src/pages/Staking.js index 436bb93..94c46ef 100644 --- a/src/pages/Staking.js +++ b/src/pages/Staking.js @@ -1,47 +1,39 @@ import React from "react" import { Stack, Image, HStack, - AspectRatio, Input, - FormControl, Box, + AspectRatio, useColorModeValue, useDisclosure, useToast, - useColorModeValue, } from "@chakra-ui/react" -import { StateCard, StakingCoinCard } from "../components" +import { StateCard, StakingCoinCard, StakingModalStrategy, StakingModalCertificate } from "../components" import { useApp } from "../AppContext" import { config } from "../config" import { ABI } from "../data" import { get_staking_balance, - get_coins_platform_all, get_coins_staking, get_ether, get_authorization_v, - get_authorization_one, get_authorization_search, get_upBalance, + get_authorization_one, get_authorization_search, } from "../api" import { approve, transfer } from '../lib' -import { ModalBox } from '../components' import { Images } from '../data' export const Staking = () => { const [balance, setBalance] = React.useState({}) - const [lock, setLock] = React.useState([]) - const [coins, setCoins] = React.useState([]) - const [depositeIndex, setDepositeIndex] = React.useState(-1) + const [strategyIndex, setStrategyIndex] = React.useState(-1) + const [certificateIndex, setCertificateIndex] = React.useState(-1) const app = useApp() const toast = useToast() const bg = useColorModeValue('white', 'gray.900') - const { isOpen: isWithdrawalOpen, onOpen: onWithdrawalOpen, onClose: onWithdrawalClose } = useDisclosure() - const { isOpen: isDepositeOpen, onOpen: onDepositeOpen, onClose: onDepositeClose } = useDisclosure() - - const withdrawalRef = React.useRef() - const depositeRef = React.useRef() + const { isOpen: isOpenStrategy, onOpen: onOpenStrategy, onClose: onCloseStrategy } = useDisclosure() + const { isOpen: isOpenCertificate, onOpen: onOpenCertificate, onClose: onCloseCertificate } = useDisclosure() const _getVaultBalance = () => { - if (!app.balance) { + if (!app.address) { return false } @@ -51,52 +43,18 @@ export const Staking = () => { }) } - const onWithdrawalConfirmed = () => { - + // click Strategy + const onStrategy = (index) => { + setStrategyIndex(index) + onOpenStrategy() } - const onDepositeConfirmed = () => { - if (depositeIndex < 0 || depositeIndex >= coins.length) { - console.error('index out of range') - return - } - const amount = depositeRef.current.value - - 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 => { - - }).catch(err => { - 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) - } - }) + const onCertificate = (index) => { + setCertificateIndex(index) + onOpenCertificate() } - - // click withdrawal - const onBtnWithdrawal = (index) => { - onWithdrawalOpen() - } - - // clicked minming - const onBtnMining = (index) => { + // clicked Certificate + const onConfirmCertificate = (index) => { if (index < 0 || index >= coins.length) { console.error('index out of range') return @@ -105,8 +63,7 @@ export const Staking = () => { let _coins = [...coins] if (_coins[index].authorized) { - setDepositeIndex(index) - onDepositeOpen() + } else { if (!app.address) { toast({ @@ -158,7 +115,6 @@ export const Staking = () => { get_coins_staking().then(res => { setCoins(res.data) - console.log(res.data) }).catch(err => { console.error('get_coins_staking() error:' + err.message) }) @@ -202,15 +158,15 @@ export const Staking = () => { - - + + - - + + @@ -224,46 +180,43 @@ export const Staking = () => { icon={config.ENDPOINT + 'upload/' + coin.name_img} symbol={coin.name} apy={coin.yield} - deposited={coin.count_use} - vl={coin.count} - remaining={coin.count - coin.count_use} - loading={coin.loading} - isNew={coin.new} - authorized={coin.authorized ?? false} - onWithdrawal={onBtnWithdrawal} - onMining={onBtnMining} + vl={coin.count_use} + assets={0.00} + onStrategy={onStrategy} + onCertificate={onCertificate} /> )) } - {/* withdrawal box */} - - Amount - + - - - {/* deposite box */} - - - Amount - - - - + ) } \ No newline at end of file