Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/QyvoraUI/Chains.swift8// Module : Qyvora UI9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0512// 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// =============================================================================4041import SwiftUI42import QyvoraCore4344// MARK: - Chain identity4546/// The four kinds of chains the wallet handles; a family shares an address format and a fee model.47public enum QChainFamily: String, Sendable, CaseIterable {48 case utxo, evm, solana, tron4950 public var name: String {51 switch self {52 case .utxo: return "Bitcoin family"53 case .evm: return "EVM networks"54 case .solana: return "Solana"55 case .tron: return "TRON"56 }57 }58}5960/// The thirteen chains, as the design system knows them: a name, a glyph and a muted tint. The identity of a chain61/// is carried by its glyph and its name; the tint is a secondary cue and is never the only one.62public enum QChain: String, Sendable, CaseIterable, Identifiable, Hashable {63 case bitcoin, litecoin, dogecoin, bitcoinCash64 case ethereum, base, arbitrum, optimism, polygon, bsc, avalanche65 case solana66 case tron6768 public var id: String { rawValue }6970 public var family: QChainFamily {71 switch self {72 case .bitcoin, .litecoin, .dogecoin, .bitcoinCash: return .utxo73 case .ethereum, .base, .arbitrum, .optimism, .polygon, .bsc, .avalanche: return .evm74 case .solana: return .solana75 case .tron: return .tron76 }77 }7879 public var name: String {80 switch self {81 case .bitcoin: return "Bitcoin"82 case .litecoin: return "Litecoin"83 case .dogecoin: return "Dogecoin"84 case .bitcoinCash: return "Bitcoin Cash"85 case .ethereum: return "Ethereum"86 case .base: return "Base"87 case .arbitrum: return "Arbitrum"88 case .optimism: return "Optimism"89 case .polygon: return "Polygon"90 case .bsc: return "BNB Chain"91 case .avalanche: return "Avalanche"92 case .solana: return "Solana"93 case .tron: return "TRON"94 }95 }9697 /// Symbol of the coin that pays the fees.98 public var nativeSymbol: String {99 switch self {100 case .bitcoin: return "BTC"101 case .litecoin: return "LTC"102 case .dogecoin: return "DOGE"103 case .bitcoinCash: return "BCH"104 case .ethereum, .base, .arbitrum, .optimism: return "ETH"105 case .polygon: return "POL"106 case .bsc: return "BNB"107 case .avalanche: return "AVAX"108 case .solana: return "SOL"109 case .tron: return "TRX"110 }111 }112113 /// Decimals of the native coin: 8, 18, 9 or 6.114 public var nativeDecimals: Int {115 switch family {116 case .utxo: return 8117 case .evm: return 18118 case .solana: return 9119 case .tron: return 6120 }121 }122123 /// Usual name of the test network offered by default.124 public var defaultTestNetworkName: String {125 switch self {126 case .bitcoin, .litecoin, .dogecoin, .bitcoinCash: return "Testnet"127 case .ethereum: return "Sepolia"128 case .base: return "Base Sepolia"129 case .arbitrum: return "Arbitrum Sepolia"130 case .optimism: return "OP Sepolia"131 case .polygon: return "Amoy"132 case .bsc: return "BNB Testnet"133 case .avalanche: return "Fuji"134 case .solana: return "Devnet"135 case .tron: return "Nile"136 }137 }138139 /// The muted tint of the chain as data (light and dark values).140 public var tint: QColorSpec {141 switch self {142 case .bitcoin: return QColorSpec(light: 0x8A5A12, dark: 0xD9A866)143 case .litecoin: return QColorSpec(light: 0x4E5B70, dark: 0xA9B4C6)144 case .dogecoin: return QColorSpec(light: 0x5F6A1E, dark: 0xB9C27E)145 case .bitcoinCash: return QColorSpec(light: 0x2F7045, dark: 0x8FC5A0)146 case .ethereum: return QColorSpec(light: 0x4A55A8, dark: 0xA3ACE6)147 case .base: return QColorSpec(light: 0x2A56B8, dark: 0x7FA8F0)148 case .arbitrum: return QColorSpec(light: 0x2F6088, dark: 0x8FB8D8)149 case .optimism: return QColorSpec(light: 0xA63D3D, dark: 0xE59A9A)150 case .polygon: return QColorSpec(light: 0x6A44B0, dark: 0xB79BE8)151 case .bsc: return QColorSpec(light: 0x7A6410, dark: 0xD8C06A)152 case .avalanche: return QColorSpec(light: 0xA04A32, dark: 0xE0A090)153 case .solana: return QColorSpec(light: 0x1F7566, dark: 0x7FD0C0)154 case .tron: return QColorSpec(light: 0x8F3A78, dark: 0xD48FC0)155 }156 }157158 public var tintColor: Color { tint.color }159160 /// What the glyph draws, in words (design documentation and tests; VoiceOver reads the chain name instead).161 public var glyphDescription: String {162 switch self {163 case .bitcoin: return "Letter B"164 case .litecoin: return "Letter L with a stroke"165 case .dogecoin: return "Letter D with a bar"166 case .bitcoinCash: return "Letter C crossed by a vertical stroke"167 case .ethereum: return "Three horizontal bars"168 case .base: return "A block resting on a line"169 case .arbitrum: return "Two nested chevrons"170 case .optimism: return "A ring around a point"171 case .polygon: return "A hexagon"172 case .bsc: return "Two nested squares"173 case .avalanche: return "Two peaks"174 case .solana: return "Letter S"175 case .tron: return "Letter T"176 }177 }178}179180public extension QChain {181 init(_ family: EVMFamily) {182 switch family {183 case .ethereum: self = .ethereum184 case .base: self = .base185 case .arbitrum: self = .arbitrum186 case .optimism: self = .optimism187 case .polygon: self = .polygon188 case .bsc: self = .bsc189 case .avalanche: self = .avalanche190 }191 }192}193194/// One network of a chain: the main network or a test network.195public struct QNetwork: Hashable, Sendable, Identifiable {196 public let chain: QChain197 /// The network's own name: the chain name on mainnet ("Ethereum"), the test network's name otherwise ("Sepolia").198 public let name: String199 public let isTest: Bool200 /// A technical identifier shown on review screens ("Chain ID 11155111"), or nil.201 public let detail: String?202 /// The full name given by whoever built the value (the registry's display name); nil when it is composed from203 /// the chain and the network name.204 private let givenFullName: String?205206 public var id: String { chain.rawValue + "/" + name }207208 /// Two values are the same network when they show the same thing, however they were built.209 public static func == (a: QNetwork, b: QNetwork) -> Bool {210 a.chain == b.chain && a.name == b.name && a.isTest == b.isTest && a.detail == b.detail && a.fullName == b.fullName211 }212213 public func hash(into hasher: inout Hasher) {214 hasher.combine(chain)215 hasher.combine(name)216 hasher.combine(isTest)217 hasher.combine(detail)218 }219220 public init(chain: QChain, name: String? = nil, isTest: Bool = false, detail: String? = nil) {221 self.chain = chain222 self.name = name ?? (isTest ? chain.defaultTestNetworkName : chain.name)223 self.isTest = isTest224 self.detail = detail225 self.givenFullName = nil226 }227228 /// A network whose two names are both known: `name` for badges and pickers ("Arb Sepolia"), `fullName` wherever229 /// the network is named on its own ("Arbitrum Sepolia"). Nothing is composed, so no word can be repeated.230 public init(chain: QChain, name: String, fullName: String, isTest: Bool, detail: String? = nil) {231 self.chain = chain232 self.name = name233 self.isTest = isTest234 self.detail = detail235 self.givenFullName = fullName236 }237238 public static func mainnet(_ chain: QChain, detail: String? = nil) -> QNetwork {239 QNetwork(chain: chain, isTest: false, detail: detail)240 }241242 public static func test(_ chain: QChain, name: String? = nil, detail: String? = nil) -> QNetwork {243 QNetwork(chain: chain, name: name, isTest: true, detail: detail)244 }245246 /// The name that identifies the network on its own: "Ethereum", "Ethereum Sepolia", "Base Sepolia", "Bitcoin Testnet".247 public var fullName: String {248 if let givenFullName { return givenFullName }249 guard isTest else { return name }250 let lowered = name.lowercased()251 let words = chain.name.lowercased().split(separator: " ")252 if lowered.contains(chain.name.lowercased()) || words.contains(where: { lowered.hasPrefix($0) }) { return name }253 if chain == .optimism, lowered.hasPrefix("op ") { return name }254 return chain.name + " " + name255 }256257 /// Spoken description: the full name and, for a test network, the words "test network".258 public var spokenName: String { isTest ? fullName + ", test network" : fullName }259260 /// One main network per chain, in the order of the wallet.261 public static let mainnets: [QNetwork] = QChain.allCases.map { .mainnet($0) }262 /// The default test network of each chain.263 public static let testnets: [QNetwork] = QChain.allCases.map { .test($0) }264}265266public extension QNetwork {267 /// Named as `QyvoraCore` names the network: `shortName` in badges, `displayName` in full.268 init(_ network: EthereumNetwork) {269 self.init(chain: QChain(network.family), name: network.shortName, fullName: network.displayName, isTest: network.isTest,270 detail: "Chain ID \(network.chainID)")271 }272273 /// Named as `QyvoraCore` names the network in full ("Bitcoin Signet", "Bitcoin Cash Testnet4"); the short name is274 /// the coin on a main network and the network alone on a test network ("Signet", "Testnet", "Testnet4").275 init(_ network: BitcoinNetwork) {276 let chain: QChain277 switch network.mainCounterpart {278 case .litecoin: chain = .litecoin279 case .dogecoin: chain = .dogecoin280 case .bitcoinCash: chain = .bitcoinCash281 default: chain = .bitcoin282 }283 self.init(chain: chain, name: network.shortName, fullName: network.displayName, isTest: network.isTest)284 }285}286287// MARK: - Glyphs288289/// The mark of a chain on a 24-unit grid: strokes only, one weight, round caps and joins. Original geometric marks290/// and letterforms; none reproduces a project's logo.291public struct ChainMark: Shape {292 public let chain: QChain293294 public init(_ chain: QChain) { self.chain = chain }295296 /// The mark in grid units (0…24), before scaling.297 public static func unitPath(_ chain: QChain) -> Path {298 var p = Path()299 func line(_ points: (CGFloat, CGFloat)...) {300 p.move(to: CGPoint(x: points[0].0, y: points[0].1))301 for q in points.dropFirst() { p.addLine(to: CGPoint(x: q.0, y: q.1)) }302 }303 // In SwiftUI's flipped space an arc with `clockwise: false` turns clockwise on screen.304 func arc(_ cx: CGFloat, _ cy: CGFloat, _ r: CGFloat, from: Double, to: Double, visuallyClockwise: Bool = true) {305 p.addArc(center: CGPoint(x: cx, y: cy), radius: r, startAngle: .degrees(from), endAngle: .degrees(to), clockwise: !visuallyClockwise)306 }307 switch chain {308 case .bitcoin:309 line((8.5, 6), (8.5, 18))310 p.move(to: CGPoint(x: 8.5, y: 6))311 p.addLine(to: CGPoint(x: 12.5, y: 6))312 arc(12.5, 9, 3, from: -90, to: 90)313 p.addLine(to: CGPoint(x: 8.5, y: 12))314 p.move(to: CGPoint(x: 12.5, y: 12))315 p.addLine(to: CGPoint(x: 13.5, y: 12))316 arc(13.5, 15, 3, from: -90, to: 90)317 p.addLine(to: CGPoint(x: 8.5, y: 18))318 case .litecoin:319 line((10, 6), (10, 18), (16.5, 18))320 line((7, 14.25), (13.5, 10.75))321 case .dogecoin:322 line((9, 6), (9, 18))323 p.move(to: CGPoint(x: 9, y: 6))324 p.addLine(to: CGPoint(x: 11, y: 6))325 arc(11, 12, 6, from: -90, to: 90)326 p.addLine(to: CGPoint(x: 9, y: 18))327 line((6.25, 12), (12.25, 12))328 case .bitcoinCash:329 p.move(to: CGPoint(x: 12 + 5.25 * cos(.pi / 4), y: 12 + 5.25 * sin(.pi / 4)))330 arc(12, 12, 5.25, from: 45, to: 315)331 line((12, 4.5), (12, 19.5))332 case .ethereum:333 line((7, 7), (17, 7))334 line((9, 12), (15, 12))335 line((7, 17), (17, 17))336 case .base:337 p.addRect(CGRect(x: 8, y: 6.5, width: 8, height: 8))338 line((5.5, 18), (18.5, 18))339 case .arbitrum:340 line((6, 17.5), (12, 6.5), (18, 17.5))341 line((9.75, 17.5), (12, 13.25), (14.25, 17.5))342 case .optimism:343 p.addEllipse(in: CGRect(x: 6, y: 6, width: 12, height: 12))344 p.addEllipse(in: CGRect(x: 11.2, y: 11.2, width: 1.6, height: 1.6))345 case .polygon:346 let points = (0..<6).map { i -> CGPoint in347 let a = Double(i) * .pi / 3 - .pi / 2348 return CGPoint(x: 12 + 6.5 * cos(a), y: 12 + 6.5 * sin(a))349 }350 p.addLines(points)351 p.closeSubpath()352 case .bsc:353 p.addRect(CGRect(x: 6.5, y: 6.5, width: 11, height: 11))354 p.addRect(CGRect(x: 10.5, y: 10.5, width: 3, height: 3))355 case .avalanche:356 line((5, 17.5), (9.5, 7), (12.75, 13.5), (15, 10), (19, 17.5))357 case .solana:358 p.move(to: CGPoint(x: 12 + 3.1 * cos(-.pi / 9), y: 9 + 3.1 * sin(-.pi / 9)))359 arc(12, 9, 3.1, from: -20, to: 90, visuallyClockwise: false)360 arc(12, 15.2, 3.1, from: -90, to: 160)361 case .tron:362 line((6.5, 7), (17.5, 7))363 line((12, 7), (12, 18))364 }365 return p366 }367368 public func path(in rect: CGRect) -> Path {369 let scale = min(rect.width, rect.height) / 24370 let dx = rect.midX - 12 * scale, dy = rect.midY - 12 * scale371 return Self.unitPath(chain).applying(CGAffineTransform(a: scale, b: 0, c: 0, d: scale, tx: dx, ty: dy))372 }373}374375/// Diagonal hatching, the texture of everything that belongs to a test network.376public struct QHatch: Shape {377 let spacing: CGFloat378379 public init(spacing: CGFloat = 5) { self.spacing = max(2, spacing) }380381 public func path(in rect: CGRect) -> Path {382 var p = Path()383 var x = rect.minX - rect.height384 while x < rect.maxX {385 p.move(to: CGPoint(x: x, y: rect.maxY))386 p.addLine(to: CGPoint(x: x + rect.height, y: rect.minY))387 x += spacing388 }389 return p390 }391}392393/// The word "TEST" in a hairline box: the textual half of the test-network treatment.394public struct QTestTag: View {395 let text: String396397 public init(_ text: String = "TEST") { self.text = text }398399 public var body: some View {400 Text(text.uppercased())401 .font(QFont.tag)402 .kerning(QMetric.tagKerning)403 .foregroundStyle(QColor.textPrimary)404 .lineLimit(1)405 .fixedSize()406 .padding(.horizontal, 5)407 .padding(.vertical, 2)408 .background(QColor.surfaceSunken, in: RoundedRectangle(cornerRadius: 4, style: .continuous))409 .overlay(RoundedRectangle(cornerRadius: 4, style: .continuous)410 .strokeBorder(QColor.strokeStrong, style: StrokeStyle(lineWidth: 1, dash: [3, 2])))411 .accessibilityLabel("Test network")412 }413}414415/// The glyph of a chain in its container: a rounded square on the same grid for every chain, the mark drawn with416/// one stroke weight in the chain's muted tint. A test network is drawn with a dashed outline and a hatched417/// container (and, where there is room, a "TEST" tag): it cannot be mistaken for the main network, with or418/// without colour.419public struct ChainGlyph: View {420 public enum Size: Sendable, Equatable {421 /// 18 pt: the sub-badge on a token and inline labels.422 case mini423 /// 28 pt: pills and compact rows.424 case small425 /// 40 pt: list rows.426 case regular427 /// 56 pt: headers.428 case large429 case custom(CGFloat)430431 public var points: CGFloat {432 switch self {433 case .mini: return 18434 case .small: return 28435 case .regular: return 40436 case .large: return 56437 case .custom(let value): return max(12, value)438 }439 }440 }441442 let chain: QChain443 let isTest: Bool444 let size: Size445 let showsTestTag: Bool446 @ScaledMetric(relativeTo: .body) private var scale: CGFloat = 1447448 public init(_ chain: QChain, isTest: Bool = false, size: Size = .regular, showsTestTag: Bool = false) {449 self.chain = chain450 self.isTest = isTest451 self.size = size452 self.showsTestTag = showsTestTag453 }454455 public init(_ network: QNetwork, size: Size = .regular, showsTestTag: Bool = false) {456 self.init(network.chain, isTest: network.isTest, size: size, showsTestTag: showsTestTag)457 }458459 /// The side of the container: the nominal size, growing with Dynamic Type up to one and a half times.460 var side: CGFloat { size.points * min(max(scale, 1), 1.5) }461462 public var body: some View {463 let d = side464 let shape = RoundedRectangle(cornerRadius: d * 0.3, style: .continuous)465 let tint = chain.tintColor466 ZStack {467 shape.fill(QColor.surfaceRaised)468 if isTest {469 QHatch(spacing: max(3, d * 0.16))470 .stroke(QColor.strokeStrong.opacity(0.55), lineWidth: 1)471 .clipShape(shape)472 // a clear disc behind the mark keeps it legible over the hatching473 Circle().fill(QColor.surfaceRaised).padding(d * 0.17)474 shape.strokeBorder(tint, style: StrokeStyle(lineWidth: max(1, d * 0.04), lineCap: .butt, dash: [d * 0.12, d * 0.09]))475 } else {476 shape.strokeBorder(tint.opacity(0.42), lineWidth: 1)477 }478 ChainMark(chain)479 .stroke(tint, style: StrokeStyle(lineWidth: max(1.25, d * 0.068), lineCap: .round, lineJoin: .round))480 }481 .frame(width: d, height: d)482 .overlay(alignment: .bottom) {483 if isTest, showsTestTag {484 // the tag sits across the bottom edge, clear of the mark485 QTestTag().offset(y: 11)486 }487 }488 .accessibilityElement(children: .ignore)489 .accessibilityLabel(isTest ? "\(chain.name), test network" : chain.name)490 }491}492493/// Deterministic muted tints for tokens. A token has no mark of its own: its monogram and, above all, the network494/// sub-badge identify it. The tint only helps to tell two neighbouring rows apart.495public enum QTokenTint {496 public static let palette: [QColorSpec] = [497 QColorSpec(light: 0x4E5B70, dark: 0xA9B4C6),498 QColorSpec(light: 0x5B5F2A, dark: 0xC2C68A),499 QColorSpec(light: 0x2F6A6A, dark: 0x8CC9C9),500 QColorSpec(light: 0x6B4A7E, dark: 0xC3A6D6),501 QColorSpec(light: 0x7A5230, dark: 0xD6B092),502 QColorSpec(light: 0x3F5F8F, dark: 0x9DB8E0),503 QColorSpec(light: 0x4F6B3A, dark: 0xADC99A),504 QColorSpec(light: 0x8A4458, dark: 0xDFA3B4),505 ]506507 /// FNV-1a over the upper-cased symbol: the same symbol always gets the same tint, on every device and launch.508 public static func index(for symbol: String) -> Int {509 var hash: UInt32 = 2_166_136_261510 for byte in symbol.uppercased().utf8 {511 hash ^= UInt32(byte)512 hash = hash &* 16_777_619513 }514 return Int(hash % UInt32(palette.count))515 }516517 public static func spec(for symbol: String) -> QColorSpec { palette[index(for: symbol)] }518519 /// At most four characters of the symbol, upper-cased, letters and digits only ("USDC", "WBTC", "1INC").520 public static func monogram(for symbol: String) -> String {521 let clean = symbol.uppercased().filter { $0.isLetter || $0.isNumber }522 return clean.isEmpty ? "?" : String(clean.prefix(4))523 }524}525526/// Round glyph of a token: its monogram in a deterministic muted tint, and a sub-badge with the glyph of the chain527/// the token lives on. The sub-badge is not optional decoration: the same symbol exists on several chains and528/// sending it on the wrong one loses it.529public struct TokenGlyph: View {530 let symbol: String531 let network: QNetwork?532 let size: ChainGlyph.Size533 @ScaledMetric(relativeTo: .body) private var scale: CGFloat = 1534535 public init(symbol: String, network: QNetwork? = nil, size: ChainGlyph.Size = .regular) {536 self.symbol = symbol537 self.network = network538 self.size = size539 }540541 var side: CGFloat { size.points * min(max(scale, 1), 1.5) }542543 public var body: some View {544 let d = side545 let tint = QTokenTint.spec(for: symbol).color546 let monogram = QTokenTint.monogram(for: symbol)547 let badge = d * 0.46548 ZStack {549 Circle().fill(QColor.surfaceRaised)550 Circle().strokeBorder(tint.opacity(0.42), lineWidth: 1)551 Text(monogram)552 .font(.system(size: d * (monogram.count <= 2 ? 0.36 : (monogram.count == 3 ? 0.29 : 0.235)), weight: .bold, design: .rounded))553 .foregroundStyle(tint)554 .lineLimit(1)555 .minimumScaleFactor(0.7)556 .padding(.horizontal, d * 0.08)557 .offset(y: network == nil ? 0 : -d * 0.035)558 }559 .frame(width: d, height: d)560 .overlay(alignment: .bottomTrailing) {561 if let network {562 ChainGlyph(network, size: .custom(badge / min(max(scale, 1), 1.5)))563 .padding(1.5)564 .background(QColor.background, in: RoundedRectangle(cornerRadius: badge * 0.34, style: .continuous))565 .offset(x: d * 0.1, y: d * 0.14)566 }567 }568 .accessibilityElement(children: .ignore)569 .accessibilityLabel(network.map { "\(symbol) on \($0.spokenName)" } ?? symbol)570 }571}572573/// What a row shows as its leading glyph: the coin of a network, or a token living on a network.574public enum QAssetIdentity: Hashable, Sendable {575 case native(QNetwork)576 case token(symbol: String, network: QNetwork)577578 public var network: QNetwork {579 switch self {580 case .native(let network), .token(_, let network): return network581 }582 }583}584585/// The glyph of an asset: `ChainGlyph` for a native coin, `TokenGlyph` with its network sub-badge for a token.586public struct AssetIdentityGlyph: View {587 let asset: QAssetIdentity588 let size: ChainGlyph.Size589590 public init(_ asset: QAssetIdentity, size: ChainGlyph.Size = .regular) {591 self.asset = asset592 self.size = size593 }594595 public var body: some View {596 switch asset {597 case .native(let network): ChainGlyph(network, size: size)598 case .token(let symbol, let network): TokenGlyph(symbol: symbol, network: network, size: size)599 }600 }601}602603// MARK: - Badges and rows604605/// Chain glyph, network name and test flag in one compact label. Use it wherever a screen must say which network606/// it is about (header of a receive screen, a history row, a token's detail).607public struct NetworkBadge: View {608 public enum Style: Sendable { case pill, plain }609610 let network: QNetwork611 let style: Style612613 public init(_ network: QNetwork, style: Style = .pill) {614 self.network = network615 self.style = style616 }617618 public var body: some View {619 HStack(spacing: 7) {620 ChainGlyph(network, size: .mini)621 Text(network.fullName)622 .font(QFont.captionStrong)623 .foregroundStyle(QColor.textPrimary)624 .lineLimit(1)625 if network.isTest { QTestTag() }626 }627 .padding(.leading, style == .pill ? 5 : 0)628 .padding(.trailing, style == .pill ? (network.isTest ? 6 : 10) : 0)629 .padding(.vertical, style == .pill ? 5 : 0)630 .background {631 if style == .pill {632 Capsule().fill(QColor.surface)633 Capsule().strokeBorder(QColor.stroke, lineWidth: 1)634 }635 }636 .accessibilityElement(children: .ignore)637 .accessibilityLabel(network.spokenName)638 }639}640641/// One chain of the wallet: glyph, name, native balance, fiat value, sync state and a chevron.642public struct ChainRow: View {643 let network: QNetwork644 let units: String?645 let fiat: String?646 let sync: QSyncState647 let hidden: Bool648 let showsChevron: Bool649 @Environment(\.dynamicTypeSize) private var typeSize650651 /// - Parameters:652 /// - units: native balance in base units, or nil when it is not known yet (a dash is shown, never a zero).653 /// - fiat: already formatted fiat value, or nil when no price is known.654 /// - sync: state of this chain's synchronisation; `.idle` shows nothing.655 public init(network: QNetwork, units: String?, fiat: String? = nil, sync: QSyncState = .idle(updated: nil), hidden: Bool = false,656 showsChevron: Bool = true) {657 self.network = network658 self.units = units659 self.fiat = fiat660 self.sync = sync661 self.hidden = hidden662 self.showsChevron = showsChevron663 }664665 /// From the second-largest standard size upwards the balance goes under the name instead of beside it.666 var stacked: Bool { typeSize >= .xxLarge }667668 @ViewBuilder var title: some View {669 VStack(alignment: .leading, spacing: 3) {670 Text(network.chain.name).font(QFont.headline).foregroundStyle(QColor.textPrimary).lineLimit(1)671 // the caption carries the network: its name and the TEST tag, then the sync state when there is one672 HStack(spacing: 6) {673 if network.isTest {674 if !sync.isVisibleInRow || stacked {675 Text(network.name).font(QFont.caption).foregroundStyle(QColor.textSecondary).lineLimit(1)676 }677 QTestTag()678 }679 if sync.isVisibleInRow { SyncPill(sync, style: .inline) }680 else if !network.isTest {681 Text(network.chain.nativeSymbol).font(QFont.caption).foregroundStyle(QColor.textSecondary).lineLimit(1)682 }683 }684 }685 }686687 @ViewBuilder var amount: some View {688 if let units {689 AmountText(units: units, decimals: network.chain.nativeDecimals, symbol: network.chain.nativeSymbol,690 maxFractionDigits: AssetPrecision.fractionDigits(units: units, decimals: network.chain.nativeDecimals),691 fiat: fiat, hidden: hidden)692 .leadingAligned(stacked)693 } else {694 Text("—").font(QFont.amount).foregroundStyle(QColor.textTertiary).accessibilityLabel("Balance not available")695 }696 }697698 public var body: some View {699 HStack(spacing: QSpace.m) {700 ChainGlyph(network)701 if stacked {702 VStack(alignment: .leading, spacing: 4) {703 title704 amount705 }706 Spacer(minLength: 0)707 } else {708 title709 Spacer(minLength: QSpace.s)710 amount711 }712 if showsChevron {713 Image(systemName: "chevron.right")714 .font(.footnote.weight(.semibold))715 .foregroundStyle(QColor.textTertiary)716 .accessibilityHidden(true)717 }718 }719 .padding(.vertical, QSpace.s)720 .frame(minHeight: QMetric.rowMinHeight)721 .contentShape(Rectangle())722 .accessibilityElement(children: .combine)723 }724}725726/// A chain in the list of networks the user can enable: glyph, name, a note and a switch.727public struct ChainPickerRow: View {728 let network: QNetwork729 let note: String?730 let lockedReason: String?731 @Binding var isOn: Bool732733 /// - Parameters:734 /// - note: one line under the name (native coin, "Requires the mainnet opt-in"…).735 /// - lockedReason: when given, the switch is disabled and the reason replaces the note.736 public init(network: QNetwork, note: String? = nil, lockedReason: String? = nil, isOn: Binding<Bool>) {737 self.network = network738 self.note = note739 self.lockedReason = lockedReason740 self._isOn = isOn741 }742743 public var body: some View {744 Toggle(isOn: $isOn) {745 HStack(spacing: QSpace.m) {746 ChainGlyph(network)747 VStack(alignment: .leading, spacing: 3) {748 HStack(spacing: 6) {749 Text(network.fullName).font(QFont.headline).foregroundStyle(QColor.textPrimary)750 if network.isTest { QTestTag() }751 }752 if let lockedReason {753 Label(lockedReason, systemImage: "lock")754 .font(QFont.caption)755 .foregroundStyle(QColor.textSecondary)756 } else {757 Text(note ?? network.chain.nativeSymbol).font(QFont.caption).foregroundStyle(QColor.textSecondary)758 }759 }760 .fixedSize(horizontal: false, vertical: true)761 }762 }763 .tint(QColor.violet)764 .disabled(lockedReason != nil)765 .padding(.vertical, QSpace.s)766 .frame(minHeight: QMetric.rowMinHeight)767 .qHaptic(.toggled, trigger: isOn)768 .accessibilityElement(children: .combine)769 .accessibilityLabel(network.spokenName)770 .accessibilityValue(isOn ? "Enabled" : "Disabled")771 .accessibilityHint(lockedReason ?? note ?? "")772 }773}774