OSDN Git Service

update BigNumber.js error correction.
[bytom/Bytom-Dapp-Demo.git] / src / components / layout / profit / action.js
index 4e3fbb0..cd1e626 100644 (file)
@@ -17,18 +17,20 @@ export function FixedLimitProfit(account, amountBill, saver) {
       }
     }).then(resp => {
       if(resp.length === 0) {
-        throw 'cannot load UTXO info.'
+        throw 'Empty UTXO info, it might be that the utxo is locked. Please retry after 60s.'
+      }else if(amountBill < 100000000){
+        throw 'Please enter an amount bigger or equal than 100000000.'
       }
 
-      const radio = BigNumber( GetContractArgs().totalAmountCapital).div(GetContractArgs().totalAmountBill)
-      const matchesAmount = radio.multipliedBy(amountBill).toNumber()
+      const radio = BigNumber( GetContractArgs().radio )
+      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 = []
@@ -57,21 +59,22 @@ export function FixedLimitProfit(account, amountBill, saver) {
           output.push(controlAddressAction(capitalAmount, capitalAsset, saver))
         }
 
-        window.bytom.advancedTransfer(account, input, output, GetContractArgs().gas*10000000, args, 1)
-          .then((resp) => {
-            if(resp.action === 'reject'){
-              reject('user reject the request')
-            }else if(resp.action === 'success'){
-              updateUtxo({"hash": utxo})
-                .then(()=>{
+        updateUtxo({"hash": utxo})
+          .then(()=>{
+            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
@@ -83,12 +86,12 @@ export function FixedLimitProfit(account, amountBill, saver) {
                   }).catch(err => {
                     throw err
                   })
-                  })
-                .catch(err => {
-                  throw err
-                })
-            }
-          })
+                }
+              })
+              .catch(err => {
+                throw err
+              })
+            })
           .catch(err => {
             throw err
           })