Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/DebugGallery.swift8// Module : Sources9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0513//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041#if DEBUG42import SwiftUI43import QyvoraUI4445/// DEBUG-only gallery of the QyvoraUI components, opened with `-QYScreen gallery -QYGallery <section>`.46/// Every value on this screen is an obviously illustrative placeholder ("DEMO" symbol, "demo…" strings):47/// it exists to review layout, contrast and Dynamic Type, and is not compiled in Release builds.48struct DebugGallery: View {49 let section: String50 @State private var amountText = ""51 @State private var addressText = ""52 @State private var words = SeedPhraseEntry.emptyWords(12)53 @State private var pin = "12"54 @State private var errors = 055 @State private var password = String(repeating: "demo", count: 3)56 @State private var range: PriceRange = .week5758 static let demoAddress = "demo1qxy0000000000000000000000000000000demo"59 static let demoWords = ["demo", "words", "only", "never", "use", "these", "as", "a", "real", "recovery", "phrase", "ok"]60 /// A sine wave: visibly synthetic, not market data.61 static let wave: [ChartPoint] = (0..<72).map { i in62 ChartPoint(date: Date(timeIntervalSinceReferenceDate: 800_000_000 + Double(i) * 3600), value: 100 + 9 * sin(Double(i) / 6) + Double(i) * 0.05)63 }6465 /// `-QYGalleryAnchor <n>` opens a design-system page scrolled to its n-th block (for screenshots of long pages).66 static var anchor: Int { DebugLaunch.defaults.integer(forKey: "QYGalleryAnchor") }67 @State private var toast: QToastMessage?6869 var body: some View {70 ScrollViewReader { proxy in71 ScrollView {72 VStack(alignment: .leading, spacing: 22) {73 Text("COMPONENT GALLERY · DEBUG · DEMO VALUES ONLY")74 .font(QFont.eyebrow)75 .kerning(1.1)76 .foregroundStyle(QColor.warning)77 content78 }79 .padding(20)80 .frame(maxWidth: .infinity, alignment: .leading)81 }82 .onAppear {83 if Self.anchor > 0 { proxy.scrollTo(Self.anchor, anchor: .top) }84 }85 }86 .qScreen()87 .qToast($toast)88 }8990 @ViewBuilder var content: some View {91 switch section {92 case "chains": GalleryChains()93 case "portfolio": GalleryPortfolio()94 case "send": GallerySend()95 case "receive": GalleryReceive()96 case "foundations": GalleryFoundations()97 case "states": GalleryStates(toast: $toast)98 case "entry":99 SectionHeader("AmountField")100 AmountField(text: $amountText, symbol: "DEMO", maxFractionDigits: 8, fiat: "fiat line supplied by caller") { amountText = "1" }101 AmountField(text: .constant("12.5"), symbol: "DEMO", maxFractionDigits: 8, error: "Error text supplied by caller")102 SectionHeader("AddressField")103 AddressField(text: $addressText) {}104 AddressField(text: .constant(Self.demoAddress), validity: .valid("Note supplied by caller"))105 AddressField(text: .constant("demo-invalid"), validity: .invalid("Reason supplied by caller"))106 case "seed":107 SectionHeader("SeedPhraseGrid")108 SeedPhraseGrid(words: Self.demoWords)109 SectionHeader("SeedPhraseGrid, masked")110 SeedPhraseGrid(words: Self.demoWords, masked: true)111 case "seed-entry":112 SectionHeader("SeedPhraseEntry")113 SeedPhraseEntry(words: $words, isValidWord: { Self.demoWords.contains($0) },114 suggestions: { prefix in Self.demoWords.filter { $0.hasPrefix(prefix) } })115 case "pin":116 PINPad(pin: $pin, message: errors > 0 ? "Wrong PIN (demo)" : nil, errorCount: errors, biometry: .faceID, onBiometry: {}) { _ in117 errors += 1118 pin = ""119 }120 case "pin-locked":121 PINPad(pin: .constant(""), lockedUntil: Date().addingTimeInterval(95)) { _ in }122 case "password":123 SectionHeader("PasswordField")124 PasswordField("Password", text: $password,125 strength: PasswordStrength(level: 2, entropyBits: 52, advice: "Advice supplied by caller."), isNewPassword: true)126 PasswordField("Password", text: .constant("x"), strength: PasswordStrength(level: 0, entropyBits: 4))127 PasswordField("Password", text: .constant("demo"), strength: PasswordStrength(level: 4, entropyBits: 104))128 PasswordField("Password", text: .constant(""))129 case "charts":130 SectionHeader("PriceChartView")131 PriceChartView(points: Self.wave, range: $range, format: { String(format: "%.2f DEMO", $0) })132 SectionHeader("PriceChartView, unavailable")133 PriceChartView(points: [], range: $range, unavailableReason: "Reason supplied by caller.", format: { "\($0)" }) {}134 SectionHeader("SparklineView")135 HStack(spacing: 20) {136 SparklineView(values: Self.wave.map(\.value)).frame(width: 80, height: 30)137 SparklineView(values: Self.wave.map { -$0.value }).frame(width: 80, height: 30)138 SparklineView(values: []).frame(width: 80, height: 30)139 }140 case "rows":141 SectionHeader("AssetRow")142 AssetRow(glyph: .bitcoin, name: "Demo asset", note: "Demo network", units: "123456789", decimals: 8, symbol: "DEMO", fiat: "fiat by caller")143 Divider()144 AssetRow(glyph: .ethereum, name: "Demo asset", note: "Demo network", units: "1500000000000000000", decimals: 18, symbol: "DEMO")145 Divider()146 AssetRow(glyph: .token(symbol: "dem"), name: "Demo token", units: "420000", decimals: 2, symbol: "DEM", hidden: true)147 SectionHeader("TransactionRow")148 TransactionRow(direction: .incoming, counterparty: Self.demoAddress, units: "250000", decimals: 8, symbol: "DEMO",149 status: .pending(confirmations: 1, target: 6), date: Date().addingTimeInterval(-420))150 Divider()151 TransactionRow(direction: .outgoing, counterparty: Self.demoAddress, units: "1000000", decimals: 8, symbol: "DEMO",152 status: .confirmed, date: Date().addingTimeInterval(-90_000))153 Divider()154 TransactionRow(direction: .contract, title: "Demo contract call", units: "0", decimals: 18, symbol: "DEMO", status: .failed)155 Divider()156 TransactionRow(direction: .selfTransfer, units: "5000", decimals: 8, symbol: "DEMO", status: .replaced)157 case "qr":158 SectionHeader("QRCodeView")159 QRCodeView(payload: Self.demoAddress, label: "Demo code").frame(maxWidth: 220)160 AddressText(Self.demoAddress)161 SectionHeader("AnimatedQRCodeView")162 AnimatedQRCodeView(frames: (1...6).map { "demo frame \($0) of 6 " + String(repeating: "x", count: 60) }).frame(maxWidth: 220)163 case "scanner":164 SectionHeader("QRScannerView")165 QRScannerView { _ in }166 case "feedback":167 WarningBanner(.info, title: "Information", message: "Message supplied by caller.")168 WarningBanner(.warning, message: "Message supplied by caller.", actionTitle: "Action") {}169 WarningBanner(.critical, title: "Critical", message: "Message supplied by caller.")170 FlowLayout(spacing: 14) { ForEach(QTone.allCases, id: \.self) { StatusDot($0, label: $0.rawValue) } }171 SegmentedSummaryBar(segments: [172 .init(label: "Demo A", value: 6, detail: "6", color: QColor.positive, pattern: .solid),173 .init(label: "Demo B", value: 3, detail: "3", color: QColor.violet, pattern: .striped),174 .init(label: "Demo C", value: 2, detail: "2", color: QColor.warning, pattern: .dotted),175 .init(label: "Demo D", value: 1, detail: "1", color: QColor.textSecondary, pattern: .hollow),176 ])177 LoadingButton("Primary action", state: .idle) {}178 LoadingButton("Primary action", loadingTitle: "Working", state: .loading) {}179 LoadingButton("Secondary action", systemImage: "arrow.up", state: .success, prominence: .secondary) {}180 HStack { CopyButton("demo", style: .labelled); CopyButton("demo") }181 SheetHeader("Sheet title", subtitle: "Subtitle") {}182 UnavailableDataView(reason: "Reason supplied by caller.", compact: true) {}183 EmptyStateView(systemImage: "tray", title: "Empty state", message: "One sentence supplied by caller.", actionTitle: "Action") {}184 GalleryStates(toast: $toast)185 default:186 SectionHeader("AmountText")187 AmountText(units: "123456789", decimals: 8, symbol: "DEMO", fiat: "fiat line supplied by caller", style: .balance)188 AmountText(units: "123456789", decimals: 8, symbol: "DEMO", fiat: "fiat", style: .balance, hidden: true)189 HStack {190 Text("row, incoming").font(QFont.caption).foregroundStyle(QColor.textSecondary)191 Spacer()192 AmountText(units: "4200000", decimals: 8, symbol: "DEMO", fiat: "fiat", sign: .incoming)193 }194 HStack {195 Text("row, outgoing").font(QFont.caption).foregroundStyle(QColor.textSecondary)196 Spacer()197 AmountText(units: "1500000000000000000", decimals: 18, symbol: "DEMO", maxFractionDigits: 6, sign: .outgoing)198 }199 HStack {200 Text("compact, below precision").font(QFont.caption).foregroundStyle(QColor.textSecondary)201 Spacer()202 AmountText(units: "1", decimals: 18, symbol: "DEMO", maxFractionDigits: 4, style: .compact)203 }204 SectionHeader("AddressText")205 AddressText(Self.demoAddress)206 AddressText(Self.demoAddress, head: .max, copyable: false)207 SectionHeader("QBadge / QKeyValueRow")208 HStack { QBadge("Neutral"); QBadge("Positive", systemImage: "checkmark", tone: .positive); QBadge("Warning", systemImage: "clock", tone: .warning) }209 QKeyValueRow("Label", "value", mono: true)210 }211 }212}213214// MARK: - Design-system pages (chains, portfolio, send, receive, foundations, states)215//216// Every figure below is a demo value: amounts are written with the pseudo-currency "DEMO", addresses and identifiers217// contain letters no real address can contain, and series are sine waves. Nothing here is compiled in Release builds.218219/// One block of a gallery page, with a title and an anchor number for `-QYGalleryAnchor`.220private struct GalleryBlock<Content: View>: View {221 let index: Int222 let title: String223 let note: String?224 let content: Content225226 init(_ index: Int, _ title: String, note: String? = nil, @ViewBuilder content: () -> Content) {227 self.index = index228 self.title = title229 self.note = note230 self.content = content()231 }232233 var body: some View {234 VStack(alignment: .leading, spacing: 14) {235 HStack(alignment: .firstTextBaseline, spacing: 8) {236 Text(title).font(QFont.headline).foregroundStyle(QColor.textPrimary).accessibilityAddTraits(.isHeader)237 Text("DEMO").font(QFont.tag).kerning(QMetric.tagKerning).foregroundStyle(QColor.warning)238 }239 if let note { Text(note).font(QFont.caption).foregroundStyle(QColor.textSecondary) }240 content241 }242 .frame(maxWidth: .infinity, alignment: .leading)243 .padding(.top, 6)244 .id(index)245 }246}247248private enum Demo {249 /// Shaped like an EVM address, with letters hexadecimal does not have.250 static let evmAddress = "0xDEM0a1b2c3d4e5f60718293a4b5c6d7e8f9aDEM0"251 static let utxoAddress = "demo1qxy2kgdygjrsqtzq2n0yrf2493p83kkfdemo0"252 static let txid = "demo7f3a9c0e5b1d2f4a6c8e0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c4e6bdemo"253 static let wave: [Double] = (0..<48).map { (i: Int) -> Double in254 let x = Double(i)255 let swing: Double = 9 * sin(x / 5)256 return 100 + swing + x * 0.12257 }258 static let waveDown: [Double] = (0..<48).map { (i: Int) -> Double in259 let x = Double(i)260 let swing: Double = 7 * cos(x / 6)261 return 100 + swing - x * 0.2262 }263 static func money(_ text: String) -> String { "DEMO " + text }264 static let unaudited = "This build has not been audited. Per-transaction limits apply; use small amounts only."265}266267private struct GalleryChains: View {268 @State private var enabled: Set<String> = ["bitcoin", "ethereum", "base", "solana"]269 @ScaledMetric(relativeTo: .body) private var cell: CGFloat = 76270 private var columns: [GridItem] { [GridItem(.adaptive(minimum: min(cell, 120)), spacing: 12, alignment: .top)] }271272 func grid(test: Bool) -> some View {273 LazyVGrid(columns: columns, alignment: .leading, spacing: 20) {274 ForEach(QChain.allCases) { chain in275 VStack(spacing: test ? 16 : 8) {276 ChainGlyph(chain, isTest: test, size: .large, showsTestTag: test)277 Text(test ? chain.defaultTestNetworkName : chain.name)278 .font(QFont.caption)279 .foregroundStyle(QColor.textSecondary)280 .multilineTextAlignment(.center)281 .lineLimit(2)282 .minimumScaleFactor(0.8)283 }284 .frame(maxWidth: .infinity)285 }286 }287 }288289 var body: some View {290 GalleryBlock(1, "ChainGlyph · 13 main networks", note: "One grid, one stroke weight, one container. Tint is a secondary cue.") {291 grid(test: false)292 }293 GalleryBlock(2, "ChainGlyph · test networks", note: "Dashed outline, hatched container and a TEST tag: readable without colour.") {294 grid(test: true)295 }296 GalleryBlock(3, "Sizes") {297 FlowLayout(spacing: 8) {298 ChainGlyph(.bitcoin, size: .mini)299 ChainGlyph(.bitcoin, size: .small)300 ChainGlyph(.bitcoin, size: .regular)301 ChainGlyph(.bitcoin, size: .large)302 ChainGlyph(.solana, isTest: true, size: .mini)303 ChainGlyph(.solana, isTest: true, size: .small)304 ChainGlyph(.solana, isTest: true, size: .regular)305 ChainGlyph(.solana, isTest: true, size: .large)306 }307 }308 GalleryBlock(4, "TokenGlyph", note: "The same symbol on six chains: the sub-badge says where the token lives.") {309 FlowLayout(spacing: 18) {310 ForEach([QChain.ethereum, .base, .arbitrum, .optimism, .polygon, .solana]) { chain in311 TokenGlyph(symbol: "USDC", network: .mainnet(chain))312 }313 }314 FlowLayout(spacing: 18) {315 TokenGlyph(symbol: "USDT", network: .mainnet(.tron))316 TokenGlyph(symbol: "DAI", network: .mainnet(.ethereum))317 TokenGlyph(symbol: "WBTC", network: .mainnet(.arbitrum))318 TokenGlyph(symbol: "OP", network: .mainnet(.optimism))319 TokenGlyph(symbol: "USDC", network: .test(.ethereum))320 TokenGlyph(symbol: "X")321 }322 }323 GalleryBlock(5, "NetworkBadge") {324 FlowLayout(spacing: 8) {325 NetworkBadge(.mainnet(.bitcoin))326 NetworkBadge(.mainnet(.bsc))327 NetworkBadge(.test(.ethereum))328 NetworkBadge(.test(.tron))329 NetworkBadge(.mainnet(.avalanche), style: .plain)330 NetworkBadge(.test(.polygon), style: .plain)331 }332 }333 GalleryBlock(6, "ChainRow") {334 QListSection {335 ChainRow(network: .mainnet(.bitcoin), units: "4213700", fiat: Demo.money("1,234.56"))336 ChainRow(network: .mainnet(.ethereum), units: "1500000000000000000", fiat: Demo.money("420.00"), sync: .syncing(progress: 0.42))337 ChainRow(network: .mainnet(.solana), units: "12345678900", sync: .stale(since: Date().addingTimeInterval(-7200)))338 ChainRow(network: .mainnet(.tron), units: nil, sync: .failed(reason: "Demo reason"))339 ChainRow(network: .test(.base), units: "250000000000000000", hidden: true)340 ChainRow(network: .test(.dogecoin), units: "123456789012")341 }342 }343 GalleryBlock(7, "ChainPickerRow") {344 QListSection {345 ForEach([QNetwork.mainnet(.bitcoin), .mainnet(.litecoin), .mainnet(.base), .test(.solana)]) { network in346 ChainPickerRow(network: network, isOn: Binding(347 get: { enabled.contains(network.chain.rawValue) },348 set: { on in if on { enabled.insert(network.chain.rawValue) } else { enabled.remove(network.chain.rawValue) } }))349 }350 ChainPickerRow(network: .mainnet(.bitcoinCash), lockedReason: "Demo: requires the mainnet opt-in", isOn: .constant(false))351 }352 }353 }354}355356private struct GalleryPortfolio: View {357 @State private var hidden = false358359 var chainItems: [AllocationItem] {360 let values: [(QChain, Double)] = [(.bitcoin, 46), (.ethereum, 24), (.solana, 12), (.base, 7), (.tron, 4), (.polygon, 3), (.litecoin, 2), (.dogecoin, 2)]361 return values.map { AllocationItem(chain: $0.0, value: $0.1, detail: Demo.money(String(format: "%.0f", $0.1 * 100))) }362 }363364 var body: some View {365 GalleryBlock(1, "PortfolioHeader · QuickActionBar") {366 PortfolioHeader(total: Demo.money("12,345.67"), change: QChange(fraction: 0.0241, amount: "290.12"), isHidden: hidden,367 onToggleHidden: { hidden.toggle() })368 QuickActionBar([.send {}, .receive {}, .scan {}, .more {}])369 }370 GalleryBlock(2, "PortfolioHeader · states") {371 QCard {372 PortfolioHeader(total: Demo.money("987.65"), change: QChange(fraction: -0.008, amount: "7.96"), onToggleHidden: {}) {373 WarningBanner(.warning, title: "Unaudited software", message: Demo.unaudited)374 }375 }376 QCard {377 PortfolioHeader(total: Demo.money("64.20"), change: QChange(fraction: 0),378 referenceLabel: "Reference value of test-network coins. They cannot be exchanged for money.")379 }380 QCard { PortfolioHeader(total: Demo.money("12,345.67"), change: QChange(fraction: 0.0241, amount: "290.12"), isHidden: true, onToggleHidden: {}) }381 QCard { PortfolioHeader(total: nil) }382 }383 GalleryBlock(3, "AllocationBar") {384 QCard { AllocationBar(items: chainItems) }385 QCard { AllocationBar(items: []) }386 }387 GalleryBlock(4, "AllocationRing") {388 QCard { AllocationRing(items: chainItems, centerTitle: "Chains", centerValue: "8") }389 }390 GalleryBlock(5, "AssetRow · multi-chain") {391 QListSection {392 AssetRow(asset: .native(.mainnet(.bitcoin)), name: "Bitcoin", units: "4213700", decimals: 8, symbol: "BTC",393 fiat: Demo.money("1,234.56"), change: QChange(fraction: 0.0241))394 AssetRow(asset: .token(symbol: "USDC", network: .mainnet(.base)), name: "USD Coin", units: "250000000", decimals: 6, symbol: "USDC",395 maxFractionDigits: 2, fiat: Demo.money("250.00"), change: QChange(fraction: 0))396 AssetRow(asset: .token(symbol: "USDC", network: .mainnet(.arbitrum)), name: "USD Coin", units: "1000000", decimals: 6, symbol: "USDC",397 maxFractionDigits: 2, fiat: Demo.money("1.00"), change: QChange(fraction: 0))398 AssetRow(asset: .native(.mainnet(.solana)), name: "Solana", units: "12345678900", decimals: 9, symbol: "SOL",399 fiat: Demo.money("88.10"), change: QChange(fraction: -0.0312))400 AssetRow(asset: .native(.test(.ethereum)), name: "Ether", units: "1500000000000000000", decimals: 18, symbol: "ETH")401 AssetRow(asset: .token(symbol: "PEPE", network: .mainnet(.ethereum)), name: "Demo meme token", units: "420690000000000000000000000000",402 decimals: 18, symbol: "PEPE", maxFractionDigits: 0, fiat: Demo.money("12.00"), hidden: hidden)403 }404 }405 GalleryBlock(6, "ValueSparkline") {406 HStack(spacing: 24) {407 ValueSparkline(values: Demo.wave).frame(width: 96, height: 36)408 ValueSparkline(values: Demo.waveDown).frame(width: 96, height: 36)409 ValueSparkline(values: []).frame(width: 40, height: 36)410 }411 }412 GalleryBlock(7, "SyncBanner · SyncPill") {413 SyncBanner(.syncing(progress: 0.42))414 SyncBanner(.stale(since: Date().addingTimeInterval(-7200))) {}415 SyncBanner(.failed(reason: "Demo reason: the endpoint did not answer.")) {}416 SyncBanner(.idle(updated: Date().addingTimeInterval(-180)))417 FlowLayout(spacing: 8) {418 SyncPill(.idle(updated: nil))419 SyncPill(.syncing(progress: nil))420 SyncPill(.syncing(progress: 0.42))421 SyncPill(.stale(since: nil))422 SyncPill(.failed(reason: "")) {}423 }424 }425 }426}427428private struct GallerySend: View {429 @State private var recipient = Demo.evmAddress430 @State private var empty = ""431 @State private var amount = "0.05"432 @State private var fee: FeeTier.Kind = .normal433 @State private var working = false434435 var body: some View {436 GalleryBlock(1, "NetworkReviewBanner") {437 QyvoraUI.NetworkReviewBanner(network: .mainnet(.ethereum, detail: "Chain ID 1"), unauditedNotice: Demo.unaudited)438 QyvoraUI.NetworkReviewBanner(network: .test(.ethereum, detail: "Chain ID 11155111"))439 }440 GalleryBlock(2, "RecipientCard") {441 RecipientCard(text: $recipient, validity: .valid("Demo note from the caller"), notes: [.checksumValid(), .firstPayment()],442 network: .mainnet(.ethereum)) {}443 RecipientCard(text: $empty, network: .test(.tron)) {}444 }445 GalleryBlock(3, "AmountEntryCard") {446 AmountEntryCard(text: $amount, unit: "DEMO", maxFractionDigits: 8, converted: "≈ " + Demo.money("123.45"), onSwitchUnit: {},447 balance: "1.2345 DEMO", onMax: { amount = "1.2345" }, note: "Demo limit: 0.1 DEMO per transaction on a main network.")448 AmountEntryCard(text: .constant("12.5"), unit: "DEMO", maxFractionDigits: 8, balance: "1.2345 DEMO", onMax: {},449 error: "Demo error: more than the available balance.")450 }451 GalleryBlock(4, "FeeTierPicker") {452 FeeTierPicker(tiers: [453 FeeTier(.slow, timeHint: "about 60 min", fee: "0.00002 DEMO", fiat: Demo.money("0.12"), rate: "2 units"),454 FeeTier(.normal, timeHint: "about 20 min", fee: "0.00006 DEMO", fiat: Demo.money("0.36"), rate: "6 units"),455 FeeTier(.fast, timeHint: "next block", fee: "0.00015 DEMO", fiat: Demo.money("0.90"), rate: "15 units"),456 FeeTier(.custom, fee: nil),457 ], selection: $fee) {}458 }459 GalleryBlock(5, "ReviewSection · ReviewRow · SlideToConfirm") {460 ReviewSection("Payment", footnote: "Demo footnote: the fee is paid to the network, not to the application.") {461 ReviewRow("Amount", value: "0.05 DEMO", secondary: Demo.money("123.45"), emphasis: .strong)462 ReviewRow("To", value: Demo.evmAddress, emphasis: .address, copyValue: Demo.evmAddress)463 ReviewRow("Network fee", value: "0.00006 DEMO", secondary: Demo.money("0.36"))464 ReviewRow("Total", value: "0.05006 DEMO", secondary: Demo.money("123.81"), emphasis: .strong)465 ReviewRow("Data", value: Demo.txid, emphasis: .mono)466 }467 SlideToConfirm("Slide to sign and send", isWorking: working) {468 working = true469 Task { @MainActor in470 try? await Task.sleep(for: .seconds(1.5))471 working = false472 }473 }474 SlideToConfirm("Slide to sign and send", isEnabled: false) {}475 Text("With VoiceOver or Switch Control:").font(QFont.caption).foregroundStyle(QColor.textSecondary)476 SlideToConfirm(buttonTitle: "Sign and send", prefersButton: true) {}477 }478 GalleryBlock(6, "ResultView · sent") {479 QCard(padding: 24) {480 ResultView(status: .sent, message: "Demo message: the network accepted the transaction.", identifier: Demo.txid,481 network: .mainnet(.ethereum)) {482 Button("View in explorer") {}.buttonStyle(.qSecondary)483 Button("Done") {}.buttonStyle(.qPrimary)484 }485 }486 }487 GalleryBlock(7, "ResultView · pending and failed") {488 QCard(padding: 24) {489 ResultView(status: .pending, message: "Demo message: broadcast, waiting for the first confirmation.", identifier: Demo.txid)490 }491 QCard(padding: 24) {492 ResultView(status: .failed, message: "Demo reason: the endpoint refused the transaction. Nothing was sent.") {493 Button("Try again") {}.buttonStyle(.qSecondary)494 }495 }496 }497 }498}499500private struct GalleryReceive: View {501 var body: some View {502 GalleryBlock(1, "AddressCard · main network") {503 AddressCard(address: Demo.evmAddress, network: .mainnet(.base), caption: "Demo account 1")504 }505 GalleryBlock(2, "AddressCard · test network, no checksum") {506 AddressCard(address: Demo.utxoAddress, network: .test(.dogecoin), caption: "Demo account 1", hasChecksum: false)507 }508 GalleryBlock(3, "ChunkedAddressText") {509 ChunkedAddressText(Demo.evmAddress)510 ChunkedAddressText("bitcoincash:" + Demo.utxoAddress, font: QFont.mono)511 }512 }513}514515private struct GalleryStates: View {516 @Binding var toast: QToastMessage?517 @State private var loading = true518519 var body: some View {520 GalleryBlock(1, "QToast") {521 QToast(.copied("Address"))522 QToast(QToastMessage("Demo warning toast", systemImage: "exclamationmark.triangle", tone: .warning))523 Button("Show a toast") { toast = .copied("Demo value") }.buttonStyle(.qSecondary)524 }525 GalleryBlock(2, "Skeleton", note: "The band stops under Reduce Motion.") {526 QListSection {527 QSkeletonRow()528 QSkeletonRow()529 AssetRow(asset: .native(.mainnet(.bitcoin)), name: "Placeholder", units: "100000000", decimals: 8, symbol: "DEMO",530 fiat: "placeholder").qSkeleton(loading)531 }532 Toggle("Loading", isOn: $loading).tint(QColor.violet)533 }534 GalleryBlock(3, "Empty and unavailable") {535 QCard {536 EmptyStateView(systemImage: "tray", title: "No activity yet", message: "Demo sentence: transactions appear here.", actionTitle: "Receive") {}537 }538 QCard { UnavailableDataView(reason: "Demo reason: the price endpoint did not answer.", compact: true) {} }539 }540 GalleryBlock(4, "QSheetScaffold") {541 QSheetScaffold("Demo sheet", subtitle: "Header, content and a pinned footer", onClose: {}) {542 ReviewSection { ReviewRow("Label", value: "Value") }543 } footer: {544 Button("Primary action") {}.buttonStyle(.qPrimary)545 }546 .frame(height: 330)547 .clipShape(RoundedRectangle(cornerRadius: QMetric.radiusLarge, style: .continuous))548 .overlay(RoundedRectangle(cornerRadius: QMetric.radiusLarge, style: .continuous).strokeBorder(QColor.stroke, lineWidth: 1))549 }550 }551}552553private struct GalleryFoundations: View {554 func swatch(_ name: String, _ color: Color, on background: Color = QColor.surface) -> some View {555 HStack(spacing: 10) {556 RoundedRectangle(cornerRadius: 8, style: .continuous).fill(color).frame(width: 36, height: 36)557 .overlay(RoundedRectangle(cornerRadius: 8, style: .continuous).strokeBorder(QColor.strokeStrong.opacity(0.5), lineWidth: 1))558 Text(name).font(QFont.caption).foregroundStyle(QColor.textPrimary).lineLimit(1).minimumScaleFactor(0.7)559 }560 .frame(maxWidth: .infinity, alignment: .leading)561 }562563 func type(_ name: String, _ font: Font) -> some View {564 HStack(alignment: .firstTextBaseline) {565 Text(name).font(font).foregroundStyle(QColor.textPrimary).lineLimit(1).minimumScaleFactor(0.5)566 Spacer(minLength: 8)567 Text("0123").font(font).foregroundStyle(QColor.textSecondary).lineLimit(1)568 }569 }570571 private let two = [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)]572573 var body: some View {574 GalleryBlock(1, "Colour · surfaces, text, accents, states") {575 LazyVGrid(columns: two, alignment: .leading, spacing: 10) {576 swatch("background", QColor.background)577 swatch("surface", QColor.surface)578 swatch("surfaceRaised", QColor.surfaceRaised)579 swatch("surfaceSunken", QColor.surfaceSunken)580 swatch("stroke", QColor.stroke)581 swatch("strokeStrong", QColor.strokeStrong)582 swatch("textPrimary", QColor.textPrimary)583 swatch("textSecondary", QColor.textSecondary)584 swatch("textTertiary", QColor.textTertiary)585 swatch("violet", QColor.violet)586 swatch("blue", QColor.blue)587 swatch("positive", QColor.positive)588 swatch("warning", QColor.warning)589 swatch("negative", QColor.negative)590 }591 }592 GalleryBlock(2, "Colour · chain tints", note: "Muted on purpose: thirteen chains, no patchwork.") {593 LazyVGrid(columns: two, alignment: .leading, spacing: 10) {594 ForEach(QChain.allCases) { swatch($0.name, $0.tintColor) }595 }596 }597 GalleryBlock(3, "Type scale") {598 VStack(alignment: .leading, spacing: 10) {599 type("display", QFont.display)600 type("titleLarge", QFont.titleLarge)601 type("title", QFont.title)602 type("headline", QFont.headline)603 type("subheadline", QFont.subheadline)604 type("body", QFont.body)605 type("callout", QFont.callout)606 type("amount", QFont.amount)607 type("footnote", QFont.footnote)608 type("figure", QFont.figure)609 type("caption", QFont.caption)610 type("monoLarge", QFont.monoLarge)611 type("mono", QFont.mono)612 QEyebrow("eyebrow")613 }614 }615 GalleryBlock(4, "Buttons · badges · card · list") {616 Button("Primary action") {}.buttonStyle(.qPrimary)617 Button("Secondary action") {}.buttonStyle(.qSecondary)618 Button("Disabled") {}.buttonStyle(.qPrimary).disabled(true)619 FlowLayout(spacing: 8) {620 QBadge("Neutral")621 QBadge("Positive", systemImage: "checkmark", tone: .positive)622 QBadge("Warning", systemImage: "clock", tone: .warning)623 QBadge("Negative", systemImage: "xmark", tone: .negative)624 QBadge("Accent", systemImage: "sparkle", tone: .accent)625 QTestTag()626 }627 QCard {628 VStack(alignment: .leading, spacing: 6) {629 QEyebrow("QCard")630 Text("Graphite surface, hairline border, no shadow.").font(QFont.callout).foregroundStyle(QColor.textSecondary)631 }632 }633 QListSection("QListSection", footnote: "Rows take the raised surface while pressed.") {634 Button {} label: { QNavigationLabel("Navigation row", subtitle: "Subtitle", systemImage: "gearshape", trailing: "Value").padding(.vertical, 8) }635 .buttonStyle(.qRow)636 Button {} label: { QNavigationLabel("Second row", systemImage: "lock", trailing: nil).padding(.vertical, 8) }637 .buttonStyle(.qRow)638 }639 }640 GalleryBlock(5, "Spacing and radius") {641 HStack(alignment: .bottom, spacing: 10) {642 ForEach([QSpace.xs, QSpace.s, QSpace.m, QSpace.l, QSpace.xl, QSpace.xxl, QSpace.xxxl], id: \.self) { step in643 VStack(spacing: 6) {644 Rectangle().fill(QColor.violet).frame(width: step, height: step)645 Text("\(Int(step))").font(QFont.caption).foregroundStyle(QColor.textSecondary)646 }647 }648 }649 HStack(spacing: 12) {650 ForEach([QMetric.radiusTiny, QMetric.radiusSmall, QMetric.radius, QMetric.radiusLarge], id: \.self) { radius in651 RoundedRectangle(cornerRadius: radius, style: .continuous)652 .strokeBorder(QColor.strokeStrong, lineWidth: 1)653 .frame(width: 64, height: 64)654 .overlay(Text("\(Int(radius))").font(QFont.caption).foregroundStyle(QColor.textSecondary))655 }656 }657 }658 }659}660#endif661