SPB Git

Repository Public

AddressChecks.swift 1.5 KB 30 lines swift

1// SP Wallet iOS2// File: Core/System/AddressChecks.swift3// Description: The app's first-line check of a destination before the server's authoritative validation, and the parsing of a4//              scanned or pasted payment code into form fields. The app never says "valid" unless SPWalletCore verified the5//              format for that exact network; otherwise it says the server will validate. A scanned code only fills a form.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation10import SPWalletCore1112enum AddressVerdict: Equatable { case valid, invalid(String), unverifiable }1314struct ScannedFields: Equatable { var network: String?; var address: String; var amount: String?; var memo: String? }1516enum AddressChecks {17    static func check(_ input: String, network: Network, own: String?) -> AddressVerdict {18        let a = input.trimmingCharacters(in: .whitespacesAndNewlines)19        if a.isEmpty { return .invalid(String(localized: "Adresse vide.")) }20        if a.count > 130 || a.contains(where: { $0.isWhitespace || $0.isNewline }) { return .invalid(String(localized: "Ce n’est pas une adresse.")) }21        if let own, own == a { return .invalid(String(localized: "C’est l’adresse de ce portefeuille.")) }22        return CoreAddressBridge.check(a, network: network)23    }24}2526enum ScannedPayment {27    enum Outcome { case success(ScannedFields), failure(String) }28    static func parse(_ raw: String, networks: [Network], current: String?) -> Outcome { CoreAddressBridge.parse(raw, networks: networks, current: current) }29}30
Files main
Menu

Theme