Comparing version 0.2.9 to 0.3.0
68
index.js
@@ -197,4 +197,5 @@ const axios = require('axios') | ||
/** | ||
* @param {string} type 0 - for navigation, 1 - for invoice | ||
* @param {string} type 0 - for navigation, 1 - for invoice, 2 for transfer to specified address (not from db) | ||
* @param {string} merchant_id id which you can find at console.crypttp.com | ||
* @param {object} to object 'currency':'address' of wallets for each currency, where transfer should be sent | ||
* @param {string} country_currency object with details of transaction | ||
@@ -211,2 +212,3 @@ * @param {string} currency only fiat currency | ||
merchant_id, | ||
to, | ||
country_currency, | ||
@@ -223,2 +225,3 @@ currency, | ||
this.tx_params.merchant_id = (typeof merchant_id != "undefined") ? merchant_id.toString().replace("#/", "") : "" | ||
this.tx_params.to = (typeof to != "undefined") ? to : {} | ||
this.tx_params.country_currency = (typeof country_currency != "undefined") ? country_currency.toString().replace("#/", "") : "" | ||
@@ -235,5 +238,5 @@ this.tx_params.currency = (typeof currency != "undefined") ? currency.toString().replace("#/", "") : "" | ||
this.chains.map(el => { | ||
this.amount[el] = (this.tx_params.amount / this.rates[this.nativeCurrency[el]]).toString() | ||
this.amount[el] = (this.tx_params.amount / this.rates[this.nativeCurrency[el]]).toString().slice(0,8) | ||
}) | ||
switch (this.tx_params.type) { | ||
@@ -243,5 +246,11 @@ case "0" : | ||
break | ||
case "1" : | ||
await this.invoice() | ||
break | ||
case "2" : | ||
await this.transferToSpecifiedAddress() | ||
break | ||
default: | ||
@@ -378,4 +387,57 @@ throw "Unknown transaction type" | ||
} | ||
transferToSpecifiedAddress () { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof this.tx_params.to == "undefined") { | ||
window.alert('Oops, seems like receival wallets not specified.') | ||
resolve(true) | ||
} | ||
else { | ||
if (this.tx_params.currency) { | ||
if (this.currencies.indexOf(this.tx_params.currency) != -1) { | ||
if (this.tx_params.to[this.tx_params.currency] != 'undefined') { | ||
this.deeplink_params.push([ | ||
this.tx_params.currency, | ||
this.amount[this.currency_to_chain[this.tx_params.currency]], | ||
this.tx_params.to[this.tx_params.currency], | ||
this.tx_params.payload, | ||
this.tx_params.memo, | ||
this.tx_params.onsuccess, | ||
this.tx_params.onerror | ||
]) | ||
} | ||
else | ||
window.alert(`Oops, seems like you specified currency, but did not specify a wallet address where to accept it`) | ||
} | ||
else | ||
window.alert(`Sorry but '${this.tx_params.currency}' payments is currently not supported`) | ||
} | ||
else { | ||
/** | ||
* this will map by wallets given by merchant | ||
*/ | ||
Object.keys(this.tx_params.to).map((el) => { | ||
if (this.currencies.indexOf(el.toUpperCase()) != -1) { | ||
this.deeplink_params.push([ | ||
el.toUpperCase(), | ||
this.amount[this.currency_to_chain[el]], | ||
this.tx_params.to[el], | ||
this.tx_params.payload, | ||
this.tx_params.memo, | ||
this.tx_params.onsuccess, | ||
this.tx_params.onerror | ||
]) | ||
} | ||
else | ||
window.alert(`Sorry but '${this.tx_params.currency}' payments is currently not supported`) | ||
}) | ||
} | ||
resolve(true) | ||
} | ||
}) | ||
} | ||
} | ||
module.exports = Crypttp |
{ | ||
"name": "crypttp", | ||
"version": "0.2.9", | ||
"version": "0.3.0", | ||
"description": "Module to call APIs of crypttp powered by alemey", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
17280
388