OSDN Git Service

update the vote and veto v3 logic
authorZhiting Lin <zlin035@uottawa.ca>
Tue, 2 Jun 2020 07:44:41 +0000 (15:44 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Tue, 2 Jun 2020 07:44:41 +0000 (15:44 +0800)
src/models/transaction.js
src/views/assetList.vue
src/views/transferDetail.vue
src/views/vote/listVote.vue
src/views/vote/veto.vue
src/views/vote/vote.vue
src/views/vote/voteConfirm.vue
src/views/vote/voteRecord.vue

index 35b64f9..ef897c5 100644 (file)
@@ -60,10 +60,10 @@ transaction.buildCrossChain = function(address, to, asset, amount, confirmations
   return retPromise;
 };
 
-transaction.buildVote = function(guid, vote, amount, confirmations, memo) {
+transaction.buildVote = function(address, vote, amount, confirmations, memo) {
   let retPromise = new Promise((resolve, reject) => {
     bytom.transaction
-      .buildVote(guid, vote, Number(amount), confirmations, memo)
+      .buildVote(address, vote, amount.toString(), confirmations, memo)
       .then(res => {
         resolve(res);
       })
@@ -74,10 +74,10 @@ transaction.buildVote = function(guid, vote, amount, confirmations, memo) {
   return retPromise;
 };
 
-transaction.buildVeto = function(guid, vote, amount, confirmations, memo) {
+transaction.buildVeto = function(address, vote, amount, confirmations, memo) {
   let retPromise = new Promise((resolve, reject) => {
     bytom.transaction
-      .buildVeto(guid, vote, Number(amount), confirmations, memo)
+      .buildVeto(address, vote, amount.toString(), confirmations, memo)
       .then(res => {
         resolve(res);
       })
index 0bf5d64..3167943 100644 (file)
@@ -283,8 +283,8 @@ export default {
             const balanceObject = transaction.balances
               .filter(b => b.asset.assetId === assetID);
 
-            const filterInput = transaction.types.includes('veto')
-            const filterOutput = transaction.types.includes('vote')
+            const filterInput = _.find(transaction.inputs, function(o) { return o.type =='veto'; })
+            const filterOutput = _.find(transaction.outputs, function(o) { return o.type =='vote'; })
 
             if(filterInput){
               transaction.type = 'veto'
@@ -304,7 +304,7 @@ export default {
               }else{
                 transaction.cDirection ='Bytom -> Vapor'
               }
-            }else if(transaction.types.includes('in_crosschain')){
+            }else  if(transaction.types.includes('in_crosschain')){
               transaction.type = 'crossChain'
               if(this.netType === 'vapor'){
                 transaction.cDirection ='Bytom -> Vapor'
index ec94be7..a270361 100644 (file)
             <div class="tx-header"
                  v-bind:class="classObject">
               <p class="value">{{transaction.direct}}{{transaction.val}}</p>
-              <small class="header-text" v-if="transaction.status_fail">
+              <small class="header-text" v-if="!transaction.status">
                 {{ $t('transactionDetail.fail') }}
               </small>
               <small class="header-text" v-else-if="transaction.hasOwnProperty('blockTimestamp')">
                           <p>{{transaction.fee}}</p>
                         </td>
                       </tr>
-                      <tr v-if="transaction.type =='vote'">
+                      <tr v-if="transaction.type =='vote' || transaction.type =='veto' ">
                         <td colspan="2"><div class="divider"></div></td>
                       </tr>
-                      <tr  v-if="transaction.type =='vote'">
+                      <tr  v-if="transaction.type =='vote' || transaction.type =='veto'">
                         <td class="label">
                           {{ $t('listVote.bpName') }}
                         </td>
         }
         console.log(params.transaction)
         if(transaction.type =='vote' || transaction.type =='veto'){
-          const node =_.find(this.listVote, {pub_key: transaction.pubkey})
+          const node =_.find(this.listVote, {pubKey: transaction.pubkey})
           transaction.vName = node.name
         }
         this.transaction = transaction
index 03eb14a..14b2fbf 100644 (file)
                         {{vote.name}}
                       </div>
                     </div>
-                    <div class="vote-number">{{$t('listVote.votes')}} {{formatNue(vote.vote_num)}} ({{formatFraction(vote.vote_num, totalVote)}})</div>
+                    <div class="vote-number">{{$t('listVote.votes')}} {{formatNue(vote.voteNum)}} ({{formatFraction(vote.voteNum, totalVote)}})</div>
                   </td>
                 <td class="text-align-right">
                   <button class="btn btn-vote" @click="openVote(vote)">
@@ -342,8 +342,8 @@ export default {
     mounted() {
       query.chainStatus().then(resp => {
         if(resp){
-          this.totalVote = resp.total_vote_num;
-          const votes =  resp.consensus_nodes.map( (item, index) => {
+          this.totalVote = resp.totalVoteNum;
+          const votes =  resp.consensusNodes.map( (item, index) => {
             item.rank = index+1;
             return item
           });
index 48238e8..c7d159d 100644 (file)
@@ -179,10 +179,10 @@ export default {
 
             const vote = this.selectVote.pubKey
             this.transaction.to = vote
-            transaction.buildVeto(this.currentAccount.guid, vote,  Num.convertToNue(this.transaction.amount,8), this.transaction.confirmations).then(result => {
+            transaction.buildVeto(this.currentAccount.vpAddress, vote, this.transaction.amount, this.transaction.confirmations).then(result => {
                 loader.hide();
                 if(!this.transaction.fee){
-                  this.transaction.fee = Number( _.sumBy(result, 'fee'));
+                  this.transaction.fee = Number( _.sumBy(result, 'tx.fee'));
                 }
                 this.$router.push({ name: 'vote-confirm', params: { account: this.currentAccount, transaction: this.transaction, assetAlias: 'BTM',rawData: result} })
             }).catch(error => {
index 5dc7aee..62efd87 100644 (file)
@@ -132,17 +132,8 @@ export default {
         let balance,
           balances = this.currentAccount.vpBalances
         if(balances && balances.length >0 ){
-          const balanceObject = balances.filter(b => b.asset === BTM)[0]
-          balance = balanceObject.balance
-
-          let vote = 0, lock = 0
-          const votes = this.currentAccount.votes
-          if(votes && votes.length >0 ){
-            vote = _.sumBy(votes,'total')
-            lock = _.sumBy(votes,'locked')
-          }
-
-          balance = (balance-vote-lock)/Math.pow(10,balanceObject.decimals)
+          const balanceObject = balances.filter(b => b.asset.assetId === BTM)[0]
+          balance = balanceObject.availableBalance
         }
 
           return `${this.$t("vote.amountPlaceHolder")}${(balance != null && balance != 0) ? balance : '0.00'}`
@@ -188,12 +179,12 @@ export default {
                 onCancel: this.onCancel
             });
 
-            const vote = this.selectVote.pub_key
+            const vote = this.selectVote.pubKey
             this.transaction.to = vote
-            transaction.buildVote(this.currentAccount.guid, vote,  Num.convertToNue(this.transaction.amount,8), this.transaction.confirmations).then(result => {
+            transaction.buildVote(this.currentAccount.vpAddress, vote,  this.transaction.amount, this.transaction.confirmations).then(result => {
                 loader.hide();
               if(!this.transaction.fee){
-                this.transaction.fee = Number( _.sumBy(result, 'fee') );
+                this.transaction.fee = Number( _.sumBy(result, 'tx.fee') );
               }
                 this.$router.push({ name: 'vote-confirm', params: { account: this.currentAccount,  transaction: this.transaction,assetAlias: 'BTM', rawData: result} })
             }).catch(error => {
index 5271cc3..d2c45cd 100644 (file)
@@ -239,7 +239,7 @@ export default {
                 onCancel: this.onCancel
             });
 
-          Promise.all(this.rawData.map( (rawdata) => transaction.transfer(this.account.guid, rawdata, this.password)))
+          Promise.all(this.rawData.map( (rawdata) => transaction.transfer(this.account.guid, rawdata, this.password, this.account.vpAddress)))
             .then(ret => {
               loader.hide();
               if(this.$route.params.type == 'popup'){
index 3e206de..462fc8a 100644 (file)
@@ -66,8 +66,8 @@
                                     {{transaction.vName}}
                                   </div>
                                   <div class="addr color-grey">
-                                    <div v-if="transaction.hasOwnProperty('block_timestamp')">
-                                      {{transaction.submission_timestamp | moment}}
+                                    <div v-if="transaction.hasOwnProperty('blockTimestamp')">
+                                      {{transaction.submissionTimestamp | moment}}
                                     </div>
                                     <div v-else>
                                       {{ $t('main.unconfirmed') }}
@@ -169,7 +169,7 @@ export default {
         },
         refreshTransactions: function (start, limit) {
             return new Promise((resolve, reject) => {
-                transaction.list(this.currentAccount.guid, BTM, start, limit, tx_types).then(transactions => {
+                transaction.list(this.currentAccount.vpAddress, BTM, start, limit, tx_types).then(transactions => {
                     if (transactions == null) {
                         return;
                     }
@@ -188,10 +188,9 @@ export default {
 
           transactions.forEach(transaction => {
             const balanceObject = transaction.balances
-              .filter(b => b.asset === assetID);
-
-            const filterInput = _.find(transaction.inputs, function(o) { return o.type =='veto'; })
+              .filter(b => b.asset.assetId === assetID);
 
+            const filterInput = transaction.types.includes('veto')
             const allVotes = this.listVote;
 
             if(filterInput){
@@ -201,14 +200,14 @@ export default {
               const inAmount = _.sumBy((transaction.inputs.filter(i => i.type ==='veto')), 'amount')
               const outAmount = _.sumBy((transaction.outputs.filter(i => i.type ==='vote')), 'amount')
               transaction.vAmount =  Num.formatNue(inAmount-outAmount,8)
-              transaction.vName =  (_.find(allVotes, {pub_key: pubkey})).name
-            }else if(_.find(transaction.outputs, function(o) { return o.type =='vote'; })){
+              transaction.vName =  (_.find(allVotes, {pubKey: pubkey})).name
+            }else if(transaction.types.includes('vote')){
 
               const pubkey = (transaction.outputs.filter(i => i.type ==='vote'))[0].vote
 
               const outAmount = _.sumBy((transaction.outputs.filter(i => i.type ==='vote')), 'amount')
               transaction.vAmount =  Num.formatNue(outAmount,8)
-              transaction.vName =  (_.find(allVotes, {pub_key: pubkey})).name
+              transaction.vName =  (_.find(allVotes, {pubKey: pubkey})).name
 
               transaction.type = 'vote'
             }