Branchwell

Bucksley / app · bucksley.ai / Sources / BucksleyUI / BrandColors.swift

1import SwiftUI
2import BucksleyKit
3
4/// Banks' own brand colors, so an account's dot reads at a glance (Bank of America red, Chase
5/// blue, Fidelity green). Unknown institutions fall back to a theme chart color.
6public enum BrandColors {
7 static let table: [(String, UInt32)] = [
8 ("bank of america", 0xE31837), ("bofa", 0xE31837), ("merrill", 0x0060A9),
9 ("chase", 0x117ACA), ("jpmorgan", 0x117ACA), ("fidelity", 0x4AA74A), ("wells fargo", 0xD71E28),
10 ("citi", 0x056DAE), ("capital one", 0xD03027), ("american express", 0x006FCF), ("amex", 0x006FCF),
11 ("discover", 0xFF6000), ("schwab", 0x00A0DF), ("vanguard", 0x96151D), ("u.s. bank", 0x0C2074),
12 ("us bank", 0x0C2074), ("pnc", 0xEF7622), ("td bank", 0x54B848), ("ally", 0x8A3291),
13 ("sofi", 0x00A8E1), ("robinhood", 0x00C805), ("coinbase", 0x0052FF), ("usaa", 0x00529B),
14 ("navy federal", 0x2B5BA8), ("marcus", 0x4D6A8E), ("goldman", 0x7399C6), ("e*trade", 0x6633CC),
15 ("etrade", 0x6633CC), ("betterment", 0x1F4FDA), ("wealthfront", 0x4840BB), ("paypal", 0x0079C1),
16 ("venmo", 0x3D95CE), ("synchrony", 0xF2B705), ("barclays", 0x00AEEF), ("apple", 0x9AA0A6),
17 ("truist", 0x7C2D8E), ("regions", 0x5E9732), ("citizens", 0x008555), ("hsbc", 0xDB0011),
18 ("santander", 0xEC0000),
19 // Card and account names that give the bank away.
20 ("sapphire", 0x117ACA), ("freedom", 0x117ACA), ("cma-edge", 0x0060A9), ("venture", 0xD03027),
21 ("quicksilver", 0xD03027), ("costco anywhere", 0x056DAE), ("double cash", 0x056DAE)
22 ]
23
24 public static func color(for institution: String) -> Color? {
25 let name = institution.lowercased()
26 return table.first { name.contains($0.0) }.map { Color(hex: $0.1) }
27 }
28}
29
30public extension BucksleyPalette {
31 /// The account's dot and badge color: its bank's brand color, else a steady theme color.
32 func color(forInstitution institution: String) -> Color {
33 BrandColors.color(for: institution) ?? color(institution.unicodeScalars.reduce(0) { $0 &+ Int($1.value) } % 5)
34 }
35
36 /// Brand color from the institution, or from the account's own name when the institution is a
37 /// connector ("SimpleFIN Bridge", "CSV import") rather than a bank.
38 func color(for account: Account) -> Color {
39 BrandColors.color(for: account.institution) ?? BrandColors.color(for: account.name) ?? color(forInstitution: account.institution + account.name)
40 }
41}