add re-import address, default wallet

This commit is contained in:
liangping 2021-11-24 11:40:03 +08:00
parent 7bbf220906
commit 4910319be7
4 changed files with 131 additions and 44 deletions

View File

@ -69,7 +69,7 @@
:to="{ name: 'accounts' }" :to="{ name: 'accounts' }"
> >
<feather-icon icon="KeyIcon" /> <feather-icon icon="KeyIcon" />
<span class="align-middle ml-25">Wallet</span> <span class="align-middle ml-25">{{ walletName }}</span>
</b-button> </b-button>
<!-- <b-dropdown <!-- <b-dropdown
class="ml-1" class="ml-1"
@ -135,7 +135,7 @@ import Locale from '@core/layouts/components/app-navbar/components/Locale.vue'
import SearchBar from '@core/layouts/components/app-navbar/components/SearchBar.vue' import SearchBar from '@core/layouts/components/app-navbar/components/SearchBar.vue'
// import CartDropdown from '@core/layouts/components/app-navbar/components/CartDropdown.vue' // import CartDropdown from '@core/layouts/components/app-navbar/components/CartDropdown.vue'
import store from '@/store' import store from '@/store'
import { timeIn, toDay } from '@/libs/data' import { getLocalAccounts, timeIn, toDay } from '@/libs/data'
// import UserDropdown from '@core/layouts/components/app-navbar/components/UserDropdown.vue' // import UserDropdown from '@core/layouts/components/app-navbar/components/UserDropdown.vue'
export default { export default {
@ -172,6 +172,10 @@ export default {
} }
}, },
computed: { computed: {
walletName() {
const key = this.$store.state.chains.defaultWallet
return key || 'Wallet'
},
selected_chain() { selected_chain() {
this.block() this.block()
return store.state.chains.selected return store.state.chains.selected
@ -180,6 +184,12 @@ export default {
return this.variant return this.variant
}, },
}, },
mounted() {
const accounts = Object.keys(getLocalAccounts())
if (!this.$store.state.chains.defaultWallet && accounts.length > 0) {
this.$store.commit('setDefaultWallet', accounts[0])
}
},
methods: { methods: {
block() { block() {
store.commit('setHeight', 0) store.commit('setHeight', 0)

View File

@ -26,6 +26,7 @@ export default {
height: 0, height: 0,
ibcChannels: {}, ibcChannels: {},
quotes: {}, quotes: {},
defaultWallet: localStorage.getItem('default-wallet'),
}, },
getters: { getters: {
getchains: state => state.chains, getchains: state => state.chains,
@ -50,6 +51,12 @@ export default {
setQuotes(state, quotes) { setQuotes(state, quotes) {
state.quotes = quotes state.quotes = quotes
}, },
setDefaultWallet(state, defaultWallet) {
if (defaultWallet && defaultWallet.length > 0) {
localStorage.setItem('default-wallet', defaultWallet)
state.chains.defaultWallet = defaultWallet
}
},
}, },
actions: { actions: {
async getQuotes(context) { async getQuotes(context) {

View File

@ -1,6 +1,7 @@
<template> <template>
<div> <div>
<form-wizard <form-wizard
ref="wizard"
color="#7367F0" color="#7367F0"
:title="null" :title="null"
:subtitle="null" :subtitle="null"
@ -131,6 +132,7 @@
v-model="name" v-model="name"
:state="errors.length > 0 ? false:null" :state="errors.length > 0 ? false:null"
placeholder="Ping Nano X" placeholder="Ping Nano X"
:readonly="edit"
/> />
<small class="text-danger">{{ errors[0] }}</small> <small class="text-danger">{{ errors[0] }}</small>
</validation-provider> </validation-provider>
@ -261,7 +263,9 @@ import {
} from 'bootstrap-vue' } from 'bootstrap-vue'
import { required } from '@validations' import { required } from '@validations'
import store from '@/store' import store from '@/store'
import { addressDecode, addressEnCode, getLedgerAddress } from '@/libs/data' import {
addressDecode, addressEnCode, getLedgerAddress, getLocalAccounts,
} from '@/libs/data'
import { toHex } from '@cosmjs/encoding' import { toHex } from '@cosmjs/encoding'
export default { export default {
@ -295,6 +299,7 @@ export default {
selected: [], selected: [],
accounts: null, accounts: null,
exludes: [], // HD Path is NOT supported, exludes: [], // HD Path is NOT supported,
edit: false,
} }
}, },
computed: { computed: {
@ -309,21 +314,43 @@ export default {
if (this.accounts && this.accounts.address) { if (this.accounts && this.accounts.address) {
const { data } = addressDecode(this.accounts.address) const { data } = addressDecode(this.accounts.address)
return this.selected.map(x => { return this.selected.map(x => {
if (this.chains[x]) {
const { logo, addr_prefix } = this.chains[x] const { logo, addr_prefix } = this.chains[x]
const addr = addressEnCode(addr_prefix, data) const addr = addressEnCode(addr_prefix, data)
return { return {
chain: x, addr, logo, hdpath: this.hdpath, chain: x, addr, logo, hdpath: this.hdpath,
} }
}) }
return null
}).filter(x => x != null)
} }
return [] return []
}, },
}, },
created() { mounted() {
const { selected } = store.state.chains const { selected } = store.state.chains
if (selected && selected.chain_name && !this.exludes.includes(selected.chain_name)) { if (selected && selected.chain_name && !this.exludes.includes(selected.chain_name)) {
this.selected.push(selected.chain_name) this.selected.push(selected.chain_name)
} }
const name = new URLSearchParams(window.location.search).get('name')
const wallets = getLocalAccounts()
if (name && wallets && wallets[name]) {
const wallet = wallets[name]
this.device = wallet.device
this.name = wallet.name
this.edit = true
if (wallet.address) {
wallet.address.forEach(a => {
if (!this.selected.includes(a.chain)) {
this.selected.push(a.chain)
}
})
this.address = wallet.address[0].addr
if (this.localAddress()) {
this.$refs.wizard.nextTab()
}
}
}
}, },
methods: { methods: {
formatPubkey(v) { formatPubkey(v) {
@ -373,6 +400,9 @@ export default {
address: this.addresses, address: this.addresses,
} }
localStorage.setItem('accounts', JSON.stringify(accounts)) localStorage.setItem('accounts', JSON.stringify(accounts))
if (!this.$store.state.chains.defaultWallet) {
this.$store.commit('setDefaultWallet', this.name)
}
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,
@ -386,7 +416,9 @@ export default {
this.$router.push('./accounts') this.$router.push('./accounts')
}, },
async validationFormDevice() { async validationFormDevice() {
let ok = false let ok = String(this.name).length > 0
if (!ok) { // new import, otherwise it's edit mode.
switch (this.device) { switch (this.device) {
case 'keplr': case 'keplr':
await this.cennectKeplr().then(accounts => { await this.cennectKeplr().then(accounts => {
@ -412,6 +444,7 @@ export default {
default: default:
ok = this.localAddress() ok = this.localAddress()
} }
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.$refs.deviceRules.validate().then(success => { this.$refs.deviceRules.validate().then(success => {
@ -438,5 +471,6 @@ export default {
</script> </script>
<style lang="scss"> <style lang="scss">
// @import '@core/assets/fonts/feather/iconfont.css';
@import '@core/scss/vue/libs/vue-wizard.scss'; @import '@core/scss/vue/libs/vue-wizard.scss';
</style> </style>

View File

@ -71,16 +71,40 @@
</b-row> </b-row>
</b-card> </b-card>
<b-tabs <div
v-for="item,index in accounts" v-for="item,index in accounts"
:key="index" :key="index"
active-nav-item-class="font-weight-bolder"
> >
<b-tab> <div>
<template #title> <div class="d-flex justify-content-between align-items-end mb-1">
<feather-icon icon="UserIcon" /> <b-button
<span>{{ item.name }}</span> v-ripple.400="'rgba(255, 255, 255, 0.15)'"
</template> variant="warning"
:to="`/wallet/import?name=${item.name}`"
>
<feather-icon
icon="EditIcon"
class="mr-50"
/>
<span class="align-middle">{{ item.name }}</span>
</b-button>
<b-form-checkbox
v-model="defaultWallet"
v-b-tooltip.hover.v-primary
:value="item.name"
title="Set as default wallet"
variant="outline-warning"
:readonly="item.name===defaultWallet"
>
<span
:class="item.name===defaultWallet ? 'text-primary' : ''"
class="font-weight-bolder pb-0"
style="font-size:16px"
>
Set as default
</span>
</b-form-checkbox>
</div>
<b-row> <b-row>
<b-col <b-col
@ -212,8 +236,8 @@
</b-card> </b-card>
</b-col> </b-col>
</b-row> </b-row>
</b-tab> </div>
</b-tabs> </div>
<router-link to="./import"> <router-link to="./import">
<b-card class="addzone"> <b-card class="addzone">
@ -230,7 +254,8 @@
<script> <script>
import { import {
BCard, BCardHeader, BCardTitle, BCardBody, VBModal, BRow, BCol, BTabs, BTab, BAvatar, BDropdown, BDropdownItem, BDropdownDivider, BCard, BCardHeader, BCardTitle, BCardBody, VBModal, BRow, BCol, BAvatar, BButton,
BDropdown, BDropdownItem, BDropdownDivider, BFormCheckbox, VBTooltip,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import Ripple from 'vue-ripple-directive' import Ripple from 'vue-ripple-directive'
import FeatherIcon from '@/@core/components/feather-icon/FeatherIcon.vue' import FeatherIcon from '@/@core/components/feather-icon/FeatherIcon.vue'
@ -252,15 +277,17 @@ export default {
BAvatar, BAvatar,
BCard, BCard,
BRow, BRow,
BButton,
BCol, BCol,
BTabs,
BTab,
BCardHeader, BCardHeader,
BCardBody, BCardBody,
BCardTitle, BCardTitle,
BDropdown, BDropdown,
BDropdownItem, BDropdownItem,
BDropdownDivider, BDropdownDivider,
BFormCheckbox,
// eslint-disable-next-line vue/no-unused-components
VBTooltip,
FeatherIcon, FeatherIcon,
OperationTransferComponent, OperationTransferComponent,
// eslint-disable-next-line vue/no-unused-components // eslint-disable-next-line vue/no-unused-components
@ -272,6 +299,7 @@ export default {
AppCollapseItem, AppCollapseItem,
}, },
directives: { directives: {
'b-tooltip': VBTooltip,
'b-modal': VBModal, 'b-modal': VBModal,
Ripple, Ripple,
}, },
@ -337,6 +365,14 @@ export default {
} }
}, },
computed: { computed: {
defaultWallet: {
get() {
return this.$store.state.chains.defaultWallet
},
set(value) {
this.$store.commit('setDefaultWallet', value)
},
},
calculateTotal() { calculateTotal() {
const v = Object.values(this.balances) const v = Object.values(this.balances)
let total = 0 let total = 0