OSDN Git Service

update the list-transactions with crossIn and crossOut.
authorZhiting Lin <zlin035@uottawa.ca>
Thu, 13 Jun 2019 07:07:09 +0000 (15:07 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Thu, 13 Jun 2019 07:07:09 +0000 (15:07 +0800)
src/features/transactions/components/DetailSummary/DetailSummary.jsx
src/locales/en/translation.json
static/images/transactions/crossIn.svg [new file with mode: 0644]
static/images/transactions/crossOut.svg [new file with mode: 0644]

index bedac81..c40198e 100644 (file)
@@ -15,11 +15,23 @@ class DetailSummary extends React.Component {
         alias: inout.assetAlias,
         decimals: (inout.assetDefinition && inout.assetDefinition.decimals && inout.assetId !== btmID)? inout.assetDefinition.decimals : null,
         issue: 0,
-        retire: 0
+        retire: 0,
+        crossOut:0,
+        crossIn:0
       }
 
-      if (['issue', 'retire'].includes(inout.type)) {
-        asset[inout.type] += inout.amount
+
+      if (['issue', 'retire', 'cross_chain_out', 'cross_chain_in'].includes(inout.type)) {
+        switch (inout.type){
+          case 'cross_chain_out':
+            asset['crossOut'] += inout.amount
+            break
+          case 'cross_chain_in':
+            asset['crossIn'] += inout.amount
+            break
+          default:
+            asset[inout.type] += inout.amount
+        }
       } else {
         let accountKey = inout.accountId || 'external'
         let account = asset[accountKey]
@@ -76,11 +88,11 @@ class DetailSummary extends React.Component {
       return amount
     }
 
-    const addType =['issue','received']
+    const addType =['issue','received', 'crossIn']
 
     Object.keys(summary).forEach((assetId) => {
       const asset = summary[assetId]
-      const nonAccountTypes = ['issue','retire']
+      const nonAccountTypes = ['issue','retire','cross_chain_out','cross_chain_in']
 
       Object.keys(asset).forEach((accountId) => {
         if (nonAccountTypes.includes(accountId)) return
@@ -93,6 +105,7 @@ class DetailSummary extends React.Component {
             let nodePubkeyArray = account.vote
             for (const nodePubkey of Object.keys(nodePubkeyArray)) {
               let amount = nodePubkeyArray[nodePubkey]
+              account['spend'] = account['spend'] - amount
               items.push({
                 type: 'vote',
                 amount: asset.decimals? converIntToDec(amount, asset.decimals) : normalizeBtmAmountUnit(assetId, amount, this.props.btmAmountUnit),
@@ -108,7 +121,25 @@ class DetailSummary extends React.Component {
             let type,
               amount = account['spend']- account['control']
 
-            if(asset.retire === 0 ){
+            if(asset.crossOut > 0){
+              if( amount < asset.crossOut ){
+                asset.crossOut = asset.crossOut - amount
+                type = 'crossOut'
+              }else{
+                const crossOut = asset.crossOut
+                amount = amount - crossOut
+                type = 'sent'
+                items.push({
+                  type: 'crossOut',
+                  amount: normalizeBtmAmountUnit(assetId,  crossOut, this.props.btmAmountUnit),
+                  asset: assetAlias ? assetAlias : <code className={styles.rawId}>{assetId}</code>,
+                  assetId: assetId,
+                  account: account.alias ? account.alias : <code className={styles.rawId}>{accountId}</code>,
+                  accountId: accountId,
+                })
+                asset.crossOut = 0
+              }
+            }else if(asset.retire === 0 ){
               type = 'sent'
             }else if(asset.retire >= amount ){
               type = 'retire'
@@ -136,8 +167,28 @@ class DetailSummary extends React.Component {
           }
 
           if(account['spend']< account['control'] && account['control'] > 0){
-            const amount = account['control']- account['spend']
-            const type = asset.issue >= amount? 'issue': 'received'
+            let type, amount = account['control']- account['spend']
+            if(asset.crossIn > 0){
+              if( amount < asset.crossIn ){
+                asset.crossIn = asset.crossIn - amount
+                type = 'crossIn'
+              }else{
+                const crossIn = asset.crossIn
+                amount = amount - crossIn
+                type = 'received'
+                items.push({
+                  type: 'crossIn',
+                  amount: normalizeBtmAmountUnit(assetId,  crossIn, this.props.btmAmountUnit),
+                  asset: assetAlias ? assetAlias : <code className={styles.rawId}>{assetId}</code>,
+                  assetId: assetId,
+                  account: account.alias ? account.alias : <code className={styles.rawId}>{accountId}</code>,
+                  accountId: accountId,
+                })
+                asset.crossIn = 0
+              }
+            }else{
+              type = asset.issue >= amount? 'issue': 'received'
+            }
             items.push({
               type: type,
               amount: asset.decimals? converIntToDec(amount, asset.decimals) : normalizeBtmAmountUnit(assetId, amount, this.props.btmAmountUnit),
@@ -151,7 +202,7 @@ class DetailSummary extends React.Component {
       })
     })
 
-    const ordering = ['vote', 'issue','received',  'retire', 'sent']
+    const ordering = ['vote', 'issue', 'cross_chain_in','received',  'retire', 'cross_chain_out', 'sent']
     items.sort((a,b) => {
       return ordering.indexOf(a.type) - ordering.indexOf(b.type)
     })
index ccb4680..7349cfa 100644 (file)
       "retire":"retire",
       "coinbase":"coinbase",
       "immature":"immature",
-      "vote":"vote"
+      "vote":"vote",
+      "crossOut":"Vapor -> Bytom",
+      "crossIn":"Bytom -> Vapor"
     },
     "new":{
       "unsaveWarning":"Your work is not saved! Are you sure you want to leave?",
diff --git a/static/images/transactions/crossIn.svg b/static/images/transactions/crossIn.svg
new file mode 100644 (file)
index 0000000..a1dc379
--- /dev/null
@@ -0,0 +1,18 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
+  <defs>
+    <style>
+      .cls-1 {
+        fill: none;
+      }
+
+      .cls-2 {
+        fill: #20252d;
+        stroke: rgba(0,0,0,0);
+      }
+    </style>
+  </defs>
+  <g id="Vapor2Bytom" transform="translate(-61 -5)">
+    <rect id="Rectangle_3694" data-name="Rectangle 3694" class="cls-1" width="18" height="18" transform="translate(61 5)"/>
+    <path id="Path_20331" data-name="Path 20331" class="cls-2" d="M-3132.482-282.418l3.553,3.553h0l-.925.926-3.553-3.554a.667.667,0,0,1-.016-.9.646.646,0,0,1,.466-.214h.016A.645.645,0,0,1-3132.482-282.418Zm11.876.715h0l-4.287,4.287-.9-.9,4.284-4.285Zm-7.421,3.74.935.936-.926.927-.936-.937.926-.926h0Zm1.839,1.839.934.935-.926.927-.936-.936.926-.926h0Zm-6.118,1.314v2.981l2.956-2.957.919.919-2.956,2.957h2.98v1.3h-5.2v-5.2Zm7.956.524,3.541,3.543a.652.652,0,0,1,0,.92l-.006.008a.652.652,0,0,1-.911.009l-3.551-3.552.926-.927h0Z" transform="translate(3197.105 290.109)"/>
+  </g>
+</svg>
diff --git a/static/images/transactions/crossOut.svg b/static/images/transactions/crossOut.svg
new file mode 100644 (file)
index 0000000..5cd573f
--- /dev/null
@@ -0,0 +1,18 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
+  <defs>
+    <style>
+      .cls-1 {
+        fill: none;
+      }
+
+      .cls-2 {
+        fill: #20252d;
+        stroke: rgba(0,0,0,0);
+      }
+    </style>
+  </defs>
+  <g id="Bytom2Vapor" transform="translate(-61 -5)">
+    <rect id="Rectangle_3694" data-name="Rectangle 3694" class="cls-1" width="18" height="18" transform="translate(61 5)"/>
+    <path id="Path_20330" data-name="Path 20330" class="cls-2" d="M-3121.729-269.8l-3.553-3.553h0l.925-.926,3.553,3.554a.667.667,0,0,1,.016.9.646.646,0,0,1-.466.214h-.016A.645.645,0,0,1-3121.729-269.8Zm-11.876-.715h0l4.287-4.287.9.9-4.284,4.285Zm7.421-3.74-.935-.936.926-.927.936.937-.926.926h0Zm-1.839-1.839-.934-.935.926-.927.936.936-.926.926h0Zm6.118-1.314v-2.981l-2.956,2.957-.919-.919,2.956-2.957h-2.98v-1.3h5.2v5.2Zm-7.956-.524-3.541-3.543a.652.652,0,0,1,0-.92l.006-.008a.652.652,0,0,1,.911-.009l3.551,3.552-.926.927h0Z" transform="translate(3197.105 290.109)"/>
+  </g>
+</svg>