Skip to content

Commit

Permalink
Merge pull request #509 from Outblock/feat/format
Browse files Browse the repository at this point in the history
Feat/format
  • Loading branch information
zhouxl authored Nov 12, 2024
2 parents b7c7a04 + 72b1cb1 commit 6be11aa
Show file tree
Hide file tree
Showing 214 changed files with 12,060 additions and 6,335 deletions.
2 changes: 1 addition & 1 deletion FRW/App/Env/Prod/InstabugConfig.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Instabug.swift
// InstabugConfig.swift
// FRW
//
// Created by cat on 2024/1/12.
Expand Down
17 changes: 13 additions & 4 deletions FRW/App/Env/ServiceConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@
import Foundation
import Instabug

// MARK: - ServiceConfig

class ServiceConfig {
static let shared = ServiceConfig()
private let dict: [String: String]
// MARK: Lifecycle

init() {
guard let filePath = Bundle.main.path(forResource: "ServiceConfig", ofType: "plist") else {
fatalError("fatalError ===> Can't find ServiceConfig.plist")
}
dict = NSDictionary(contentsOfFile: filePath) as? [String: String] ?? [:]
self.dict = NSDictionary(contentsOfFile: filePath) as? [String: String] ?? [:]
}

// MARK: Internal

static let shared = ServiceConfig()

static func configure() {
ServiceConfig.shared.setupInstabug()
ServiceConfig.shared.setupMixPanel()
}

// MARK: Private

private let dict: [String: String]
}

// MARK: instabug config
Expand All @@ -35,7 +44,7 @@ extension ServiceConfig {

InstabugConfig.start(token: token)
}

