调整部分页面

This commit is contained in:
myf 2022-06-13 19:52:37 +08:00
parent f1dd02bb55
commit 202ab6b28f
13 changed files with 753 additions and 4 deletions

View File

@ -24,7 +24,8 @@ REACT_APP_SNAPSHOT_VOTING_API = "https://xtjyd0liqe.execute-api.ap-northeast-1.a
# REACT_APP_REQUEST_URL = 'http://192.253.237.94:9090'
REACT_APP_REQUEST_URL = 'http://101.35.117.69:9090'
REACT_APP_REQUEST_URL = 'http://HousedeMacBook-Air.local:8080'
# REACT_APP_REQUEST_URL = 'http://101.35.117.69:9090'
# REACT_APP_REQUEST_URL = 'http://192.168.2.147:8080'
# REACT_APP_REQUEST_URL = 'http://192.168.2.:8080'
# REACT_APP_REQUEST_URL = 'http://6o7g1fv83e.51xd.pub'

View File

@ -0,0 +1,449 @@
[
{
"inputs": [
{ "internalType": "address", "name": "_hccAddress", "type": "address" },
{ "internalType": "address", "name": "_otherPaymentAddress", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "approved", "type": "address" },
{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "operator", "type": "address" },
{ "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" }
],
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" },
{ "indexed": true, "internalType": "uint256", "name": "code", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "tpe", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }
],
"name": "CreateNft",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "address", "name": "newHccAddress", "type": "address" }],
"name": "HccAddressChange",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint256", "name": "newHccPrice", "type": "uint256" }],
"name": "HccPriceChange",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "address", "name": "newNftHolderPool", "type": "address" }],
"name": "NftHolderPoolChange",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "address", "name": "newOtherPaymentAddress", "type": "address" }],
"name": "OtherPaymentAddressChange",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint256", "name": "newOtherPaymentPirce", "type": "uint256" }],
"name": "OtherPaymentPirceChange",
"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": false, "internalType": "bool", "name": "pause", "type": "bool" }],
"name": "PauseEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" },
{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [],
"name": "START_AT",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "_lastTokenID",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "_userPowerMap",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "_timestamp", "type": "uint256" },
{ "internalType": "uint256", "name": "code", "type": "uint256" },
{ "internalType": "uint256", "name": "tpe", "type": "uint256" },
{ "internalType": "bytes", "name": "_signature", "type": "bytes" }
],
"name": "adminMint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "approve",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "owner", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "baseTokenURI",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "executorAddress",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }],
"name": "getApproved",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "hccAddress",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "operator", "type": "address" }
],
"name": "isApprovedForAll",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "num", "type": "uint256" },
{ "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": "uint256", "name": "tpe", "type": "uint256" },
{ "internalType": "bytes", "name": "_signature", "type": "bytes" }
],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "nftHolderPool",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "nftRewardPool",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_findAddress", "type": "address" }],
"name": "notifyPowerChange",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "otherPaymentAddress",
"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": "uint256", "name": "tokenId", "type": "uint256" }],
"name": "ownerOf",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }],
"name": "rawOwnerOf",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{ "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "bytes", "name": "_data", "type": "bytes" }
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "operator", "type": "address" },
{ "internalType": "bool", "name": "approved", "type": "bool" }
],
"name": "setApprovalForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "string", "name": "baseURI", "type": "string" }],
"name": "setBaseURI",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "executor", "type": "address" }],
"name": "setExecutorAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newHccAddress", "type": "address" }],
"name": "setHccAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newNftHolderPool", "type": "address" }],
"name": "setNftHolderPool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newOtherPaymentAddress", "type": "address" }],
"name": "setOtherPaymentAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bool", "name": "_pause", "type": "bool" }],
"name": "setPause",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "num", "type": "uint256" },
{ "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" },
{ "internalType": "uint256", "name": "code", "type": "uint256" },
{ "internalType": "uint256", "name": "_timestamp", "type": "uint256" },
{ "internalType": "bytes", "name": "_signature", "type": "bytes" }
],
"name": "signatureWallet",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }],
"name": "supportsInterface",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "index", "type": "uint256" }],
"name": "tokenByIndex",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "uint256", "name": "index", "type": "uint256" }
],
"name": "tokenOfOwnerByIndex",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }],
"name": "tokenURI",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalToken",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_owner", "type": "address" }],
"name": "walletOfOwner",
"outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "tokenAddress", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "withDrawToken",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

View File

