}
}).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 = []
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
}).catch(err => {
throw err
})
- })
- .catch(err => {
- throw err
- })
- }
- })
+ }
+ })
+ .catch(err => {
+ throw err
+ })
+ })
.catch(err => {
throw err
})