转账
This commit is contained in:
@@ -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 })
|
||||
|
||||
@@ -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: {},
|
||||
|
||||
Reference in New Issue
Block a user