@ -0,0 +1,129 @@
[
{
"inputs": [
{ "internalType": "contract IERC20", "name": "_HCC", "type": "address" },
{ "internalType": "address", "name": "_HCCNftAddress", "type": "address" },
{ "internalType": "address", "name": "_HCCNFTReawardPool", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"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": "value", "type": "uint256" }
],
"name": "UserFightPoint",
"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"
},
{
"inputs": [],
"name": "HCC",
"outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "HCCNFTReawardPool",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "HCCNftAddress",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "_poolInfo",
"outputs": [
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" },
{ "internalType": "uint256", "name": "totalReward", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "paused",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
"name": "pendingHCC",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{ "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ "inputs": [], "name": "setPause", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "updatePool", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "userInfo",
"outputs": [
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
{ "internalType": "uint256", "name": "rewardDebt", "type": "uint256" },
{ "internalType": "uint256", "name": "receiveReward", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "_amount", "type": "uint256" },
{ "internalType": "address", "name": "_user", "type": "address" }
],
"name": "userPowerChange",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
"name": "withdrawHCC",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

View File

@ -35,6 +35,17 @@
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "buy", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "pay", "type": "uint256" },
{ "indexed": false, "internalType": "bool", "name": "isCredited", "type": "bool" }
],
"name": "Purchase",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint256", "name": "newLockTime", "type": "uint256" }],

View File

@ -42,7 +42,12 @@ export default {
idoPurchase: {
97: '0x2f562A9fE0325501A6Aa92cd9e2081B026fC35aa',
56: '0x2f562A9fE0325501A6Aa92cd9e2081B026fC35aa', // NEED CHANGE IDO兑换
5: '0xC7dB5e542f63CB616fF7D25c683f82f96dBfBEe6',
5: '0x81cdaf31147b86ffe6303b1bde6f20a5377d87b1',
},
blindBox: {
97: '0x0e226d7b83b511ce224803b1330beb4a59bfa5d6',
56: '0x0e226d7b83b511ce224803b1330beb4a59bfa5d6', // NEED CHANGE 官方市场 盲盒
5: '0x0e226d7b83b511ce224803b1330beb4a59bfa5d6',
},
lotteryV2: {
97: '0x5790c3534F30437641541a0FA04C992799602998',

View File

@ -28,6 +28,7 @@ import {
getBoardchefContract,
getReferralRewardchefContract,
getIdoPurchaseContract,
getHccGiftNftContract,
} from 'utils/contractHelpers'
// Imports below migrated from Exchange useContract.ts
@ -114,6 +115,10 @@ export const useIdoPurchase = () => {
const { library } = useActiveWeb3React()
return useMemo(() => getIdoPurchaseContract(library.getSigner()), [library])
}
export const useHccGiftNft = () => {
const { library } = useActiveWeb3React()
return useMemo(() => getHccGiftNftContract(library.getSigner()), [library])
}
export const useReferralRewardchef = () => {
const { library } = useActiveWeb3React()
return useMemo(() => getReferralRewardchefContract(library.getSigner()), [library])

View File

@ -14,5 +14,11 @@ export const getBoxDetail = (id) => {
method: 'get',
})
}
export const getPurchase = (id) => {
return request.request({
url: `/high_city/app/api/box/purchase/${id}`,
method: 'get',
})
}
export default getBoxPage

View File

@ -0,0 +1,30 @@
import { createSlice } from '@reduxjs/toolkit'
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, getBlindBoxAddress } from 'utils/addressHelpers'
const payWayList = {
usdt: tokens.usdt,
hcc: tokens.hcc,
}
export const fetchBlindBoxUserAllowances = async (account: string) => {
const calls = Object.values(payWayList).map((payWayItem) => {
const tokenAddresses = getAddress(payWayItem.address)
const referralChefAddress = getBlindBoxAddress()
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 fetchBlindBoxUserAllowances

View File

@ -77,3 +77,6 @@ export const getBunnySpecialPredictionAddress = () => {
export const getIdoPurchaseAddress = () => {
return getAddress(addresses.idoPurchase)
}
export const getBlindBoxAddress = () => {
return getAddress(addresses.blindBox)
}

View File

@ -28,6 +28,7 @@ import {
getReferralAddress,
getReferralRewardAddress,
getIdoPurchaseAddress,
getBlindBoxAddress,
} from 'utils/addressHelpers'
// ABI
@ -61,6 +62,7 @@ import MultiCallAbi from 'config/abi/Multicall.json'
import bunnySpecialCakeVaultAbi from 'config/abi/bunnySpecialCakeVault.json'
import bunnySpecialPredictionAbi from 'config/abi/bunnySpecialPrediction.json'
import idoPurchase from 'config/abi/idoPurchase.json'
import blindBox from 'config/abi/blindBox.json'
import { ChainLinkOracleContract, PredictionsContract } from './types'
const getContract = (abi: any, address: string, signer?: ethers.Signer | ethers.providers.Provider) => {
@ -132,6 +134,9 @@ export const getReferralRewardchefContract = (signer?: ethers.Signer | ethers.pr
export const getIdoPurchaseContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(idoPurchase, getIdoPurchaseAddress(), signer)
}
export const getHccGiftNftContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(blindBox, getBlindBoxAddress(), signer)
}
export const getClaimRefundContract = (signer?: ethers.Signer | ethers.providers.Provider) => {
return getContract(claimRefundAbi, getClaimRefundAddress(), signer)
}

View File

@ -1,5 +1,10 @@
import { useCallback } from 'react'
import { getBoxPage, getBoxDetail } from 'services/blindBox'
import { useHccGiftNft } from 'hooks/useContract'
import blindBox from 'config/abi/blindBox.json'
import { getAddress, getBlindBoxAddress } from 'utils/addressHelpers'
import multicall from 'utils/multicall'
import { ethers, Contract } from 'ethers'
import { getBoxPage, getBoxDetail, getPurchase } from 'services/blindBox'
// nft盒子
export const useGetList = () => {
@ -18,4 +23,41 @@ export const useGetBoxDetail = () => {
return data
}
// 授权usdt
export const useApproveUsdt = (tokenContract: Contract) => {
const handleApprove = useCallback(async () => {
try {
const tx = await tokenContract.approve(getBlindBoxAddress(), ethers.constants.MaxUint256)
const receipt = await tx.wait()
return receipt.status
} catch (e) {
return false
}
}, [tokenContract])
return { onApprove: handleApprove }
}
export const useApproveHccGiftNft = (tokenContract: Contract) => {
const handleApprove = useCallback(async () => {
try {
const tx = await tokenContract.approve(getBlindBoxAddress(), ethers.constants.MaxUint256)
const receipt = await tx.wait()
return receipt.status
} catch (e) {
return false
}
}, [tokenContract])
return { onApprove: handleApprove }
}
// 购买
export const useGetPurchase = () => {
const data = async (id) => {
const result = await getPurchase(id)
return result
}
return data
}
export default useGetList

View File

@ -2,15 +2,19 @@ import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { useTranslation } from 'contexts/Localization'
import { useAccount } from 'state/userInfo/hooks'
import { getAddress } from 'utils/addressHelpers'
import { fetchBlindBoxUserAllowances } from 'state/blindBox'
import { useERC20 } from 'hooks/useContract'
import UnlockButton from 'components/UnlockButton'
import SwiperCore, { Keyboard, Mousewheel, Pagination } from 'swiper'
import { Swiper, SwiperSlide } from 'swiper/react'
import { Card, Text, Flex, Image, Button } from '@pancakeswap/uikit'
import { UnOpenModel } from 'components/Modal'
import tokens from 'config/constants/tokens'
import { ListProp } from 'types/blindBox'
import Header from './component/Header'
import Operation from './component/Operation'
import { useGetList } from './hooks'
import { useGetList, useApproveHccGiftNft } from './hooks'
import 'swiper/swiper.min.css'
import 'swiper/components/pagination/pagination.min.css'
@ -139,13 +143,47 @@ const BuyButton = styled(Button)`
width: 500px;
}
`
const AuthorizationBtn = styled(Button)`
width: 40%;
margin: 20px auto 0px auto;
border-radius: 50px;
background: linear-gradient(180deg, #7be0fc 0%, #ac7bf1 100%);
border: none;
`
const BlindBox: React.FC = () => {
const { t } = useTranslation()
const [allowanceList, setAllowanceList] = useState({ usdt: 0, hcc: 0 })
const [loading, setLoading] = useState(false)
const account = useAccount()
const [blindBoxList, setBlindBoxList] = useState<ListProp[]>()
const [buyNum, setBuyNum] = useState(0)
const usdtContract = useERC20(getAddress(tokens.usdt.address))
const hccContract = useERC20(getAddress(tokens.hcc.address))
const { onApprove: onUsdtApprove } = useApproveHccGiftNft(usdtContract)
const { onApprove: onHccApprove } = useApproveHccGiftNft(hccContract)
const getAllowances = async () => {
const allowances = await fetchBlindBoxUserAllowances(account)
setAllowanceList({
usdt: allowances.usdt,
hcc: allowances.hcc,
})
}
const handleApprove = async (approve) => {
try {
setLoading(true)
await approve()
setLoading(false)
getAllowances()
} catch (e) {
console.error(e)
}
}
const getList = useGetList()
const getData = async () => {
@ -199,6 +237,28 @@ const BlindBox: React.FC = () => {
<Operation detail={item} getNum={(v) => setBuyNum(v)} />
</BlindBoxCard>
{account ? <BuyButton onClick={handleBuy}>{t('Buy It Now')}</BuyButton> : <UnlockButtonDiv />}
{!allowanceList.usdt && (
<AuthorizationBtn
disabled={loading}
onClick={() => {
handleApprove(onUsdtApprove)
}}
>
{t('Approve %coin% Contract', { coin: 'USDT' })}
</AuthorizationBtn>
)}
{!allowanceList.hcc && (
<AuthorizationBtn
disabled={loading}
onClick={() => {
handleApprove(onHccApprove)
}}
>
{t('Approve %coin% Contract', { coin: 'HCC' })}
</AuthorizationBtn>
)}
</BlindBoxFlex>
</SwiperSlide>
)

View File

@ -68,6 +68,8 @@ export const useGetRound = () => {
}
const { id } = data
const idoPurchaseAddress = getIdoPurchaseAddress()
console.log(idoPurchaseAddress)
console.log(id)
const calls = [
{
address: idoPurchaseAddress,
@ -76,6 +78,7 @@ export const useGetRound = () => {
},
]
const res = await multicall(idoPurchaseABI, calls)
console.log(res)
const detail = res.map((item) => {
return {
beginTime: new BigNumber(item?.beginTime._hex).toNumber() * 1000,