feat: 邀请功能

This commit is contained in:
gary 2022-04-14 11:13:49 +08:00
parent a0d8070adc
commit bb561b4453
15 changed files with 1112 additions and 4 deletions

View File

@ -47,6 +47,7 @@ const AddLiquidity = lazy(() => import('./views/AddLiquidity'))
const Pool = lazy(() => import('./views/Pool')) const Pool = lazy(() => import('./views/Pool'))
const PoolFinder = lazy(() => import('./views/PoolFinder')) const PoolFinder = lazy(() => import('./views/PoolFinder'))
const RemoveLiquidity = lazy(() => import('./views/RemoveLiquidity')) const RemoveLiquidity = lazy(() => import('./views/RemoveLiquidity'))
const Referral = lazy(() => import('./views/Referral'))
// This config is required for number formatting // This config is required for number formatting
BigNumber.config({ BigNumber.config({
@ -85,6 +86,9 @@ const App: React.FC = () => {
<Route path="/pools"> <Route path="/pools">
<Pools /> <Pools />
</Route> </Route>
<Route path="/referral">
<Referral />
</Route>
{/* <Route path="/lottery"> {/* <Route path="/lottery">
<Lottery /> <Lottery />
</Route> </Route>

View File

@ -35,6 +35,11 @@ const config: (t: ContextApi['t']) => MenuEntry[] = (t) => [
icon: 'PoolIcon', icon: 'PoolIcon',
href: '/pools', href: '/pools',
}, },
{
label: t('Referral'),
icon: 'PoolIcon',
href: '/referral',
},
// { // {
// label: t('Prediction (BETA)'), // label: t('Prediction (BETA)'),
// icon: 'PredictionsIcon', // icon: 'PredictionsIcon',

464
src/config/abi/board.json Normal file
View File

@ -0,0 +1,464 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_candy",
"type": "address"
},
{
"internalType": "address",
"name": "_xCandy",
"type": "address"
},
{
"internalType": "bool",
"name": "_turnOnCondition",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "EmergencyWithdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "NodeReward",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Withdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "WithdrawNodeReward",
"type": "event"
},
{
"inputs": [],
"name": "Candy",
"outputs": [
{
"internalType": "contract IHRC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "XCandy",
"outputs": [
{
"internalType": "contract IHRC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "uint256",
"name": "rewardNum",
"type": "uint256"
}
],
"name": "addNodeReward",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "addWhitelisted",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "canGetRewardMap",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_thresholdDivider",
"type": "uint256"
}
],
"name": "changeThresholdDivider",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "conditionTurnOn",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "enterStake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "firstStakeThreshold",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_findAddress",
"type": "address"
}
],
"name": "getIsNodeMembers",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "isWhitelisted",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "leaveStake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "leaveStakePrecheck",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "nodeMembers",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "nodeToPeriod",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "removeWhitelisted",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "_turnOn",
"type": "bool"
}
],
"name": "switchCondition",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "thresholdDivider",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "userInfo",
"outputs": [
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "stakeTs",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withDrawReward",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

View File

@ -0,0 +1,324 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "InviteReward",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "WithdrawInviteReward",
"type": "event"
},
{
"inputs": [],
"name": "_candy",
"outputs": [
{
"internalType": "contract ICandy",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "child",
"type": "address"
},
{
"internalType": "address",
"name": "invite",
"type": "address"
}
],
"name": "addInviteAddress",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "invite",
"type": "address"
},
{
"internalType": "uint256",
"name": "rewardNum",
"type": "uint256"
}
],
"name": "addInviteReward",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "addWhitelisted",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "canGetRewardMap",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "findAddress",
"type": "address"
}
],
"name": "getInviteAddress",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "inviteNumMap",
"outputs": [
{
"internalType": "int128",
"name": "",
"type": "int128"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "inviteTotalRewardMap",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "isWhitelisted",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "leaderMap",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "removeWhitelisted",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "candy",
"type": "address"
}
],
"name": "setCandyTokenAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "withDrawReward",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

View File

@ -7,6 +7,14 @@ export default {
97: '0xd3af5fe61dbaf8f73149bfcfa9fb653ff096029a', 97: '0xd3af5fe61dbaf8f73149bfcfa9fb653ff096029a',
56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95', 56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95',
}, },
boardChef: {
97: '0x4BC67bBC22a245035fDd1F00DCa7d4F2E1e8f636',
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约
},
referralChef: {
97: '0x3Dcf2586519a25719658Afb2cDB4CEf0DD647Ea3',
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请合约
},
lotteryV2: { lotteryV2: {
97: '0x5790c3534F30437641541a0FA04C992799602998', 97: '0x5790c3534F30437641541a0FA04C992799602998',
56: '0x5aF6D33DE2ccEC94efb1bDF8f92Bd58085432d2c', 56: '0x5aF6D33DE2ccEC94efb1bDF8f92Bd58085432d2c',

View File

@ -24,6 +24,8 @@ import {
getLotteryV2Contract, getLotteryV2Contract,
getBunnySpecialCakeVaultContract, getBunnySpecialCakeVaultContract,
getBunnySpecialPredictionContract, getBunnySpecialPredictionContract,
getReferralchefContract,
getBoardchefContract,
} from 'utils/contractHelpers' } from 'utils/contractHelpers'
// Imports below migrated from Exchange useContract.ts // Imports below migrated from Exchange useContract.ts
@ -98,7 +100,14 @@ export const useMasterchef = () => {
const { library } = useActiveWeb3React() const { library } = useActiveWeb3React()
return useMemo(() => getMasterchefContract(library.getSigner()), [library]) return useMemo(() => getMasterchefContract(library.getSigner()), [library])
} }
export const useBoardchef = () => {
const { library } = useActiveWeb3React()
return useMemo(() => getBoardchefContract(library.getSigner()), [library])
}
export const useReferralchef = () => {
const { library } = useActiveWeb3React()
return useMemo(() => getReferralchefContract(library.getSigner()), [library])
}
export const useSousChef = (id) => { export const useSousChef = (id) => {
const { library } = useActiveWeb3React() const { library } = useActiveWeb3React()
return useMemo(() => getSouschefContract(id, library.getSigner()), [id, library]) return useMemo(() => getSouschefContract(id, library.getSigner()), [id, library])

32
src/services/referral.ts Normal file
View File

@ -0,0 +1,32 @@
import request from 'utils/request'
export const setInviteCode = (data) => {
return request.request({
url: '/api/v1/setInviteCode',
method: 'post',
data,
})
}
export const getAddressInviteInfo = (data) => {
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,
})
}

View File

@ -11,6 +11,7 @@ export {
updateUserStakedBalance, updateUserStakedBalance,
} from './pools' } from './pools'
export { setUserInfo, clearUserInfo } from './userInfo' export { setUserInfo, clearUserInfo } from './userInfo'
export { fetchReferralInfoAsync } from './referral'
export { profileFetchStart, profileFetchSucceeded, profileFetchFailed } from './profile' export { profileFetchStart, profileFetchSucceeded, profileFetchFailed } from './profile'
export { fetchStart, teamFetchSucceeded, fetchFailed, teamsFetchSucceeded } from './teams' export { fetchStart, teamFetchSucceeded, fetchFailed, teamsFetchSucceeded } from './teams'
export { setBlock } from './block' export { setBlock } from './block'

View File

@ -11,6 +11,7 @@ import collectiblesReducer from './collectibles'
import votingReducer from './voting' import votingReducer from './voting'
import lotteryReducer from './lottery' import lotteryReducer from './lottery'
import userInfo from './userInfo' import userInfo from './userInfo'
import referral from './referral'
import application from './application/reducer' import application from './application/reducer'
import { updateVersion } from './global/actions' import { updateVersion } from './global/actions'
@ -36,6 +37,7 @@ const store = configureStore({
voting: votingReducer, voting: votingReducer,
lottery: lotteryReducer, lottery: lotteryReducer,
userInfo, userInfo,
referral,
// Exchange // Exchange
application, application,
user, user,

View File

@ -0,0 +1,50 @@
/* eslint-disable no-param-reassign */
import { createSlice } from '@reduxjs/toolkit'
import { getAddressInviteInfo, getAddressOtherReward } from 'services/referral'
import referralChefAbi from 'config/abi/referral.json'
import multicall from 'utils/multicall'
import BigNumber from 'bignumber.js'
import { getReferralAddress } from 'utils/addressHelpers'
import { getBalanceNumber } from 'utils/formatBalance'
import { Referral, ReferralState } from '../types'
const initialState: ReferralState = { data: {} }
export const referralSlice = createSlice({
name: 'Referral',
initialState,
reducers: {
setInfo: (state, action) => {
state.data = action.payload
},
},
})
// Actions
export const { setInfo } = referralSlice.actions
// Thunks
export const fetchReferralInfoAsync = (account) => async (dispatch) => {
if (!account) {
dispatch(setInfo({}))
return
}
const data: any = await getAddressInviteInfo({ address: account })
const otherReward = await getAddressOtherReward({ address: account })
const [totalReward, canWithdrawReward] = await multicall(referralChefAbi, [
{
address: getReferralAddress(),
name: 'inviteTotalRewardMap',
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

View File

@ -487,7 +487,18 @@ export interface UserInfoState {
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 {
data: Referral
}
// Global state // Global state
export interface State { export interface State {
@ -501,5 +512,6 @@ export interface State {
collectibles: CollectiblesState collectibles: CollectiblesState
voting: VotingState voting: VotingState
userInfo: UserInfoState userInfo: UserInfoState
referral: ReferralState
lottery: LotteryState lottery: LotteryState
} }

View File

@ -20,6 +20,12 @@ export const getMasterChefAddress = () => {
export const getMulticallAddress = () => { export const getMulticallAddress = () => {
return getAddress(addresses.multiCall) return getAddress(addresses.multiCall)
} }
export const getBoardAddress = () => {
return getAddress(addresses.boardChef)
}
export const getReferralAddress = () => {
return getAddress(addresses.referralChef)
}
export const getWbnbAddress = () => { export const getWbnbAddress = () => {
return getAddress(tokens.wbnb.address) return getAddress(tokens.wbnb.address)
} }

View File

@ -24,6 +24,8 @@ import {
getMulticallAddress, getMulticallAddress,
getBunnySpecialCakeVaultAddress, getBunnySpecialCakeVaultAddress,
getBunnySpecialPredictionAddress, getBunnySpecialPredictionAddress,
getBoardAddress,
getReferralAddress,
} from 'utils/addressHelpers' } from 'utils/addressHelpers'
// ABI // ABI
@ -41,6 +43,8 @@ import ifoV2Abi from 'config/abi/ifoV2.json'
import pointCenterIfo from 'config/abi/pointCenterIfo.json' import pointCenterIfo from 'config/abi/pointCenterIfo.json'
import lotteryV2Abi from 'config/abi/lotteryV2.json' import lotteryV2Abi from 'config/abi/lotteryV2.json'
import masterChef from 'config/abi/masterchef.json' import masterChef from 'config/abi/masterchef.json'
import referralChef from 'config/abi/referral.json'
import boardChef from 'config/abi/board.json'
import sousChef from 'config/abi/sousChef.json' import sousChef from 'config/abi/sousChef.json'
import sousChefV2 from 'config/abi/sousChefV2.json' import sousChefV2 from 'config/abi/sousChefV2.json'
import sousChefBnb from 'config/abi/sousChefBnb.json' import sousChefBnb from 'config/abi/sousChefBnb.json'
@ -111,6 +115,12 @@ export const getLotteryV2Contract = (signer?: ethers.Signer | ethers.providers.P
export const getMasterchefContract = (signer?: ethers.Signer | ethers.providers.Provider) => { export const getMasterchefContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(masterChef, getMasterChefAddress(), signer) return getContract(masterChef, getMasterChefAddress(), signer)
} }
export const getBoardchefContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(boardChef, getBoardAddress(), signer)
}
export const getReferralchefContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(referralChef, getReferralAddress(), signer)
}
export const getClaimRefundContract = (signer?: ethers.Signer | ethers.providers.Provider) => { export const getClaimRefundContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(claimRefundAbi, getClaimRefundAddress(), signer) return getContract(claimRefundAbi, getClaimRefundAddress(), signer)
} }

View File

@ -17,8 +17,9 @@ export const getBalanceAmount = (amount: BigNumber, decimals = 18) => {
/** /**
* This function is not really necessary but is used throughout the site. * This function is not really necessary but is used throughout the site.
*/ */
export const getBalanceNumber = (balance: BigNumber, decimals = 18) => { export const getBalanceNumber = (balance: BigNumber, decimals = 18, decimalPlaces?: number) => {
return getBalanceAmount(balance, decimals).toNumber() const displayBalance = getBalanceAmount(balance, decimals)
return decimalPlaces ?displayBalance.decimalPlaces(decimalPlaces).toNumber():displayBalance.toNumber()
} }
export const getFullDisplayBalance = (balance: BigNumber, decimals = 18, displayDecimals?: number) => { export const getFullDisplayBalance = (balance: BigNumber, decimals = 18, displayDecimals?: number) => {

View File

@ -0,0 +1,180 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable no-unneeded-ternary */
import React, { useEffect, useCallback, useState, useRef, useMemo } from 'react'
import { Button, Heading, CopyToClipboard, Text, Flex } from '@pancakeswap/uikit'
import styled from 'styled-components'
import { State } from 'state/types'
import { useDispatch, useSelector } from 'react-redux'
import { useWeb3React } from '@web3-react/core'
import { useTranslation } from 'contexts/Localization'
import PageHeader from 'components/PageHeader'
import Page from 'components/Layout/Page'
import { getAddressInviteList } from 'services/referral'
// import { useInviteHarvest } from 'hooks/useHarvest'
import { fetchReferralInfoAsync } from 'state/actions'
const Header = styled.div`
padding: 32px 0px;
padding-left: 16px;
padding-right: 16px;
text-align: center;
${({ theme }) => theme.mediaQueries.sm} {
padding-left: 24px;
padding-right: 24px;
}
`
const PageContainer = styled(Page)`
max-width: 600px;
margin: 0 auto;
`
const LinkContainer = styled.div`
border: 1px solid rgb(216, 222, 227);
padding: 10px 0px;
line-height: 46px;
display: flex;
text-align: center;
flex-direction: column;
align-items: center;
border-radius: 2px;
`
const AddressContainer = styled.div`
border: 1px solid rgb(216, 222, 227);
margin-top: 20px;
text-align: center;
`
const AddressTitle = styled.div`
border-bottom: 1px solid rgb(216, 222, 227);
color: ${({ theme }) => theme.colors.primary};
font-size: 18px;
padding: 10px 20px;s
line-height: 28px;
background: rgb(244, 247, 250);
font-weight: 600;
`
const AddressList = styled.div`
font-size: 14px;
padding: 10px;
line-height: 24px;
`
const NoData = styled.div`
color: rgb(153, 153, 153);
`
const RewardContainer = styled.div`
text-align: center;
margin-bottom: 20px;
`
const SecondText = styled(Text)`
white-space: break-spaces;
`
const Farms: React.FC = () => {
const { t } = useTranslation()
const dispatch = useDispatch()
const { account } = useWeb3React()
const [inviteList, setInviteList] = useState([])
const [loading, setLoading] = useState(false)
const inviteInfo = useSelector((state: State) => state.referral.data)
const inviteAddress = useMemo(() => {
return inviteInfo.InviteCode
? `${window.location.origin}/#/farms?code=${inviteInfo.InviteCode}`
: window.location.origin
}, [inviteInfo])
useEffect(() => {
if (account) {
getInviteList()
} else {
setInviteList([])
}
}, [account])
// const { onReward } = useInviteHarvest()
const handleWithdraw = async () => {
// setLoading(true)
// try {
// await onReward()
// dispatch(fetchReferralInfoAsync(account))
// setLoading(false)
// } catch (e) {
// setLoading(false)
// }
}
const getInviteList = async () => {
const data: any = await getAddressInviteList({ address: account })
setInviteList(data)
}
return (
<>
<PageHeader>
<Flex justifyContent="space-between" flexDirection={['column', null, null, 'row']}>
<Flex flex="1" flexDirection="column" mr={['8px', 0]}>
<Heading as="h1" scale="xxl" color="secondary" mb="24px">
{t('Referral')}
</Heading>
<Heading scale="md" color="text">
{t('Share referral link and get rewards daily.')}
</Heading>
<Heading scale="md" color="text">
{t('Invite more friends, earn more rewards.')}
</Heading>
</Flex>
<Flex flex="1" height="fit-content" justifyContent="center" alignItems="center" mt={['24px', null, '0']}>
{/* <BountyCard /> */}
</Flex>
</Flex>
</PageHeader>
{/* <Header>
<Heading as="h1" size="xl" color="text" mb="10px" mt="10px">
{t('Referral')}
</Heading>
<Text fontSize="28px" color="text">
{t('Share referral link and get rewards daily.')}
<br />
{t('Invite more friends, earn more rewards.')}
</Text>
</Header> */}
<PageContainer>
<RewardContainer>
<Text> {t('Total Rewards')}</Text>
<Text color="primary" bold fontSize="30px">
{inviteInfo.totalReward ? Number(inviteInfo.totalReward).toFixed(5) : '0.00000'}
</Text>
</RewardContainer>
<RewardContainer>
<Text> {t('Unclaimed Rewards')}</Text>
<Text color="primary" bold fontSize="30px">
{inviteInfo.canWithdrawReward ? Number(inviteInfo.canWithdrawReward).toFixed(5) : '0.00000'}
</Text>
<Button
scale="md"
disabled={loading || !inviteInfo.canWithdrawReward ? true : false}
onClick={handleWithdraw}
>
{t('Harvest')}
</Button>
</RewardContainer>
<LinkContainer>
<Text marginBottom={1} fontSize="20px">
{inviteAddress}
</Text>
<CopyToClipboard toCopy={inviteAddress}> {t('Copy Link')}</CopyToClipboard>
</LinkContainer>
<AddressContainer>
<AddressTitle>{t('Address')}</AddressTitle>
<AddressList>
{inviteList.length === 0 ? (
<NoData>{t('No Data')}</NoData>
) : (
inviteList.map((item, index) => (
<Text key={item.ID} color="text">
{item.Address}
</Text>
))
)}
</AddressList>
</AddressContainer>
</PageContainer>
</>
)
}
export default Farms