es/ae/index.js
async function transferFunds (percentage, recipientId, options = { excludeFee: false }) {
  if (percentage < 0 || percentage > 1) throw new Error(`Percentage should be a number between 0 and 1, got ${percentage}`)
  const opt = R.merge(this.Ae.defaults, options)

  const requestTransferAmount = BigNumber(await this.balance(await this.address())).times(percentage)
  let spendTx = await this.spendTx(R.merge(opt, { senderId: await this.address(), recipientId, amount: requestTransferAmount }))

  const { tx: txObject } = TxBuilder.unpackTx(spendTx)
  // If the requestTransferAmount should include the fee keep calculating the fee
  let amount = requestTransferAmount
  if (!options.excludeFee) {
    while (amount.plus(txObject.fee).gt(requestTransferAmount)) {
      amount = requestTransferAmount.minus(txObject.fee)
    }
  }

  // Rebuild tx
  spendTx = await this.spendTx(R.merge(opt, { senderId: await this.address(), recipientId, amount }))

  return this.send(spendTx, opt)
}
async function transferFunds (percentage, recipientId, options = { excludeFee: false }) {
  if (percentage < 0 || percentage > 1) throw new Error(`Percentage should be a number between 0 and 1, got ${percentage}`)
  const opt = R.merge(this.Ae.defaults, options)

  const requestTransferAmount = BigNumber(await this.balance(await this.address())).times(percentage)
  let spendTx = await this.spendTx(R.merge(opt, { senderId: await this.address(), recipientId, amount: requestTransferAmount }))

  const { tx: txObject } = TxBuilder.unpackTx(spendTx)
  // If the requestTransferAmount should include the fee keep calculating the fee
  let amount = requestTransferAmount
  if (!options.excludeFee) {
    while (amount.plus(txObject.fee).gt(requestTransferAmount)) {
      amount = requestTransferAmount.minus(txObject.fee)
    }
  }

  // Rebuild tx
  spendTx = await this.spendTx(R.merge(opt, { senderId: await this.address(), recipientId, amount }))

  return this.send(spendTx, opt)
}
async function transferFunds ( percentage , recipientId , options = { excludeFee : false } ) { if ( percentage < 0 || percentage > 1 ) throw new Error ( ` ${ percentage } ` ) const opt = R . merge ( this . Ae . defaults , options ) const requestTransferAmount = BigNumber ( await this . balance ( await this . address ( ) ) ) . times ( percentage ) let spendTx = await this . spendTx ( R . merge ( opt , { senderId : await this . address ( ) , recipientId , amount : requestTransferAmount } ) ) const { tx : txObject } = TxBuilder . unpackTx ( spendTx ) // If the requestTransferAmount should include the fee keep calculating the fee let amount = requestTransferAmount if ( ! options . excludeFee ) { while ( amount . plus ( txObject . fee ) . gt ( requestTransferAmount ) ) { amount = requestTransferAmount . minus ( txObject . fee ) } } // Rebuild tx spendTx = await this . spendTx ( R . merge ( opt , { senderId : await this . address ( ) , recipientId , amount } ) ) return this . send ( spendTx , opt ) }
Send a percentage of funds to another account
@instance
@category async
@rtype (percentage: Number|String, recipientId: String, options?: Object) => Promise[String]
@param {Number|String} percentage - Percentage of amount to spend
@param {String} recipientId - Address of recipient account
@param {Object} options - Options
@return {String|String} Transaction or transaction hash
Send a percentage of funds to another account