Skip to content

Commit

Permalink
add configId parameters to widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
levalleux-ludo committed Sep 1, 2023
1 parent dc14441 commit e933691
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/widgets/finance/Finance.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { FinanceWidget } from "@bosonprotocol/react-kit";
import { ConfigId, FinanceWidget } from "@bosonprotocol/react-kit";
import { useSearchParams } from "react-router-dom";

import { CONFIG } from "../../../config";
import { getDefaultConfigId } from "../../../utils";

export const financePath = "/finance";
export function Finance() {
const [searchParams] = useSearchParams();
const configId = (searchParams.get("configId") as ConfigId) || undefined;
const sellerId = searchParams.get("sellerId");
if (!sellerId) {
return <p>Missing 'sellerId' query param</p>;
Expand All @@ -15,6 +17,7 @@ export function Finance() {
<FinanceWidget
sellerId={sellerId}
envName={CONFIG.envName}
configId={configId || getDefaultConfigId(CONFIG.envName)}
metaTx={{
apiKey: CONFIG.metaTxApiKey as string,
apiIds: CONFIG.metaTxApiIds as string
Expand Down
4 changes: 4 additions & 0 deletions src/components/widgets/redeem/Redeem.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {
ConfigId,
RedemptionBypassMode,
RedemptionWidget
} from "@bosonprotocol/react-kit";
import { useSearchParams } from "react-router-dom";

import { CONFIG } from "../../../config";
import { getDefaultConfigId } from "../../../utils";

export const redeemPath = "/redeem";
export function Redeem() {
const [searchParams] = useSearchParams();
const configId = (searchParams.get("configId") as ConfigId) || undefined;
const exchangeId = searchParams.get("exchangeId") || undefined;
const bypassMode: RedemptionBypassMode = checkBypassMode(
searchParams.get("bypassMode") || undefined
Expand All @@ -32,6 +35,7 @@ export function Redeem() {
<RedemptionWidget
exchangeId={exchangeId}
envName={CONFIG.envName}
configId={configId || getDefaultConfigId(CONFIG.envName)}
metaTx={{
apiKey: CONFIG.metaTxApiKey as string,
apiIds: CONFIG.metaTxApiIds as string
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
ConfigId,
EnvironmentType,
getEnvConfigs
} from "@bosonprotocol/react-kit";

export function getDefaultConfigId(envName: EnvironmentType): ConfigId {
if (getEnvConfigs(envName).length === 0) {
throw new Error(`No config found for envNAme '${envName}'`);
}
return getEnvConfigs(envName)[0].configId;
}

0 comments on commit e933691

Please sign in to comment.