在 webworker (services/api) 里调用 randomSecword 导致出错 "window is not defined"。因此直接调用 ticCrypto.randomSecword。
登录后刷新地址和余额。
This commit is contained in:
@@ -3,5 +3,5 @@
|
|||||||
export const seckey2pubkey = seckey => ticCrypto.seckey2pubkey(seckey)
|
export const seckey2pubkey = seckey => ticCrypto.seckey2pubkey(seckey)
|
||||||
export const secword2address = secword => ticCrypto.secword2address(secword)
|
export const secword2address = secword => ticCrypto.secword2address(secword)
|
||||||
export const secword2account = secword => ticCrypto.secword2account(secword)
|
export const secword2account = secword => ticCrypto.secword2account(secword)
|
||||||
export const randomSecword = lang => ticCrypto.randomSecword(lang)
|
// export const randomSecword = lang => ticCrypto.randomSecword(lang)
|
||||||
export const isAddress = address => ticCrypto.isAddress(address)
|
export const isAddress = address => ticCrypto.isAddress(address)
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ export default {
|
|||||||
secword2address: async secword => instance.secword2address(secword),
|
secword2address: async secword => instance.secword2address(secword),
|
||||||
isAddress: async address => instance.isAddress(address),
|
isAddress: async address => instance.isAddress(address),
|
||||||
secword2account: async secword => instance.secword2account(secword),
|
secword2account: async secword => instance.secword2account(secword),
|
||||||
randomSecword: async lang => instance.randomSecword(lang),
|
// randomSecword: async lang => instance.randomSecword(lang),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import router from '../../router'
|
import router from '../../router'
|
||||||
import { i18n } from '../../i18n'
|
import { i18n } from '../../i18n'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import ticCrypto from 'tic.crypto'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@@ -38,7 +39,6 @@ export default {
|
|||||||
async login({ state, commit }) {
|
async login({ state, commit }) {
|
||||||
commit('updateSign', true)
|
commit('updateSign', true)
|
||||||
const account = (await ticApi.secword2account(state.mnemonic)) || {}
|
const account = (await ticApi.secword2account(state.mnemonic)) || {}
|
||||||
console.log(account)
|
|
||||||
commit('updateSign', false)
|
commit('updateSign', false)
|
||||||
if (await ticApi.isAddress(account.address)) {
|
if (await ticApi.isAddress(account.address)) {
|
||||||
commit('updateAccount', _.omit(account, 'seckey'), { root: true })
|
commit('updateAccount', _.omit(account, 'seckey'), { root: true })
|
||||||
@@ -48,11 +48,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async createSecword({ state, commit }) {
|
async createSecword({ state, commit }) {
|
||||||
alert('entering createSecword')
|
let secword = ticCrypto.randomSecword() // 不能用 webworker 里的randomSecword,会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。
|
||||||
let secword = await ticApi.randomSecword() // 这句导致报错 "window is not defined"。猜测是 bitcore-mnemonic 不能在前端页面里使用。
|
commit('updateMnemonic', secword)
|
||||||
alert('after secword')
|
|
||||||
console.info('secword=' + secword)
|
|
||||||
alert('secword=' + secword)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export default {
|
|||||||
fetching: false,
|
fetching: false,
|
||||||
filter: '',
|
filter: '',
|
||||||
balance: 0,
|
balance: 0,
|
||||||
|
address: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
@@ -40,6 +41,10 @@ export default {
|
|||||||
updateBalance(state, balance) {
|
updateBalance(state, balance) {
|
||||||
state.balance = balance
|
state.balance = balance
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateAddress(state, address) {
|
||||||
|
state.address = address
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
@@ -47,6 +52,7 @@ export default {
|
|||||||
let account = sessionStorage.getItem('KEY_ACCOUNT')
|
let account = sessionStorage.getItem('KEY_ACCOUNT')
|
||||||
try {
|
try {
|
||||||
account = JSON.parse(account)
|
account = JSON.parse(account)
|
||||||
|
commit('updateAddress', account.address)
|
||||||
const result = await axios.post('Account/getBalance', {
|
const result = await axios.post('Account/getBalance', {
|
||||||
Account: { address: account.address },
|
Account: { address: account.address },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<div class="owner-page">
|
<div class="owner-page">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="app-card elevation-1">
|
<div class="app-card elevation-1">
|
||||||
|
<div>主人地址为 {{ address }}</div>
|
||||||
<div>余额为 {{ balance }}</div>
|
<div>余额为 {{ balance }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="app-sep"></div>
|
<div class="app-sep"></div>
|
||||||
@@ -68,6 +69,7 @@ export default {
|
|||||||
'fetching',
|
'fetching',
|
||||||
'filter',
|
'filter',
|
||||||
'balance',
|
'balance',
|
||||||
|
'address',
|
||||||
]),
|
]),
|
||||||
...mapGetters([]),
|
...mapGetters([]),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user