Skip to content

Commit

Permalink
Merge pull request #11 from swaponline/account-list
Browse files Browse the repository at this point in the history
account list issue-#6
  • Loading branch information
nikitaGetman authored Dec 28, 2020
2 parents aa35a19 + ed27777 commit 5e8ad8d
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 68 deletions.
90 changes: 90 additions & 0 deletions src/components/Wallets/HeaderList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<div>
<v-toolbar class="header-list" color="purple">
<v-btn class="header-list__button ml-1" icon @click="openAccountMenu">
<v-img :src="photo" width="48" height="48" class="rounded-circle" position="center top" />
</v-btn>
<v-spacer></v-spacer>
<v-toolbar-items class="header-list__summ align-center">
<span>{{ balance }}</span>
</v-toolbar-items>
</v-toolbar>
<div
class="header-list__extension"
:style="openMenu ? styleParams : ''"
:class="{
'header-list__extension--visible': openMenu
}"
>
<v-list class="py-0">
<v-list-item v-for="account in accounts" :key="account.id" @click="setAccount(account.id)">
{{ account.name }}
</v-list-item>
</v-list>
</div>
</div>
</template>

<script>
import { mapActions } from 'vuex'
import { MODULE_NAME as WALLETS_MODULE, SET_ACCOUNT_ID } from '@/store/modules/Wallets'
export default {
name: 'HeaderList',
data() {
return {
openMenu: false
}
},
computed: {
photo() {
// eslint-disable-next-line vue/max-len
return `https://sun9-60.userapi.com/impg/zCF4saFPwlwi0PtC41GIQ1WP30Khy-thQ9FtuA/b6bn4u-Y9D4.jpg?size=646x1148&quality=96&proxy=1&sign=b1ff76233f1ee088d886dd165748e481&type=album`
},
balance() {
return this.$store.getters.walletsSumm
},
styleParams() {
return `max-height: ${48 * this.accounts.length}px;`
},
accounts() {
return this.$store.state[WALLETS_MODULE].list
}
},
methods: {
...mapActions({
actionSetAccount: SET_ACCOUNT_ID
}),
openAccountMenu() {
this.openMenu = !this.openMenu
},
setAccount(id) {
this.actionSetAccount(id)
this.openMenu = false
}
}
}
</script>

<style lang="scss">
.header-list {
font-size: 18px;
max-height: 64px;
&__summ {
color: $--white;
font-weight: 500;
}
&__extension {
overflow: hidden;
max-height: 0;
transition: 0.5s;
background: yellow;
&--visible {
height: auto;
// @include tablet {
// min-height: calc(100vh - 152px) !important;
// }
}
}
}
</style>
17 changes: 13 additions & 4 deletions src/components/Wallets/HeaderWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
<v-icon>mdi-arrow-left</v-icon>
</v-btn>

<v-toolbar-title class="header-wallet__title pl-2">Bitcoin (Personal)</v-toolbar-title>
<v-toolbar-title class="header-wallet__title pl-2">{{ name }}</v-toolbar-title>

<v-spacer />

<v-btn icon color="white" @click.stop="share">
<v-icon>mdi-share-variant</v-icon>
</v-btn>

<v-btn icon color="white" @click.stop="$emit('openMenu', 'menu')">
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
<v-tooltip top>
<template v-slot:activator="{ on }">
<v-btn icon color="white" @click.stop="$emit('openMenu', 'menu')" v-on="on">
<v-icon>mdi-settings</v-icon>
</v-btn>
</template>
<span>Settings Wallet</span>
</v-tooltip>
</v-toolbar>
</template>