private func setupMixPanel() {
guard let token = dict["MixPanelToken"] else {
fatalError("fatalError ===> Can't find MixPanel Token at ServiceConfig.plist")
Expand Down
2 changes: 1 addition & 1 deletion FRW/Foundation/Define/AppPlaceholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct AppPlaceholder {
enum AppPlaceholder {
static var image: String = "https://lilico.app/placeholder-2.0.png"
static var imageURL = URL(string: AppPlaceholder.image)!
}
10 changes: 6 additions & 4 deletions FRW/Foundation/Model/AddressBookInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extension Contact {
case flowns = 2
case meow = 3

// MARK: Internal

var domain: String {
switch self {
case .unknown:
Expand All @@ -38,10 +40,10 @@ extension Contact {
}
}

// MARK: - AddressBook
// MARK: - Contact

struct Contact: Codable, Identifiable {
enum WalletType: String,Codable {
enum WalletType: String, Codable {
case flow
case evm
case link
Expand All @@ -56,7 +58,7 @@ struct Contact: Codable, Identifiable {
var walletType: WalletType? = .flow

var needShowLocalAvatar: Bool {
return contactType == .domain
contactType == .domain
}

var localAvatar: String? {
Expand Down Expand Up @@ -99,6 +101,6 @@ struct Contact: Codable, Identifiable {
}

var uniqueId: String {
return "\(address ?? "")-\(domain?.domainType?.rawValue ?? 0)-\(name)-\(contactType?.rawValue ?? 0)"
"\(address ?? "")-\(domain?.domainType?.rawValue ?? 0)-\(name)-\(contactType?.rawValue ?? 0)"
}
}
20 changes: 11 additions & 9 deletions FRW/Foundation/Model/AppExternalLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ enum AppExternalLinks: String, CaseIterable {
case lilico = "lilico://"
case frwUL = "https://frw-link.lilico.app"
case fcwUL = "https://fcw-link.lilico.app"


// MARK: Internal

static var allLinks: [String] {
AppExternalLinks.allCases.map(\.rawValue)
}

var isUniversalLink: Bool {
switch self {
case .frwUL, .fcwUL:
Expand All @@ -22,19 +28,15 @@ enum AppExternalLinks: String, CaseIterable {
return false
}
}

static var allLinks: [String] {
AppExternalLinks.allCases.map(\.rawValue)
}


static func exactWCLink(link: String) -> String {
let newLink = link
.replacingOccurrences(of: "wc%2Fwc", with: "wc")
.replacingOccurrences(of: "wc/wc", with: "wc")

return newLink
.deletingPrefixes(allLinks.map{link in "\(link)/wc?uri=" })
.deletingPrefixes(allLinks.map{link in "\(link)wc?uri=" })
.deletingPrefixes(allLinks.map { link in "\(link)/wc?uri=" })
.deletingPrefixes(allLinks.map { link in "\(link)wc?uri=" })
.deletingPrefixes(allLinks)
}
}
143 changes: 95 additions & 48 deletions FRW/Foundation/Model/WalletModels.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
//
// TokenModel.swift
// WalletModels.swift
// Flow Wallet
//
// Created by Hao Fu on 30/4/2022.
//

import BigInt
import Flow
import Foundation
import BigInt

// MARK: - Coin
// MARK: - QuoteMarket

enum QuoteMarket: String {
case binance
case kraken
case huobi

// MARK: Internal

var flowPricePair: String {
switch self {
case .kraken:
Expand All @@ -35,17 +37,32 @@ enum QuoteMarket: String {
}

var iconName: String {
return rawValue
rawValue
}
}

// MARK: - ListedToken

enum ListedToken: String, CaseIterable {
case flow
case fusd
case stFlow
case usdc
case other

// MARK: Lifecycle

init?(rawValue: String) {
if let item = ListedToken.allCases
.first(where: { $0.rawValue.lowercased() == rawValue.lowercased() }) {
self = item
} else {
self = .other
}
}

// MARK: Internal

enum PriceAction {
case fixed(price: Decimal)
case query(String)
Expand All @@ -66,16 +83,10 @@ enum ListedToken: String, CaseIterable {
return .fixed(price: 0.0)
}
}

init?(rawValue: String) {
if let item = ListedToken.allCases.first(where: { $0.rawValue.lowercased() == rawValue.lowercased() }) {
self = item
} else {
self = .other
}
}
}

// MARK: - TokenModel

struct TokenModel: Codable, Identifiable, Mockable {
let name: String
var address: FlowNetworkModel
Expand All @@ -94,7 +105,7 @@ struct TokenModel: Codable, Identifiable, Mockable {
}

var isFlowCoin: Bool {
return symbol?.lowercased() ?? "" == ListedToken.flow.rawValue
symbol?.lowercased() ?? "" == ListedToken.flow.rawValue
}

var contractId: String {
Expand Down Expand Up @@ -126,11 +137,39 @@ struct TokenModel: Codable, Identifiable, Mockable {
}

var id: String {
return symbol ?? ""
symbol ?? ""
}

var isActivated: Bool {
if let symbol = symbol {
return WalletManager.shared.isTokenActivated(symbol: symbol)
}

return false
}

static func mock() -> TokenModel {
TokenModel(
name: "mockname",
address: FlowNetworkModel(
mainnet: nil,
testnet: nil,
crescendo: nil,
previewnet: nil
),
contractName: "contractname",
storagePath: FlowTokenStoragePath(balance: "", vault: "", receiver: ""),
decimal: 999,
icon: nil,
symbol: randomString(),
website: nil,
evmAddress: nil,
flowIdentifier: nil
)
}

func getAddress() -> String? {
return address.addressByNetwork(LocalUserDefaults.shared.flowNetwork.toFlowType())
address.addressByNetwork(LocalUserDefaults.shared.flowNetwork.toFlowType())
}

func getPricePair(market: QuoteMarket) -> String {
Expand All @@ -143,27 +182,6 @@ struct TokenModel: Codable, Identifiable, Mockable {
return market.flowPricePair // TODO: #six Need to confirm
}
}

var isActivated: Bool {
if let symbol = symbol {
return WalletManager.shared.isTokenActivated(symbol: symbol)
}

return false
}

static func mock() -> TokenModel {
return TokenModel(name: "mockname",
address: FlowNetworkModel(mainnet: nil, testnet: nil, crescendo: nil, previewnet: nil),
contractName: "contractname",
storagePath: FlowTokenStoragePath(balance: "", vault: "", receiver: ""),
decimal: 999,
icon: nil,
symbol: randomString(),
website: nil,
evmAddress: nil,
flowIdentifier: nil)
}
}

extension TokenModel {
Expand All @@ -182,6 +200,8 @@ extension TokenModel {
}
}

// MARK: - FlowNetworkModel

struct FlowNetworkModel: Codable {
let mainnet: String?
var testnet: String?
Expand All @@ -202,12 +222,16 @@ struct FlowNetworkModel: Codable {
}
}

// MARK: - FlowTokenStoragePath

struct FlowTokenStoragePath: Codable {
let balance: String
let vault: String
let receiver: String
}

// MARK: - SingleTokenResponse

struct SingleTokenResponse: Codable {
let name: String
let network: String?
Expand All @@ -221,6 +245,8 @@ struct SingleTokenResponse: Codable {
}
}

// MARK: - SingleToken

struct SingleToken: Codable {
let chainId: Int
let address: String
Expand All @@ -237,28 +263,49 @@ struct SingleToken: Codable {
func toTokenModel(network: LocalUserDefaults.FlowNetworkType) -> TokenModel {
let logo = URL(string: logoURI ?? "")

let model = TokenModel(name: name,
address: FlowNetworkModel(mainnet: network == .mainnet ? address : nil, testnet: network == .testnet ? address : nil, crescendo: nil, previewnet: network == .previewnet ? address : nil),
contractName: contractName ?? "", storagePath: path ?? FlowTokenStoragePath(balance: "", vault: "", receiver: ""), decimal: decimals, icon: logo, symbol: symbol, website: extensions?.website, evmAddress: evmAddress, flowIdentifier: flowIdentifier)
let model = TokenModel(
name: name,
address: FlowNetworkModel(
mainnet: network == .mainnet ? address : nil,
testnet: network == .testnet ? address : nil,
crescendo: nil,
previewnet: network == .previewnet ? address : nil
),
contractName: contractName ?? "",
storagePath: path ??
FlowTokenStoragePath(balance: "", vault: "", receiver: ""),
decimal: decimals,
icon: logo,
symbol: symbol,
website: extensions?.website,
evmAddress: evmAddress,
flowIdentifier: flowIdentifier
)
return model
}
}

// MARK: - TokenExtension

struct TokenExtension: Codable {
let website: URL?
let twitter: URL?
let discord: URL?
// MARK: Lifecycle

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.website = try? container.decode(URL.self, forKey: .website)
self.twitter = try? container.decode(URL.self, forKey: .twitter)
self.discord = try? container.decode(URL.self, forKey: .discord)
}

// MARK: Internal

enum CodingKeys: String, CodingKey {
case website
case twitter
case discord
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
website = try? container.decode(URL.self, forKey: .website)
twitter = try? container.decode(URL.self, forKey: .twitter)
discord = try? container.decode(URL.self, forKey: .discord)
}
let website: URL?
let twitter: URL?
let discord: URL?
}
Loading

0 comments on commit 6be11aa

Please sign in to comment.