Skip to content

Commit

Permalink
working build
Browse files Browse the repository at this point in the history
  • Loading branch information
dschlabach committed Nov 14, 2024
1 parent b51ceb9 commit c8b7ace
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions playground/nextjs-app-router/components/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type Paymaster,
TransactionTypes,
} from '@/types/onchainkit';
import { initializeStateFromUrl } from '@/lib/url-params';

type State = {
activeComponent?: OnchainKitComponent;
Expand Down
51 changes: 29 additions & 22 deletions playground/nextjs-app-router/lib/url-params.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
// export function getShareableUrl(activeComponent?: OnchainKitComponent) {
// if (!activeComponent) {
// return window.location.origin;
// }

// const relevantParams = getComponentQueryParams(activeComponent);
// const params = new URLSearchParams();

// for (const param of relevantParams) {
// params.set(param, localStorage.getItem(param) || '');
// }
// return `${window.location.origin}?${params.toString()}`;
// }

// export function getComponentQueryParams(component: OnchainKitComponent) {
// const options = URL_PARAM_MAPPING[component];
// if (!options) {
// return [];
// }

// return options.map((option) => option.name);
// }
import { OnchainKitComponent } from '@/types/onchainkit';

const URL_PARAM_MAPPING: Partial<Record<OnchainKitComponent, string[]>> = {
[OnchainKitComponent.Checkout]: ['chargeId', 'productId'],
[OnchainKitComponent.Transaction]: ['calls', 'contracts'],
};

export function getShareableUrl(activeComponent?: OnchainKitComponent) {
if (!activeComponent) {
return window.location.origin;
}

const relevantParams = getComponentQueryParams(activeComponent);
const params = new URLSearchParams();

for (const param of relevantParams) {
params.set(param, localStorage.getItem(param) || '');
}
return `${window.location.origin}?${params.toString()}`;
}

export function getComponentQueryParams(component: OnchainKitComponent) {
const options = URL_PARAM_MAPPING[component];
if (!options) {
return [];
}

return options.map((option) => option.name);
}

export function initializeStateFromUrl(): Record<string, string> {
if (typeof window === 'undefined') {
Expand Down

0 comments on commit c8b7ace

Please sign in to comment.