Expand All @@ -30,6 +35,10 @@ export default {
address: {
type: String,
required: true
},
name: {
type: String,
required: true
}
},
methods: {
Expand Down
13 changes: 11 additions & 2 deletions src/components/Wallets/ItemTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
</v-list-item-title>
<v-list-item-subtitle>
<form class="item-transaction__descr" @submit.prevent="addComment">
<input v-model="comment" type="text" class="item-transaction__input-descr" @click.stop />
<input
v-model="comment"
type="text"
class="item-transaction__input-descr"
@keyup.space.prevent
@click.stop
/>
</form>
</v-list-item-subtitle>
</v-list-item-content>
Expand Down Expand Up @@ -136,7 +142,10 @@ export default {
},
currentBalance() {
const wallet = this.journal[0].balance.find(wall => wall.wallet === this.address)
return (wallet.balance / 10 ** this.decimal).toFixed(this.currentDecimal)
if (wallet) {
return (wallet.balance / 10 ** this.decimal).toFixed(this.currentDecimal)
}
return ''
},
isReceived() {
return this.to === this.address
Expand Down
113 changes: 84 additions & 29 deletions src/store/modules/Wallets/index.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,113 @@
import { SET_MODEL } from '@/store/common/mutations.types'
import { pickCommonMutations } from '@/store/common/mutations'

export const MODULE_NAME = 'Wallets'
export const SET_ACCOUNT_ID = 'SET_ACCOUNT_ID'
export const GET_ACCOUNT_ID = 'GET_ACCOUNT_ID'

export default {
state: {
model: {
accountId: null
},
list: [
{
name: 'BTC',
value: 0.056734,
icon: 'btc',
subWallets: [
id: 'iasduah415fni1j832jh8rjnfimda0m',
name: 'Vasilii',
list: [
{
name: 'Default',
name: 'BTC',
value: 0.056734,
address: '1C9Uae6kyDtPo4ykzd5AJaLzLEZSpEbP3y'
}
]
},
{
name: 'ETH',
value: 43.0561,
subWallets: [
{
name: 'Default',
value: 40.0561,
address: '0xd19615f2Eab2ABfBF7ca16618b5eD43386374DD0'
icon: 'btc',
subWallets: [
{
name: 'Default',
value: 0.056734,
address: '1C9Uae6kyDtPo4ykzd5AJaLzLEZSpEbP3y'
}
]
},
{
name: 'Swaps',
value: 3.0
name: 'ETH',
value: 43.0561,
subWallets: [
{
name: 'Default',
value: 40.0561,
address: '0xd19615f2Eab2ABfBF7ca16618b5eD43386374DD0'
},
{
name: 'Swaps',
value: 3.0,
address: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
},
{
name: 'Expenses',
value: 0.0,
address: '0x7a250d5630B4cF539739dF2C5dAcb4c659F24882'
}
]
},
{
name: 'Expenses',
value: 0.0
name: 'USDT',
value: 100.1,
subWallets: [
{
name: 'Default',
value: 100.1,
address: 'GUzPzmRhx5VgsYH3vZjGjLgtFQMHkJzyHU'
}
]
}
]
},
{
name: 'USDT',
value: 100.1,
subWallets: [
id: 'iasd123uahfni1j832jh8rjnfimda0m',
name: 'Corporat',
list: [
{
name: 'Default',
value: 100.1,
address: 'GUzPzmRhx5VgsYH3vZjGjLgtFQMHkJzyHU'
name: 'ETH',
value: 43.0561,
subWallets: [
{
name: 'Default',
value: 40.0561,
address: '0xd19615f2Eab2ABfBF7ca16618b5eD43386374DD0'
}
]
}
]
}
]
},
getters: {
siblingList(state) {
return state.list.reduce((acc, el) => {
currentListWallets(state) {
const account = state.list.find(el => el.id === state.model.accountId) || {}
return account.list
},
siblingList(state, { currentListWallets }) {
return currentListWallets?.reduce((acc, el) => {
acc.push(...el.subWallets)
return acc
}, [])
},
walletsSumm(state, { currentListWallets }) {
return currentListWallets?.reduce((balance, el) => {
return balance + el.value
}, 0)
}
},
actions: {
[GET_ACCOUNT_ID]({ state, commit }) {
const accountId = window.localStorage.getItem('accountId') || state.list[0].id
commit(SET_MODEL, { model: { accountId } })
},
[SET_ACCOUNT_ID]({ commit }, accountId) {
window.localStorage.setItem('accountId', accountId)
commit(SET_MODEL, { model: { accountId } })
}
},
mutations: {
...pickCommonMutations([SET_MODEL])
}
}
14 changes: 9 additions & 5 deletions src/views/Wallet.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="wallet">
<header-wallet :address="wallet" @openMenu="openMenu" />
<div v-if="currentWallet.address" class="wallet">
<header-wallet :address="currentWallet.address" :name="currentWallet.name" @openMenu="openMenu" />
<div class="wallet__content">
<div class="wallet__info" :class="{ 'wallet__info--open-menu': open !== null }">
<p class="wallet__value">
Expand All @@ -9,7 +9,7 @@
</p>
<p class="wallet__value-in-usd"><span>USD</span> 3000.04</p>

<v-tooltip v-model="show" top activator="#copyAdress">
<v-tooltip v-model="show" top :open-on-hover="false" activator="#copyAdress">
<span>Copied</span>
</v-tooltip>
<button id="copyAdress" class="wallet__address" @click="copy">
Expand Down Expand Up @@ -100,9 +100,12 @@ export default {
}
},
computed: {
siblingList() {
return this.$store.getters.siblingList
},
currentWallet() {
if (this.wallet) {
return this.$store.getters.siblingList.find(el => el.address === this.wallet)
if (this.wallet && this.siblingList) {
return this.siblingList.find(el => el.address === this.wallet)
}
return {}
},
Expand Down Expand Up @@ -228,6 +231,7 @@ export default {
}
}
&__address {
position: relative;
opacity: 0.5;
outline: none;
padding-left: 24px;
Expand Down
Loading

0 comments on commit 5e8ad8d

Please sign in to comment.