Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change boson-widgets script and add parentOrigin param to finance widget #94

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@bosonprotocol/react-kit": "^0.22.0-alpha.14",
"@bosonprotocol/react-kit": "^0.22.0-alpha.16",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
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