diff --git a/scripts/floTokenAPI.js b/scripts/floTokenAPI.js index 894f0c0..a87876f 100644 --- a/scripts/floTokenAPI.js +++ b/scripts/floTokenAPI.js @@ -1,4 +1,4 @@ -(function(EXPORTS) { //floTokenAPI v1.0.3 +(function(EXPORTS) { //floTokenAPI v1.0.3a /* Token Operator to send/receive tokens via blockchain using API calls*/ 'use strict'; const tokenAPI = EXPORTS; @@ -58,7 +58,7 @@ tokenAPI.sendToken = function(privKey, amount, receiverID, message = "", token = DEFAULT.currency, options = {}) { return new Promise((resolve, reject) => { let senderID = floCrypto.getFloID(privKey); - if (typeof amount !== "number" || amount <= 0) + if (typeof amount !== "number" || isNaN(amount) || amount <= 0) return reject("Invalid amount"); getBalance(senderID, token).then(bal => { if (amount > bal) diff --git a/scripts/fn_ui.js b/scripts/fn_ui.js index 2a38c54..40cae4d 100644 --- a/scripts/fn_ui.js +++ b/scripts/fn_ui.js @@ -373,16 +373,17 @@ function completeCashToTokenRequest(request) { function confirmTopUp(button) { const { message: { amount }, vectorClock, senderID } = floGlobals.cashierProcessingRequest; + var tokenAmt = amount; buttonLoader(button, true); floBlockchainAPI.getBalance(senderID).then(async user_balance => { - let sendAmt_FLO = floGlobals.sendAmt; + let floAmt = floGlobals.sendAmt; if(user_balance < floGlobals.settings.user_flo_threshold){ - let cur_rate = await floExchangeAPI.getRates("FLO"); - sendAmt_FLO = floGlobals.settings.send_user_flo; - amount -= cur_rate * sendAmt_FLO; + let cur_rate = (await floExchangeAPI.getRates("FLO")).rate; + floAmt = floGlobals.settings.send_user_flo; + tokenAmt -= cur_rate * floAmt; } - User.sendToken(senderID, amount, 'for cash-to-token', {sendAmt: sendAmt_FLO}).then(txid => { - console.warn(`${amount} cash-to-token for ${senderID}`, txid); + User.sendToken(senderID, tokenAmt, 'for cash-to-token', {sendAmt: floAmt}).then(txid => { + console.warn(`${amount} (${tokenAmt}|${floAmt}) cash-to-token for ${senderID}`, txid); Cashier.finishRequest(floGlobals.cashierProcessingRequest, txid).then(result => { console.log(result); console.info('Completed cash-to-token request:', vectorClock); @@ -390,7 +391,7 @@ function confirmTopUp(button) { hidePopup() }).catch(error => console.error(error)) }).catch(error => console.error(error)) - }).catch(error => reject(error)) + }).catch(error => console.error(error)) } getRef('top_up__reason_selector').addEventListener('change', e => {