Skip to content

Commit

Permalink
fix: update public limit api
Browse files Browse the repository at this point in the history
  • Loading branch information
xsteadybcgo committed Sep 6, 2021
1 parent 5040108 commit 0b05427
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/core/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Menu } from '../types/classes/chain'
import { httpPost, httpGet } from './http'
import { API_DOMAIN } from '../../config/origin'
import { StatT } from '../types/classes/stat'
import { StatT, LimitData } from '../types/classes/stat'
import axios from 'axios'

/**
Expand Down Expand Up @@ -57,6 +57,12 @@ export const apiCreateProject = async (data: ProjectCreatDto) =>
export const apiDelProject = async (data: { id: string }) =>
await httpPost<unknown>(`${API_DOMAIN}/project/delete`, data)

/**
* elara limit data
*/
export const apiGetPublicSetting = async () =>
await httpGet<LimitData>(`${API_DOMAIN}/public/limit`)

/**
* total requests on homepage
*/
Expand Down
7 changes: 6 additions & 1 deletion src/core/types/classes/stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ export interface StatT {
delay: number
inReqCnt: number
reqCnt: number
}
}

export interface LimitData {
projectNum: number
bwDayLimit: number
}
17 changes: 12 additions & 5 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { ReactElement, useEffect, useRef, useState } from 'react'
import * as echarts from 'echarts'
import './index.css'
import { LimitData } from '../../core/types/classes/stat'
import {
apiGetTotalStatics,
apiGetLast30DaysRequests,
apiGetPublicSetting,
} from '../../core/data/api'
import { useTranslation } from 'react-i18next'
import img1 from '../../assets/easy-use.webp'
Expand All @@ -28,13 +30,17 @@ const imgList = [img1, img2, img3, img4, img5, img6, img7, img8]
const Home: React.FC = (): ReactElement => {
const [isLoginModalVisible, setLoginModalVisible] = useState(false)
const [total, setTotal] = useState({ request: 0, bandwidth: 0 })
const [limit, setLimit] = useState<LimitData>({
bwDayLimit: 0,
projectNum: 0,
})
const [loaded, setLoaded] = useState<boolean>(false)
const [chartType, setChartType] = useState<'request' | 'bandwidth'>(
'bandwidth'
)
const requestsEchart = useRef<HTMLDivElement>(null)
const history = useHistory()
const { isLogged, user, homeHeight } = useApi()
const { isLogged, homeHeight } = useApi()
const { t, i18n } = useTranslation()
const carousel = useRef<any>(null)

Expand All @@ -47,6 +53,9 @@ const Home: React.FC = (): ReactElement => {

useEffect(() => {
window.scrollTo({ top: homeHeight.height })
apiGetPublicSetting().then((data) => {
setLimit(data)
})
}, [homeHeight.height])

useEffect(() => {
Expand Down Expand Up @@ -259,8 +268,7 @@ const Home: React.FC = (): ReactElement => {
<p className="product-tip">每天每个账户</p>
)}
<p className="product-text">
{/* {Math.floor(user.bwDayLimit / Math.pow(1000, 3))} GB */}
10 GB
{Math.floor(limit.bwDayLimit / Math.pow(1000, 3))} GB
</p>
<p className="product-tip">
{i18n.language === Language.zh
Expand All @@ -272,8 +280,7 @@ const Home: React.FC = (): ReactElement => {
<div>
<div className="autoplay-content">
<p className="product-text">
{/* {user.maxProjectNum} */}
10
{limit.projectNum}
{t('Projects')}
</p>
</div>
Expand Down

0 comments on commit 0b05427

Please sign in to comment.