Skip to content

Commit

Permalink
Remove hardcoded query param assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
Prajwal-Kamboj authored and debajitr committed Sep 8, 2022
1 parent fb59356 commit 1b86ecb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 100 deletions.
53 changes: 7 additions & 46 deletions dist/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,10 @@ module.exports = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.c
},{}],7:[function(require,module,exports){
module.exports={
"name": "@transak/transak-sdk",
"version": "1.0.29",
"version": "1.1.0",
"description": "Transak SDK that allows you to easily integrate the fiat on/ramp",
"main": "dist/sdk.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "browserify ./src/index.js -o ./dist/sdk.js -p esmify -s TransakSDK"
},
"repository": {
Expand Down Expand Up @@ -1509,50 +1508,12 @@ async function generateURL(configData) {
}

try {
environment = environment.toUpperCase(); // let partnerDataBackend = await fetchAPIKey(configData.apiKey, config.ENVIRONMENT[environment].BACKEND);
// if (partnerDataBackend) {

partnerData.apiKey = configData.apiKey;
if (configData.sdkVersion) partnerData.sdkVersion = configData.sdkVersion;
if (configData.cryptoCurrencyCode) partnerData.cryptoCurrencyCode = configData.cryptoCurrencyCode;
if (configData.defaultCryptoCurrency) partnerData.defaultCryptoCurrency = configData.defaultCryptoCurrency;
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.themeColor) partnerData.themeColor = configData.themeColor.replace("#", "");
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.fiatAmount) partnerData.fiatAmount = configData.fiatAmount;
if (configData.defaultFiatAmount) partnerData.defaultFiatAmount = configData.defaultFiatAmount;
if (configData.defaultCryptoAmount) partnerData.defaultCryptoAmount = configData.defaultCryptoAmount;

if (configData.walletAddressesData && (configData.walletAddressesData.networks || configData.walletAddressesData.coins)) {
partnerData.walletAddressesData = {};
if (configData.walletAddressesData.networks) partnerData.walletAddressesData.networks = configData.walletAddressesData.networks;
if (configData.walletAddressesData.coins) partnerData.walletAddressesData.coins = configData.walletAddressesData.coins;
partnerData.walletAddressesData = JSON.stringify(partnerData.walletAddressesData);
}

if (configData.fiatCurrency) partnerData.fiatCurrency = configData.fiatCurrency;
if (configData.countryCode) partnerData.countryCode = configData.countryCode;
if (configData.paymentMethod) partnerData.paymentMethod = configData.paymentMethod;
if (configData.defaultPaymentMethod) partnerData.defaultPaymentMethod = configData.defaultPaymentMethod;
if (configData.isAutoFillUserData) partnerData.isAutoFillUserData = configData.isAutoFillUserData;
if (configData.isFeeCalculationHidden) partnerData.isFeeCalculationHidden = configData.isFeeCalculationHidden;
if (configData.disablePaymentMethods) partnerData.disablePaymentMethods = configData.disablePaymentMethods;
if (configData.email) partnerData.email = configData.email;
if (configData.userData) partnerData.userData = JSON.stringify(configData.userData);
if (configData.partnerOrderId) partnerData.partnerOrderId = configData.partnerOrderId;
if (configData.partnerCustomerId) partnerData.partnerCustomerId = configData.partnerCustomerId;
if (configData.exchangeScreenTitle) partnerData.exchangeScreenTitle = configData.exchangeScreenTitle;
if (configData.hideMenu) partnerData.hideMenu = configData.hideMenu;
if (configData.accessToken) partnerData.accessToken = configData.accessToken;
if (configData.hideExchangeScreen) partnerData.hideExchangeScreen = configData.hideExchangeScreen;
if (configData.isDisableCrypto) partnerData.isDisableCrypto = configData.isDisableCrypto;
if (configData.redirectURL) partnerData.redirectURL = configData.redirectURL;
if (configData.hostURL) partnerData.hostURL = configData.hostURL ? configData.hostURL : window.location.origin;
if (configData.disableWalletAddressForm) partnerData.disableWalletAddressForm = configData.disableWalletAddressForm;
if (configData.cryptoCurrencyList) partnerData.cryptoCurrencyList = configData.cryptoCurrencyList.split(',');
if (configData.networks) partnerData.networks = configData.networks.split(',');
if (configData.defaultNetwork) partnerData.defaultNetwork = configData.defaultNetwork;
if (configData.network) partnerData.network = configData.network;
environment = environment.toUpperCase();
Object.keys(configData).map(key => {
if (configData[key] instanceof Object) {
partnerData[key] = JSON.stringify(configData[key]);
} else partnerData[key] = configData[key];
});
queryString = _queryString.default.stringify(partnerData, {
arrayFormat: 'comma'
});
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "@transak/transak-sdk",
"version": "1.0.31",
"version": "1.1.0",
"description": "Transak SDK that allows you to easily integrate the fiat on/ramp",
"main": "dist/sdk.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "browserify ./src/index.js -o ./dist/sdk.js -p esmify -s TransakSDK"
},
"repository": {
Expand Down
68 changes: 16 additions & 52 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import events from 'events';
import {config, errorsLang, EVENTS} from "./constants";
import {UrlEncode} from "./utils/generalUtil";
import {closeSVGIcon} from './assets/svg';
import {getCSS} from './assets/css';
import { config, errorsLang, EVENTS } from "./constants";
import { UrlEncode } from "./utils/generalUtil";
import { closeSVGIcon } from './assets/svg';
import { getCSS } from './assets/css';
import queryStringLib from 'query-string'
import { version } from "../package.json"

Expand Down Expand Up @@ -47,7 +47,7 @@ TransakSDK.prototype.closeRequest = function () {
TransakSDK.prototype.modal = async function () {
try {
if (this.partnerData) {
let {url, width, height, partnerData} = await generateURL({ ...this.partnerData, sdkVersion: this.sdkVersion });
let { url, width, height, partnerData } = await generateURL({ ...this.partnerData, sdkVersion: this.sdkVersion });
let wrapper = document.createElement('div');
wrapper.id = "transakFiatOnOffRamp";
wrapper.innerHTML = `<div class="transak_modal-overlay" id="transak_modal-overlay"></div><div class="transak_modal" id="transak_modal"><div class="transak_modal-content"><span class="transak_close">${closeSVGIcon}</span><div class="transakContainer"><iframe id="transakOnOffRampWidget" allow="camera;fullscreen;accelerometer;gyroscope;magnetometer" allowFullScreen src="${url}" style="width: ${width}; height: ${height}"></iframe></div></div></div>`;
Expand Down Expand Up @@ -81,7 +81,7 @@ TransakSDK.prototype.modal = async function () {
else window.attachEvent("onmessage", handleMessage);
}
} catch (e) {
throw(e)
throw (e)
}
}

Expand All @@ -94,57 +94,21 @@ async function generateURL(configData) {
}
try {
environment = environment.toUpperCase();
// let partnerDataBackend = await fetchAPIKey(configData.apiKey, config.ENVIRONMENT[environment].BACKEND);
// if (partnerDataBackend) {
partnerData.apiKey = configData.apiKey;
if (configData.sdkVersion) partnerData.sdkVersion = configData.sdkVersion;
if (configData.cryptoCurrencyCode) partnerData.cryptoCurrencyCode = configData.cryptoCurrencyCode;
if (configData.defaultCryptoCurrency) partnerData.defaultCryptoCurrency = configData.defaultCryptoCurrency;
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.themeColor) partnerData.themeColor = configData.themeColor.replace("#", "");
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.fiatAmount) partnerData.fiatAmount = configData.fiatAmount;
if (configData.defaultFiatAmount) partnerData.defaultFiatAmount = configData.defaultFiatAmount;
if (configData.defaultCryptoAmount) partnerData.defaultCryptoAmount = configData.defaultCryptoAmount;
if (configData.walletAddressesData && (configData.walletAddressesData.networks || configData.walletAddressesData.coins)) {
partnerData.walletAddressesData = {}
if (configData.walletAddressesData.networks) partnerData.walletAddressesData.networks = configData.walletAddressesData.networks;
if (configData.walletAddressesData.coins) partnerData.walletAddressesData.coins = configData.walletAddressesData.coins;
partnerData.walletAddressesData = JSON.stringify(partnerData.walletAddressesData)
}
if (configData.fiatCurrency) partnerData.fiatCurrency = configData.fiatCurrency;
if (configData.countryCode) partnerData.countryCode = configData.countryCode;
if (configData.paymentMethod) partnerData.paymentMethod = configData.paymentMethod;
if (configData.defaultPaymentMethod) partnerData.defaultPaymentMethod = configData.defaultPaymentMethod;
if (configData.isAutoFillUserData) partnerData.isAutoFillUserData = configData.isAutoFillUserData;
if (configData.isFeeCalculationHidden) partnerData.isFeeCalculationHidden = configData.isFeeCalculationHidden;
if (configData.disablePaymentMethods) partnerData.disablePaymentMethods = configData.disablePaymentMethods;
if (configData.email) partnerData.email = configData.email;
if (configData.userData) partnerData.userData = JSON.stringify(configData.userData)
if (configData.partnerOrderId) partnerData.partnerOrderId = configData.partnerOrderId;
if (configData.partnerCustomerId) partnerData.partnerCustomerId = configData.partnerCustomerId;
if (configData.exchangeScreenTitle) partnerData.exchangeScreenTitle = configData.exchangeScreenTitle;
if (configData.hideMenu) partnerData.hideMenu = configData.hideMenu;
if (configData.accessToken) partnerData.accessToken = configData.accessToken;
if (configData.hideExchangeScreen) partnerData.hideExchangeScreen = configData.hideExchangeScreen;
if (configData.isDisableCrypto) partnerData.isDisableCrypto = configData.isDisableCrypto;
if (configData.redirectURL) partnerData.redirectURL = configData.redirectURL;
if (configData.hostURL) partnerData.hostURL = (configData.hostURL ? configData.hostURL : window.location.origin);
if (configData.disableWalletAddressForm) partnerData.disableWalletAddressForm = configData.disableWalletAddressForm;
if (configData.cryptoCurrencyList) partnerData.cryptoCurrencyList = configData.cryptoCurrencyList.split(',');
if (configData.networks) partnerData.networks = configData.networks.split(',');
if (configData.defaultNetwork) partnerData.defaultNetwork = configData.defaultNetwork;
if (configData.network) partnerData.network = configData.network;
queryString = queryStringLib.stringify(partnerData, {arrayFormat: 'comma'});
Object.keys(configData).map((key) => {
if (configData[key] instanceof Object) {
partnerData[key] = JSON.stringify(configData[key]);
} else partnerData[key] = configData[key];
});
queryString = queryStringLib.stringify(partnerData, { arrayFormat: 'comma' });
} catch (e) {
throw(e)
throw (e)
}
}
else throw(errorsLang.ENTER_API_KEY);
else throw (errorsLang.ENTER_API_KEY);
if (configData.widgetWidth) width = configData.widgetWidth;
if (configData.widgetHeight) height = configData.widgetHeight;
}
return {width, height, partnerData, url: `${config.ENVIRONMENT[environment].FRONTEND}?${queryString}`}
return { width, height, partnerData, url: `${config.ENVIRONMENT[environment].FRONTEND}?${queryString}` }
}

async function setStyle(themeColor, width, height) {
Expand Down Expand Up @@ -216,7 +180,7 @@ function handleMessage(event) {
});
break;
}
default : {
default: {
}
}
}
Expand Down

0 comments on commit 1b86ecb

Please sign in to comment.