SPB Git

Repository Public

AssetIcon.swift 3.4 KB 76 lines swift

1// SP Wallet iOS2// File: Components/AssetIcon.swift3// Description: Real logos only (the backend's own sanitized set, bundled in the asset catalog under Logos/). An unknown symbol4//              keeps a neutral letter disc — a logo is never invented, and a logo is never a proof of authenticity.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI9import UIKit1011struct AssetIcon: View {12    let symbol: String13    var network: String?14    var size: CGFloat = 401516    private static func image(_ name: String) -> UIImage? { UIImage(named: name) }17    private var logoName: String { "logo-asset-" + symbol.lowercased().replacingOccurrences(of: ".", with: "-").replacingOccurrences(of: "₮", with: "t") }1819    var body: some View {20        ZStack(alignment: .bottomTrailing) {21            disc22            if let network, let img = NetworkIcon.image(for: network), !NetworkIcon.isHome(symbol: symbol, network: network) {23                Image(uiImage: img).resizable().scaledToFit()24                    .frame(width: size * 0.42, height: size * 0.42)25                    .clipShape(Circle())26                    .overlay(Circle().strokeBorder(Theme.surface, lineWidth: 1.5))27                    .offset(x: size * 0.08, y: size * 0.08)28            }29        }30        .frame(width: size, height: size)31        .accessibilityHidden(true)32    }3334    @ViewBuilder private var disc: some View {35        if let img = Self.image(logoName) {36            Image(uiImage: img).resizable().scaledToFit().frame(width: size, height: size)37                .background(Color.white).clipShape(Circle())38                .overlay(Circle().strokeBorder(Theme.hairline, lineWidth: 0.5))39        } else {40            Circle().fill(Theme.elev)41                .overlay(Text(symbol.prefix(1).uppercased()).font(.system(size: size * 0.42, weight: .semibold)).foregroundStyle(Theme.mute))42                .overlay(Circle().strokeBorder(Theme.hairline, lineWidth: 0.5))43        }44    }45}4647struct NetworkIcon: View {48    let network: String49    var size: CGFloat = 285051    /** Native coin of each network, used when the network has no mark of its own in the set. */52    static let nativeSymbol: [String: String] = [53        "ethereum": "eth", "polygon": "pol", "bnb": "bnb", "avalanche": "avax", "hyperevm": "hype", "bitcoin": "btc", "litecoin": "ltc",54        "dogecoin": "doge", "bitcoin-cash": "bch", "solana": "sol", "tron": "trx", "xrpl": "xrp", "stellar": "xlm", "aptos": "apt",55        "cosmos": "atom", "sui": "sui", "near": "near", "ton": "ton", "cardano": "ada", "polkadot": "dot",56    ]57    static func image(for network: String) -> UIImage? {58        UIImage(named: "logo-network-" + network) ?? nativeSymbol[network].flatMap { UIImage(named: "logo-asset-" + $0) }59    }60    /** The asset is its network's own coin: no network badge needed. */61    static func isHome(symbol: String, network: String) -> Bool { nativeSymbol[network] == symbol.lowercased() }6263    var body: some View {64        Group {65            if let img = Self.image(for: network) {66                Image(uiImage: img).resizable().scaledToFit().background(Color.white)67            } else {68                Theme.elev.overlay(Text(network.prefix(1).uppercased()).font(.system(size: size * 0.45, weight: .semibold)).foregroundStyle(Theme.mute))69            }70        }71        .frame(width: size, height: size).clipShape(Circle())72        .overlay(Circle().strokeBorder(Theme.hairline, lineWidth: 0.5))73        .accessibilityHidden(true)74    }75}76
Files main
Menu

Theme