Commit 5d21644f authored by xhx's avatar xhx

调整

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