This commit is contained in:
saplf
2019-02-26 00:26:16 +08:00
parent 54a0bd7f88
commit 79d3577bd6
9 changed files with 10810 additions and 11 deletions

View File

@@ -39,6 +39,7 @@ export default {
async login({ state, commit }) {
commit('updateSign', true)
const account = (await ticApi.secword2account(state.mnemonic)) || {}
account.mnemonic = state.mnemonic
commit('updateSign', false)
if (await ticApi.isAddress(account.address)) {
commit('updateAccount', _.omit(account, 'seckey'), { root: true })

View File

@@ -1,4 +1,6 @@
import axios from 'axios'
import { app } from '../../services'
import { ticApi } from '../../services/api'
export default {
namespaced: true,
@@ -33,11 +35,17 @@ export default {
address: '',
transferVisible: false,
submitting: false, // 提交转账
targetAddress: '',
transferAmount: '',
transferFee: '',
transferRemark: '',
wrongAddress: '',
wrongAmount: '',
wrongFee: '',
transferResult: '',
},
mutations: {
@@ -59,6 +67,7 @@ export default {
toggleTransferDlg(state, value) {
state.transferVisible = value
state.transferResult = ''
},
changeTargetAddress(state, value) {
@@ -76,6 +85,26 @@ export default {
changeTransferRemark(state, value) {
state.transferRemark = value
},
updateSubmitting(state, submitting) {
state.submitting = submitting
},
updateWrongAddress(state, msg) {
state.wrongAddress = msg
},
updateWrongAmount(state, msg) {
state.wrongAmount = msg
},
updateWrongFee(state, msg) {
state.wrongFee = msg
},
updateTransferResult(state, msg) {
state.transferResult = msg
},
},
actions: {
@@ -94,6 +123,56 @@ export default {
commit('setActions', actions && actions.data ? actions.data : [])
} catch (e) {}
},
async performTransfer({ state, commit, rootState }) {
commit('updateSubmitting', true)
const {
targetAddress,
transferAmount,
transferFee,
// transferRemark,
} = state
let wrongAddress, wrongAmount, wrongFee
if (!(await ticApi.isAddress(targetAddress))) {
wrongAddress = '错误的地址'
} else {
wrongAddress = ''
}
if (!(+transferAmount > 0)) {
wrongAmount = '请输入正确的交易金额'
} else {
wrongAmount = ''
}
if (!(+transferFee > 0)) {
wrongFee = '请输入正确的手续费'
} else {
wrongFee = ''
}
commit('updateWrongAddress', wrongAddress)
commit('updateWrongAmount', wrongAmount)
commit('updateWrongFee', wrongFee)
if (wrongAddress || wrongAmount || wrongFee) {
commit('updateSubmitting', false)
return
}
const res = await ticApi.transferTic({
mnemonic: rootState.account.mnemonic,
to: targetAddress,
amount: +transferAmount,
fee: +transferFee,
})
if (res) {
// success
commit('updateTransferResult', '转账成功')
await app.delay(1000)
commit('toggleTransferDlg', false)
} else {
// fail
commit('updateTransferResult', '转账失败')
}
commit('updateSubmitting', false)
},
},
getters: {},