From 6643f6ebf4eef56dda3487c525167a32cf13c914 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AD=BE=E5=88=B0=E6=97=A5?= =?UTF-8?q?=E5=8E=86=E7=9A=84=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91,=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BAutc=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 2 +- src/utils/chainapi.js | 83 ++++++------------------------------ src/utils/utcdate.util.js | 12 ++++++ src/utils/webapi.js | 17 ++++++-- src/views/home/calenView.vue | 53 ++++++++--------------- 5 files changed, 57 insertions(+), 110 deletions(-) create mode 100644 src/utils/utcdate.util.js diff --git a/.env.production b/.env.production index c7982a9..3044f8d 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,5 @@ # API -VUE_APP_API_URL = 'https://oauth-svr.cebggame.com/task/' +VUE_APP_API_URL = 'https://oauth-svr.cebggame.com/task' VUE_APP_WL_URL = 'https://nftwl.counterfire.games/wl_test' VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8' diff --git a/src/utils/chainapi.js b/src/utils/chainapi.js index 4ba741f..83baa3c 100644 --- a/src/utils/chainapi.js +++ b/src/utils/chainapi.js @@ -2,13 +2,7 @@ const targetAddress = '0x50A8e60041A206AcaA5F844a1104896224be6F39'; import Web3 from 'web3' - -// 签到 -export const sendDailyCheckIn = async (address) => { - // const web3 = Web3; - // console.log( web3.utils.utf8ToHex(dataStr)) - // return - const dataStr = 'data:,{"p":"cf-20","op":"check"}'; +export const sendScription = async (address, dataStr) => { const data = Web3.utils.utf8ToHex(dataStr) const provider = new Web3(window.ethereum); let gasPrice = await provider.eth.getGasPrice() @@ -27,85 +21,32 @@ export const sendDailyCheckIn = async (address) => { Object.assign(sendObj, {gasPrice, gasLimit}) return provider.eth.sendTransaction(sendObj) } +// 签到 +export const sendDailyCheckIn = async (address) => { + const dataStr = 'data:,{"p":"cf-20","op":"check"}'; + return sendScription(address, dataStr) +} // 开宝箱 export const sendOpenChest = async (address, chestId) => { - // const web3 = window.w3; - const openChestStr = `data:,{"p":"cf-20","op":"chest_open","id":"${chestId}"}` - const data = Web3.utils.utf8ToHex(openChestStr) - const provider = new Web3(window.ethereum); - let gasPrice = await provider.eth.getGasPrice() * 2n - // const gasPrice = 100000000n; - console.log('gasPrice: ',gasPrice) - let sendObj = { - from: address, - to: targetAddress, - value: '0x0', - data - } - let gasLimit = await provider.eth.estimateGas(sendObj) - console.log('gasLimit: ', gasLimit) - Object.assign(sendObj, {gasPrice, gasLimit}) - return provider.eth.sendTransaction(sendObj) + const dataStr = `data:,{"p":"cf-20","op":"chest_open","id":"${chestId}"}` + return sendScription(address, dataStr) } // 领积分 export const sendClaimTask = async (address, taskId) => { - const openClaimTaskStr = `data:,{"p":"cf-20","op":"task_claim","val":"${taskId}"}` - const data = Web3.utils.utf8ToHex(openClaimTaskStr) - const provider = new Web3(window.ethereum); - console.log(provider) - let gasPrice = await provider.eth.getGasPrice() * 2n - // const gasPrice = 100000000n; - console.log('gasPrice: ',gasPrice) - let sendObj = { - from: address, - to: targetAddress, - value: '0x0', - data - } - let gasLimit = await provider.eth.estimateGas(sendObj) - console.log('gasLimit: ', gasLimit) - Object.assign(sendObj, {gasPrice, gasLimit}) - return provider.eth.sendTransaction(sendObj) + const dataStr = `data:,{"p":"cf-20","op":"task_claim","val":"${taskId}"}` + return sendScription(address, dataStr) } // 探索 export const sendExplore = async (address, explore_id) => { const openCExploreStr = `data:,{"p":"cf-20","op":"explore","val":"${explore_id}"}` - const data = Web3.utils.utf8ToHex(openCExploreStr) - const provider = new Web3(window.ethereum); - let gasPrice = await provider.eth.getGasPrice() * 2n - // const gasPrice = 100000000n; - console.log('gasPrice: ',gasPrice) - let sendObj = { - from: address, - to: targetAddress, - value: '0x0', - data - } - let gasLimit = await provider.eth.estimateGas(sendObj) - console.log('gasLimit: ', gasLimit) - Object.assign(sendObj, {gasPrice, gasLimit}) - return provider.eth.sendTransaction(sendObj) + return sendScription(address, openCExploreStr) } // 助力 export const sendHelp = async (address, shareCode) => { const openHelpStr = `data:,{"p":"cf-20","op":"chest_enhance","val":"${shareCode}"}` - const data = Web3.utils.utf8ToHex(openHelpStr) - const provider = new Web3(window.ethereum); - let gasPrice = await provider.eth.getGasPrice() * 2n - // const gasPrice = 100000000n; - console.log('gasPrice: ',gasPrice) - let sendObj = { - from: address, - to: targetAddress, - value: '0x0', - data - } - let gasLimit = await provider.eth.estimateGas(sendObj) - console.log('gasLimit: ', gasLimit) - Object.assign(sendObj, {gasPrice, gasLimit}) - return provider.eth.sendTransaction(sendObj) + return sendScription(address, openHelpStr) } diff --git a/src/utils/utcdate.util.js b/src/utils/utcdate.util.js new file mode 100644 index 0000000..109778b --- /dev/null +++ b/src/utils/utcdate.util.js @@ -0,0 +1,12 @@ +export const formatDate = (date) => { + const year = date.getUTCFullYear() + const month = (date.getUTCMonth() + 1 + '').padStart(2, '0') + const day = (date.getUTCDate() + '').padStart(2, '0') + return `${year}${month}${day}` +} + +export const getDayBegin = (date) => { + let result = new Date(date.getTime()) + result.setUTCHours(0, 0, 0, 0) + return result +} \ No newline at end of file diff --git a/src/utils/webapi.js b/src/utils/webapi.js index 0128f0a..614e4b4 100644 --- a/src/utils/webapi.js +++ b/src/utils/webapi.js @@ -18,6 +18,17 @@ const httpPost = async (url, data) => { }).then(toJson); } +const httpGet = async (url) => { + let headers = {"Content-Type": "application/json"}; + if (token) { + headers['Authorization'] = `Bearer ${token}`; + } + return fetch(url, { + method: "GET", + headers + }).then(toJson); +} + const base58Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; export const hexToBase58 = (hexString) => { @@ -156,9 +167,9 @@ export const apiGameStep = async (id) => { } // 签到列表 -export const apiCheckin = async () => { - const url = `${API_BASE}/api/user/checkin/list/tag`; - return httpPost(url, { }) +export const apiCheckin = async (tag) => { + const url = `${API_BASE}/api/user/checkin/list/${tag}`; + return httpGet(url) } // 连续签到奖励 diff --git a/src/views/home/calenView.vue b/src/views/home/calenView.vue index a7462d0..c573a89 100644 --- a/src/views/home/calenView.vue +++ b/src/views/home/calenView.vue @@ -18,6 +18,9 @@