From b9248d85a97a2a36648606c2030c68f60a0ec6bf Mon Sep 17 00:00:00 2001 From: monky Date: Wed, 2 Jan 2019 22:17:26 +0800 Subject: [PATCH] fix: no update for dom of balance --- src/views/home.vue | 144 ++++++++++++++++++++++++------------------------- src/views/homeMenu.vue | 9 ++-- 2 files changed, 74 insertions(+), 79 deletions(-) diff --git a/src/views/home.vue b/src/views/home.vue index d5cd821..c264eeb 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -137,11 +137,11 @@
- {{currentAccount.balance}} + {{accountBalance}} BTM
@@ -236,22 +236,24 @@ export default { this.leaveActive = '' } }, - currentAccount: { - deep: true, - immediate: true, - handler(newVal, oldName) { - if (newVal.guid == undefined) { - return; - } + currentAccount(newVal, oldVal) { + if (newVal.guid == undefined) { + return; + } - this.setupShortAddr(newVal.address) - this.refreshBalance(newVal.guid); - this.refreshTransactions(newVal.guid, newVal.address).then(transactions => { - this.transactions = transactions - }); - }, + this.refreshTransactions(newVal.guid, newVal.address).then(transactions => { + this.transactions = transactions + }); }, }, + computed: { + shortAddress: function () { + return address.short(this.currentAccount.address) + }, + accountBalance: function () { + return this.currentAccount.balance + } + }, methods: { setupShortAddr(rawAddress) { this.currentAccount.address_short = address.short(rawAddress); @@ -286,11 +288,6 @@ export default { account.setupNet(this.network); this.refreshAccounts(); }, - accountToggle: function (selectedAccount) { - localStorage.currentAccount = JSON.stringify(selectedAccount); - this.currentAccount = selectedAccount; - this.refreshAccounts(); - }, showQrcode: function () { this.$refs.qrcode.open(this.currentAccount.address); }, @@ -300,45 +297,23 @@ export default { transferOpen: function () { this.$router.push({ name: 'transfer', params: { account: this.currentAccount } }) }, - transactionsFormat: function (transactions) { - transactions.forEach(transaction => { - let inputSum = 0; - let outputSum = 0; - let selfInputSum = 0; - let selfoutputSum = 0; - let inputAddresses = []; - let outputAddresses = []; - transaction.inputs.forEach(input => { - inputSum += input.amount; - if (input.address == this.currentAccount.address) { - selfInputSum += input.amount; - return; - } - - inputAddresses.push(input.address); + handleScroll(vertical, horizontal, nativeEvent) { + if (vertical.process == 0) { + this.start = 0; + this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address).then(transactions => { + this.transactions = transactions }); - transaction.outputs.forEach(output => { - outputSum += output.amount; - if (output.address == this.currentAccount.address) { - selfoutputSum += output.amount; - return; - } + return; + } - outputAddresses.push(output.address); + if (vertical.process == 1) { + this.start += this.limit; + this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address, this.start, this.limit).then(transactions => { + transactions.forEach(transaction => { + this.transactions.push(transaction); + }); }); - - let val = selfoutputSum - selfInputSum; - if (val > 0) { - transaction.direct = "+"; - transaction.address = address.short(inputAddresses.pop()); - } else { - val = selfInputSum - selfoutputSum; - transaction.direct = "-"; - transaction.address = address.short(outputAddresses.pop()); - } - transaction.val = Number(val / 100000000); - transaction.fee = Number(inputSum - outputSum) / 100000000; - }); + } }, refreshAccounts: function () { account.list().then(accounts => { @@ -348,10 +323,8 @@ export default { } if (localStorage.currentAccount != undefined) { - this.currentAccount = JSON.parse(localStorage.currentAccount); } else { - this.currentAccount = accounts[0]; } }) @@ -359,6 +332,7 @@ export default { refreshBalance: function (guid) { account.balance(guid).then(balance => { this.currentAccount.balance = balance; + this.currentAccount = Object.assign({}, this.currentAccount); }).catch(error => { console.log(error); }); @@ -380,30 +354,52 @@ export default { }); }) }, - handleScroll(vertical, horizontal, nativeEvent) { - if (vertical.process == 0) { - this.start = 0; - this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address).then(transactions => { - this.transactions = transactions + transactionsFormat: function (transactions) { + transactions.forEach(transaction => { + let inputSum = 0; + let outputSum = 0; + let selfInputSum = 0; + let selfoutputSum = 0; + let inputAddresses = []; + let outputAddresses = []; + transaction.inputs.forEach(input => { + inputSum += input.amount; + if (input.address == this.currentAccount.address) { + selfInputSum += input.amount; + return; + } + + inputAddresses.push(input.address); }); - return; - } + transaction.outputs.forEach(output => { + outputSum += output.amount; + if (output.address == this.currentAccount.address) { + selfoutputSum += output.amount; + return; + } - if (vertical.process == 1) { - this.start += this.limit; - this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address, this.start, this.limit).then(transactions => { - transactions.forEach(transaction => { - this.transactions.push(transaction); - }); + outputAddresses.push(output.address); }); - } - } + + let val = selfoutputSum - selfInputSum; + if (val > 0) { + transaction.direct = "+"; + transaction.address = address.short(inputAddresses.pop()); + } else { + val = selfInputSum - selfoutputSum; + transaction.direct = "-"; + transaction.address = address.short(outputAddresses.pop()); + } + transaction.val = Number(val / 100000000); + transaction.fee = Number(inputSum - outputSum) / 100000000; + }); + }, }, mounted() { this.setupNetwork(); this.setupClipboard(); this.setupRefreshTimer(); - this.refreshAccounts() + this.refreshAccounts(); }, beforeDestroy() { this.clipboard.destroy(); diff --git a/src/views/homeMenu.vue b/src/views/homeMenu.vue index 91226f7..b2b5589 100644 --- a/src/views/homeMenu.vue +++ b/src/views/homeMenu.vue @@ -91,15 +91,14 @@ export default { name: "", data() { return { - accounts: "", - selectedAccount: "", - enterActive: "animated faster fadeInLeft", - leaveActive: "animated faster fadeOutLeft" + accounts: [], + selectedAccount: {}, }; }, methods: { accountSelected: function (accountInfo) { - this.$router.push({ name: 'home', params: { selectedAccount: accountInfo } }) + this.selectedAccount = accountInfo; + this.$router.push({ name: 'home', params: { selectedAccount: this.selectedAccount } }) }, }, mounted() { let params = this.$route.params; -- 2.11.0