Skip to content

Commit

Permalink
Merge pull request #2 from randomlino/improve-ux
Browse files Browse the repository at this point in the history
Improve ux
  • Loading branch information
Dragon Master authored Mar 7, 2019
2 parents ca5bdfc + 2ea4100 commit 4a112d8
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 155 deletions.
112 changes: 46 additions & 66 deletions src/backend/wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,28 @@ const getWiccApi = (network) => {
return new WiccAPI(network)
}

const getMnemonic = (address) => {
return vaultStorage.getMnemonic(address)
const getSignInfo = (network, address) => {
const baasApi = new BaasAPI(network)
let srcRegId = null

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID

if (!srcRegId || !String(srcRegId).trim()) {
throw new Error('ADDRESS_NOT_ACTIVATED')
}

return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)

return {
srcRegId,
height,
privateKey
}
})
}

export default {
Expand Down Expand Up @@ -196,8 +216,8 @@ export default {
vaultStorage.logout()
},

async getMnemonic ({ network, address }) {
return getMnemonic(address)
async getMnemonic ({ address }) {
return vaultStorage.getMnemonic(address)
},

async getPrivateKey ({ network, address }) {
Expand All @@ -209,7 +229,7 @@ export default {
},

async getState () {
const state = stateStore.getState()
const state = stateStore.getState() || {}
let isLocked = !!state.isLocked
if (!vaultStorage.isLogin()) {
isLocked = true
Expand Down Expand Up @@ -243,6 +263,12 @@ export default {
}
},

getTransHistory ({ network, address }) {
return transStorage.list(network, address).then((value) => {
return value || []
})
},

registerAccount ({ address }) {
const network = getAddressNetwork(address)
const wiccApi = getWiccApi(network)
Expand All @@ -264,23 +290,11 @@ export default {
})
},

getTransHistory ({ network, address }) {
return transStorage.list(network, address).then((value) => {
return value || []
})
},

callContract ({ network, address, destRegId, value, fees, contract }) {
const wiccApi = getWiccApi(network)
const baasApi = new BaasAPI(network)
let srcRegId = null

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID
return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)

return getSignInfo(network, address).then(({ srcRegId, height, privateKey }) => {
return wiccApi.createContractSign(privateKey, height, srcRegId, destRegId, value, fees, contract)
}).then((sign) => {
return baasApi.submitOfflineTrans(sign)
Expand All @@ -294,38 +308,23 @@ export default {
publishContract ({ network, address, fees, script, scriptDesc }) {
const wiccApi = getWiccApi(network)
const baasApi = new BaasAPI(network)
let srcRegId = null

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID
return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)

return getSignInfo(network, address).then(({ srcRegId, height, privateKey }) => {
return wiccApi.createRegisterAppSign(privateKey, height, srcRegId, fees, script, scriptDesc)
}).then((sign) => {
return baasApi.submitOfflineTrans(sign)
}).then((value) => {
transStorage.append(network, address, 5, value)

return value
}).catch((error) => {
console.log('publish contract error:', error)
throw error
})
},

send ({ network, address, destAddr, value, fees, desc }) {
const wiccApi = getWiccApi(network)
const baasApi = new BaasAPI(network)
let srcRegId = null

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID
return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)

return getSignInfo(network, address).then(({ srcRegId, height, privateKey }) => {
return wiccApi.createTxSign(privateKey, height, srcRegId, destAddr, value, fees)
}).then((sign) => {
return baasApi.submitOfflineTrans(sign)
Expand All @@ -339,7 +338,6 @@ export default {
async vote ({ network, address, votes, fees }) {
const wiccApi = getWiccApi(network)
const baasApi = new BaasAPI(network)
let srcRegId = null

votes = votes || []
if (votes.length === 0) {
Expand All @@ -359,12 +357,7 @@ export default {
})
}))

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID
return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)
return getSignInfo(network, address).then(({ srcRegId, height, privateKey }) => {
// createDelegateTxSign (privateKey, height, srcRegId, delegateData, fees)
return wiccApi.createDelegateTxSign(privateKey, height, srcRegId, delegateData, fees)
}).then((sign) => {
Expand All @@ -373,22 +366,15 @@ export default {
transStorage.append(network, address, 6, value)

return value
}).catch((error) => {
console.log('vote error:', error)
throw error
})
},

getAccountInfo ({ network, address }) {
const baasApi = new BaasAPI(network)

return baasApi.getAccountInfo(address)
return new BaasAPI(network).getAccountInfo(address)
},

getTokenInfo ({ network, address, regId }) {
const baasApi = new BaasAPI(network)

return baasApi.getTokenInfo(regId, address)
return new BaasAPI(network).getTokenInfo(regId, address)
},

async addToken ({ accountId, network, name, regId, precision }) {
Expand All @@ -410,14 +396,8 @@ export default {
async sendToken ({ network, address, regId, destAddress, amount, fees, desc, name }) {
const wiccApi = getWiccApi(network)
const baasApi = new BaasAPI(network)
let srcRegId = null

return baasApi.getAccountInfo(address).then((data) => {
srcRegId = data.regID
return baasApi.getBlockInfo()
}).then((data) => {
const height = data.syncheight
const privateKey = vaultStorage.getPrivateKey(address)

return getSignInfo(network, address).then(({ srcRegId, height, privateKey }) => {
const contract = getSendTokenContract(destAddress, amount * Math.pow(10, 8))
return wiccApi.createContractSign(privateKey, height, srcRegId, regId, 0, fees, contract)
}).then((sign) => {
Expand All @@ -428,9 +408,6 @@ export default {

tokenTransStorage.append(network, address, name, regId, destAddress, amount, desc, txObject)
return txObject
}).catch((error) => {
console.log('send token error:', error)
throw error
})
},

Expand All @@ -444,7 +421,10 @@ export default {
data = data || {}
return new Promise((resolve, reject) => {
if (typeof this[action] === 'function') {
this[action](data).then(resolve, reject)
this[action](data).then(resolve, (error) => {
console.log('action failed:', action, data, error)
reject(error)
})
} else {
reject(new Error('unknown action ' + action))
}
Expand Down
3 changes: 0 additions & 3 deletions src/backend/wallet/storage/vault-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ export default {
})
},

async importWallet (password, mnemonic) {
},

async unlock (password, vaultBlob) {
state.vaultBlob = vaultBlob
return passworder.decrypt(password, vaultBlob).then((value) => {
Expand Down
6 changes: 6 additions & 0 deletions src/popup/account/components/coin-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
},
openRegisterConfirm () {
if (this.value === 0) {
this.$toast(this.$t('common.insufficientBalance'), {
type: 'center'
})
return
}
openRegisterConfirmDialog(this.address)
},
Expand Down
7 changes: 7 additions & 0 deletions src/popup/account/send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
<div class="content-body">
<div class="from-title">{{ $t('account.send.fromLabel') }}</div>
<div class="from-address">{{ activeAddress }}</div>

<wallet-input
v-model="destAddr"
:label="$t('account.send.destLabel')"
:placeholder="$t('account.send.destPlaceHolder')">
</wallet-input>

<wallet-input
v-model="value"
type="number"
postfix="WICC"
:label="$t('account.send.valueLabel')"
:placeholder="$t('account.send.valuePlaceHolder')">
</wallet-input>

<wallet-input
v-model="desc"
:label="$t('account.send.descLabel')">
</wallet-input>

<fees-slider v-model="fees"></fees-slider>
</div>

Expand Down Expand Up @@ -86,6 +91,8 @@
methods: {
confirmSend() {
if (!this.validateAddress(this.destAddr)) return
this.$loading(this.$t('account.send.confirmLoading'))
API.send(this.network || 'testnet', this.activeAddress, this.destAddr, this.value, this.fees, this.desc)
Expand Down
27 changes: 27 additions & 0 deletions src/popup/account/state-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ export default {
},

methods: {
validateAddress (address) {
const from = this.activeAddress || ''
const network = from[0] === 'w' ? 'testnet' : 'mainnet'
address = address || ''

let valid = true
if (network === 'testnet') {
valid = address[0] === 'w'
} else if (network === 'mainnet') {
valid = address[0] === 'W'
}

if (valid) {
valid = address.length === 34
}

if (!valid) {
this.$toast(network === 'testnet'
? this.$t('account.send.testnetAddressInvalid')
: this.$t('account.send.addressInvalid'), {
type: 'center'
})
}

return valid
},

handleNetworkChange (network) {
this.network = network

Expand Down
6 changes: 6 additions & 0 deletions src/popup/account/token/send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
<div class="content-body">
<div class="from-title">{{ $t('account.sendToken.fromLabel') }}</div>
<div class="from-address">{{ activeAddress }}</div>

<wallet-input
v-model="destAddr"
:label="$t('account.sendToken.destLabel')"
:placeholder="$t('account.sendToken.destPlaceHolder')">
</wallet-input>

<wallet-input
v-model="amount"
type="number"
:postfix="name"
:label="$t('account.sendToken.valueLabel')"
:placeholder="$t('account.sendToken.valuePlaceHolder')">
</wallet-input>

<wallet-input
v-model="desc"
:label="$t('account.sendToken.descLabel')">
Expand Down Expand Up @@ -98,6 +102,8 @@
methods: {
confirmSend() {
if (!this.validateAddress(this.destAddr)) return
this.$loading(this.$t('account.sendToken.confirmLoading'))
// sendToken (network, address, name, regId, destAddress, amount, fees, desc)
API.sendToken(this.network || 'testnet', this.activeAddress, this.name, this.regId, this.destAddr, parseFloat(this.amount), this.fees, this.desc)
Expand Down
12 changes: 10 additions & 2 deletions src/popup/api/format-error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import i18nUtil from './i18n'
import locale from '../locale'

export default function (error) {
if (!error) return ''

if (error.message) {
return error.message
const message = error.message

if (message === 'ADDRESS_NOT_ACTIVATED') {
const language = i18nUtil.getLanguage()
return locale[language].common.accountNotActivated
} else if (message) {
return message
}

return JSON.stringify(error)
Expand Down
13 changes: 10 additions & 3 deletions src/popup/components/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:readonly="readOnly"
@input="handleInput"></textarea>
<input
v-if="type === 'text' || type === 'password'"
v-if="type === 'text' || type === 'password' || type === 'number'"
class="wallet-input--input display-block"
:placeholder="placeholder"
:type="type"
Expand Down Expand Up @@ -58,7 +58,15 @@
methods: {
handleInput (event) {
this.$emit('input', event.target.value)
const type = this.type
let value = event.target.value
if (type === 'number') {
const parsed = parseFloat(value)
if (!isNaN(parsed)) {
value = parsed
}
}
this.$emit('input', value)
}
}
}
Expand Down Expand Up @@ -92,7 +100,6 @@
resize: none;
font-size: 16px;
line-height: 30px;
letter-spacing: 2px;
height: 120px;
}
Expand Down
Loading

0 comments on commit 4a112d8

Please sign in to comment.