From f5defd759a599f9c87ed9b61a8ff2c51d2eb2a5b Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 7 Jul 2020 21:13:39 +0800 Subject: [PATCH 1/3] update for ledger connector --- src/core/ontLedger.js | 7 +++++-- src/renderer/components/Common/SignSendTx.vue | 13 +++++++++++-- src/renderer/store/modules/LedgerConnector.js | 12 ++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/core/ontLedger.js b/src/core/ontLedger.js index c306746..e3cc85e 100644 --- a/src/core/ontLedger.js +++ b/src/core/ontLedger.js @@ -45,7 +45,7 @@ const BIP44 = (acct = 0, neo = false) => { acctNumber ) } - +var ledger export default class OntLedger { path: string; device: any; @@ -59,13 +59,16 @@ export default class OntLedger { * @return {Promise} */ static async init() { + if(ledger) { + return ledger.open() + } const supported = await LedgerNode.isSupported() // if (!supported) { throw new Error(`Your computer does not support the ledger!`) } if (!supported) { throw 'NOT_SUPPORT' } const paths = await OntLedger.list() // if (paths.length === 0) throw new Error('USB Error: No device found.') if (paths.length === 0) throw 'NOT_FOUND' - const ledger = new OntLedger(paths[0]) + ledger = new OntLedger(paths[0]) return ledger.open() } diff --git a/src/renderer/components/Common/SignSendTx.vue b/src/renderer/components/Common/SignSendTx.vue index 37c4b80..0cad4d4 100644 --- a/src/renderer/components/Common/SignSendTx.vue +++ b/src/renderer/components/Common/SignSendTx.vue @@ -49,8 +49,15 @@ export default { }, mounted(){ - if(!this.wallet.key) {//common wallet - this.$store.dispatch('getLedgerStatus') + + }, + watch: { + visible(newV, oldV) { + if(newV) { + if(!this.wallet.key) {//common wallet + this.$store.dispatch('getLedgerStatus') + } + } } }, beforeDestroy() { @@ -102,9 +109,11 @@ export default { const signature = pri.sign(tx) this.$store.dispatch("hideLoadingModals"); this.$emit('afterSign', signature) // 返回签名message结果 + this.walletPassword = '' } else { TransactionBuilder.signTransaction(tx, pri); this.sendTx(tx); + this.walletPassword = '' } } else { diff --git a/src/renderer/store/modules/LedgerConnector.js b/src/renderer/store/modules/LedgerConnector.js index 9ffaffe..5cab0f0 100644 --- a/src/renderer/store/modules/LedgerConnector.js +++ b/src/renderer/store/modules/LedgerConnector.js @@ -36,7 +36,6 @@ function getDevice(commit, state) { } function getLedgerPublicKey(commit, state) { - // 这里如果去掉,再SelectWallet组件里,切换类型后不再重新获取ledger地址,会产生bug。 // if (state.publicKey) { // return; // } @@ -89,17 +88,22 @@ const mutations = { } } +const LEDGER_CONNECTOR_INTERVAL = 'ledger_connector_intervalId' + const actions = { getLedgerStatus({dispatch,commit,state}, interval) { - let time = interval || 3000; + let time = interval || 5000; getDevice(commit, state) const intervalId = setInterval(() => { getDevice(commit, state) }, time) - commit('UPDATE_LEDGER_CONNECTOR_INTERVALID', {intervalId: intervalId}) + localStorage.setItem(LEDGER_CONNECTOR_INTERVAL, intervalId) }, stopGetLedgerStatus({commit, state}) { - clearInterval(state.intervalId) + const intervalId = localStorage.getItem(LEDGER_CONNECTOR_INTERVAL) || '' + clearInterval(intervalId) + localStorage.removeItem(LEDGER_CONNECTOR_INTERVAL) + commit('UPDATE_LEDGER_PUBLICKEY', {publicKey: ''}) } } From b32b4f03bc20256031cb0d9194bad4c52bd8c9e5 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Wed, 8 Jul 2020 14:09:08 +0800 Subject: [PATCH 2/3] update ledger connector --- src/core/ontLedger.js | 7 ++----- src/renderer/components/Common/SignSendTx.vue | 5 ++--- src/renderer/components/Node/NodeApply/Register.vue | 1 + 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/core/ontLedger.js b/src/core/ontLedger.js index e3cc85e..c306746 100644 --- a/src/core/ontLedger.js +++ b/src/core/ontLedger.js @@ -45,7 +45,7 @@ const BIP44 = (acct = 0, neo = false) => { acctNumber ) } -var ledger + export default class OntLedger { path: string; device: any; @@ -59,16 +59,13 @@ export default class OntLedger { * @return {Promise} */ static async init() { - if(ledger) { - return ledger.open() - } const supported = await LedgerNode.isSupported() // if (!supported) { throw new Error(`Your computer does not support the ledger!`) } if (!supported) { throw 'NOT_SUPPORT' } const paths = await OntLedger.list() // if (paths.length === 0) throw new Error('USB Error: No device found.') if (paths.length === 0) throw 'NOT_FOUND' - ledger = new OntLedger(paths[0]) + const ledger = new OntLedger(paths[0]) return ledger.open() } diff --git a/src/renderer/components/Common/SignSendTx.vue b/src/renderer/components/Common/SignSendTx.vue index 0cad4d4..c183b69 100644 --- a/src/renderer/components/Common/SignSendTx.vue +++ b/src/renderer/components/Common/SignSendTx.vue @@ -57,11 +57,12 @@ export default { if(!this.wallet.key) {//common wallet this.$store.dispatch('getLedgerStatus') } + } else { + this.$store.dispatch('stopGetLedgerStatus') } } }, beforeDestroy() { - clearInterval(this.intervalId); this.$store.dispatch('stopGetLedgerStatus') }, data(){ @@ -131,7 +132,6 @@ export default { }, err => { this.sending = false; - this.ledgerStatus = ""; this.$store.dispatch("hideLoadingModals"); this.$message.error(this.$t('ledgerWallet.signFailed')) } @@ -152,7 +152,6 @@ export default { }, err => { this.sending = false; - this.ledgerStatus = ""; this.$store.dispatch("hideLoadingModals"); this.$message.error(this.$t('ledgerWallet.signFailed')) } diff --git a/src/renderer/components/Node/NodeApply/Register.vue b/src/renderer/components/Node/NodeApply/Register.vue index a309599..0dc8e16 100644 --- a/src/renderer/components/Node/NodeApply/Register.vue +++ b/src/renderer/components/Node/NodeApply/Register.vue @@ -183,6 +183,7 @@ export default { return; } this.current += 1; + this.$store.dispatch('stopGetLedgerStatus') // 防止过多ledger请求 }, cancel() { this.current -= 1; From d2a44f80d1d1d788bc5e82b37671e15bb6eb9561 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Wed, 8 Jul 2020 15:30:38 +0800 Subject: [PATCH 3/3] update texts --- src/common/lang/en.js | 2 +- src/common/lang/zh.js | 2 +- src/renderer/components/Node/NodeStake/NodeInfo.vue | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/lang/en.js b/src/common/lang/en.js index a734cd5..3a2957d 100644 --- a/src/common/lang/en.js +++ b/src/common/lang/en.js @@ -749,7 +749,7 @@ Within their 50% share each consensus node will receive their share according to submit: 'Submit', updateSuccess: 'Update node info succeed', updateFailed: 'Update node info failed', - ledgerWalletNotSupportForNow: 'Nodes registered with ledger currently do not support updating node-related information ' + ledgerWalletNotSupportForNow: 'Nodes registered with ledger currently do not support updating node-related information. Please email to: ' }, exchange: { exchange: 'Exchange', diff --git a/src/common/lang/zh.js b/src/common/lang/zh.js index 313f58a..0470bae 100644 --- a/src/common/lang/zh.js +++ b/src/common/lang/zh.js @@ -744,7 +744,7 @@ export default { submit: '提交', updateSuccess: '更新成功', updateFailed: '更新失败', - ledgerWalletNotSupportForNow: '使用Ledger注册的节点,暂时不支持更新节点相关信息' + ledgerWalletNotSupportForNow: '使用Ledger注册的节点,暂时不支持更新节点相关信息.请发送邮件至:' }, exchange: { exchange: 'Exchange', diff --git a/src/renderer/components/Node/NodeStake/NodeInfo.vue b/src/renderer/components/Node/NodeStake/NodeInfo.vue index c340405..51c973b 100644 --- a/src/renderer/components/Node/NodeStake/NodeInfo.vue +++ b/src/renderer/components/Node/NodeStake/NodeInfo.vue @@ -1,7 +1,10 @@