OSDN Git Service

update BigNumber.js error correction.
authorZhiting Lin <zlin035@uottawa.ca>
Wed, 6 Mar 2019 07:32:36 +0000 (15:32 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Wed, 6 Mar 2019 07:32:36 +0000 (15:32 +0800)
src/components/layout/profit/action.js
src/components/layout/profit/index.jsx
src/components/layout/save/action.js
src/components/layout/save/index.jsx

index be49302..cd1e626 100644 (file)
@@ -23,14 +23,14 @@ export function FixedLimitProfit(account, amountBill, saver) {
       }
 
       const radio = BigNumber( GetContractArgs().radio )
-      const matchesAmount = radio.multipliedBy(amountBill).toNumber()
+      const profitAmount = radio.multipliedBy(amountBill).toNumber()
 
-      const result = matchesUTXO(resp, matchesAmount)
+      const result = matchesUTXO(resp, profitAmount)
       const capitalAmount = result.amount
       const capitalAsset = result.asset
       const utxo = result.hash
 
-      if(matchesAmount > capitalAmount) {
+      if(profitAmount > capitalAmount) {
         throw 'input amount must be smaller or equal to ' + capitalAmount/radio.toNumber() + '.'
       }else{
         const input = []
@@ -61,19 +61,20 @@ export function FixedLimitProfit(account, amountBill, saver) {
 
         updateUtxo({"hash": utxo})
           .then(()=>{
-            window.bytom.advancedTransfer(account, input, output, GetContractArgs().gas*10000000, args, 1)
+            window.bytom.advancedTransfer(input, output, GetContractArgs().gas*10000000, args, 1)
               .then((resp) => {
                 if(resp.action === 'reject'){
                   reject('user reject the request')
                 }else if(resp.action === 'success'){
+                  const transactionHash = resp.message.result.data.transaction_hash
                   updateBalances({
-                    "tx_id": resp.message.result.data.transaction_hash,
+                    "tx_id": transactionHash,
                     "address": saver,
                     "asset": GetContractArgs().assetDeposited,
-                    "amount": amountBill*GetContractArgs().totalAmountCapital/GetContractArgs().totalAmountBill
+                    "amount": profitAmount
                   }).then(()=>{
                     updateBalances({
-                      "tx_id": resp.message.result.data.transaction_hash,
+                      "tx_id": transactionHash,
                       "address": account.address,
                       "asset": GetContractArgs().assetBill,
                       "amount": -amountBill
index 658ec12..01c4601 100644 (file)
@@ -1,6 +1,7 @@
 import React from 'react'
 import { FixedLimitProfit } from './action'
 import GetContractArgs from "../../constants";
+import BigNumber from 'bignumber.js'
 
 class Profit extends React.Component {
 
@@ -47,7 +48,7 @@ class Profit extends React.Component {
       .then(()=> {
         this.setState({
           error:'',
-          msg:`Submit success!!! you spent ${amount} bill asset, and gain ${amount*GetContractArgs().totalAmountCapital/GetContractArgs().totalAmountBill} deposit asset.`
+          msg:`Submit success!!! you spent ${amount} bill asset, and gain ${BigNumber(amount).multipliedBy(GetContractArgs().radio).toNumber()} deposit asset.`
         })
       }).catch(err => {
       this.setState({
@@ -63,7 +64,7 @@ class Profit extends React.Component {
         <h2>Profit</h2>
         <div className="mt-3 mb-4">
           <p className='lead'>Profit should get above the block height {GetContractArgs().dueBlockHeight}.</p>
-          <p className='lead'>Send {this.state.amount} Bill Asset from your chrome extension account <b className="font-weight-bolder text-uppercase">{this.state.account && this.state.account.alias}</b>, and the address {this.state.address} will gain {this.state.amount*GetContractArgs().totalAmountCapital/GetContractArgs().totalAmountBill || ''} Deposit Asset.</p>
+          <p className='lead'>Send {this.state.amount} Bill Asset from your chrome extension account <b className="font-weight-bolder text-uppercase">{this.state.account && this.state.account.alias}</b>, and the address {this.state.address} will gain {BigNumber(this.state.amount).multipliedBy(GetContractArgs().radio).toNumber() || ''} Deposit Asset.</p>
         </div>
         <form onSubmit={this.handleSubmit}>
           <div className="form-group">
index 1a3753b..ea49419 100644 (file)
@@ -7,7 +7,7 @@ import GetContractArgs from '../../constants'
 import { matchesUTXO } from '../../filter'
 import BigNumber from 'bignumber.js'
 
-export function FixedLimitDeposit(account, amount, address) {
+export function FixedLimitDeposit(amount, address) {
   return new Promise((resolve, reject) => {
     return listDappUTXO({
       "program": GetContractArgs().depositProgram,
@@ -51,7 +51,7 @@ export function FixedLimitDeposit(account, amount, address) {
 
         updateUtxo({"hash": utxo})
           .then(()=>{
-          window.bytom.advancedTransfer(account, input, output, GetContractArgs().gas*10000000, args, 1)
+          window.bytom.advancedTransfer(input, output, GetContractArgs().gas*10000000, args, 1)
             .then((resp) => {
               if(resp.action === 'reject'){
                 reject('user reject the request')
index 4cc3d2f..21e3d8d 100644 (file)
@@ -43,7 +43,7 @@ class Save extends React.Component {
     const account = this.state.account
     const address = account.address
 
-    FixedLimitDeposit(account, amount, address)
+    FixedLimitDeposit(amount, address)
       .then(()=> {
           this.setState({
             error:'',