Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

refactor: correctly sort wallets and contacts in overview and sidebar #1044

Merged
merged 14 commits into from Feb 7, 2019
Merged
25 changes: 14 additions & 11 deletions src/renderer/components/Wallet/WalletSidebar/WalletSidebar.vue
Expand Up @@ -195,11 +195,14 @@ export default {
}),

computed: {
fetchContactsOnly () {
dated marked this conversation as resolved.
Show resolved Hide resolved
return this.currentWallet && this.currentWallet.isContact && !this.currentWallet.isWatchOnly
},

wallets () {
const wallets = this.currentWallet && this.currentWallet.isContact && !this.currentWallet.isWatchOnly
return this.fetchContactsOnly
? this.$store.getters['wallet/contactsByProfileId'](this.session_profile.id)
: this.$store.getters['wallet/byProfileId'](this.session_profile.id)
return this.wallet_sortByName(wallets)
},

activeWallet () {
Expand All @@ -226,11 +229,8 @@ export default {
},

async created () {
this.selectableWallets = this.wallets
this.refreshWallets()

if (this.$store.getters['ledger/isConnected']) {
this.refreshLedgerWallets()
}
this.$eventBus.on('ledger:wallets-updated', this.refreshLedgerWallets)
this.$eventBus.on('ledger:disconnected', this.ledgerDisconnected)
this.$eventBus.on('wallet:wallet-updated', this.refreshWallets)
Expand Down Expand Up @@ -271,7 +271,10 @@ export default {
},

refreshLedgerWallets () {
const ledgerWallets = this.$store.getters['ledger/wallets']
const ledgerWallets = !this.fetchContactsOnly
? this.$store.getters['ledger/wallets']
: []

this.selectableWallets = this.wallet_sortByName(uniqBy([
...ledgerWallets,
...this.wallets
Expand All @@ -282,21 +285,21 @@ export default {
if (this.$store.getters['ledger/isConnected']) {
this.refreshLedgerWallets()
} else {
this.selectableWallets = this.wallets
this.selectableWallets = this.wallet_sortByName(this.wallets)
}
},

ledgerDisconnected () {
this.refreshWallets()
if (!this.activeWallet || !this.activeWallet.address || this.activeWallet.isLedger) {
if (this.$refs.MenuNavigation && this.$route.name === 'wallet-show') {
if (this.wallets.length) {
this.$refs.MenuNavigation.switchToId(this.wallets[0].address)
if (this.selectableWallets.length) {
this.$refs.MenuNavigation.switchToId(this.selectableWallets[0].address)
} else {
this.$router.push({ name: 'wallets' })
}
}
}
this.selectableWallets = this.wallets
}
}
}
Expand Down