Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Wallet for macOS9// File : Features/NFTs/NFTsView.swift10// Description : Entry of the NFT feature: the gallery of the wallet's NFTs11// (virtualized grid, filters by network / collection /12// status, search, sort, grouping), the honest account of13// where the inventory comes from (which provider, when, what14// is not discovered), the synchronisation the server offers,15// and the navigation to an item, a collection, the explicit16// lookup / manual tracking and the signer's NFT controls.17// Remote names are plain text, media only ever comes through18// the server's proxy, and there is no market write anywhere:19// the backend has none.20// Module : Features21// Repository : https://git.spboucher.ai/sp-wallet-macos22// Created : 2026-11-1823// Last Modified : 2026-11-1824//25// =============================================================================26// AUTHOR & PROFESSIONAL AFFILIATION27// =============================================================================28//29// Author : Simon-Pierre Boucher30// Position : Professor of Finance31// Institution : Université du Québec en Outaouais (UQO)32// Department : Département des sciences administratives33// Organization : SP Boucher34//35// Website : https://spboucher.ai36// Git : https://git.spboucher.ai37//38// =============================================================================39// OFFICIAL CONTACT DIRECTORY40// =============================================================================41//42// General : info@spboucher.ai43// Professional : contact@spboucher.ai44// Direct : simon@spboucher.ai45// Research : research@spboucher.ai46// Development : dev@spboucher.ai47// Support : support@spboucher.ai48// Security/Admin : admin@spboucher.ai49// Notifications : notifications@spboucher.ai50//51// Preferred Contact: support@spboucher.ai52//53// =============================================================================54// COPYRIGHT & INTELLECTUAL PROPERTY55// =============================================================================56//57// Copyright (c) 202658// Simon-Pierre Boucher59//60// All rights reserved where applicable.61//62// This file is governed by the applicable project license,63// copyright notices, institutional agreements and relevant law.64//65// Unless expressly authorized by the applicable license or66// rights holder, copying, redistribution, sublicensing,67// publication and commercial exploitation are not permitted.68//69// Existing third-party rights and notices remain unaffected.70//71// =============================================================================72// CONFIDENTIALITY & SECURITY73// =============================================================================74//75// Classification : Public76// Distribution : Public repository; use is governed by the project license77// Security Contact : admin@spboucher.ai78//79// Access to this source does not independently grant permission80// to redistribute or disclose confidential materials.81//82// Do not embed credentials, private keys, access tokens,83// certificates or confidential personal information.84//85// =============================================================================86// LICENSE & MAINTENANCE87// =============================================================================88//89// License : None specified (no license file in this repository)90// Maintainer : Simon-Pierre Boucher91// Technical Contact: dev@spboucher.ai92//93// =============================================================================94// END OF SP BOUCHER SOURCE HEADER95// =============================================================================9697import SwiftUI98import SPWalletCore99100enum NFTRoute: Hashable {101 case item(String)102 case collection(String)103 case controls104}105106/// Plain text, never Markdown, never a localisation key: the only way server-provided text is put on screen.107func NFTPlain(_ s: String) -> Text { Text(verbatim: s) }108109struct NFTsView: View {110 let model: AppModel111 @State private var gallery: NFTGallery?112 @State private var path: [NFTRoute] = []113114 var body: some View {115 Group {116 if let gallery {117 switch path.last {118 case nil: NFTGalleryPage(model: model, gallery: gallery, open: { path.append($0) })119 case .item(let key): NFTItemPage(model: model, gallery: gallery, key: key, open: { path.append($0) }, back: back).id(key)120 case .collection(let key): NFTCollectionPage(model: model, gallery: gallery, key: key, open: { path.append($0) }, back: back).id(key)121 case .controls: NFTControlsPage(model: model, gallery: gallery, back: back)122 }123 } else { ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity) }124 }125 .task {126 if gallery == nil { gallery = NFTGallery(model: model) }127 await gallery?.load()128 }129 .onDisappear { gallery?.stop() }130 }131 private func back() { if !path.isEmpty { path.removeLast() } }132}133134/// The "‹ back" row every sub-page starts with.135struct NFTBackBar: View {136 let title: String137 let back: () -> Void138 var body: some View {139 Button(action: back) { Label(title, systemImage: "chevron.left") }.buttonStyle(.link)140 }141}142143// MARK: - Gallery144145private struct NFTGalleryPage: View {146 let model: AppModel147 @Bindable var gallery: NFTGallery148 let open: (NFTRoute) -> Void149 @State private var showLookup = false150 @State private var showSources = false151152 private let columns = [GridItem(.adaptive(minimum: 172, maximum: 240), spacing: 14, alignment: .top)]153154 var body: some View {155 Page("NFT", subtitle: "Inventaire découvert par les fournisseurs configurés sur le serveur, vérifié sur la chaîne à l’ouverture de chaque fiche.") {156 banners157 toolbar158 NFTSourcesCard(model: model, gallery: gallery, expanded: $showSources)159 if gallery.items.isEmpty { emptyInventory }160 else if gallery.sections.isEmpty {161 EmptyState(symbol: "line.3.horizontal.decrease.circle", title: "Aucun NFT ne correspond aux filtres",162 detail: gallery.hiddenSpam > 0 ? "\(gallery.hiddenSpam) élément(s) signalé(s) comme indésirables par un indexeur sont masqués par le filtre actuel." : nil)163 } else {164 counts165 LazyVGrid(columns: columns, alignment: .leading, spacing: 14) {166 ForEach(gallery.sections) { section in167 SwiftUI.Section {168 ForEach(section.items) { item in tile(item) }169 } header: {170 NFTSectionHeader(section: section, open: open)171 }172 }173 }174 }175 }176 .sheet(isPresented: $showLookup) { NFTLookupSheet(model: model, gallery: gallery, open: { showLookup = false; open($0) }, close: { showLookup = false }) }177 }178179 private func tile(_ item: NFTSummary) -> some View {180 Button { open(.item(item.key)) } label: { NFTTile(item: item, gallery: gallery) }.buttonStyle(.plain)181 }182183 @ViewBuilder private var banners: some View {184 if gallery.fromCache, let d = gallery.fetchedAt {185 Banner(.warning, "Lecture seule — inventaire tel que synchronisé par cette app le \(Fmt.date(d)). Il peut ne plus refléter la chaîne. Seules les miniatures déjà téléchargées sont affichées ; les transferts sont désactivés.")186 } else if !model.canOperate {187 Banner(.warning, "Session ou portefeuille indisponible : lecture seule, aucune synchronisation ni transfert possible.")188 }189 if let e = gallery.error { Banner(.danger, e) }190 if !gallery.complete { Banner(.warning, "Inventaire incomplet : la lecture s’est arrêtée à \(gallery.items.count) éléments sur \(gallery.total) annoncés par le serveur.") }191 }192193 @ViewBuilder private var emptyInventory: some View {194 if gallery.loading || !gallery.loadedOnce { HStack { ProgressView().controlSize(.small); Text("Lecture de l’inventaire…").foregroundStyle(.secondary) } }195 else {196 EmptyState(symbol: "square.grid.2x2", title: "Aucun NFT dans l’inventaire",197 detail: "Aucun NFT n’a été découvert pour les adresses de ce portefeuille. Sur les réseaux EVM, la découverte dépend du fournisseur configuré sur le serveur : sans lui, un NFT entre dans l’inventaire en le suivant à la main (bouton « Rechercher ou suivre »). Voir « Sources de l’inventaire » ci-dessus.")198 }199 }200201 private var counts: some View {202 HStack {203 NFTPlain("\(gallery.visibleCount) affiché(s) sur \(gallery.items.count)").font(.callout).foregroundStyle(.secondary)204 if gallery.hiddenSpam > 0 {205 Button { gallery.spam = .show } label: { NFTPlain("\(gallery.hiddenSpam) signalé(s) comme indésirables masqué(s) — afficher") }.buttonStyle(.link).font(.callout)206 }207 Spacer()208 Text("Aucune valeur n’est attribuée aux NFT : ce portefeuille ne sait pas en établir une de façon fiable.").font(.caption).foregroundStyle(.secondary)209 }210 }211212 private var toolbar: some View {213 Card {214 HStack(spacing: 10) {215 Image(systemName: "magnifyingglass").foregroundStyle(.secondary)216 TextField("Rechercher", text: $gallery.search, prompt: Text("Nom, collection, contrat, mint ou identifiant")).textFieldStyle(.plain)217 if !gallery.search.isEmpty { Button { gallery.search = "" } label: { Image(systemName: "xmark.circle.fill") }.buttonStyle(.plain).foregroundStyle(.secondary) }218 Divider().frame(height: 18)219 if gallery.loading { ProgressView().controlSize(.small) }220 Button { Task { await gallery.refresh() } } label: { Label("Relire", systemImage: "arrow.clockwise") }221 .disabled(!gallery.canFetch || gallery.loading).help("Relit l’inventaire tel que le serveur le stocke maintenant. Ne lance pas de découverte : voir « Synchroniser ».")222 Button { showLookup = true } label: { Label("Rechercher ou suivre…", systemImage: "plus.magnifyingglass") }.disabled(!model.canOperate)223 Button { open(.controls) } label: { Label("Contrôles du signataire", systemImage: "lock.shield") }224 }225 Divider()226 HStack(spacing: 12) {227 Picker("Réseau", selection: $gallery.chain) {228 Text("Tous les réseaux").tag("")229 ForEach(gallery.chainsPresent, id: \.self) { NFTPlain(gallery.networkName($0)).tag($0) }230 }231 Picker("Collection", selection: $gallery.collection) {232 Text("Toutes les collections").tag("")233 ForEach(gallery.collectionsPresent, id: \.key) { c in NFTPlain("\(c.name) (\(c.count))").tag(c.key) }234 }235 Picker("État", selection: $gallery.status) { ForEach(NFTGallery.Status.allCases) { Text($0.label).tag($0) } }236 Picker("Indésirables", selection: $gallery.spam) { ForEach(NFTGallery.Spam.allCases) { Text($0.label).tag($0) } }237 }.labelsHidden()238 HStack(spacing: 12) {239 Picker("Tri", selection: $gallery.sort) { ForEach(NFTGallery.Sort.allCases) { Text($0.label).tag($0) } }.frame(maxWidth: 220)240 Picker("Regroupement", selection: $gallery.grouping) { ForEach(NFTGallery.Grouping.allCases) { Text($0.label).tag($0) } }.frame(maxWidth: 220)241 if !gallery.collection.isEmpty { Button("Page de la collection") { open(.collection(gallery.collection)) } }242 Spacer()243 }.labelsHidden()244 }245 }246}247248private struct NFTSectionHeader: View {249 let section: NFTGallerySection250 let open: (NFTRoute) -> Void251 var body: some View {252 if !section.title.isEmpty {253 HStack(spacing: 10) {254 NFTPlain(section.title).font(.headline)255 NFTPlain(String(section.items.count)).font(.callout).foregroundStyle(.secondary).monospacedDigit()256 if let key = section.collectionKey { Button("Page de la collection") { open(.collection(key)) }.buttonStyle(.link).font(.callout) }257 Spacer()258 }.padding(.top, 8)259 }260 }261}262263/// One NFT of the grid. Its flags are on the tile itself: an indexer's spam signal, an item that left the wallet, a stale ownership.264struct NFTTile: View {265 let item: NFTSummary266 let gallery: NFTGallery267268 var body: some View {269 VStack(alignment: .leading, spacing: 6) {270 NFTThumbView(mediaId: item.image?.id, kind: item.image?.kind, pixels: NFTMediaStore.gridPixels, api: gallery.mediaAPI, maxBytes: gallery.mediaLimit)271 .aspectRatio(1, contentMode: .fit)272 .overlay(alignment: .topLeading) {273 VStack(alignment: .leading, spacing: 3) {274 if let s = item.spam { NFTFlag(text: "Indésirable selon \(NFTText.sourceName(s.by))", color: Theme.negative, symbol: "exclamationmark.triangle.fill") }275 if !item.inWallet { NFTFlag(text: NFTText.ownership(item.state), color: Theme.warning) }276 }.padding(6)277 }278 .overlay(alignment: .bottomTrailing) {279 if item.quantity != "1" { NFTPlain("× \(Fmt.amount(item.quantity))").font(.caption.weight(.semibold)).monospacedDigit().padding(.horizontal, 6).padding(.vertical, 2).background(.thinMaterial, in: Capsule()).padding(6) }280 }281 NFTPlain(NFTClean.line(item.displayName, max: 80) ?? "Sans nom — \(Fmt.short(item.tokenId ?? item.assetId))").font(.callout.weight(.medium)).lineLimit(1)282 .foregroundStyle(item.displayName == nil ? .secondary : .primary)283 NFTPlain(NFTClean.line(item.collection?.name, max: 80) ?? "Sans collection").font(.caption).foregroundStyle(.secondary).lineLimit(1)284 HStack(spacing: 4) {285 NFTPlain(gallery.networkName(item.chain)).lineLimit(1)286 Text("·")287 NFTPlain(NFTText.standardShort(item.standard)).lineLimit(1)288 if item.stale { Image(systemName: "clock.badge.exclamationmark").foregroundStyle(Theme.warning).help("La propriété n’a pas été relue récemment sur la chaîne.") }289 if item.origin == "manual" { Image(systemName: "pin").help("Suivi à la main") }290 }.font(.caption2).foregroundStyle(.secondary)291 }292 .padding(8)293 .background(Theme.card, in: RoundedRectangle(cornerRadius: Theme.corner))294 .overlay(RoundedRectangle(cornerRadius: Theme.corner).strokeBorder(item.spam != nil ? Theme.negative.opacity(0.6) : Theme.stroke.opacity(0.6)))295 .contentShape(RoundedRectangle(cornerRadius: Theme.corner))296 .accessibilityElement(children: .combine)297 }298}299300/// A square media tile: the downsampled bitmap, or a neutral placeholder that says why there is none.301struct NFTThumbView: View {302 let mediaId: String?303 let kind: String?304 let pixels: Int305 let api: NFTAPI?306 let maxBytes: Int307 @State private var thumbnail: NFTThumbnail?308309 /// Kinds that are never downloaded for a tile: they are not images.310 private var nonImage: String? {311 switch kind {312 case "video": "Vidéo — ouvrir la fiche"313 case "audio": "Audio — ouvrir la fiche"314 case "html": "Média non affichable (document HTML)"315 case "model": "Média non affichable (modèle 3D)"316 default: nil317 }318 }319320 var body: some View {321 ZStack {322 RoundedRectangle(cornerRadius: 8).fill(Color.secondary.opacity(0.10))323 if mediaId == nil { placeholder("photo", "Aucun média déclaré") }324 else if let nonImage { placeholder(kind == "video" ? "film" : kind == "audio" ? "waveform" : "eye.slash", nonImage) }325 else {326 switch thumbnail {327 case .image(let image): Image(decorative: image, scale: 1).resizable().interpolation(.medium).aspectRatio(contentMode: .fit).clipShape(RoundedRectangle(cornerRadius: 8))328 case .notDisplayable(let why): placeholder("eye.slash", "Média non affichable").help(why)329 case .unavailable(let why): placeholder("icloud.slash", "Média indisponible").help(why)330 case nil: ProgressView().controlSize(.small)331 }332 }333 }334 .task(id: "\(mediaId ?? "")|\(api == nil)") {335 guard let mediaId, nonImage == nil else { return }336 let t = await NFTMediaStore.shared.thumbnail(id: mediaId, pixels: pixels, api: api, maxBytes: maxBytes)337 if !Task.isCancelled { thumbnail = t }338 }339 }340 private func placeholder(_ symbol: String, _ text: String) -> some View {341 VStack(spacing: 6) {342 Image(systemName: symbol).font(.title2).foregroundStyle(.tertiary)343 Text(text).font(.caption2).foregroundStyle(.secondary).multilineTextAlignment(.center)344 }.padding(8)345 }346}347348// MARK: - Where the inventory comes from349350private struct NFTSourcesCard: View {351 let model: AppModel352 let gallery: NFTGallery353 @Binding var expanded: Bool354355 var body: some View {356 Card {357 DisclosureGroup(isExpanded: $expanded) {358 VStack(alignment: .leading, spacing: 12) {359 if let caps = gallery.capabilities {360 let listed = caps.chains.filter { $0.inventory != "unsupported" || !$0.sections.isEmpty }361 ForEach(listed) { chain in row(chain) }362 let others = caps.chains.count - listed.count363 if others > 0 { Text("\(others) autre(s) réseau(x) du registre : aucun adaptateur NFT sur ce serveur.").font(.caption).foregroundStyle(.secondary) }364 Divider()365 Text("Fournisseurs du serveur").font(.subheadline.weight(.medium))366 ForEach(caps.providers) { p in367 HStack(alignment: .firstTextBaseline, spacing: 8) {368 Image(systemName: p.on ? "checkmark.circle.fill" : "minus.circle").foregroundStyle(p.on ? Theme.positive : .secondary)369 NFTPlain(p.id).font(Theme.monoSmall)370 NFTPlain(p.on ? "actif" : "inactif\(p.unlockedBy.map { " — s’active par la variable serveur \($0)" } ?? "")").foregroundStyle(.secondary)371 Spacer()372 NFTPlain("ce qui sort du serveur : \(p.sends)").font(.caption).foregroundStyle(.secondary)373 }374 }375 if !caps.anyMarketWrite { Text("Aucune écriture de marché (mise en vente, achat, offre) n’existe dans le serveur : cette app n’en propose donc aucune.").font(.caption).foregroundStyle(.secondary) }376 } else {377 Text(gallery.loading ? "Lecture de la matrice de capacités…" : "Matrice de capacités indisponible.").foregroundStyle(.secondary)378 }379 if let e = gallery.syncError { Banner(.danger, e) }380 }.padding(.top, 8)381 } label: {382 HStack(spacing: 10) {383 Text("Sources de l’inventaire").font(.headline)384 NFTPlain(summaryLine).font(.callout).foregroundStyle(.secondary).lineLimit(1)385 Spacer()386 if !gallery.syncRunning.isEmpty {387 ProgressView().controlSize(.small)388 NFTPlain("Synchronisation en cours côté serveur : \(gallery.syncRunning.map(gallery.networkName).joined(separator: ", "))").font(.callout).foregroundStyle(.secondary).lineLimit(1)389 }390 Button { Task { await gallery.startSync(chain: nil) } } label: { Label("Synchroniser", systemImage: "arrow.triangle.2.circlepath") }391 .disabled(!model.canOperate || gallery.syncStarting || !gallery.syncRunning.isEmpty)392 .help("Demande au serveur d’interroger ses fournisseurs pour chaque réseau qui en a un (6 demandes par minute au plus). L’inventaire est relu quand le serveur a terminé.")393 }394 }395 }396 }397398 private var summaryLine: String {399 guard let caps = gallery.capabilities else { return "" }400 let sources = Set(caps.chains.flatMap { $0.sections.filter { $0.status == "ok" }.compactMap(\.source) }).map(NFTText.sourceName).sorted()401 let last = gallery.lastSyncedAt.values.max() ?? caps.chains.flatMap { $0.sections.compactMap(\.syncedAt) }.max()402 return (sources.isEmpty ? "aucune source n’a encore répondu" : sources.joined(separator: ", ")) + (last.map { " · dernière synchronisation \(Fmt.relative($0))" } ?? "")403 }404405 private func row(_ chain: NFTChainCapability) -> some View {406 VStack(alignment: .leading, spacing: 3) {407 HStack(alignment: .firstTextBaseline, spacing: 8) {408 NFTPlain(chain.name).fontWeight(.medium)409 NFTFlag(text: NFTText.inventory(chain.inventory), color: chain.inventory == "supported" ? Theme.positive : chain.inventory == "partial" ? Theme.warning : .secondary)410 NFTPlain(NFTText.inventoryReason(chain.reason) + (chain.unlockedBy.map { " — variable serveur \($0)" } ?? "")).font(.caption).foregroundStyle(.secondary)411 Spacer()412 if let d = gallery.lastSyncedAt[chain.network] { NFTPlain("synchronisé \(Fmt.relative(d))").font(.caption).foregroundStyle(.secondary) }413 if gallery.syncRunning.contains(chain.network) { ProgressView().controlSize(.mini) }414 else if chain.inventory == "supported" || chain.inventory == "partial" {415 Button("Synchroniser") { Task { await gallery.startSync(chain: chain.network) } }.controlSize(.small).disabled(!model.canOperate || gallery.syncStarting)416 }417 }418 ForEach(chain.sections, id: \.section) { s in419 HStack(spacing: 6) {420 Image(systemName: s.status == "ok" ? "checkmark" : "exclamationmark.triangle").foregroundStyle(s.status == "ok" ? Theme.positive : Theme.warning).font(.caption)421 NFTPlain("\(s.section) — \(s.source.map(NFTText.sourceName) ?? "aucune source") : \(NFTText.sectionStatus(s.status))\(s.code.map { " (\($0))" } ?? "")\(s.unlockedBy.map { ", variable serveur \($0)" } ?? ""), \(s.count) élément(s)\(s.truncated ? ", liste TRONQUÉE par le serveur" : "")\(s.syncedAt.map { ", le \(Fmt.date($0))" } ?? "")")422 .font(.caption).foregroundStyle(.secondary)423 }.padding(.leading, 12)424 }425 HStack(spacing: 10) {426 NFTPlain("Transfert : \(chain.canPrepareTransfers ? "préparable pour \((chain.transferStandards ?? []).map(NFTText.standardShort).joined(separator: ", "))" : "non construit\(chain.transferReason.map { " — \(NFTText.blockReason($0))" } ?? "")")")427 NFTPlain("Lecture de marché : \(chain.marketRead ? "oui" : "non")")428 }.font(.caption).foregroundStyle(.secondary).padding(.leading, 12)429 }430 }431}432433// MARK: - Explicit lookup and manual tracking434435/// The owner types a chain identifier: the server reads that asset on-chain (lookup, never part of the inventory) or tracks it (verified on-chain first). This is how an EVM NFT enters the inventory when no discovery provider is configured.436private struct NFTLookupSheet: View {437 let model: AppModel438 let gallery: NFTGallery439 let open: (NFTRoute) -> Void440 let close: () -> Void441 @State private var chain = ""442 @State private var address = ""443 @State private var tokenId = ""444 @State private var busy = false445 @State private var error: String?446447 private var chains: [NFTChainCapability] { (gallery.capabilities?.chains ?? []).filter { $0.lookup || $0.manualAdd } }448 private var selected: NFTChainCapability? { chains.first { $0.network == chain } }449 private var isEVM: Bool { selected?.family == "evm" }450 private var trimmed: String { address.trimmingCharacters(in: .whitespacesAndNewlines) }451 private var problem: String? {452 guard selected != nil else { return "Choisissez un réseau." }453 if trimmed.count < 26 || trimmed.count > 64 { return isEVM ? "Entrez l’adresse du contrat." : "Entrez l’adresse du mint ou de l’actif." }454 if isEVM, tokenId.trimmingCharacters(in: .whitespaces).isEmpty { return "Entrez l’identifiant du jeton (décimal ou 0x…)." }455 return nil456 }457458 var body: some View {459 VStack(alignment: .leading, spacing: 14) {460 Text("Rechercher ou suivre un NFT").font(.title2.weight(.semibold))461 Text("Le serveur lit cet actif sur la chaîne à partir de l’identifiant saisi. « Ouvrir » l’affiche sans l’ajouter à l’inventaire ; « Suivre » l’ajoute après vérification sur la chaîne (c’est ainsi qu’un NFT EVM entre dans l’inventaire sans fournisseur de découverte).")462 .font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)463 if chains.isEmpty { Banner(.warning, "Aucun réseau ne permet la recherche explicite sur ce serveur (ou la matrice de capacités n’a pas pu être lue).") }464 Form {465 Picker("Réseau", selection: $chain) {466 Text("Choisir…").tag("")467 ForEach(chains) { NFTPlain($0.name).tag($0.network) }468 }469 TextField(isEVM ? "Contrat" : "Mint / actif", text: $address).font(Theme.monoSmall)470 if isEVM { TextField("Identifiant du jeton", text: $tokenId).font(Theme.monoSmall) }471 }.formStyle(.grouped).scrollDisabled(true)472 if let e = error { Banner(.danger, e) }473 HStack {474 if let p = problem, !address.isEmpty { Text(p).font(.callout).foregroundStyle(.secondary) }475 Spacer()476 if busy { ProgressView().controlSize(.small) }477 Button("Annuler", action: close)478 Button("Suivre dans l’inventaire") { run(track: true) }.disabled(problem != nil || busy || !model.canOperate || selected?.manualAdd != true)479 Button("Ouvrir") { run(track: false) }.buttonStyle(.borderedProminent).disabled(problem != nil || busy || !model.canOperate || selected?.lookup != true)480 }481 }482 .padding(20).frame(width: 620)483 }484485 private func run(track: Bool) {486 let token = tokenId.trimmingCharacters(in: .whitespaces)487 let ref = NFTReference(chain: chain, address: trimmed, tokenId: isEVM && !token.isEmpty ? token : nil)488 busy = true; error = nil489 Task {490 defer { busy = false }491 do {492 let asset = track ? try await gallery.api.track(ref) : try await gallery.api.lookup(ref)493 if track { await gallery.load() }494 open(.item(asset.key))495 } catch { self.error = model.describe(error) }496 }497 }498}499