diff --git a/public/locales/en-US.json b/public/locales/en-US.json index 8b5a9bd..40148a3 100644 --- a/public/locales/en-US.json +++ b/public/locales/en-US.json @@ -1053,15 +1053,10 @@ "Community Auctions": "Community Auctions", "FAQs": "FAQs", "Auction duration": "Auction duration", - "Terms & Conditions": "Terms & Conditions", - - - - - "Hcc Info":"HighCityCoin", - "Hcc Nft":"其作用主要是在HighCitySwap上购买NFT、NFT盒子与其他可交易产品。", - "Hcc BTC":"同时,HCC与BTC、ETH具有相同属性,可以进行自由交易。", - "Bazaar":"NFT市场" - + "Hcc Info": "HighCityCoin", + "Hcc Nft": "其作用主要是在HighCitySwap上购买NFT、NFT盒子与其他可交易产品。", + "Hcc BTC": "同时,HCC与BTC、ETH具有相同属性,可以进行自由交易。", + "Bazaar": "NFT市场", + "Insufficient Balance": "余额不足" } diff --git a/public/locales/zh-CN.json b/public/locales/zh-CN.json index f05b163..1edfa37 100644 --- a/public/locales/zh-CN.json +++ b/public/locales/zh-CN.json @@ -1055,70 +1055,69 @@ "Auction duration": "Auction duration", "Terms & Conditions": "Terms & Conditions", - - - "Hcc Info":"HighCityCoin简称HCC,由HighCityTM铸造,", - "Hcc Nft":"其作用主要是在HighCitySwap上购买NFT、NFT盒子与其他可交易产品。", - "Hcc BTC":"同时,HCC与BTC、ETH具有相同属性,可以进行自由交易。", - "Bazaar":"NFT市场", - "HlighCitySwapInfo":"HIighCitySwap的诞生,源于创始人Liu Bus对区块链技术的狂热追求,他始终相信区块链技术能够得到更广泛的应用。为此,他做了一个勇敢的决定,放弃在其他领域的投资,身心专注投入到区块链技术实践应用当中去,将自己所熟悉的领域——互联网社交,与区块链技术融合,HighCitySwap由此诞生。这就是我们的开始,感谢你们的支持,HighCity团队将永远前行。", - "Stage one: Origin":"第一阶段:起源", - "Stage two: Action":"第二阶段:行动", - "Stage three: Creation":"第三阶段:创造", - "Stage four: Integration":"第四阶段:融合", - "Stage five: Closing the curtain":"第五阶段:落幕", - "The project concept was born in May 2021":"2021年5月项目概念的诞生;", - "Set up HighClty team in June 2021":"2021年6月搭建HighClty团队;", - "May 2021 -- January 2022 Team run-in":"2021年5月~2022年1月团队磨合;", - "In April 2022, social networking and media release activities, HighCity coin started and dividend mechanism went online":"2022年4月社交建社,交媒体发布活动,HighCity铸币开始,分红机制上线;", - "In March 2022, project approval, web design, roadmap announcement, smart contract development":"2022年3月项目立项,网页设计,路线图公布,智能合约开发;", - "Launch of social software in December 2022":"2022年12月社交软件落地;", - "Created by NFT in May 2022":"2022年5月NFT创造;", - "June 2022 social software development":"2022年6月社交软件开发;", - "December 2022 NFT bonus binding social software":"2022年12月NFT分红绑定社交软件;", - "In December 2022, HighCity Ecology was preliminarily completed":"2022年12月HighCity生态初步建成;", - "HighCity Ecology completed in December 2022":"2022年12月HighCity生态建成;", - "Maintain dividend income growth in December 2022":"2022年12月保持分红收益增长;", - "Buy commander NFT":"购买军团长NFT", - "Upgrade recommendation rights, can enjoy the share of secondary recommendation":"升级推荐权益,可享有二级推荐的分成", - "Enjoy a higher percentage than ordinary users":"享有比普通用户更高的分成比例", - "Commander NFT can be traded in the NFT market":"军团长NFT可在NFT市场内进行交易", - "First stage sharing ratio":"一级分成比例", - "Secondary split ratio":"二级分成比例", - "Buy It Now":"立即购买", - "recommend":"推荐", - "The lower the number of":"下级数量", - "NFT total revenue":"NFT总收益", - "HCC total revenue":"HCC总收益", - "To get profit":"待领收益", - "No income is received temporarily":"暂无收益领取", - "Upgrade commander":"升级军团长", - "Regimental recommendation":"军团长推荐", - "Number of secondary subordinates":"二级下级人数", - "Number of first-level subordinates":"一级下级人数", - "Immediately to receive":"立即领取", - "buy again":"再次购买", - "Connect the purse":"连接钱包", - "HCC total revenue percentage :10%":"HCC总收益(分成比例:10%)", - "Contract address":"合约地址", - "Assets agreement":"资产协议", - "Assets and chain":"资产公链", - "each time":"1.当倒计时少于1小时时,每次加价增加倒计时时间1小时", - "last bid":"2.拍卖每次固定加价10%,倒计时结束后,拍卖品由最后出价的出价人获得", - "commission fee":"3.拍卖成功后,平台将收取发布人收益的6%作为手续费", - "announcement":"公告", - "return":"返回", - "Total capital pool":"资金池总额", - "The total amount of dividends":"分红总额", - "Pending dividend":"待领取分红", - "Number of boards":"董事会数量", - "Number of holders":"持有人数量", - "total revenue":"总收益", - "revenue":"收益", - "purchase":"购买", - "Enter a keyword search":"输入关键字搜索", - "By using the invitation at the top right of the page, new users can be invited to enter and obtained after users purchase coins":"使用页面右上方的邀请,可邀请新用户进入,并在用户购买币后获得", - "The commission":"的提成!", - "market value":"市值", - "Loaded all":"已加载全部" + "Hcc Info": "HighCityCoin简称HCC,由HighCityTM铸造,", + "Hcc Nft": "其作用主要是在HighCitySwap上购买NFT、NFT盒子与其他可交易产品。", + "Hcc BTC": "同时,HCC与BTC、ETH具有相同属性,可以进行自由交易。", + "Bazaar": "NFT市场", + "HlighCitySwapInfo": "HIighCitySwap的诞生,源于创始人Liu Bus对区块链技术的狂热追求,他始终相信区块链技术能够得到更广泛的应用。为此,他做了一个勇敢的决定,放弃在其他领域的投资,身心专注投入到区块链技术实践应用当中去,将自己所熟悉的领域——互联网社交,与区块链技术融合,HighCitySwap由此诞生。这就是我们的开始,感谢你们的支持,HighCity团队将永远前行。", + "Stage one: Origin": "第一阶段:起源", + "Stage two: Action": "第二阶段:行动", + "Stage three: Creation": "第三阶段:创造", + "Stage four: Integration": "第四阶段:融合", + "Stage five: Closing the curtain": "第五阶段:落幕", + "The project concept was born in May 2021": "2021年5月项目概念的诞生;", + "Set up HighClty team in June 2021": "2021年6月搭建HighClty团队;", + "May 2021 -- January 2022 Team run-in": "2021年5月~2022年1月团队磨合;", + "In April 2022, social networking and media release activities, HighCity coin started and dividend mechanism went online": "2022年4月社交建社,交媒体发布活动,HighCity铸币开始,分红机制上线;", + "In March 2022, project approval, web design, roadmap announcement, smart contract development": "2022年3月项目立项,网页设计,路线图公布,智能合约开发;", + "Launch of social software in December 2022": "2022年12月社交软件落地;", + "Created by NFT in May 2022": "2022年5月NFT创造;", + "June 2022 social software development": "2022年6月社交软件开发;", + "December 2022 NFT bonus binding social software": "2022年12月NFT分红绑定社交软件;", + "In December 2022, HighCity Ecology was preliminarily completed": "2022年12月HighCity生态初步建成;", + "HighCity Ecology completed in December 2022": "2022年12月HighCity生态建成;", + "Maintain dividend income growth in December 2022": "2022年12月保持分红收益增长;", + "Buy commander NFT": "购买军团长NFT", + "Upgrade recommendation rights, can enjoy the share of secondary recommendation": "升级推荐权益,可享有二级推荐的分成", + "Enjoy a higher percentage than ordinary users": "享有比普通用户更高的分成比例", + "Commander NFT can be traded in the NFT market": "军团长NFT可在NFT市场内进行交易", + "First stage sharing ratio": "一级分成比例", + "Secondary split ratio": "二级分成比例", + "Buy It Now": "立即购买", + "recommend": "推荐", + "The lower the number of": "下级数量", + "NFT total revenue": "NFT总收益", + "HCC total revenue": "HCC总收益", + "To get profit": "待领收益", + "No income is received temporarily": "暂无收益领取", + "Upgrade commander": "升级军团长", + "Regimental recommendation": "军团长推荐", + "Number of secondary subordinates": "二级下级人数", + "Number of first-level subordinates": "一级下级人数", + "Immediately to receive": "立即领取", + "buy again": "再次购买", + "Connect the purse": "连接钱包", + "HCC total revenue percentage :10%": "HCC总收益(分成比例:10%)", + "Contract address": "合约地址", + "Assets agreement": "资产协议", + "Assets and chain": "资产公链", + "each time": "1.当倒计时少于1小时时,每次加价增加倒计时时间1小时", + "last bid": "2.拍卖每次固定加价10%,倒计时结束后,拍卖品由最后出价的出价人获得", + "commission fee": "3.拍卖成功后,平台将收取发布人收益的6%作为手续费", + "announcement": "公告", + "return": "返回", + "Total capital pool": "资金池总额", + "The total amount of dividends": "分红总额", + "Pending dividend": "待领取分红", + "Number of boards": "董事会数量", + "Number of holders": "持有人数量", + "total revenue": "总收益", + "revenue": "收益", + "purchase": "购买", + "Enter a keyword search": "输入关键字搜索", + "By using the invitation at the top right of the page, new users can be invited to enter and obtained after users purchase coins": "使用页面右上方的邀请,可邀请新用户进入,并在用户购买币后获得", + "The commission": "的提成!", + "market value": "市值", + "Loaded all": "已加载全部", + "Insufficient Balance": "余额不足" } diff --git a/src/App.tsx b/src/App.tsx index 44c7424..a9544fb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,7 +8,7 @@ import { usePollCoreFarmData, useFetchProfile, usePollBlockNumber } from 'state/ import { DatePickerPortal } from 'components/DatePicker' import { initAxios } from 'utils/request' import useToast from 'hooks/useToast' -import { fetchUserInfo } from 'state/actions' +import { fetchUserInfo, clearUserInfo } from 'state/actions' import { useAccount } from 'state/userInfo/hooks' import GlobalStyle from './style/Global' import Menu from './components/Menu' @@ -70,7 +70,9 @@ const App: React.FC = () => { const account = useAccount() useEffect(() => { - initAxios(dispatch, toast) + initAxios(() => { + dispatch(clearUserInfo) + }, toast) }, []) useEffect(() => { account && dispatch(fetchUserInfo()) diff --git a/src/config/abi/referral.json b/src/config/abi/referral.json index 558fea0..9faa686 100644 --- a/src/config/abi/referral.json +++ b/src/config/abi/referral.json @@ -2,9 +2,7 @@ { "inputs": [ { "internalType": "address", "name": "_hccAddress", "type": "address" }, - { "internalType": "address", "name": "_otherPaymentAddress", "type": "address" }, - { "internalType": "uint256", "name": "_hccPirce", "type": "uint256" }, - { "internalType": "uint256", "name": "_otherPaymentPirce", "type": "uint256" } + { "internalType": "address", "name": "_otherPaymentAddress", "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" @@ -159,13 +157,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "hccPirce", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { "internalType": "address", "name": "owner", "type": "address" }, @@ -176,7 +167,20 @@ "stateMutability": "view", "type": "function" }, - { "inputs": [], "name": "mint", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "hccPirce", "type": "uint256" }, + { "internalType": "uint256", "name": "otherPaymentPirce", "type": "uint256" }, + { "internalType": "uint256", "name": "_timestamp", "type": "uint256" }, + { "internalType": "uint256", "name": "code", "type": "uint256" }, + { "internalType": "bytes", "name": "_signature", "type": "bytes" } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "name", @@ -191,13 +195,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "otherPaymentPirce", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "owner", @@ -274,13 +271,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [{ "internalType": "uint256", "name": "newHccPirce", "type": "uint256" }], - "name": "setHccPirce", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [{ "internalType": "address", "name": "newOtherPaymentAddress", "type": "address" }], "name": "setOtherPaymentAddress", @@ -288,13 +278,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [{ "internalType": "uint256", "name": "newOtherPaymentPirce", "type": "uint256" }], - "name": "setOtherPaymentPirce", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [{ "internalType": "bool", "name": "_pause", "type": "bool" }], "name": "setPause", @@ -302,6 +285,20 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "hccPirce", "type": "uint256" }, + { "internalType": "uint256", "name": "otherPaymentPirce", "type": "uint256" }, + { "internalType": "uint256", "name": "_timestamp", "type": "uint256" }, + { "internalType": "uint256", "name": "code", "type": "uint256" }, + { "internalType": "bytes", "name": "_signature", "type": "bytes" } + ], + "name": "signatureMint", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "pure", + "type": "function" + }, { "inputs": [ { "internalType": "address", "name": "wallet", "type": "address" }, diff --git a/src/config/constants/contracts.ts b/src/config/constants/contracts.ts index 04c5966..ded3014 100644 --- a/src/config/constants/contracts.ts +++ b/src/config/constants/contracts.ts @@ -8,19 +8,19 @@ export default { 56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95', }, boardChef: { - 97: '0xfe73bcc71c1e8f41f29c07ee921777ff8232eba7', + 97: '0x7e64aac0806597cb2efddf7c001e59d6b4e9cb15', 56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约 }, holderChef: { - 97: '0xc49ef97410f495164604be0de2baae908913c4cc', + 97: '0x4cbbb9e9569a208c9975574675ba24eccea342b3', 56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 持币人 }, referralChef: { - 97: '0x2f2aec0ee0da9f81e28e78a072cfbea6f35b1e06', + 97: '0x86a510e82aceb27ed9e9880fb981d4b42ff16cb4', 56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长 }, referralRewardChef: { - 97: '0xe031cf7053ea3b7605bb289efe2307356f6ace6d', + 97: '0x86a510e82aceb27ed9e9880fb981d4b42ff16cb4', 56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长收益 }, lotteryV2: { diff --git a/src/config/constants/tokens.ts b/src/config/constants/tokens.ts index 3d95c65..4d39671 100644 --- a/src/config/constants/tokens.ts +++ b/src/config/constants/tokens.ts @@ -73,7 +73,7 @@ const tokens = { symbol: 'HCC', address: { 56: '0x20de22029ab63cf9A7Cf5fEB2b737Ca1eE4c82A6', - 97: '0xbdd6c43fb8e97a73e464fca5ab6f3d2f402be20c', + 97: '0x77f2efa78c1c2798ad3c753330aa4e1babcaeff8', }, decimals: 18, projectLink: 'https://tranchess.com/', diff --git a/src/services/referral.ts b/src/services/referral.ts index 1367736..23fb4a8 100644 --- a/src/services/referral.ts +++ b/src/services/referral.ts @@ -1,18 +1,39 @@ import request from 'utils/request' -export const getReferralInfo = () => { +export const getReferralRewardInfo = () => { return request.request({ url: '/high_city/app/api/invite/reward', method: 'get', }) } -export const withdrawReward = () => { +export const getReferralConfigInfo = () => { + return request.request({ + url: '/high_city/app/api/invite/config', + method: 'get', + }) +} + +export const getBuyReferralParams = () => { + return request.request({ + url: '/high_city/app/api/invite/commander/purchase', + method: 'get', + }) +} + +export const getWithdrawRewardParams = () => { return request.request({ url: '/high_city/app/api/invite/reward/receive', method: 'get', }) } +export const checkBuyResult = (params) => { + return request.request({ + url: '/high_city/app/api/invite/commander/tx', + method: 'post', + params, + }) +} export const inviteReceive = () => { return request.request({ @@ -21,4 +42,4 @@ export const inviteReceive = () => { }) } -export default getReferralInfo +export default getReferralRewardInfo diff --git a/src/state/boards/fetchBoardsUser.ts b/src/state/boards/fetchBoardsUser.ts index d7a039b..ed2b299 100644 --- a/src/state/boards/fetchBoardsUser.ts +++ b/src/state/boards/fetchBoardsUser.ts @@ -8,8 +8,8 @@ import { getAddress, getBoardAddress } from 'utils/addressHelpers' export const fetchBoardUserAllowances = async (account: string) => { const calls = boardsConfig.map((board) => { const tokenAddresses = getAddress(board.tokenAddresses) - const boardChefAdress = getAddress(board.contractAddress) - return { address: tokenAddresses, name: 'allowance', params: [account, boardChefAdress] } + const boardChefAddress = getAddress(board.contractAddress) + return { address: tokenAddresses, name: 'allowance', params: [account, boardChefAddress] } }) const rawLpAllowances = await multicall(erc20ABI, calls) @@ -53,7 +53,6 @@ export const fetchBoardUserInfo = async (account: string) => { }, ] const [userInfo, estimatedProfit] = await multicall(board.abi, calls) - console.log(estimatedProfit) return { stakedBalance: new BigNumber(userInfo.amount._hex).toJSON(), unLockTime: userInfo.unLockTime ? new BigNumber(userInfo.unLockTime._hex).toNumber() : 0, diff --git a/src/state/referral/index.ts b/src/state/referral/index.ts index b2c1433..766d4de 100644 --- a/src/state/referral/index.ts +++ b/src/state/referral/index.ts @@ -1,6 +1,11 @@ import { createSlice } from '@reduxjs/toolkit' -import { getReferralInfo } from 'services/referral' -import { ReferralInfo, ReferralConfigType } from 'types/referral' +import { getReferralRewardInfo, getReferralConfigInfo } from 'services/referral' +import { ReferralInfo, ReferralConfigType, ReferralConfigInfo } from 'types/referral' +import BigNumber from 'bignumber.js' +import erc20ABI from 'config/abi/erc20.json' +import multicall from 'utils/multicall' +import tokens from 'config/constants/tokens' +import { getAddress, getReferralAddress } from 'utils/addressHelpers' import { ReferralState } from '../types' const initialState: ReferralState = { @@ -9,6 +14,10 @@ const initialState: ReferralState = { isCommander: false, rewardInfo: {}, } +const payWayList = { + usdt: tokens.usdt, + hcc: tokens.hcc, +} export const referralSlice = createSlice({ name: 'Referral', initialState, @@ -30,15 +39,33 @@ export const fetchReferralInfoAsync = (account) => async (dispatch) => { dispatch(setReferralInfo({})) return } - const data: ReferralInfo = await getReferralInfo() + const data: ReferralInfo = await getReferralRewardInfo() + const configInfo: ReferralConfigInfo[] = await getReferralConfigInfo() dispatch( setReferralInfo({ - commanderConfigInfo: data.inviteConfigList?.find((item) => item.type === ReferralConfigType.COMMANDER), - normalConfigInfo: data.inviteConfigList?.find((item) => item.type === ReferralConfigType.NORMAL), + commanderConfigInfo: configInfo?.find((item) => item.type === ReferralConfigType.COMMANDER), + normalConfigInfo: configInfo?.find((item) => item.type === ReferralConfigType.NORMAL), isCommander: data.isCommander, - rewardInfo: data.reward, + rewardInfo: data.reward || {}, }), ) } +export const fetchReferralUserAllowances = async (account: string) => { + const calls = Object.values(payWayList).map((payWayItem) => { + const tokenAddresses = getAddress(payWayItem.address) + const referralChefAddress = getReferralAddress() + return { address: tokenAddresses, name: 'allowance', params: [account, referralChefAddress] } + }) + + const rawLpAllowances = await multicall(erc20ABI, calls) + const parsedLpAllowances = rawLpAllowances.map((balance) => { + return new BigNumber(balance).toNumber() + }) + return { + usdt: parsedLpAllowances[0], + hcc: parsedLpAllowances[1], + } +} + export default referralSlice.reducer diff --git a/src/utils/request.ts b/src/utils/request.ts index 2f2bf2d..3134713 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,6 +1,4 @@ -import { Dispatch } from 'react' import axios from 'axios' -// import { clearUserInfo } from 'state/actions' import { CACHE_TOKEN } from 'config/constants/cacheKey' // create an axios instance @@ -9,7 +7,7 @@ const request = axios.create({ timeout: 50000, // request timeout }) let hasInit = false -export const initAxios = (dispatch: Dispatch, toast) => { +export const initAxios = (clearUserInfo, toast) => { if (hasInit) return hasInit = true request.interceptors.request.use( @@ -28,7 +26,7 @@ export const initAxios = (dispatch: Dispatch, toast) => { const res: any = response.data if (res.code !== 200) { if (res.code === 401) { - // dispatch(clearUserInfo()) + clearUserInfo() toast.toastError('Login expiration') return Promise.reject(new Error('Login expiration')) } diff --git a/src/views/Referral/components/BuyActions.tsx b/src/views/Referral/components/BuyActions.tsx new file mode 100644 index 0000000..5916940 --- /dev/null +++ b/src/views/Referral/components/BuyActions.tsx @@ -0,0 +1,109 @@ +import React, { useState, useEffect } from 'react' +import { Flex, Button, Modal, Image } from '@pancakeswap/uikit' +import styled from 'styled-components' +import { useTranslation } from 'contexts/Localization' +import { useAccount } from 'state/userInfo/hooks' +import { fetchReferralUserAllowances } from 'state/referral' +import { useERC20 } from 'hooks/useContract' +import { getAddress } from 'utils/addressHelpers' +import useToast from 'hooks/useToast' +import { checkBuyResult } from 'services/referral' +import useRefresh from 'hooks/useRefresh' +import tokens from 'config/constants/tokens' +import { useCheckTokenBalance, useApproveReferral, useBuyTransaction } from '../hooks' + +// interface BuyActionsProps { + +// } + +const Btn = styled(Button)` + width: 50%; + margin: 20px auto 0px auto; + border-radius: 50px; + background: linear-gradient(180deg, #7be0fc 0%, #ac7bf1 100%); + border: none; +` +const BuyActions: React.FC = () => { + const { t } = useTranslation() + const account = useAccount() + const [allowanceList, setAllowanceList] = useState({ usdt: 0, hcc: 0 }) + const usdtContract = useERC20(getAddress(tokens.usdt.address)) + const [loading, setLoading] = useState(false) + const [txId, setTxId] = useState() + const { toastSuccess } = useToast() + const { fastRefresh } = useRefresh() + const hccContract = useERC20(getAddress(tokens.hcc.address)) + const { onApprove: onUsdtApprove } = useApproveReferral(usdtContract) + const { onApprove: onHccApprove } = useApproveReferral(hccContract) + const buyTransaction = useBuyTransaction() + const handleApprove = async (approve) => { + try { + setLoading(true) + await approve() + setLoading(false) + getAllowances() + } catch (e) { + console.error(e) + } + } + const getAllowances = async () => { + const allowances = await fetchReferralUserAllowances(account) + setAllowanceList({ + usdt: allowances.usdt, + hcc: allowances.hcc, + }) + } + const handleBuy = async () => { + await buyTransaction() + } + const getTransactionResult = async () => { + const res = await checkBuyResult({ tx: txId }) + if (res?.success) { + setLoading(false) + setTxId(undefined) + toastSuccess('Buy Success') + } + } + useEffect(() => { + if (txId && loading) { + getTransactionResult() + } + }, [fastRefresh]) + + useEffect(() => { + if (account) { + getAllowances() + } else { + setAllowanceList({ usdt: 0, hcc: 0 }) + } + }, []) + + return ( + + {!allowanceList.usdt && ( + { + handleApprove(onUsdtApprove) + }} + > + {t('Approve %coin% Contract', { coin: 'usdt' })} + + )} + + {!allowanceList.hcc && ( + { + handleApprove(onHccApprove) + }} + > + {t('Approve %coin% Contract', { coin: 'hcc' })} + + )} + {allowanceList?.usdt && allowanceList.hcc ? {t('Buy It Now')} : null} + + ) +} + +export default BuyActions diff --git a/src/views/Referral/components/BuyNftModal.tsx b/src/views/Referral/components/BuyNftModal.tsx index ff31720..839a35e 100644 --- a/src/views/Referral/components/BuyNftModal.tsx +++ b/src/views/Referral/components/BuyNftModal.tsx @@ -3,6 +3,7 @@ import styled from 'styled-components' import { useTranslation } from 'contexts/Localization' import { useReferralNormalConfigInfo, useReferralCommanderConfigInfo } from 'state/referral/hooks' import { Flex, Button, Modal, Image } from '@pancakeswap/uikit' +import BuyActions from './BuyActions' import TextFlex from './TextFlex' import FlexCom from './FlexCom' @@ -27,13 +28,7 @@ const InfoDiv = styled.div` margin-left: 60px; } ` -const UpBtn = styled(Button)` - width: 50%; - margin: 20px auto 0px auto; - border-radius: 50px; - background: linear-gradient(180deg, #7be0fc 0%, #ac7bf1 100%); - border: none; -` + const ImageDiv = styled(Image)` width: 300px; height: 300px; @@ -77,10 +72,10 @@ const BuyNftModal: React.FC = () => { - - + + {/* {t('Buy It Now')} - + */} ) } diff --git a/src/views/Referral/components/Connected.tsx b/src/views/Referral/components/Connected.tsx index 6407c7b..9651bbc 100644 --- a/src/views/Referral/components/Connected.tsx +++ b/src/views/Referral/components/Connected.tsx @@ -55,9 +55,7 @@ const ConnectedCom: React.FC = () => { const { t } = useTranslation() const [onBuyModal] = useModal() const referralNormalConfigInfo = useReferralNormalConfigInfo() - console.log('referralNormalConfigInfo:', referralNormalConfigInfo) const referralRewardInfo = useReferralRewardInfo() - console.log('referralRewardInfo:', referralRewardInfo) const referralCommanderConfigInfo = useReferralCommanderConfigInfo() const getInviteReceive = async () => { await inviteReceive() diff --git a/src/views/Referral/hooks/index.ts b/src/views/Referral/hooks/index.ts index 42e7d4d..25f5a16 100644 --- a/src/views/Referral/hooks/index.ts +++ b/src/views/Referral/hooks/index.ts @@ -1,40 +1,41 @@ import { useState, useCallback } from 'react' import { useReferralchef, useReferralRewardchef } from 'hooks/useContract' -import useTokenBalance, { useGetBnbBalance } from 'hooks/useTokenBalance' -import { getAddress } from 'utils/addressHelpers' +import useTokenBalance from 'hooks/useTokenBalance' +import { getAddress, getReferralAddress } from 'utils/addressHelpers' import tokensList from 'config/constants/tokens' import useToast from 'hooks/useToast' import { useTranslation } from 'contexts/Localization' +import { ethers, Contract } from 'ethers' import { getBalanceNumber, getDecimalAmountNumber } from 'utils/formatBalance' -import { withdrawReward } from 'services/referral' +import { getWithdrawRewardParams, getBuyReferralParams } from 'services/referral' -const useCheckTokenBalance = ({ isBnb, isHcc, isUsdt }) => { - const { balance: bnbTokenBalance } = useGetBnbBalance() +export const useCheckTokenBalance = ({ isBnb, isHcc, isUsdt }) => { const { balance: usdtTokenBalance } = useTokenBalance(getAddress(tokensList.usdt.address)) const { balance: hccTokenBalance } = useTokenBalance(getAddress(tokensList.hcc.address)) const { toastWarning } = useToast() const { t } = useTranslation() - const onCheck = useCallback(() => { - if ( - (isBnb && getBalanceNumber(bnbTokenBalance) === 0) || - (isHcc && getBalanceNumber(hccTokenBalance) === 0) || - (isUsdt && getBalanceNumber(usdtTokenBalance) === 0) - ) { - toastWarning(t('Insufficient Balance')) - } - }, [isBnb, isHcc, isUsdt]) + const onCheck = useCallback( + (hccAmount, usdtAmount) => { + if ( + (isHcc && getBalanceNumber(hccTokenBalance) === hccAmount) || + (isUsdt && getBalanceNumber(usdtTokenBalance) === usdtAmount) + ) { + toastWarning(t('Insufficient Balance')) + } + }, + [isBnb, isHcc, isUsdt], + ) return [onCheck] } export const useBuyTransaction = () => { const referralContract = useReferralchef() const transaction = async () => { - const data = await withdrawReward() - const { to, amount, code, signature } = data - console.log(data) - const params = [to, amount, code, signature] - const price = getDecimalAmountNumber(amount) - const res = await referralContract.adminMint(...params, { value: price }) + const data = await getBuyReferralParams() + const { address, hccPrice, otherPaymentPirce, code, timestamp, sign } = data + const params = [address, hccPrice, otherPaymentPirce, code, timestamp, sign] + // const price = getDecimalAmountNumber(receive) + const res = await referralContract.mint(...params) return res } return transaction @@ -43,15 +44,28 @@ export const useBuyTransaction = () => { export const useWithdraw = () => { const referralRewardContract = useReferralRewardchef() const transaction = async () => { - const data = await withdrawReward() - const { to, amount, expiredTime, signature } = data - console.log(data) - const params = [to, amount, expiredTime, signature] - const price = getDecimalAmountNumber(amount) + const data = await getWithdrawRewardParams() + const { address, receive, timestamp, sign } = data + const params = [address, receive, timestamp, sign] + const price = getDecimalAmountNumber(receive) const res = await referralRewardContract.withDrawReward(...params, { value: price }) return res } return transaction } +export const useApproveReferral = (tokenContract: Contract) => { + const handleApprove = useCallback(async () => { + try { + const tx = await tokenContract.approve(getReferralAddress(), ethers.constants.MaxUint256) + const receipt = await tx.wait() + return receipt.status + } catch (e) { + return false + } + }, [tokenContract]) + + return { onApprove: handleApprove } +} + export default useCheckTokenBalance