diff --git a/package-lock.json b/package-lock.json index 91eef1d..23fbda8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "widgets", "version": "0.1.0", "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", @@ -2152,9 +2152,9 @@ } }, "node_modules/@bosonprotocol/common": { - "version": "1.24.0-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.24.0-alpha.11.tgz", - "integrity": "sha512-Rhf9Hptm1dvhUNgjPARyw5GMtRZsxyG9sGRWDiHiq6JgeTbYUDosv/0QWk6/oywhTt2mc7XNY+kqLmLK5TqjyQ==", + "version": "1.24.0-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.24.0-alpha.13.tgz", + "integrity": "sha512-mpzpAr+7Kr9MSaQIObcaeQPECHfWFC3DJUQtG2+rMrwH49hdsiK6Oessdj2nRQcYTNaAlCYotsoAGQzsnnSQGA==", "dependencies": { "@bosonprotocol/metadata": "^1.13.0", "@ethersproject/abi": "^5.5.0", @@ -2166,11 +2166,11 @@ } }, "node_modules/@bosonprotocol/core-sdk": { - "version": "1.33.0-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.33.0-alpha.11.tgz", - "integrity": "sha512-flc5gK5zF1uHyuGpN0+aYuxYGeEMoyfRUHEuEZR18vPCLGwtuaYOtH/PCggAKnSyPJdua85Ya1Kw4mWf4aCQAw==", + "version": "1.33.0-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.33.0-alpha.13.tgz", + "integrity": "sha512-UsYMjgSETKvo8Pam5v4x9xQn4DGmqaqcSJblucbpXijQWKZ+mTQfply86/sFQDF8gXutEoE1eQlPVjSGRimebQ==", "dependencies": { - "@bosonprotocol/common": "^1.24.0-alpha.11", + "@bosonprotocol/common": "^1.24.0-alpha.13", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -2199,11 +2199,11 @@ } }, "node_modules/@bosonprotocol/ethers-sdk": { - "version": "1.12.10-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.10-alpha.11.tgz", - "integrity": "sha512-NAlYNMT2lXwf/FL3ZNARYAZF1TqN3BDZHuODikJ5v1ujh3I6817C3I3SPJaPhi+yERr2ImyYNVVsC/A1DZi+Ww==", + "version": "1.12.10-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.10-alpha.13.tgz", + "integrity": "sha512-MI9c7BUwdKQ2ypRV7JJoXbF5fkGJbNUOxW0cm2f7OCn/h07gWWBc/wjsEMqlfxz5onmMxC6SVYARN0gTLr/S7A==", "dependencies": { - "@bosonprotocol/common": "^1.24.0-alpha.11" + "@bosonprotocol/common": "^1.24.0-alpha.13" }, "peerDependencies": { "ethers": "^5.5.0" @@ -2229,13 +2229,13 @@ } }, "node_modules/@bosonprotocol/react-kit": { - "version": "0.22.0-alpha.14", - "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.22.0-alpha.14.tgz", - "integrity": "sha512-sMYPWCSSeqtu9dkn5MnlUZT8PgsT74Mn2rJTGkh4l3F4Fyx23AeCWcD56YKuMZvUTM7o5FJkmhGfUAE0CbvC2g==", + "version": "0.22.0-alpha.16", + "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.22.0-alpha.16.tgz", + "integrity": "sha512-pRpFe9E/B7Wsb3NQsVLAVErXxToIhseuirAAAL+BJH0pc7X7FAAzjtIPzp4msR8Q4qCTGZ4oUwGLgedvKIELfA==", "dependencies": { "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/core-sdk": "^1.33.0-alpha.11", - "@bosonprotocol/ethers-sdk": "^1.12.10-alpha.11", + "@bosonprotocol/core-sdk": "^1.33.0-alpha.13", + "@bosonprotocol/ethers-sdk": "^1.12.10-alpha.13", "@bosonprotocol/ipfs-storage": "^1.10.10", "@davatar/react": "1.11.1", "@ethersproject/units": "5.6.0", @@ -31112,9 +31112,9 @@ } }, "@bosonprotocol/common": { - "version": "1.24.0-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.24.0-alpha.11.tgz", - "integrity": "sha512-Rhf9Hptm1dvhUNgjPARyw5GMtRZsxyG9sGRWDiHiq6JgeTbYUDosv/0QWk6/oywhTt2mc7XNY+kqLmLK5TqjyQ==", + "version": "1.24.0-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/common/-/common-1.24.0-alpha.13.tgz", + "integrity": "sha512-mpzpAr+7Kr9MSaQIObcaeQPECHfWFC3DJUQtG2+rMrwH49hdsiK6Oessdj2nRQcYTNaAlCYotsoAGQzsnnSQGA==", "requires": { "@bosonprotocol/metadata": "^1.13.0", "@ethersproject/abi": "^5.5.0", @@ -31126,11 +31126,11 @@ } }, "@bosonprotocol/core-sdk": { - "version": "1.33.0-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.33.0-alpha.11.tgz", - "integrity": "sha512-flc5gK5zF1uHyuGpN0+aYuxYGeEMoyfRUHEuEZR18vPCLGwtuaYOtH/PCggAKnSyPJdua85Ya1Kw4mWf4aCQAw==", + "version": "1.33.0-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/core-sdk/-/core-sdk-1.33.0-alpha.13.tgz", + "integrity": "sha512-UsYMjgSETKvo8Pam5v4x9xQn4DGmqaqcSJblucbpXijQWKZ+mTQfply86/sFQDF8gXutEoE1eQlPVjSGRimebQ==", "requires": { - "@bosonprotocol/common": "^1.24.0-alpha.11", + "@bosonprotocol/common": "^1.24.0-alpha.13", "@ethersproject/abi": "^5.5.0", "@ethersproject/address": "^5.5.0", "@ethersproject/bignumber": "^5.5.0", @@ -31158,11 +31158,11 @@ } }, "@bosonprotocol/ethers-sdk": { - "version": "1.12.10-alpha.11", - "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.10-alpha.11.tgz", - "integrity": "sha512-NAlYNMT2lXwf/FL3ZNARYAZF1TqN3BDZHuODikJ5v1ujh3I6817C3I3SPJaPhi+yERr2ImyYNVVsC/A1DZi+Ww==", + "version": "1.12.10-alpha.13", + "resolved": "https://registry.npmjs.org/@bosonprotocol/ethers-sdk/-/ethers-sdk-1.12.10-alpha.13.tgz", + "integrity": "sha512-MI9c7BUwdKQ2ypRV7JJoXbF5fkGJbNUOxW0cm2f7OCn/h07gWWBc/wjsEMqlfxz5onmMxC6SVYARN0gTLr/S7A==", "requires": { - "@bosonprotocol/common": "^1.24.0-alpha.11" + "@bosonprotocol/common": "^1.24.0-alpha.13" } }, "@bosonprotocol/ipfs-storage": { @@ -31185,13 +31185,13 @@ } }, "@bosonprotocol/react-kit": { - "version": "0.22.0-alpha.14", - "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.22.0-alpha.14.tgz", - "integrity": "sha512-sMYPWCSSeqtu9dkn5MnlUZT8PgsT74Mn2rJTGkh4l3F4Fyx23AeCWcD56YKuMZvUTM7o5FJkmhGfUAE0CbvC2g==", + "version": "0.22.0-alpha.16", + "resolved": "https://registry.npmjs.org/@bosonprotocol/react-kit/-/react-kit-0.22.0-alpha.16.tgz", + "integrity": "sha512-pRpFe9E/B7Wsb3NQsVLAVErXxToIhseuirAAAL+BJH0pc7X7FAAzjtIPzp4msR8Q4qCTGZ4oUwGLgedvKIELfA==", "requires": { "@bosonprotocol/chat-sdk": "^1.3.1-alpha.9", - "@bosonprotocol/core-sdk": "^1.33.0-alpha.11", - "@bosonprotocol/ethers-sdk": "^1.12.10-alpha.11", + "@bosonprotocol/core-sdk": "^1.33.0-alpha.13", + "@bosonprotocol/ethers-sdk": "^1.12.10-alpha.13", "@bosonprotocol/ipfs-storage": "^1.10.10", "@davatar/react": "1.11.1", "@ethersproject/units": "5.6.0", diff --git a/package.json b/package.json index 463a8a0..ddb9cfd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/public/scripts/boson-widgets.js b/public/scripts/boson-widgets.js index 987fd47..0fabd99 100644 --- a/public/scripts/boson-widgets.js +++ b/public/scripts/boson-widgets.js @@ -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; @@ -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(); @@ -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 }, @@ -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() ); } diff --git a/src/components/widgets/finance/Finance.tsx b/src/components/widgets/finance/Finance.tsx index 4e48cf8..d3d891e 100644 --- a/src/components/widgets/finance/Finance.tsx +++ b/src/components/widgets/finance/Finance.tsx @@ -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
Missing 'sellerId' query param
; - } const configId = searchParams.get("configId") as ConfigId; if (!configId) { returnMissing 'configId' query param
; } + const sellerId = searchParams.get("sellerId"); + const parentOrigin = searchParams.get("parentOrigin"); + if (sellerId && !parentOrigin) { + returnMissing 'parentOrigin' query param
; + } + if (!sellerId && parentOrigin) { + returnMissing 'sellerId' query param
; + } return (