X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcomponents%2Flayout%2Fprofit%2Faction.js;h=cd1e626679c45564cc6cc9c8038ac62f8013e1e9;hb=d1f568a0aed072fef425dc857cd5e5b6598e9fa1;hp=4e3fbb0b90483149ca270cd59928d5e43b24982b;hpb=6344e36a1941f23b2152d1d37fc072f9d3f9d9db;p=bytom%2FBytom-Dapp-Demo.git diff --git a/src/components/layout/profit/action.js b/src/components/layout/profit/action.js index 4e3fbb0..cd1e626 100644 --- a/src/components/layout/profit/action.js +++ b/src/components/layout/profit/action.js @@ -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 })