Hi. I am trying to create an automatic currency converter based on the one of the NPM packages (current-currency) published in the library. Code works well on the back-end but returns to undefined when I call it from the front-end side.
The front end page is a dynamic item page that shows the price in Euros but I would like to show the price in additional currencies at the same time too.
Could you check it?
back-end (convertPrice.jsw)
import { convert } from "current-currency";
export function convertEuroToLira(referenceAmount) {
convert("EUR", referenceAmount, "TRY")
.then((result) => {
let amountInLiras = parseFloat(result.amount).toFixed(2);
console.log("Back end response is ", amountInLiras);
let currency = result.currency;
console.log("Back end returns this", `${amountInLiras} ${currency}`);
return {amountInLiras,currency};
//referenceAmount
// {currency: "TRY", amount: 275.21}
})
}
front-end (a dynamic item page)
import { convertEuroToLira } from 'backend/trainingEvents/convertPrice.jsw';
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
let itemObj = $w("#dynamicDataset").getCurrentItem();
let price = itemObj.price
convertEuroToLira(price)
.then((res) => {
console.log("Front end respose", res);
let liraPrice = res.amountInLiras;
//console.log("Front end price", liraPrice);
$w('#priceText').text = `€${price} or ${liraPrice} TRY`
//console.log(`€${price} or ${liraPrice}`)
})
});
});
I couldn’t figure it out. Hope you can help me.