import { Wallet } from '@/wallet/index.js' import store from '@/store' // 开宝箱 export const sendOpenChest = async (address, chestId) => { const dataStr = `data:,{"p":"cf-20","op":"chest_open","id":"${chestId}"}` return new Wallet().sendScription(address, dataStr) } /** * 发送链上请求 * @param {*} type * @param {*} address * @param {*} val * @returns */ export const sendToChain = async (type, address, val) => { const storeageKey = `${address}_${type}_${val || 'default'}` if (localStorage.getItem(storeageKey)) { return } if (store.state.wallet.chainId+'' !== process.env.VUE_APP_CHAIN_ID){ await new Wallet().changeChain() } let dataStr = `data:,{"p":"cf-20","op":"${type}","val":"${val}"}` if (type === 'check') { dataStr = 'data:,{"p":"cf-20","op":"check"}'; } else if (type === 'chest_open') { dataStr = `data:,{"p":"cf-20","op":"chest_open","id":"${val}"}` } let chainRes = await new Wallet().sendScription(address, dataStr) if (!chainRes?.transactionHash) { throw new Error('Failed to claim task') } localStorage.setItem(storeageKey, chainRes.transactionHash) return storeageKey } // 探索 export const sendExplore = async (address, explore_id) => { const openCExploreStr = `data:,{"p":"cf-20","op":"explore","val":"${explore_id}"}` return new Wallet().sendScription(address, openCExploreStr) } // 助力 export const sendHelp = async (address, shareCode) => { const openHelpStr = `data:,{"p":"cf-20","op":"chest_enhance","val":"${shareCode}"}` return new Wallet().sendScription(address, openHelpStr) }