From aca23682cab9e5989c23bde318e576854aeaacbc Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Mon, 26 Nov 2018 16:28:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=20webworker=20(services/api)=20?= =?UTF-8?q?=E9=87=8C=E8=B0=83=E7=94=A8=20randomSecword=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=87=BA=E9=94=99=20"window=20is=20not=20defined"?= =?UTF-8?q?=E3=80=82=E5=9B=A0=E6=AD=A4=E7=9B=B4=E6=8E=A5=E8=B0=83=E7=94=A8?= =?UTF-8?q?=20ticCrypto.randomSecword=E3=80=82=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E5=88=B7=E6=96=B0=E5=9C=B0=E5=9D=80=E5=92=8C=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/api/tic-bg.js | 2 +- src/services/api/tic.js | 2 +- src/store/modules/login.js | 9 +++------ src/store/modules/owner.js | 6 ++++++ src/views/Owner.vue | 2 ++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/services/api/tic-bg.js b/src/services/api/tic-bg.js index 901d861..8095fe7 100644 --- a/src/services/api/tic-bg.js +++ b/src/services/api/tic-bg.js @@ -3,5 +3,5 @@ export const seckey2pubkey = seckey => ticCrypto.seckey2pubkey(seckey) export const secword2address = secword => ticCrypto.secword2address(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) diff --git a/src/services/api/tic.js b/src/services/api/tic.js index adcd1c1..7b2d6fa 100644 --- a/src/services/api/tic.js +++ b/src/services/api/tic.js @@ -8,5 +8,5 @@ export default { secword2address: async secword => instance.secword2address(secword), isAddress: async address => instance.isAddress(address), secword2account: async secword => instance.secword2account(secword), - randomSecword: async lang => instance.randomSecword(lang), +// randomSecword: async lang => instance.randomSecword(lang), } diff --git a/src/store/modules/login.js b/src/store/modules/login.js index 60545b2..9798fbb 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -2,6 +2,7 @@ import router from '../../router' import { i18n } from '../../i18n' import _ from 'lodash' +import ticCrypto from 'tic.crypto' export default { namespaced: true, @@ -38,7 +39,6 @@ export default { async login({ state, commit }) { commit('updateSign', true) const account = (await ticApi.secword2account(state.mnemonic)) || {} - console.log(account) commit('updateSign', false) if (await ticApi.isAddress(account.address)) { commit('updateAccount', _.omit(account, 'seckey'), { root: true }) @@ -48,11 +48,8 @@ export default { } }, async createSecword({ state, commit }) { - alert('entering createSecword') - let secword = await ticApi.randomSecword() // 这句导致报错 "window is not defined"。猜测是 bitcore-mnemonic 不能在前端页面里使用。 - alert('after secword') - console.info('secword=' + secword) - alert('secword=' + secword) + let secword = ticCrypto.randomSecword() // 不能用 webworker 里的randomSecword,会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。 + commit('updateMnemonic', secword) }, }, } diff --git a/src/store/modules/owner.js b/src/store/modules/owner.js index 299efdd..a425e39 100644 --- a/src/store/modules/owner.js +++ b/src/store/modules/owner.js @@ -30,6 +30,7 @@ export default { fetching: false, filter: '', balance: 0, + address: '', }, mutations: { @@ -40,6 +41,10 @@ export default { updateBalance(state, balance) { state.balance = balance }, + + updateAddress(state, address) { + state.address = address + } }, actions: { @@ -47,6 +52,7 @@ export default { let account = sessionStorage.getItem('KEY_ACCOUNT') try { account = JSON.parse(account) + commit('updateAddress', account.address) const result = await axios.post('Account/getBalance', { Account: { address: account.address }, }) diff --git a/src/views/Owner.vue b/src/views/Owner.vue index 5be6d33..3c2dfb2 100644 --- a/src/views/Owner.vue +++ b/src/views/Owner.vue @@ -2,6 +2,7 @@
+
主人地址为 {{ address }}
余额为 {{ balance }}
@@ -68,6 +69,7 @@ export default { 'fetching', 'filter', 'balance', + 'address', ]), ...mapGetters([]), },