|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { DatabaseIcon, NetworkIcon, ShieldIcon } from "lucide-react"; |
| 4 | +import { useMemo, useState } from "react"; |
| 5 | +import type { ThirdwebClient } from "thirdweb"; |
| 6 | +import { ClientOnly } from "@/components/blocks/client-only"; |
| 7 | +import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors"; |
| 8 | +import { |
| 9 | + Card, |
| 10 | + CardContent, |
| 11 | + CardDescription, |
| 12 | + CardHeader, |
| 13 | + CardTitle, |
| 14 | +} from "@/components/ui/card"; |
| 15 | +import { useAllChainsData } from "@/hooks/chains/allChains"; |
| 16 | +import { Badge } from "../../../../../../../../../@/components/ui/badge"; |
| 17 | +import { ChainIconClient } from "../../../../../../../../../@/icons/ChainIcon"; |
| 18 | +import { OrderSummary } from "./order-summary"; |
| 19 | +import { |
| 20 | + type PaymentFrequency, |
| 21 | + PaymentFrequencySelector, |
| 22 | +} from "./payment-frequency-selector"; |
| 23 | +import { type ServiceConfig, ServiceSelector } from "./service-selector"; |
| 24 | + |
| 25 | +const services = { |
| 26 | + accountAbstraction: { |
| 27 | + description: "Smart wallets & gasless transactions", |
| 28 | + features: [ |
| 29 | + "Fully managed Bundler & Paymaster", |
| 30 | + "Audited ERC-4337 smart wallets out of the box", |
| 31 | + "ERC-7702 support", |
| 32 | + "Session key support", |
| 33 | + ], |
| 34 | + icon: ShieldIcon, |
| 35 | + id: "account-abstraction" as const, |
| 36 | + monthlyPrice: 750, |
| 37 | + name: "Account Abstraction", |
| 38 | + upsellReason: " ", |
| 39 | + }, |
| 40 | + insight: { |
| 41 | + description: "Instant, real-time data APIs, without the hassle", |
| 42 | + features: [ |
| 43 | + "Comprehensive onchain data APIs", |
| 44 | + "Webhooks for real-time event streaming", |
| 45 | + "Instant wallet, token & NFT balance lookups", |
| 46 | + "Fully managed and battle-tested", |
| 47 | + ], |
| 48 | + icon: DatabaseIcon, |
| 49 | + id: "insight" as const, |
| 50 | + monthlyPrice: 2000, |
| 51 | + name: "Insight", |
| 52 | + upsellReason: " ", |
| 53 | + }, |
| 54 | + rpc: { |
| 55 | + description: "Low-latency edge RPC with no node maintenance", |
| 56 | + features: [ |
| 57 | + "Low-latency edge RPC", |
| 58 | + "Auto-scaling & global load balancing", |
| 59 | + "Smart caching & automatic failover", |
| 60 | + "Fully managed and battle-tested", |
| 61 | + ], |
| 62 | + icon: NetworkIcon, |
| 63 | + id: "rpc" as const, |
| 64 | + monthlyPrice: 2000, |
| 65 | + name: "RPC", |
| 66 | + required: true, |
| 67 | + upsellReason: " ", |
| 68 | + }, |
| 69 | +} satisfies Record<string, ServiceConfig>; |
| 70 | + |
| 71 | +const serviceConfigs = [ |
| 72 | + services.rpc, |
| 73 | + services.insight, |
| 74 | + services.accountAbstraction, |
| 75 | +]; |
| 76 | + |
| 77 | +export function InfrastructureCheckout(props: { client: ThirdwebClient }) { |
| 78 | + const [selectedChain, setSelectedChain] = useState<number>(0); |
| 79 | + const { idToChain } = useAllChainsData(); |
| 80 | + const [selectedServices, setSelectedServices] = useState<ServiceConfig[]>([ |
| 81 | + services.rpc, |
| 82 | + ]); |
| 83 | + |
| 84 | + const selectedChainDetails = useMemo(() => { |
| 85 | + return idToChain.get(selectedChain); |
| 86 | + }, [idToChain, selectedChain]); |
| 87 | + |
| 88 | + const [paymentFrequency, setPaymentFrequency] = |
| 89 | + useState<PaymentFrequency>("monthly"); |
| 90 | + |
| 91 | + return ( |
| 92 | + <div className="grid lg:grid-cols-3 gap-8"> |
| 93 | + {/* Configuration Section */} |
| 94 | + <div className="lg:col-span-2 space-y-6"> |
| 95 | + {/* Chain Selection */} |
| 96 | + <Card> |
| 97 | + <CardHeader className="space-y-2"> |
| 98 | + <CardTitle className="flex items-center gap-2"> |
| 99 | + <Badge className="font-mono" variant="outline"> |
| 100 | + Step 1 |
| 101 | + </Badge> |
| 102 | + Select Chain |
| 103 | + </CardTitle> |
| 104 | + <CardDescription> |
| 105 | + Choose the chain to deploy infrastructure on. |
| 106 | + </CardDescription> |
| 107 | + </CardHeader> |
| 108 | + <CardContent> |
| 109 | + <ClientOnly ssr={false}> |
| 110 | + <SingleNetworkSelector |
| 111 | + chainId={selectedChain} |
| 112 | + className="bg-background" |
| 113 | + client={props.client} |
| 114 | + disableDeprecated |
| 115 | + onChange={setSelectedChain} |
| 116 | + placeholder="Select a chain" |
| 117 | + /> |
| 118 | + </ClientOnly> |
| 119 | + </CardContent> |
| 120 | + </Card> |
| 121 | + |
| 122 | + {/* Service Selection */} |
| 123 | + <Card> |
| 124 | + <CardHeader className="space-y-2"> |
| 125 | + <CardTitle className="flex items-center gap-2"> |
| 126 | + <Badge className="font-mono" variant="outline"> |
| 127 | + Step 2 |
| 128 | + </Badge> |
| 129 | + Select Services |
| 130 | + </CardTitle> |
| 131 | + <CardDescription> |
| 132 | + Choose the infrastructure services you need. RPC service is |
| 133 | + required for all other services. |
| 134 | + </CardDescription> |
| 135 | + </CardHeader> |
| 136 | + <CardContent> |
| 137 | + <ServiceSelector |
| 138 | + selectedServices={selectedServices} |
| 139 | + services={serviceConfigs} |
| 140 | + setSelectedServices={setSelectedServices} |
| 141 | + /> |
| 142 | + </CardContent> |
| 143 | + </Card> |
| 144 | + |
| 145 | + {/* Payment Frequency */} |
| 146 | + <Card> |
| 147 | + <CardHeader className="space-y-2"> |
| 148 | + <CardTitle className="flex items-center gap-2"> |
| 149 | + <Badge className="font-mono" variant="outline"> |
| 150 | + Step 3 |
| 151 | + </Badge> |
| 152 | + Payment Frequency |
| 153 | + </CardTitle> |
| 154 | + <CardDescription> |
| 155 | + Choose your billing frequency. Save 15% with annual payment. |
| 156 | + </CardDescription> |
| 157 | + </CardHeader> |
| 158 | + <CardContent> |
| 159 | + <PaymentFrequencySelector |
| 160 | + annualDiscountPercent={15} |
| 161 | + paymentFrequency={paymentFrequency} |
| 162 | + setPaymentFrequency={setPaymentFrequency} |
| 163 | + /> |
| 164 | + </CardContent> |
| 165 | + </Card> |
| 166 | + </div> |
| 167 | + |
| 168 | + {/* Pricing Summary */} |
| 169 | + <div className="lg:col-span-1"> |
| 170 | + <Card className="sticky top-8"> |
| 171 | + <CardHeader className="space-y-2"> |
| 172 | + <CardTitle>Order Summary</CardTitle> |
| 173 | + <CardDescription> |
| 174 | + {selectedChainDetails ? ( |
| 175 | + <div className="flex justify-between gap-4"> |
| 176 | + <span className="flex grow gap-2 truncate text-left"> |
| 177 | + <ChainIconClient |
| 178 | + className="size-5" |
| 179 | + client={props.client} |
| 180 | + loading="lazy" |
| 181 | + src={selectedChainDetails.icon?.url} |
| 182 | + /> |
| 183 | + {selectedChainDetails.name} |
| 184 | + </span> |
| 185 | + <Badge className="gap-2 max-sm:hidden" variant="outline"> |
| 186 | + <span className="text-muted-foreground">Chain ID</span> |
| 187 | + {selectedChainDetails.chainId} |
| 188 | + </Badge> |
| 189 | + </div> |
| 190 | + ) : ( |
| 191 | + <span className="text-muted-foreground">Select a chain</span> |
| 192 | + )} |
| 193 | + </CardDescription> |
| 194 | + </CardHeader> |
| 195 | + <CardContent> |
| 196 | + <OrderSummary |
| 197 | + paymentFrequency={paymentFrequency} |
| 198 | + selectedChainId={selectedChain} |
| 199 | + selectedServices={selectedServices} |
| 200 | + /> |
| 201 | + </CardContent> |
| 202 | + </Card> |
| 203 | + </div> |
| 204 | + </div> |
| 205 | + ); |
| 206 | +} |
0 commit comments