Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension page for integration with wm tools #33

Merged
merged 13 commits into from
Sep 2, 2024
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
/.vscode
Dockerfile
.dockerignore
.git
.git
/.cert
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules
.env
build
/public/build
/.vscode
/.vscode
/.cert
/.exclude
6 changes: 3 additions & 3 deletions app/components/dialpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const DialPadKey = ({ label, id }: DialPadKeyProps) => {
setAmountValue(`${amountValue.substring(0, amountValue.length - 1)}`);
} else if (amountValue === "0" && id !== DialPadIds.Dot) {
setAmountValue(
`${amountValue.substring(0, amountValue.length - 1)}${label}`
`${amountValue.substring(0, amountValue.length - 1)}${label}`,
);
} else if (
(id === DialPadIds.Dot &&
Expand All @@ -120,7 +120,7 @@ const DialPadKey = ({ label, id }: DialPadKeyProps) => {
<li
className={cn(
"cursor-pointer hover:text-green-1",
id === DialPadIds.Dot ? "pl-1" : ""
id === DialPadIds.Dot ? "pl-1" : "",
)}
tabIndex={0}
id={id}
Expand All @@ -144,7 +144,7 @@ export const AmountDisplay = (args: AmountDisplayProps) => {
: `${getCurrencySymbol(assetCode)} ${amountValue}`;

return (
<div className="w-full whitespace-nowrap flex items-center justify-center text-5xl text-green-1">
<div className="amount-display w-full whitespace-nowrap flex items-center justify-center text-5xl text-green-1">
{value}
</div>
);
Expand Down
59 changes: 59 additions & 0 deletions app/components/presets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useEffect } from "react";
import { cn } from "~/lib/cn";
import { useDialPadContext } from "~/lib/context/dialpad";

const presetPadKeyClasses =
"cursor-pointer flex flex-wrap content-center justify-center items-center text-lg aspect-square rounded-full border border-gray-300 w-14";

type PresetPadKeyProps = {
label: string;
currency: string;
id: string;
};
const PresetPadKey = ({ label, id, currency }: PresetPadKeyProps) => {
const { setAmountValue } = useDialPadContext();

return (
<li
className={presetPadKeyClasses}
id={id}
onClick={() => {
const formattedNumber = Number(id || 0).toFixed(2);
setAmountValue(String(formattedNumber));
}}
>
{currency}
{label}
</li>
);
};
PresetPadKey.displayName = "PresetPadKey";

type PresetPadProps = {
values: string[];
currency: string;
onMore: () => void;
};
export const PresetPad = ({ values, currency, onMore }: PresetPadProps) => {
return (
<ul>
<div className="preset-pad flex justify-evenly text-muted">
{values.map((value) => (
<PresetPadKey
label={value}
id={value}
currency={currency}
key={value}
/>
))}
<li
className={cn(presetPadKeyClasses, "rotate-90 pb-2.5")}
onClick={() => onMore()}
>
...
</li>
</div>
</ul>
);
};
PresetPad.displayName = "PresetPad";
10 changes: 7 additions & 3 deletions app/components/quoteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export default function Quote({

return (
<Transition.Root show={open} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={() => setOpen(false)}>
<Dialog
as="div"
className="bg-foreground text-primary relative z-10"
onClose={() => setOpen(false)}
>
<Transition.Child
as={Fragment}
enter="transition-opacity duration-500"
Expand Down Expand Up @@ -66,12 +70,12 @@ export default function Quote({
<Form method="POST" {...form.props}>
<Field
label="You send:"
value={debitAmount}
defaultValue={debitAmount}
variant="info"
></Field>
<Field
label={`${receiverName} receives (approximately): `}
value={receiveAmount}
defaultValue={receiveAmount}
variant="info"
></Field>
<div className="flex justify-center items-center gap-3">
Expand Down
4 changes: 3 additions & 1 deletion app/components/ui/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface FieldProps extends InputHTMLAttributes<HTMLInputElement> {
className?: string;
variant?: "default" | "info" | "highlight";
trailing?: ReactNode;
compact?: boolean;
}

export const Field = ({
Expand All @@ -34,6 +35,7 @@ export const Field = ({
className,
variant,
trailing,
compact,
...props
}: FieldProps) => {
const fallbackId = useId();
Expand All @@ -53,7 +55,7 @@ export const Field = ({
trailing={trailing}
{...props}
/>
<div className="pb-3">
<div className={cx("pb-3", compact && !errorId && 'hidden')}>
{errorId ? <ErrorList id={errorId} errors={errors} /> : null}
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/lib/cn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
return twMerge(clsx(inputs));
}
4 changes: 2 additions & 2 deletions app/lib/open-payments.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function fetchQuote(
)
.catch(() => {
throw new Error(
`Could not create quote for receiver ${receiver.publicName}.`
`Could not create quote for receiver ${receiver.publicName}.`,
);
});

Expand Down Expand Up @@ -327,7 +327,7 @@ export async function finishPayment(
},
}
)
.catch(() => {
.catch((error) => {
throw new Error("Could not create outgoing payment.");
});

Expand Down
11 changes: 11 additions & 0 deletions app/lib/tdb_decompress_css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const decompressCss = (value: string) => {
const decoded = atob(value.replaceAll("-", "+").replaceAll("_", "/"));
const u8 = new Uint8Array(decoded.length);
for (let i = 0; i < decoded.length; i++) {
u8[i] = decoded.charCodeAt(i);
}
const stream = new Blob([u8])
.stream()
.pipeThrough(new DecompressionStream("gzip"));
return new Response(stream).text();
};
25 changes: 22 additions & 3 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Scripts,
ScrollRestoration,
isRouteErrorResponse,
useLocation,
useNavigation,
useRouteError,
} from "@remix-run/react";
Expand All @@ -21,6 +22,7 @@ import { Button } from "./components/ui/button";
import { FinishError } from "./components/icons";
import { DialogProvider } from "./components/providers/dialogProvider";
import { BackdropProvider } from "./components/providers/backdropProvider";
import { cn } from "./lib/cn";

export const links: LinksFunction = () => [
{
Expand All @@ -35,6 +37,10 @@ export const links: LinksFunction = () => [

export default function App() {
const navigation = useNavigation();
const location = useLocation();

// detect if it's loaded in wm tools
const isEmbeded = location.pathname.indexOf("extension") !== -1;

useEffect(() => {
if (navigation.state === "loading" || navigation.state === "submitting") {
Expand All @@ -45,16 +51,29 @@ export default function App() {
}, [navigation.state]);

return (
<html lang="en" className="h-full overflow-x-hidden">
<html
lang="en"
className={cn("h-full overflow-x-hidden", isEmbeded && "overflow-hidden")}
>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>

<body className="bg-foreground text-primary flex justify-center items-center h-screen">
<div className="w-full h-full p-20">
<body
className={cn(
isEmbeded
? "ilpay_body bg-transparent flex justify-center items-center h-screen"
: "bg-foreground text-primary flex justify-center items-center h-screen"
)}
>
<div
className={cn(
isEmbeded ? "w-full h-full pt-4" : "w-full h-full p-20"
)}
>
<BackdropProvider>
<DialogProvider>
<DialPadProvider>
Expand Down
Loading