From b78421c3e367e6e9d258432e947768ac17d0eb2e Mon Sep 17 00:00:00 2001 From: jakehobbs Date: Fri, 14 Feb 2025 22:10:44 -0800 Subject: [PATCH 1/5] fix: session key demo: improve timers, styles, and error handling --- .../src/components/small-cards/MintCard.tsx | 11 +- .../components/small-cards/Transactions.tsx | 30 ++-- .../small-cards/TransactionsCard.tsx | 16 +-- .../src/components/small-cards/Wrapper.tsx | 2 +- .../src/hooks/useRecurringTransactions.ts | 132 ++++++++++++------ ...lchemyGasAndPaymasterAndDataMiddleware.mdx | 68 +++++++++ 6 files changed, 180 insertions(+), 79 deletions(-) create mode 100644 site/pages/reference/account-kit/infra/functions/alchemyGasAndPaymasterAndDataMiddleware.mdx diff --git a/examples/ui-demo/src/components/small-cards/MintCard.tsx b/examples/ui-demo/src/components/small-cards/MintCard.tsx index 57fab59326..d5f60b3af0 100644 --- a/examples/ui-demo/src/components/small-cards/MintCard.tsx +++ b/examples/ui-demo/src/components/small-cards/MintCard.tsx @@ -54,12 +54,11 @@ const MintCardInner = ({ )} -
-
-

- Gasless transactions -

-
+
+

+ Gasless transactions +

+ {!mintStarted ? ( <>

diff --git a/examples/ui-demo/src/components/small-cards/Transactions.tsx b/examples/ui-demo/src/components/small-cards/Transactions.tsx index d3dc457410..4d45866d80 100644 --- a/examples/ui-demo/src/components/small-cards/Transactions.tsx +++ b/examples/ui-demo/src/components/small-cards/Transactions.tsx @@ -1,8 +1,10 @@ import { ExternalLinkIcon } from "@/components/icons/external-link"; import { CheckCircleFilledIcon } from "@/components/icons/check-circle-filled"; import { LoadingIcon } from "@/components/icons/loading"; -import { useEffect, useState } from "react"; import { TransactionType } from "@/hooks/useRecurringTransactions"; +import { cn } from "@/lib/utils"; +import { useEffect, useState } from "react"; +import { time } from "console"; export type loadingState = "loading" | "success" | "initial"; @@ -25,41 +27,31 @@ const Transaction = ({ externalLink, buyAmountUsdc, state, + secUntilBuy = 0, }: TransactionType & { className?: string }) => { - const [countdownSeconds, setCountdownSeconds] = useState(10); - - useEffect(() => { - if (state === "next") { - const interval = setInterval(() => { - setCountdownSeconds((prev) => (prev === 0 ? 0 : prev - 1)); - }, 1000); - return () => clearInterval(interval); - } else { - setCountdownSeconds(10); - } - }, [state]); - const getText = () => { if (state === "initial") { return "Waiting..."; } + if (state === "next") { + return secUntilBuy <= 0 + ? "Waiting for previous transaction..." + : `Next buy in ${secUntilBuy} second${secUntilBuy === 1 ? "" : "s"}`; + } if (state === "initiating") { return "Buying 1 ETH"; } - if (state === "next") { - return `Next buy in ${countdownSeconds} seconds`; - } if (state === "complete") { return `Bought 1 ETH for ${buyAmountUsdc.toLocaleString()} USDC`; } }; return ( -

+
{state === "complete" ? ( - + ) : ( )} diff --git a/examples/ui-demo/src/components/small-cards/TransactionsCard.tsx b/examples/ui-demo/src/components/small-cards/TransactionsCard.tsx index cae416083c..1b625c1286 100644 --- a/examples/ui-demo/src/components/small-cards/TransactionsCard.tsx +++ b/examples/ui-demo/src/components/small-cards/TransactionsCard.tsx @@ -38,16 +38,16 @@ const TransactionsCardInner = ({ }, [cardStatus]); return ( -
-
-
+
+
+

New!

-
-

+
+

Recurring transactions

@@ -59,9 +59,7 @@ const TransactionsCardInner = ({ ) : cardStatus === "setup" ? (
-

- Creating session key and minting USDC... -

+

Creating session key...

) : ( @@ -69,7 +67,7 @@ const TransactionsCardInner = ({