Commit 5d21644f authored by xhx's avatar xhx

调整

parent c064f79c
NODE_ENV="development" NODE_ENV="development"
VUE_APP_URL="http://172.16.100.59:8000" VUE_APP_URL="http://172.16.100.59:8000"
\ No newline at end of file VUE_CHAIN_URL="http://172.16.100.59:8801"
\ No newline at end of file
NODE_ENV="production" NODE_ENV="production"
// VUE_APP_URL="http://" // VUE_APP_URL="http://"
\ No newline at end of file VUE_CHAIN_URL="http://172.16.100.59:8801"
\ No newline at end of file
...@@ -43,9 +43,6 @@ export default Vue.extend({ ...@@ -43,9 +43,6 @@ export default Vue.extend({
type: Object type: Object
} }
}, },
methods: {
}
}) })
</script> </script>
......
...@@ -73,58 +73,6 @@ async function getTransaction(hash: string) { ...@@ -73,58 +73,6 @@ async function getTransaction(hash: string) {
}]) }])
} }
async function signFun(b: any, fn: any, fail?: any) {
await signTransition(b.data.result, async (sign: any) => {
let s = {} as any
if (typeof sign === 'string') {
s = JSON.parse(sign)
} else {
s = sign
}
if (s.error) {
Toast.clear()
fail()
return
}
const send = await sendTransaction(s.signHash)
if (send.data.error) {
Toast(send.data.error)
fail()
return
}
let res = {} as any
const timer = setInterval(async() => {
res = await getTransaction(send.data.result)
if (!res.data.error) {
clearInterval(timer)
if (res.data.result.receipt.ty === 1) {
if (fail) {
Toast(res.data.result.receipt.tyName)
fail()
}
} else {
if (fn) fn(res)
}
}
}, 1000)
})
// web 测试
// const sign = await signTransition(b.data.result, test.privateKey)
// const send = await sendTransaction(sign.data.result)
// let res = {} as any
// const timer = setInterval(async() => {
// res = await getTransaction(send.data.result)
// if (!res.data.error) {
// clearInterval(timer)
// if (res.data.result.receipt.ty === 1) {
// if (fail) fail()
// } else {
// if (fn) fn(res)
// }
// }
// }, 1000)
}
export default { export default {
/** /**
...@@ -132,17 +80,6 @@ export default { ...@@ -132,17 +80,6 @@ export default {
* @param data * @param data
* @returns * @returns
*/ */
createRawTransaction: async function (data: rawTransaction, fn?: any, fail?: any) {
const res = await chainRequire('Chain33.CreateRawTransaction', [data])
console.log(res)
// if 判断
return signFun(res, fn, fail)
},
/**
* 构造交易
* @param data
* @returns
*/
createTransaction: async function (data: rawTransaction, fn?: any, fail?: any) { createTransaction: async function (data: rawTransaction, fn?: any, fail?: any) {
return await chainRequire('Chain33.CreateRawTransaction', [data]) return await chainRequire('Chain33.CreateRawTransaction', [data])
}, },
...@@ -198,6 +135,11 @@ export default { ...@@ -198,6 +135,11 @@ export default {
getTransaction, getTransaction,
/**
* 挖矿绑定
* @param data
* @returns
*/
createBindMiner: async function (data: { createBindMiner: async function (data: {
bindAddr: string, bindAddr: string,
originAddr: string, originAddr: string,
...@@ -208,6 +150,7 @@ export default { ...@@ -208,6 +150,7 @@ export default {
return res return res
}, },
createRawTxGroup: function (data: { createRawTxGroup: function (data: {
txs: any txs: any
}) { }) {
......
import { request } from "./service"; import { request } from "./service";
import store from '@/store/index' import store from '@/store/index'
import { Toast } from 'vant'
const service = request('/api') const service = request('/api')
service.interceptors.request.use(function (config) { service.interceptors.request.use(function (config) {
// do something before request is sent
console.log(store.state) console.log(store.state)
if ((store.state as any).app.address) { if ((store.state as any).app.address) {
const str = (store.state as any).app.address const str = (store.state as any).app.address
...@@ -16,36 +14,49 @@ service.interceptors.request.use(function (config) { ...@@ -16,36 +14,49 @@ service.interceptors.request.use(function (config) {
return Promise.reject(error); return Promise.reject(error);
}); });
// service.interceptors.response.use( /**
// response => { * 邀请用户
// // if the custom code is not 200, it is judged as an error. * @param invitation
// // tryHideFullScreenLoading() * @returns
// return response */
// }, error => {
// console.log('error', error)
// // Do something with response error
// // console.log(error.response)
// const err = error.response
// Toast(err.data.reason || '请求失败')
// return Promise.reject(error);
// })
export const invitePool = function(invitation: string) { export const invitePool = function(invitation: string) {
return service.post('/web/pool-invite', { invitation }) return service.post('/web/pool-invite', { invitation })
} }
export const bindPool = function(id: string, amount: string|number) { /**
return service.post('/web/bind-pool', { id: id, amount }) * 绑定购买
* @param id
* @param amount
* @param isBind
* @returns
*/
export const bindPool = function(id: string, amount: string|number, isBind?: boolean) {
return service.post('/web/bind-pool', { id, amount, isBind })
} }
/**
* 是否初次绑定购买
* @param id
* @returns
*/
export const checkBind = function(id: string) { export const checkBind = function(id: string) {
return service.get('/web/check-bind', { params: {id}}) return service.get('/web/check-bind', { params: {id}})
} }
/**
* 矿池信息
* @param id
* @returns
*/
export const poolInfo = function(id: string|number) { export const poolInfo = function(id: string|number) {
return service.get('/web/pool-info', { params: {id}}) return service.get('/web/pool-info', { params: {id}})
} }
/**
* 矿池市场
* @param data
* @returns
*/
export const poolList = function(data: { export const poolList = function(data: {
page: number, page: number,
pageSize: number, pageSize: number,
...@@ -54,12 +65,16 @@ export const poolList = function(data: { ...@@ -54,12 +65,16 @@ export const poolList = function(data: {
return service.get('/web/pool-list', { params: data }) return service.get('/web/pool-list', { params: data })
} }
/**
* 矿机列表
* @param data
* @returns
*/
export const userMachineList = function(data: { export const userMachineList = function(data: {
id?: string|number, // id?: string|number,
addr?: string, // addr?: string,
page: string|number, page: string|number,
pageSize: string|number, pageSize: string|number,
limit?: string|number,
status?: string|number status?: string|number
}) { }) {
return service.get('/web/user-machine-list', { params: data }) return service.get('/web/user-machine-list', { params: data })
......
// export const test = { // export const test = {
// addr: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp',
// privateKey: '0xCC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944'
// }
// export const test = {
// addr: '14KEKbYtKKQm4wMthSK9J4La4nAiidGozt', // addr: '14KEKbYtKKQm4wMthSK9J4La4nAiidGozt',
// privateKey: '0xCC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944' // privateKey: '0xCC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944'
// } // }
......
...@@ -106,10 +106,9 @@ ...@@ -106,10 +106,9 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import { Loading, NavBar, Stepper, Toast } from 'vant' import { NavBar, Stepper, Toast } from 'vant'
import { poolInfo, bindPool, checkBind } from '@/service/pool' import { poolInfo, bindPool, checkBind } from '@/service/pool'
import { signTxGroup } from '@33cn/wallet-api' import { signTxGroup } from '@33cn/wallet-api'
import { signGroup } from '@/utils/bridge'
import service from '@/service/chain33' import service from '@/service/chain33'
export default Vue.extend({ export default Vue.extend({
components: { components: {
...@@ -122,7 +121,7 @@ export default Vue.extend({ ...@@ -122,7 +121,7 @@ export default Vue.extend({
info: {} as any, info: {} as any,
fee: 0, fee: 0,
profit: 0, profit: 0,
isBind: false, isBind: false, // 初次购买 true: 否 false: 是
ticketNum: 10000 // BTY 转票比例 ticketNum: 10000 // BTY 转票比例
} }
}, },
...@@ -152,20 +151,18 @@ export default Vue.extend({ ...@@ -152,20 +151,18 @@ export default Vue.extend({
}) })
}, },
checkBind() { checkBind() {
checkBind(this.info.id).then(res => { checkBind(this.$route.query.id as string).then(res => {
if (res.data.data.isSucc) { if (res.data.data.isSucc) {
this.isBind = true this.isBind = true
} }
}).catch(() => {
this.isBind = false
}) })
}, },
signGroup(txs:Array<string>){ signGroup(txs:Array<string>){
return signTxGroup(txs.join(),'none',-1); return signTxGroup(txs.join(),'none',-1);
}, },
async buy() { async buy() {
if (this.isBind) {
Toast('你已购买该矿池,不可重复购买当前矿池')
return
}
if (this.profit < +this.info.minTicket) { if (this.profit < +this.info.minTicket) {
Toast(`您的票数余额为${this.profit}票,不足${this.info.minTicket}票`) Toast(`您的票数余额为${this.profit}票,不足${this.info.minTicket}票`)
return return
...@@ -176,7 +173,6 @@ export default Vue.extend({ ...@@ -176,7 +173,6 @@ export default Vue.extend({
amount: this.ticketNum * +this.value * 1e8, amount: this.ticketNum * +this.value * 1e8,
checkBalance: false checkBalance: false
}) })
console.log(bindRes.data)
const transRes = await service.createTransaction({ const transRes = await service.createTransaction({
fee: this.fee, fee: this.fee,
to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp', to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp',
...@@ -184,7 +180,6 @@ export default Vue.extend({ ...@@ -184,7 +180,6 @@ export default Vue.extend({
note: 'coins->ticket', note: 'coins->ticket',
execName: 'ticket' execName: 'ticket'
}) })
console.log(transRes)
const sign = await this.signGroup([bindRes.data.result.txHex, transRes.data.result]); const sign = await this.signGroup([bindRes.data.result.txHex, transRes.data.result]);
Toast.loading({ Toast.loading({
duration: 0, duration: 0,
...@@ -193,7 +188,6 @@ export default Vue.extend({ ...@@ -193,7 +188,6 @@ export default Vue.extend({
}) })
console.log('sign', sign) console.log('sign', sign)
const send = await service.sendTransaction(sign) const send = await service.sendTransaction(sign)
console.log(send)
if (send.data.result.error) { if (send.data.result.error) {
Toast('购买失败') Toast('购买失败')
return return
...@@ -202,18 +196,16 @@ export default Vue.extend({ ...@@ -202,18 +196,16 @@ export default Vue.extend({
const timer = setInterval(async() => { const timer = setInterval(async() => {
res = await service.getTransaction(send.data.result) res = await service.getTransaction(send.data.result)
if (!res.data.error) { if (!res.data.error) {
console.log('res', res.data)
clearInterval(timer) clearInterval(timer)
const next = res.data.result.tx.next const next = res.data.result.tx.next
console.log('next',next)
const transaction = await service.getTransaction(next) const transaction = await service.getTransaction(next)
if (transaction.data.result.receipt.ty === 1) { if (transaction.data.result.receipt.ty === 1) {
Toast(res.data.result.receipt.tyName) Toast(res.data.result.receipt.tyName)
} else { } else {
bindPool(this.info.id, this.value).then(async (r: any) => { const isBind = this.isBind ? true : false
bindPool(this.info.id, this.value, isBind).then(async (r: any) => {
if (r.data.data.isSucc) { if (r.data.data.isSucc) {
this.$toast('购买成功') this.$toast('购买成功')
Toast.clear()
} }
}).catch(e => { }).catch(e => {
Toast(e.response.data.reason) Toast(e.response.data.reason)
...@@ -239,7 +231,6 @@ export default Vue.extend({ ...@@ -239,7 +231,6 @@ export default Vue.extend({
text-align: left; text-align: left;
border-bottom: 1px solid #47474B; border-bottom: 1px solid #47474B;
} }
.details-item { .details-item {
line-height: 36px; line-height: 36px;
color: rgba(255, 255, 255, 0.75); color: rgba(255, 255, 255, 0.75);
...@@ -248,34 +239,27 @@ export default Vue.extend({ ...@@ -248,34 +239,27 @@ export default Vue.extend({
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
} }
.hide { .hide {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.special { .special {
color: #FA6400 color: #FA6400
} }
/deep/ .van-nav-bar { /deep/ .van-nav-bar {
background: #323232; background: #323232;
color: #fff; color: #fff;
} }
/deep/ .van-nav-bar .van-icon { /deep/ .van-nav-bar .van-icon {
color: #fff; color: #fff;
} }
/deep/ .van-nav-bar__content { /deep/ .van-nav-bar__content {
height: 56px; height: 56px;
} }
/deep/ .van-hairline--bottom::after { /deep/ .van-hairline--bottom::after {
border-bottom: none; border-bottom: none;
} }
/deep/ .van-stepper__minus, /deep/ .van-stepper__minus,
/deep/ .van-stepper__plus, /deep/ .van-stepper__plus,
/deep/ .van-stepper__input { /deep/ .van-stepper__input {
...@@ -283,14 +267,12 @@ export default Vue.extend({ ...@@ -283,14 +267,12 @@ export default Vue.extend({
background: #3A3A3C; background: #3A3A3C;
border-color: #7A7979; border-color: #7A7979;
} }
/deep/ .van-stepper__minus--disabled, /deep/ .van-stepper__minus--disabled,
/deep/ .van-stepper__plus--disabled { /deep/ .van-stepper__plus--disabled {
color: #c8c9cc; color: #c8c9cc;
background-color: #3A3A3C; background-color: #3A3A3C;
cursor: not-allowed; cursor: not-allowed;
} }
/deep/ .van-stepper__minus--disabled, /deep/ .van-stepper__minus--disabled,
/deep/ .van-stepper__plus--disabled, /deep/ .van-stepper__plus--disabled,
/deep/ .van-stepper__minus--disabled:active, /deep/ .van-stepper__minus--disabled:active,
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
<div class="text-2xl text-white">社区矿池</div> <div class="text-2xl text-white">社区矿池</div>
<div class="flex-shrink-0 text-sm text-white" @click="goMining"> <div class="flex-shrink-0 text-sm text-white" @click="goMining">
我的矿机 我的矿机
<span class="icon bg-gradient-1"> <span class="inline-block w-4 h-4 rounded-full bg-gradient-1">
<van-icon name="arrow" color="#323232" size="12" /> <van-icon name="arrow" color="#323232" size="12" />
</span> </span>
</div> </div>
</div> </div>
<div class="px-4 pt-20"> <div class="px-4 pt-20">
<div class="mine-card flex flex-column bg-card bg-cover rounded-lg"> <div class="flex flex-col py-4 px-5 mb-11 bg-card bg-cover rounded-lg">
<div class="text-sm text-left pb-3 tracking-normal hide">当前地址:{{ addr }}</div> <div class="text-sm text-left pb-3 tracking-normal hide">当前地址:{{ addr }}</div>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div> <div>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Icon, PullRefresh, Toast, Popup, List } from 'vant' import { Icon, PullRefresh, Toast, Popup } from 'vant'
import MiningCard from '@/components/MiningCard.vue' import MiningCard from '@/components/MiningCard.vue'
import Vue from 'vue' import Vue from 'vue'
import service from '@/service/chain33' import service from '@/service/chain33'
...@@ -79,14 +79,14 @@ export default Vue.extend({ ...@@ -79,14 +79,14 @@ export default Vue.extend({
}, },
data() { data() {
return { return {
addr: this.$store.state.app.address, addr: '',
btnText: '领取收益', btnText: '领取收益',
btnType: false, btnType: false,
lists: [] as any, lists: [] as any,
isLoading: false, isLoading: false,
count: 0, count: 0,
timer: 0, timer: 0,
waiter: 18000, waiter: 180000,
page: 1, page: 1,
pageSize: 10, pageSize: 10,
ticketNum: 0, ticketNum: 0,
...@@ -106,9 +106,14 @@ export default Vue.extend({ ...@@ -106,9 +106,14 @@ export default Vue.extend({
if (res.data.data.isSucc) { if (res.data.data.isSucc) {
this.$toast('添加成功') this.$toast('添加成功')
this.show = false this.show = false
this.getInfo()
this.getList() this.getList()
this.getTicket() this.getTicket()
} else {
this.$toast('请输入正确的推荐人地址')
} }
}).catch(() => {
this.$toast('请输入正确的推荐人地址')
}) })
}, },
getFee() { getFee() {
...@@ -124,10 +129,8 @@ export default Vue.extend({ ...@@ -124,10 +129,8 @@ export default Vue.extend({
getList() { getList() {
poolList({ poolList({
page: this.page, page: this.page,
pageSize: this.pageSize, pageSize: this.pageSize
limit: 10000
}).then((res: any) => { }).then((res: any) => {
console.log(res)
if (this.refresh) { if (this.refresh) {
this.refresh = false this.refresh = false
this.lists = [] this.lists = []
...@@ -136,25 +139,19 @@ export default Vue.extend({ ...@@ -136,25 +139,19 @@ export default Vue.extend({
this.count = +res.data.data.count this.count = +res.data.data.count
document.addEventListener('scroll', this.scrollEvent) document.addEventListener('scroll', this.scrollEvent)
}).catch(e => { }).catch(e => {
console.log(e)
const err = e.response const err = e.response
if (err.data?.code === 406 && err.data?.reason === 'USER_NOT_BIND') { if (err.data?.code === 406 && err.data?.reason === 'USER_NOT_BIND') {
this.show = true this.show = true
} }
if (this.timer) {
clearInterval(this.timer)
}
}) })
this.isLoading = false this.isLoading = false
}, },
getInfo() { getInfo() {
service.getBalance(this.$store.state.app.address, 'ticket').then((res: any) => { service.getBalance(this.$store.state.app.address, 'ticket').then((res: any) => {
console.log(res)
this.profit = Math.floor((res.data.result as any)[0].balance / 1e8) this.profit = Math.floor((res.data.result as any)[0].balance / 1e8)
Toast.clear()
}).catch(() => {
Toast({
duration: 3000,
message: '请求失败',
forbidClick: true
})
}) })
}, },
async getIncome() { async getIncome() {
...@@ -169,16 +166,15 @@ export default Vue.extend({ ...@@ -169,16 +166,15 @@ export default Vue.extend({
forbidClick: true, forbidClick: true,
duration: 0 duration: 0
}) })
const b = await service.createTransaction({ const transaction = await service.createTransaction({
to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp', to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp',
amount: this.profit * 1e8, amount: this.profit * 1e8,
// amount: 1e8 * 1,
fee: this.fee, fee: this.fee,
note: 'ticket -> coins', note: 'ticket -> coins',
isWithdraw: true, isWithdraw: true,
execName: 'ticket' execName: 'ticket'
}) })
await service.signTransition((b as any).data.result, async (sign: any) => { await service.signTransition((transaction as any).data.result, async (sign: any) => {
let s = {} as any let s = {} as any
if (typeof sign === 'string') { if (typeof sign === 'string') {
s = JSON.parse(sign) s = JSON.parse(sign)
...@@ -245,17 +241,17 @@ export default Vue.extend({ ...@@ -245,17 +241,17 @@ export default Vue.extend({
setTimer() { setTimer() {
if (this.timer) clearInterval(this.timer) if (this.timer) clearInterval(this.timer)
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.getList() this.onRefresh()
}, this.waiter) }, this.waiter)
} }
}, },
mounted() { mounted() {
this.addr = this.$store.state.app.address this.addr = this.$store.state.app.address
const that = this
this.getList() this.getList()
this.getInfo() this.getInfo()
this.getFee() this.getFee()
this.getTicket() this.getTicket()
this.setTimer()
}, },
beforeDestroy() { beforeDestroy() {
const that = this const that = this
...@@ -274,19 +270,7 @@ export default Vue.extend({ ...@@ -274,19 +270,7 @@ export default Vue.extend({
z-index: 50; z-index: 50;
background: #323232; background: #323232;
} }
.icon { .card-list {
display: inline-block;
width: 16px;
height: 16px;
border-radius: 50%;
}
.mine-card {
display: flex;
flex-direction: column;
padding: 16px 20px;
margin-bottom: 46px;
}
.card-list {
border: 1px solid #A67855; border: 1px solid #A67855;
border-top: none; border-top: none;
border-radius: 5px; border-radius: 5px;
......
...@@ -51,11 +51,6 @@ export default Vue.extend({ ...@@ -51,11 +51,6 @@ export default Vue.extend({
} }
}, },
methods: { methods: {
getList() {
this.isLoading = false
},
getNowList() { getNowList() {
userMachineList({ userMachineList({
page: this.page, page: this.page,
...@@ -90,7 +85,11 @@ export default Vue.extend({ ...@@ -90,7 +85,11 @@ export default Vue.extend({
if (this.lists.length < this.count) { if (this.lists.length < this.count) {
if (h > (g * this.page * (this.pageSize - 3))) { if (h > (g * this.page * (this.pageSize - 3))) {
this.page++ this.page++
this.getList() if (this.active === 1) {
this.getNowList()
} else {
this.getEndList()
}
} }
} }
}, },
...@@ -114,7 +113,6 @@ export default Vue.extend({ ...@@ -114,7 +113,6 @@ export default Vue.extend({
} }
}, },
mounted() { mounted() {
// this.getList()
this.getNowList() this.getNowList()
}, },
beforeDestroy() { beforeDestroy() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment