diff --git a/package-lock.json b/package-lock.json index d2a0580..db1ddcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.2", - "@requestnetwork/payment-widget": "^0.1.2", + "@requestnetwork/payment-widget": "^0.2.0", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "cmdk": "^1.0.0", @@ -5202,9 +5202,9 @@ } }, "node_modules/@requestnetwork/payment-widget": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@requestnetwork/payment-widget/-/payment-widget-0.1.2.tgz", - "integrity": "sha512-F63mJ1oJrU2Yw+m3uh1y8lDfTZAomZw7CmOoY/GleN5QUMFoYk6e26kjzzp/5hI+PXJtqgJegdFSTvCdstDiIw==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@requestnetwork/payment-widget/-/payment-widget-0.2.0.tgz", + "integrity": "sha512-nvuKK+7t5T+c5fHvxN8vDLL4GieQN29UicT0ZI8Qh9atZvXblxCNl+6Usn29Umng5uBsWHoEWfgGDC/xNN9jwQ==", "dependencies": { "@requestnetwork/payment-processor": "^0.47.0", "@requestnetwork/request-client.js": "^0.49.0", diff --git a/package.json b/package.json index 0a7bc2a..3efda8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rn-checkout", - "version": "0.1.0", + "version": "0.1.1", "private": true, "scripts": { "dev": "next dev", @@ -18,7 +18,7 @@ "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.2", - "@requestnetwork/payment-widget": "^0.1.2", + "@requestnetwork/payment-widget": "^0.2.0", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "cmdk": "^1.0.0", diff --git a/src/components/Playground.tsx b/src/components/Playground.tsx index fbcab49..b82c621 100644 --- a/src/components/Playground.tsx +++ b/src/components/Playground.tsx @@ -4,7 +4,7 @@ import { PropsValidation } from "@/lib/validation"; import { zodResolver } from "@hookform/resolvers/zod"; import PaymentWidget from "@requestnetwork/payment-widget/react"; import { CopyIcon } from "lucide-react"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Button } from "./ui/button"; @@ -21,6 +21,9 @@ import { AccordionTrigger, } from "./ui/accordion"; +import { cn } from "@/lib/utils"; +import { ZERO_ADDRESS } from "@/lib/constants"; + export const Playground = () => { const { register, @@ -38,6 +41,8 @@ export const Playground = () => { buyerInfo: {}, invoiceNumber: "", enableBuyerInfo: false, + feeAddress: ZERO_ADDRESS, + feeAmount: 0, }, }); @@ -65,6 +70,10 @@ export const Playground = () => { formValues.supportedCurrencies?.length && `supportedCurrencies={${JSON.stringify(formValues.supportedCurrencies)}}`, formValues.invoiceNumber && `invoiceNumber="${formValues.invoiceNumber}"`, + formValues.feeAddress && + formValues.feeAddress !== ZERO_ADDRESS && + `feeAddress="${formValues.feeAddress}"`, + formValues.feeAmount && `feeAmountInUSD={${formValues.feeAmount}}`, ] .filter(Boolean) .join("\n "); @@ -99,6 +108,13 @@ const YourComponent = () => { } }; + useEffect(() => { + if (formValues.feeAddress?.length === 0) { + setValue("feeAddress", ZERO_ADDRESS); + setValue("feeAmount", 0); + } + }, [formValues.feeAddress, formValues.feeAmount]); + return (
@@ -359,10 +375,17 @@ const YourComponent = () => {
{/* Seller Address */}
- + {errors.sellerAddress?.message && ( {errors.sellerAddress.message} @@ -371,12 +394,19 @@ const YourComponent = () => { {/* Amount in USD */}
- + {errors.amountInUSD?.message && ( {errors.amountInUSD.message} @@ -392,10 +422,44 @@ const YourComponent = () => { )}
+ {/* Fee */} +
+ + + {errors.feeAddress?.message && ( + {errors.feeAddress.message} + )} + + + {errors.feeAmount?.message && ( + {errors.feeAmount.message} + )} +
+ {/* Currencies */}
- - + +
{formValues.supportedCurrencies?.map((currency) => { return ( @@ -408,6 +472,9 @@ const YourComponent = () => { ); })}
+ {errors.supportedCurrencies?.message && ( + {errors.supportedCurrencies.message} + )}
@@ -426,6 +493,18 @@ const YourComponent = () => { // @ts-ignore supportedCurrencies={formValues.supportedCurrencies} invoiceNumber={formValues.invoiceNumber} + feeAddress={ + formValues.feeAddress && formValues.feeAddress.length > 0 + ? formValues.feeAddress + : ZERO_ADDRESS + } + feeAmountInUSD={ + formValues.feeAddress && + formValues.feeAddress.length > 0 && + formValues.feeAddress !== ZERO_ADDRESS + ? formValues.feeAmount + : 0 + } />
diff --git a/src/components/ui/combobox.tsx b/src/components/ui/combobox.tsx index db841e3..d0ea982 100644 --- a/src/components/ui/combobox.tsx +++ b/src/components/ui/combobox.tsx @@ -29,9 +29,14 @@ const currencies = Object.entries(CURRENCY_ID).map(([key, value]) => ({ interface CurrencyComboboxProps { register: UseFormRegister; name: string; + className?: string; } -export function CurrencyCombobox({ register, name }: CurrencyComboboxProps) { +export function CurrencyCombobox({ + register, + name, + className, +}: CurrencyComboboxProps) { const [open, setOpen] = React.useState(false); const [selectedCurrencies, setSelectedCurrencies] = React.useState( [] @@ -55,7 +60,7 @@ export function CurrencyCombobox({ register, name }: CurrencyComboboxProps) { variant="outline" role="combobox" aria-expanded={open} - className="w-[300px] justify-between" + className={cn("w-[300px] justify-between", className)} > {selectedCurrencies.length > 0 ? `${selectedCurrencies.length} selected` diff --git a/src/lib/constants.ts b/src/lib/constants.ts new file mode 100644 index 0000000..6cfbec2 --- /dev/null +++ b/src/lib/constants.ts @@ -0,0 +1 @@ +export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"; diff --git a/src/lib/validation.ts b/src/lib/validation.ts index d0a3e18..08784a0 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -62,4 +62,13 @@ export const PropsValidation = z.object({ .default([]), invoiceNumber: z.string().optional(), enableBuyerInfo: z.boolean().default(false), + feeAddress: z + .string() + .refine(isEthereumAddress, "Invalid fee address") + .optional() + .nullable(), + feeAmount: z + .number() + .gte(0, "Fee amount needs to be higher than 0") + .default(0), });