From 90408a29bb90400fef1ebc9710f36b41fe90a26a Mon Sep 17 00:00:00 2001 From: Zhiting Lin Date: Tue, 11 Aug 2020 11:29:58 +0800 Subject: [PATCH] update transfer page. --- src/assets/language/cn.js | 5 +- src/assets/style.css | 16 +- src/components/MenubarComponent.vue | 3 +- src/components/backButton/button.vue | 13 +- src/components/modal-passwd.vue | 50 ++- src/components/selection-page/page.vue | 7 +- src/models/transaction.js | 97 ++++-- src/utils/Keychain.js | 2 + src/utils/address.js | 10 + src/views/sendTransaction/assetSelection.vue | 39 ++- src/views/sendTransaction/transfer.vue | 487 ++++++++++++++++----------- src/views/viewBase.vue | 1 - 12 files changed, 450 insertions(+), 280 deletions(-) diff --git a/src/assets/language/cn.js b/src/assets/language/cn.js index e2fb9f9..56a50e3 100644 --- a/src/assets/language/cn.js +++ b/src/assets/language/cn.js @@ -87,7 +87,8 @@ const cn = { hide:'隐藏', viewAll:'展示全部', hideAll:'隐藏全部', - types:'交易类型' + types:'交易类型', + password:'请输入密码' }, listAsset: { all:'全部', @@ -238,6 +239,8 @@ const cn = { BTM0002:'助记词验证失败,请输入正确助记词。', BTM0003:'请选择Keystore文件。', BTM0004:'请输入Keystore。', + BTM0005:'输入数量大于可用余额。', + BTM0006:'输入有效的地址格式。', }, successMsg:{ createWallet:{ diff --git a/src/assets/style.css b/src/assets/style.css index fe632e3..7a834be 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -429,7 +429,7 @@ hr { bottom: 0; opacity: 1; visibility: visible; - background-color: rgba(0, 0, 0, 0.7); + background-color: rgba(0, 0, 0, 0.4); } .menu-title { @@ -547,6 +547,20 @@ hr { border: none; } +.btn-outlined +{ + border: 1px solid #D6D6D6; + background: white; + color: #D6D6D6; +} + +.btn-outlined:active, +.btn-outlined:hover, +.btn-outlined:focus { + color: #ffffff; + background-color: #D6D6D6; +} + .btn-warning { background-color: #E60000; } diff --git a/src/components/MenubarComponent.vue b/src/components/MenubarComponent.vue index 958b982..ca80a47 100644 --- a/src/components/MenubarComponent.vue +++ b/src/components/MenubarComponent.vue @@ -31,7 +31,8 @@ RouteNames.HOME, RouteNames.ASSET, RouteNames.TRANSFER, - RouteNames.RECEIVE + RouteNames.RECEIVE, + RouteNames.ASSET_SELECTION ] switch(name){ case 'HOME':{ diff --git a/src/components/backButton/button.vue b/src/components/backButton/button.vue index 91cac80..5481277 100644 --- a/src/components/backButton/button.vue +++ b/src/components/backButton/button.vue @@ -8,12 +8,19 @@ export default { props: { des:null, - small:false + small:false, + back:{ + type: Function + } }, methods: { goBack:function () { - this.des? - this.$router.push({name: this.des}): this.$router.go(-1) + if(this.back){ + this.back() + }else{ + this.des? + this.$router.push({name: this.des}): this.$router.go(-1) + } } } }; diff --git a/src/components/modal-passwd.vue b/src/components/modal-passwd.vue index ce9a61b..1732488 100644 --- a/src/components/modal-passwd.vue +++ b/src/components/modal-passwd.vue @@ -1,31 +1,29 @@ @@ -33,16 +31,15 @@
--> -
+
- -
- +
+
-
{{ $t('welcome.confirm') }}
-
{{ $t('welcome.cancel') }}
+
{{ $t('welcome.cancel') }}
+
{{ $t('welcome.confirm') }}
@@ -53,8 +50,6 @@ import { getLanguage } from "@/assets/language" import { mapGetters } from 'vuex' -const CLASS_CN = "form-item-content form-item-content-cn"; -const CLASS_EN = "form-item-content form-item-content-en" export default { data() { return { @@ -69,16 +64,9 @@ export default { } }, computed: { - passwdStyle: function () { - if (this.i18n == "cn") { - return CLASS_CN; - } else if (this.i18n == "en") { - return CLASS_EN; - } - return CLASS_CN; - }, ...mapGetters([ - 'language' + 'language', + 'netType' ]) }, methods: { @@ -92,9 +80,9 @@ export default { }, confirm() { if (this.passwd == "") { - this.$dialog.show({ - body: this.$t("transfer.emptyPassword") - }); + this.$toast.error( + this.$t("transfer.emptyPassword") + ); return; } diff --git a/src/components/selection-page/page.vue b/src/components/selection-page/page.vue index 1a14fa9..81adaf8 100644 --- a/src/components/selection-page/page.vue +++ b/src/components/selection-page/page.vue @@ -3,7 +3,7 @@
+
@@ -39,8 +39,11 @@ export default { align-items: center; justify-content: space-between; padding: 16px; - margin-bottom: 20px; color: rgba(0, 0, 0, 0.88); font-size:15px; } +.select-item:not(:last-child){ + margin-bottom: 20px; + +} diff --git a/src/models/transaction.js b/src/models/transaction.js index b4582d9..e3a2588 100644 --- a/src/models/transaction.js +++ b/src/models/transaction.js @@ -35,7 +35,7 @@ transaction.asset = function(asset_id) { transaction.build = function(address, to, asset, amount, fee, confirmations) { let retPromise = new Promise((resolve, reject) => { bytom.transaction - .buildPayment(address, to, asset, amount.toString(), fee, confirmations) + .buildPayment(address, to, asset, amount.toString(), confirmations) .then(res => { resolve(res); }) @@ -134,35 +134,58 @@ transaction.decodeTransaction = function(rawTx) { return retPromise; }; -transaction.transfer = function(guid, transaction, password, address, context) { +transaction.transfer = function(transaction, password, address, context) { let retPromise = new Promise((resolve, reject) => { - signTx( - guid, - JSON.stringify(snakeize(transaction)), - password, - context - ) - .then(ret => { - bytom.transaction - .submitPayment(address, ret.raw_transaction, ret.signatures) - .then(res3 => { - const object ={ - transactionHash: res3.txHash - } - resolve(object); - }) - .catch(error => { - reject(error); - }); + + const {to, asset, amount, confirmations} = transaction + bytom.transaction + .buildPayment(address, to, asset, amount.toString(), confirmations) + .then(result => { + Promise.all(result.map( (data) => + signSubmit( data, password, address, context))) + .then((ret )=>{ + resolve(ret) + }) + .catch(error => { + throw error + }); }) .catch(error => { reject(error); }); - }); + }) return retPromise; }; +function signSubmit (txObject, password, address, context) { + let retPromise = new Promise((resolve, reject) => { + signTx( + address, + JSON.stringify(snakeize(txObject)), + password, + context + ) + .then(ret => { + bytom.transaction + .submitPayment(address, ret.raw_transaction, ret.signatures) + .then(res3 => { + const object = { + transactionHash: res3.txHash + } + resolve(object); + }) + .catch(error => { + throw error + }); + }) + .catch(error => { + reject(error); + }); + }); + return retPromise; +}; + transaction.signMessage = function(message, password, address) { return bytom.keys.signMessage(message, password,address); @@ -203,21 +226,23 @@ transaction.advancedTransfer = function(guid, transaction, password, arrayData, -function signTx(guid, transaction, password, context){ - return bytom.accounts.getAccountXpubById(guid).then((xpub)=>{ - const keyArray = context.bytom.keychain.findIdentity(xpub); - if(!keyArray){ - throw 'xpub not found' - }else{ - const key = keyArray.key - return bytom.transaction - ._signTransaction( - transaction, - password, - key - ) - } - }) +function signTx(address, transaction, password, context){ + const keyArray = context.bytom.keychain.findByAddress(address); + if(!keyArray){ + throw 'Account not found.' + }else{ + const key = JSON.stringify(keyArray.keystore) + return bytom.transaction + ._signTransaction( + transaction, + password, + key + ) + } +} + +transaction.estimateFee = function(address, asset_amounts, confirmations){ + return bytom.transaction.estimateFee(address, asset_amounts, confirmations) } export default transaction; diff --git a/src/utils/Keychain.js b/src/utils/Keychain.js index 4398e80..21192b9 100644 --- a/src/utils/Keychain.js +++ b/src/utils/Keychain.js @@ -13,6 +13,8 @@ export default class Keychain { findIdentity(publicKey){ return Object.values(this.pairs).find(id => id.xpub === publicKey); } findByGuid(guid){ return Object.values(this.pairs).find(id => id.guid === guid); } + findByAddress(address){ return Object.values(this.pairs).find(id => id.address === address || id.vpAddress=== address); } + removeUnverifyIdentity(){ const pairObject = Object.values(this.pairs).filter(id => !id.vMnemonic ); diff --git a/src/utils/address.js b/src/utils/address.js index 9a866e4..e32a437 100644 --- a/src/utils/address.js +++ b/src/utils/address.js @@ -12,4 +12,14 @@ export default class address { let endSome = rawAddress.substr(rawAddress.length - length, length) return startSome + '...' + endSome } + + static isValid(address, netType) { + if (netType == 'vapor') { + const vpArray = ['vp', 'tp', 'sp'] + return vpArray.includes( address.substring(0,2) ) + }else{ + const bmArray = ['bm', 'tm', 'sm'] + return bmArray.includes( address.substring(0,2) ) + } + } } diff --git a/src/views/sendTransaction/assetSelection.vue b/src/views/sendTransaction/assetSelection.vue index b991cac..20ea8d0 100644 --- a/src/views/sendTransaction/assetSelection.vue +++ b/src/views/sendTransaction/assetSelection.vue @@ -7,6 +7,17 @@ font-size: 20px; } } + .button-section{ + position: fixed; + width: calc( 100% - 120px); + bottom: 0; + padding-bottom: 30px; + } + + .selction-section{ + height: calc( 100% - 149px ); + overflow: scroll; + } @@ -18,10 +29,10 @@
{{ $t('transfer.asset')}}
-
+
-
+
@@ -53,6 +64,9 @@ export default { } }, + ...mapState([ + 'currentAsset' + ]), ...mapGetters([ 'currentAccount', 'netType' @@ -62,15 +76,26 @@ export default { assetToggle: function(event){ this.asset = event.target.value }, - ...mapActions([ - Actions.SET_CURRENT_ASSET, - ]), setAsset(asset){ - this[Actions.SET_CURRENT_ASSET](asset) + let balance + if(this.netType === 'vapor'){ + balance = this.currentAccount.vpBalances.find(b => b.asset.symbol ==asset) + }else{ + balance = this.currentAccount.balances.find(b => b.asset.symbol ==asset) + } + if(balance){ + this[Actions.SET_CURRENT_ASSET](balance.asset) + } this.$router.go(-1) - } + }, + ...mapActions([ + Actions.SET_CURRENT_ASSET, + ]) }, mounted() { + if(this.currentAsset){ + this.asset = this.currentAsset.symbol + } }, }; diff --git a/src/views/sendTransaction/transfer.vue b/src/views/sendTransaction/transfer.vue index a81acd2..38a121b 100644 --- a/src/views/sendTransaction/transfer.vue +++ b/src/views/sendTransaction/transfer.vue @@ -1,166 +1,197 @@ diff --git a/src/views/viewBase.vue b/src/views/viewBase.vue index 3187fdb..729c4af 100644 --- a/src/views/viewBase.vue +++ b/src/views/viewBase.vue @@ -33,7 +33,6 @@ -
-- 2.11.0