feat: 修改军团长
This commit is contained in:
parent
e3b2433d23
commit
4105fed6e2
|
|
@ -1,32 +1,10 @@
|
||||||
import request from 'utils/request'
|
import request from 'utils/request'
|
||||||
|
|
||||||
export const setInviteCode = (data) => {
|
export const getReferralInfo = () => {
|
||||||
return request.request({
|
return request.request({
|
||||||
url: '/api/v1/setInviteCode',
|
url: '/high_city/app/api/invite/reward',
|
||||||
method: 'post',
|
method: 'get',
|
||||||
data,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAddressInviteInfo = (data) => {
|
export default getReferralInfo
|
||||||
return request.request({
|
|
||||||
url: '/api/v1/getAddressInviteInfo',
|
|
||||||
method: 'post',
|
|
||||||
data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getAddressInviteList = (data) => {
|
|
||||||
return request.request({
|
|
||||||
url: '/api/v1/getAddressInviteList',
|
|
||||||
method: 'post',
|
|
||||||
data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
export const getAddressOtherReward = (data) => {
|
|
||||||
return request.request({
|
|
||||||
url: '/api/v1/getAddressOtherReward',
|
|
||||||
method: 'post',
|
|
||||||
data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
import { State } from '../types'
|
||||||
|
|
||||||
|
export const useReferralConfigInfo = () => {
|
||||||
|
return useSelector((state: State) => state.referral.configInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useReferralRewardInfo = () => {
|
||||||
|
return useSelector((state: State) => state.referral.rewardInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useReferralIsCommander = () => {
|
||||||
|
return useSelector((state: State) => state.referral.isCommander)
|
||||||
|
}
|
||||||
|
|
@ -1,50 +1,37 @@
|
||||||
/* eslint-disable no-param-reassign */
|
|
||||||
import { createSlice } from '@reduxjs/toolkit'
|
import { createSlice } from '@reduxjs/toolkit'
|
||||||
import { getAddressInviteInfo, getAddressOtherReward } from 'services/referral'
|
import { getReferralInfo } from 'services/referral'
|
||||||
import referralChefAbi from 'config/abi/referral.json'
|
import { ReferralInfo } from 'types/referral'
|
||||||
import multicall from 'utils/multicall'
|
import { ReferralState } from '../types'
|
||||||
import BigNumber from 'bignumber.js'
|
|
||||||
import { getReferralAddress } from 'utils/addressHelpers'
|
|
||||||
import { getBalanceNumber } from 'utils/formatBalance'
|
|
||||||
import { Referral, ReferralState } from '../types'
|
|
||||||
|
|
||||||
const initialState: ReferralState = { data: {} }
|
const initialState: ReferralState = { configInfo: {}, isCommander: false, rewardInfo: {} }
|
||||||
export const referralSlice = createSlice({
|
export const referralSlice = createSlice({
|
||||||
name: 'Referral',
|
name: 'Referral',
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
setInfo: (state, action) => {
|
setReferralInfo: (state, action) => {
|
||||||
state.data = action.payload
|
state.configInfo = action.payload.configInfo
|
||||||
|
state.isCommander = action.payload.isCommander
|
||||||
|
state.rewardInfo = action.payload.rewardInfo
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
export const { setInfo } = referralSlice.actions
|
export const { setReferralInfo } = referralSlice.actions
|
||||||
// Thunks
|
// Thunks
|
||||||
export const fetchReferralInfoAsync = (account) => async (dispatch) => {
|
export const fetchReferralInfoAsync = (account) => async (dispatch) => {
|
||||||
if (!account) {
|
if (!account) {
|
||||||
dispatch(setInfo({}))
|
dispatch(setReferralInfo({}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const data: any = await getAddressInviteInfo({ address: account })
|
const data: ReferralInfo = await getReferralInfo()
|
||||||
const otherReward = await getAddressOtherReward({ address: account })
|
dispatch(
|
||||||
const [totalReward, canWithdrawReward] = await multicall(referralChefAbi, [
|
setReferralInfo({
|
||||||
{
|
configInfo: data.inviteConfigList[0],
|
||||||
address: getReferralAddress(),
|
isCommander: data.isCommander,
|
||||||
name: 'inviteTotalRewardMap',
|
rewardInfo: data.reward,
|
||||||
params: [account],
|
}),
|
||||||
},
|
)
|
||||||
{
|
|
||||||
address: getReferralAddress(),
|
|
||||||
name: 'canGetRewardMap',
|
|
||||||
params: [account],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
data.totalReward = getBalanceNumber(new BigNumber(totalReward), 18, 5)
|
|
||||||
data.canWithdrawReward = getBalanceNumber(new BigNumber(canWithdrawReward), 18, 5)
|
|
||||||
data.otherReward = otherReward
|
|
||||||
dispatch(setInfo(data))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default referralSlice.reducer
|
export default referralSlice.reducer
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import {
|
||||||
Team,
|
Team,
|
||||||
BoardConfig,
|
BoardConfig,
|
||||||
} from 'config/constants/types'
|
} from 'config/constants/types'
|
||||||
|
import { UserInfo } from 'types/user'
|
||||||
|
import { ReferralConfigInfo, ReferralRewardInfo } from 'types/referral'
|
||||||
|
|
||||||
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, State, unknown, AnyAction>
|
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, State, unknown, AnyAction>
|
||||||
|
|
||||||
|
|
@ -475,28 +477,16 @@ export interface UserRound {
|
||||||
|
|
||||||
export type UserTicketsResponse = [ethers.BigNumber[], number[], boolean[]]
|
export type UserTicketsResponse = [ethers.BigNumber[], number[], boolean[]]
|
||||||
|
|
||||||
export interface UserInfo {
|
|
||||||
id?: number
|
|
||||||
inviteCode?: string
|
|
||||||
name?: string
|
|
||||||
address?: string
|
|
||||||
}
|
|
||||||
export interface UserInfoState {
|
export interface UserInfoState {
|
||||||
userInfo: UserInfo
|
userInfo: UserInfo
|
||||||
token?: string
|
token?: string
|
||||||
account?: string
|
account?: string
|
||||||
}
|
}
|
||||||
export interface Referral {
|
|
||||||
Address?: string
|
|
||||||
ID?: number
|
|
||||||
InviteAddress?: string
|
|
||||||
InviteCode?: string
|
|
||||||
totalReward?: string
|
|
||||||
otherReward?: number // 其他特殊奖励
|
|
||||||
canWithdrawReward?: number
|
|
||||||
}
|
|
||||||
export interface ReferralState {
|
export interface ReferralState {
|
||||||
data: Referral
|
configInfo: ReferralConfigInfo
|
||||||
|
isCommander: boolean
|
||||||
|
rewardInfo: ReferralRewardInfo
|
||||||
}
|
}
|
||||||
export interface Boards extends BoardConfig {
|
export interface Boards extends BoardConfig {
|
||||||
tokenAmount?: number
|
tokenAmount?: number
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
|
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
|
||||||
import { queryUserInfo } from 'services/user'
|
import { queryUserInfo } from 'services/user'
|
||||||
import { CACHE_TOKEN, CACHE_ACCOUNT, CACHE_USERINFO } from 'config/constants/cacheKey'
|
import { CACHE_TOKEN, CACHE_ACCOUNT, CACHE_USERINFO } from 'config/constants/cacheKey'
|
||||||
import multicall from 'utils/multicall'
|
import { UserInfo } from 'types/user'
|
||||||
// import inviteAbi from 'config/abi/invite.json'
|
import { UserInfoState } from '../types'
|
||||||
// import { getInviteAddress } from 'utils/addressHelpers'
|
|
||||||
import { getBalanceNumber } from 'utils/formatBalance'
|
|
||||||
import { UserInfoState, UserInfo } from '../types'
|
|
||||||
|
|
||||||
const initialState: UserInfoState = {
|
const initialState: UserInfoState = {
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
|
|
@ -18,17 +15,6 @@ export const fetchUserInfo = createAsyncThunk<UserInfo, null>('userInfo/fetchUse
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|
||||||
// export const fetchUserInviteInfo = createAsyncThunk<number, string>('userInfo/fetchUserInviteInfo', async (account) => {
|
|
||||||
// const [canWithdrawReward] = await multicall(inviteAbi, [
|
|
||||||
// {
|
|
||||||
// address: getInviteAddress(),
|
|
||||||
// name: 'canGetRewardMap',
|
|
||||||
// params: [account],
|
|
||||||
// },
|
|
||||||
// ])
|
|
||||||
// return getBalanceNumber(canWithdrawReward)
|
|
||||||
// })
|
|
||||||
|
|
||||||
export const userInfoSlice = createSlice({
|
export const userInfoSlice = createSlice({
|
||||||
name: 'userInfo',
|
name: 'userInfo',
|
||||||
initialState,
|
initialState,
|
||||||
|
|
@ -56,9 +42,6 @@ export const userInfoSlice = createSlice({
|
||||||
state.userInfo = action.payload
|
state.userInfo = action.payload
|
||||||
localStorage.setItem(CACHE_USERINFO, JSON.stringify(state.userInfo))
|
localStorage.setItem(CACHE_USERINFO, JSON.stringify(state.userInfo))
|
||||||
})
|
})
|
||||||
// .addCase(fetchUserInviteInfo.fulfilled, (state, action) => {
|
|
||||||
// state.userInfo = { ...state.userInfo, invite_reward: action.payload }
|
|
||||||
// })
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
export interface ReferralConfigInfo {
|
||||||
|
dividendFirst?: number
|
||||||
|
dividendSecond?: number
|
||||||
|
id?: number
|
||||||
|
properties?: Record<string, unknown>
|
||||||
|
type?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReferralRewardInfo {
|
||||||
|
inviteNum?: number
|
||||||
|
invitePurchase?: number
|
||||||
|
inviteReward?: number
|
||||||
|
inviteRewardReceive?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReferralInfo {
|
||||||
|
inviteConfigList: ReferralConfigInfo
|
||||||
|
isCommander: boolean
|
||||||
|
reward: ReferralRewardInfo
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
export interface ProtraitDetailType {
|
export interface UserInfo {
|
||||||
id?: string
|
id?: number
|
||||||
url?: string
|
inviteCode?: string
|
||||||
}
|
name?: string
|
||||||
|
address?: string
|
||||||
export interface InviteDetailType {
|
|
||||||
id: number
|
|
||||||
created_at: string
|
|
||||||
name: string
|
|
||||||
avatar: string
|
|
||||||
invite_num: number
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import { useTranslation } from 'contexts/Localization'
|
import { useTranslation } from 'contexts/Localization'
|
||||||
import { Button, Heading, Text } from '@pancakeswap/uikit'
|
import { Heading, Text } from '@pancakeswap/uikit'
|
||||||
|
import UnlockButton from 'components/UnlockButton'
|
||||||
|
|
||||||
const HeadingDiv = styled(Heading)`
|
const HeadingDiv = styled(Heading)`
|
||||||
padding-top: 90px;
|
padding-top: 90px;
|
||||||
`
|
`
|
||||||
|
|
||||||
const ButtonDiv = styled(Button)`
|
const UnlockButtonDiv = styled(UnlockButton)`
|
||||||
width: 80%;
|
width: 80%;
|
||||||
margin: 80px auto 10px auto;
|
margin: 80px auto 10px auto;
|
||||||
margin-left: 10%;
|
margin-left: 10%;
|
||||||
border-radius: 50px;
|
|
||||||
`
|
`
|
||||||
const FooterDiv = styled.div`
|
const FooterDiv = styled.div`
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
|
@ -30,7 +30,7 @@ const UnunitedCom: React.FC = () => {
|
||||||
<HeadingDiv scale="xl" mb="24px" textAlign="center">
|
<HeadingDiv scale="xl" mb="24px" textAlign="center">
|
||||||
{t('recommend')}
|
{t('recommend')}
|
||||||
</HeadingDiv>
|
</HeadingDiv>
|
||||||
<ButtonDiv>{t('Connect the purse')}</ButtonDiv>
|
<UnlockButtonDiv />
|
||||||
<FooterDiv>
|
<FooterDiv>
|
||||||
<TextDiv color="textSubtle">{t('each time')}</TextDiv>
|
<TextDiv color="textSubtle">{t('each time')}</TextDiv>
|
||||||
<TextDiv color="textSubtle">{t('last bid')}</TextDiv>
|
<TextDiv color="textSubtle">{t('last bid')}</TextDiv>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
import { fetchReferralInfoAsync } from 'state/actions'
|
||||||
|
import { useAccount } from 'state/userInfo/hooks'
|
||||||
|
import { useReferralConfigInfo } from 'state/referral/hooks'
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
import UnunitedCom from './components/UnunitedCom'
|
import UnunitedCom from './components/UnunitedCom'
|
||||||
import ConnectedCom from './components/Connected'
|
import ConnectedCom from './components/Connected'
|
||||||
import RegimentalCom from './components/Regimental'
|
import RegimentalCom from './components/Regimental'
|
||||||
|
|
@ -35,12 +39,18 @@ const ContentDiv = styled.div`
|
||||||
const Nft: React.FC = () => {
|
const Nft: React.FC = () => {
|
||||||
// 邀请false普通邀请 true军团长邀请
|
// 邀请false普通邀请 true军团长邀请
|
||||||
const [type, setType] = useState(false)
|
const [type, setType] = useState(false)
|
||||||
// 是否连接钱包
|
const dispatch = useDispatch()
|
||||||
const [status, setStatus] = useState(true)
|
const account = useAccount()
|
||||||
|
|
||||||
|
const referralConfigInfo = useReferralConfigInfo()
|
||||||
|
console.log(referralConfigInfo)
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchReferralInfoAsync(account))
|
||||||
|
}, [account])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MainDiv>
|
<MainDiv>
|
||||||
{type ? <RegimentalCom /> : <ContentDiv>{status ? <ConnectedCom /> : <UnunitedCom />}</ContentDiv>}
|
{type ? <RegimentalCom /> : <ContentDiv>{account ? <ConnectedCom /> : <UnunitedCom />}</ContentDiv>}
|
||||||
</MainDiv>
|
</MainDiv>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue