Skip to content

Commit 03cced2

Browse files
feat: added shims for invoice and form components (#115)
Co-authored-by: Aimen Sahnoun <aimensahnoun@outlook.com>
1 parent 44f9e58 commit 03cced2

File tree

15 files changed

+235
-5
lines changed

15 files changed

+235
-5
lines changed

package-lock.json

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-invoice-form/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"svelte": "./dist/index.js",
2121
"require": "./dist/web-component.umd.cjs",
2222
"default": "./dist/web-component.js"
23+
},
24+
"./react": {
25+
"types": "./dist/react/CreateInvoiceForm.d.ts",
26+
"default": "./dist/react/CreateInvoiceForm.jsx"
2327
}
2428
},
2529
"files": [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @ts-nocheck
2+
import React, { useLayoutEffect, useRef } from "react";
3+
import("../web-component");
4+
5+
export const CreateInvoiceForm = (props) => {
6+
const widgetRef = useRef(null);
7+
8+
useLayoutEffect(() => {
9+
if (widgetRef.current) {
10+
Object.entries(props).forEach(([key, value]) => {
11+
widgetRef.current[key] = value;
12+
});
13+
}
14+
}, [props, widgetRef?.current]);
15+
16+
return React.createElement("create-invoice-form", { ref: widgetRef });
17+
};
18+
19+
export default CreateInvoiceForm;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import type { IConfig } from "@requestnetwork/shared-types";
3+
import type { RequestNetwork, Types } from "@requestnetwork/request-client.js";
4+
export interface CreateInvoiceFormProps {
5+
config: IConfig;
6+
signer: string;
7+
requestNetwork: RequestNetwork | null | undefined;
8+
currencies: {
9+
symbol: string;
10+
address: string;
11+
network: string;
12+
decimals: number;
13+
type: Types.RequestLogic.CURRENCY;
14+
}[];
15+
}
16+
17+
/**
18+
* CreateInvoiceForm is a React component that allows users to create invoices and manage the invoice creation process.
19+
*
20+
* This component provides functionalities for selecting currencies, entering invoice details, and submitting the form.
21+
* It also handles the creation process by interacting with the Request Network.
22+
*
23+
* @param {CreateInvoiceFormProps} props - The component props
24+
* @returns {JSX.Element}
25+
*
26+
* @example
27+
* <CreateInvoiceForm
28+
* config={config}
29+
* signer={signer}
30+
* requestNetwork={requestNetwork}
31+
* currencies={[
32+
* {
33+
* symbol: "USDC",
34+
* address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
35+
* network: "sepolia",
36+
* decimals: 6,
37+
* type: Types.RequestLogic.CURRENCY.ERC20,
38+
* },
39+
* ]}
40+
* />
41+
*/
42+
declare const CreateInvoiceForm: React.FC<CreateInvoiceFormProps>;
43+
44+
export default CreateInvoiceForm;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare namespace JSX {
2+
interface IntrinsicElements {
3+
"create-invoice-form": React.DetailedHTMLProps<
4+
React.HTMLAttributes<HTMLElement>,
5+
HTMLElement
6+
>;
7+
}
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist/react",
5+
"declaration": true,
6+
"jsx": "react-jsx",
7+
"lib": ["ES2017", "DOM"],
8+
"esModuleInterop": true,
9+
"allowSyntheticDefaultImports": true,
10+
"allowJs": true,
11+
"noImplicitAny": false,
12+
"strict": false
13+
},
14+
"include": ["src/lib/react/**/*"]
15+
}

packages/create-invoice-form/vite.wc.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@ export default defineConfig({
2424
commonjsOptions: {
2525
transformMixedEsModules: true,
2626
},
27+
rollupOptions: {
28+
external: ["react", "react-dom"],
29+
output: {
30+
globals: {
31+
react: "React",
32+
"react-dom": "ReactDOM",
33+
},
34+
},
35+
},
2736
},
2837
});

packages/invoice-dashboard/package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,38 @@
2020
"svelte": "./dist/index.js",
2121
"require": "./dist/web-component.umd.cjs",
2222
"default": "./dist/web-component.js"
23+
},
24+
"./react": {
25+
"types": "./dist/react/InvoiceDashboard.d.ts",
26+
"default": "./dist/react/InvoiceDashboard.jsx"
2327
}
2428
},
2529
"files": [
2630
"dist",
2731
"!dist/**/*.test.*",
2832
"!dist/**/*.spec.*"
2933
],
34+
"peerDependencies": {
35+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
36+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
37+
},
3038
"dependencies": {
3139
"@requestnetwork/payment-detection": "0.43.1-next.2043",
3240
"@requestnetwork/payment-processor": "0.45.1-next.2043",
3341
"@requestnetwork/request-client.js": "0.47.1-next.2043",
3442
"ethers": "^5.7.2",
3543
"svelte-sonner": "^0.3.27",
36-
"viem": "^2.9.15"
44+
"viem": "^2.9.15",
45+
"vite-plugin-node-polyfills": "^0.22.0"
3746
},
3847
"devDependencies": {
3948
"@sveltejs/package": "^2.0.0",
4049
"@sveltejs/vite-plugin-svelte": "^2.5.2",
4150
"@tailwindcss/typography": "^0.5.13",
51+
"@types/react": "^18.3.4",
52+
"@types/react-dom": "^18.3.0",
53+
"react": "^18.3.1",
54+
"react-dom": "^18.3.1",
4255
"svelte": "^4.0.5",
4356
"svelte-check": "^3.6.0",
4457
"tslib": "^2.4.1",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import type { IConfig } from "@requestnetwork/shared-types";
3+
import type { WalletState } from "@requestnetwork/shared-types/web3Onboard";
4+
import type { RequestNetwork } from "@requestnetwork/request-client.js";
5+
import { Currency } from "../types";
6+
7+
export interface InvoiceDashboardProps {
8+
config: IConfig;
9+
wallet: WalletState | null;
10+
requestNetwork: RequestNetwork | null | undefined;
11+
currencies: Currency[];
12+
}
13+
/**
14+
* InvoiceDashboard is a React component that integrates with the Request Network to manage and display invoices.
15+
*
16+
* This component provides functionalities to fetch, display, and manage invoice data, allowing users
17+
* to search, sort, and paginate through their requests. It also handles the state of individual requests,
18+
* providing real-time updates on payment status.
19+
*
20+
* @param {InvoiceDashboardProps} props - The component props
21+
* @returns {JSX.Element}
22+
*
23+
* @example
24+
* <InvoiceDashboard
25+
* config={config}
26+
* wallet={wallet}
27+
* requestNetwork={requestNetwork}
28+
* currencies={currencies}
29+
* />
30+
*/
31+
declare const InvoiceDashboard: React.FC<InvoiceDashboardProps>;
32+
33+
export default InvoiceDashboard;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @ts-nocheck
2+
import React, { useLayoutEffect, useRef } from "react";
3+
import("../web-component");
4+
5+
export const InvoiceDashboard = (props) => {
6+
const widgetRef = useRef(null);
7+
8+
useLayoutEffect(() => {
9+
if (widgetRef.current) {
10+
Object.entries(props).forEach(([key, value]) => {
11+
widgetRef.current[key] = value;
12+
});
13+
}
14+
}, [props, widgetRef?.current]);
15+
16+
return React.createElement("invoice-dashboard", { ref: widgetRef });
17+
};
18+
19+
export default InvoiceDashboard;

0 commit comments

Comments
 (0)