This commit is contained in:
sairajzero 2022-05-24 19:28:38 +05:30
parent 4eb2bae4a8
commit 4a6e063ed8
2 changed files with 10 additions and 9 deletions

View File

@ -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*/ /* Token Operator to send/receive tokens via blockchain using API calls*/
'use strict'; 'use strict';
const tokenAPI = EXPORTS; const tokenAPI = EXPORTS;
@ -58,7 +58,7 @@
tokenAPI.sendToken = function(privKey, amount, receiverID, message = "", token = DEFAULT.currency, options = {}) { tokenAPI.sendToken = function(privKey, amount, receiverID, message = "", token = DEFAULT.currency, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let senderID = floCrypto.getFloID(privKey); let senderID = floCrypto.getFloID(privKey);
if (typeof amount !== "number" || amount <= 0) if (typeof amount !== "number" || isNaN(amount) || amount <= 0)
return reject("Invalid amount"); return reject("Invalid amount");
getBalance(senderID, token).then(bal => { getBalance(senderID, token).then(bal => {
if (amount > bal) if (amount > bal)

View File

@ -373,16 +373,17 @@ function completeCashToTokenRequest(request) {
function confirmTopUp(button) { function confirmTopUp(button) {
const { message: { amount }, vectorClock, senderID } = floGlobals.cashierProcessingRequest; const { message: { amount }, vectorClock, senderID } = floGlobals.cashierProcessingRequest;
var tokenAmt = amount;
buttonLoader(button, true); buttonLoader(button, true);
floBlockchainAPI.getBalance(senderID).then(async user_balance => { floBlockchainAPI.getBalance(senderID).then(async user_balance => {
let sendAmt_FLO = floGlobals.sendAmt; let floAmt = floGlobals.sendAmt;
if(user_balance < floGlobals.settings.user_flo_threshold){ if(user_balance < floGlobals.settings.user_flo_threshold){
let cur_rate = await floExchangeAPI.getRates("FLO"); let cur_rate = (await floExchangeAPI.getRates("FLO")).rate;
sendAmt_FLO = floGlobals.settings.send_user_flo; floAmt = floGlobals.settings.send_user_flo;
amount -= cur_rate * sendAmt_FLO; tokenAmt -= cur_rate * floAmt;
} }
User.sendToken(senderID, amount, 'for cash-to-token', {sendAmt: sendAmt_FLO}).then(txid => { User.sendToken(senderID, tokenAmt, 'for cash-to-token', {sendAmt: floAmt}).then(txid => {
console.warn(`${amount} cash-to-token for ${senderID}`, txid); console.warn(`${amount} (${tokenAmt}|${floAmt}) cash-to-token for ${senderID}`, txid);
Cashier.finishRequest(floGlobals.cashierProcessingRequest, txid).then(result => { Cashier.finishRequest(floGlobals.cashierProcessingRequest, txid).then(result => {
console.log(result); console.log(result);
console.info('Completed cash-to-token request:', vectorClock); console.info('Completed cash-to-token request:', vectorClock);
@ -390,7 +391,7 @@ function confirmTopUp(button) {
hidePopup() hidePopup()
}).catch(error => console.error(error)) }).catch(error => console.error(error))
}).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 => { getRef('top_up__reason_selector').addEventListener('change', e => {