Skip to content

Commit

Permalink
feat: change boson-widgets script
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfolch-redeemeum committed Nov 24, 2023
1 parent af1c68c commit 7433e17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
29 changes: 14 additions & 15 deletions public/scripts/boson-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ const constants = {
deliveryInfoMessageResponse: "boson-delivery-info-response",
redemptionSubmittedMessage: "boson-redemption-submitted",
redemptionConfirmedMessage: "boson-redemption-confirmed",
financeUrl: (widgetsHost) => `${widgetsHost}/#/finance`,
redeemUrl: (widgetsHost) => `${widgetsHost}/#/redeem`
financeUrl: (widgetsHost, params) =>
`${widgetsHost}/#/finance?${new URLSearchParams(params).toString()}`,
redeemUrl: (widgetsHost, params) =>
`${widgetsHost}/#/redeem?${new URLSearchParams(params).toString()}`
};
const scripts = document.getElementsByTagName("script");
let widgetsHost = null;
Expand Down Expand Up @@ -97,11 +99,10 @@ const hideIFrame = () => {
el.remove();
}
};
const buildParams = (paramsTable) =>
paramsTable
.map((param) => (param.value ? `${param.tag}=${param.value}` : undefined))
.filter((p) => !!p)
.join("&");
const toCleanedObject = (paramsTable) =>
Object.fromEntries(
paramsTable.filter((p) => !!p.value).map(({ tag, value }) => [tag, value])
);
window.addEventListener("message", (event) => {
if (event.data === constants.hideModalMessage) {
hideIFrame();
Expand Down Expand Up @@ -201,7 +202,7 @@ function bosonWidgetReload() {
bosonWidgetReload();

function bosonWidgetShowRedeem(args) {
const params = buildParams([
const paramsObject = toCleanedObject([
{ tag: "exchangeId", value: args.exchangeId },
{ tag: "sellerId", value: args.sellerId },
{ tag: "sellerIds", value: args.sellerIds },
Expand Down Expand Up @@ -241,22 +242,20 @@ function bosonWidgetShowRedeem(args) {
]);
showLoading();
hideIFrame();
createIFrame(
`${constants.redeemUrl(widgetsHost)}${params ? "?" + params : ""}`,
() => hideLoading()
createIFrame(constants.redeemUrl(widgetsHost, paramsObject), () =>
hideLoading()
);
}

function bosonWidgetShowFinance(args) {
const params = buildParams([
const paramsObject = toCleanedObject([
{ tag: "sellerId", value: args.sellerId },
{ tag: "configId", value: args.configId },
{ tag: "account", value: args.account }
]);
showLoading(constants.loadingDurationMSec);
hideIFrame();
createIFrame(
`${constants.financeUrl(widgetsHost)}${params ? "?" + params : ""}`,
() => hideLoading()
createIFrame(constants.financeUrl(widgetsHost, paramsObject), () =>
hideLoading()
);
}
13 changes: 9 additions & 4 deletions src/components/widgets/finance/Finance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ import { CONFIG, getMetaTxConfig } from "../../../config";
export const financePath = "/finance";
export function Finance() {
const [searchParams] = useSearchParams();
const sellerId = searchParams.get("sellerId");
if (!sellerId) {
return <p>Missing 'sellerId' query param</p>;
}
const configId = searchParams.get("configId") as ConfigId;
if (!configId) {
return <p>Missing 'configId' query param</p>;
}
const sellerId = searchParams.get("sellerId");
const parentOrigin = searchParams.get("parentOrigin");
if (sellerId && !parentOrigin) {
return <p>Missing 'parentOrigin' query param</p>;
}
if (!sellerId && parentOrigin) {
return <p>Missing 'sellerId' query param</p>;
}
return (
<FinanceWidget
sellerId={sellerId}
parentOrigin={parentOrigin as `http${string}` | null}
configId={configId}
envName={CONFIG.envName}
metaTx={getMetaTxConfig(configId)}
Expand Down
3 changes: 1 addition & 2 deletions src/components/widgets/finance/FinanceDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { financePath } from "./Finance";

export function FinanceDisplay() {
const financeQPobj = {
sellerId: "25",
configId: getEnvConfigs(CONFIG.envName)[0].configId
};
const financeQP = new URLSearchParams(
Object.entries(financeQPobj)
).toString();
const title = "Finance widget";
const width = "100%";
const height = "400px";
const height = "650px";
const iframeText = `<iframe width="${width}" height="${height}" src="${`/#${financePath}?${decodeURIComponent(
financeQP
)}`}" title="${title}" />`;
Expand Down

0 comments on commit 7433e17

Please sign in to comment.