Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-2180 - Handle MATIC->POL update #670

Merged
merged 7 commits into from
Sep 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct Debugger {
case .debugUI:
return [.Error, .Navigation, .UI, .Images, .Debug]
case .debugNetwork:
return [.Network, .WebSockets, .Error, .Debug, .mpc]
return [.Network, .WebSockets, .Error, .Debug]
case .custom(let topics):
return topics
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct DefaultAppVersionFetcher: AppVersionApi {
polygonMintingReleased: response.polygonClaimingReleased,
mintingZilTldOnPolygonReleased: response.mintingZilTldOnPolygonReleased,
dotcoinDeprecationReleased: response.dotcoinDeprecationReleased,
mobileUnsReleaseVersion: response.mobileUnsReleaseVersion,
tlds: response.tlds,
tldsToPurchase: response.tldsToPurchase,
dnsTlds: response.dnsTlds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ struct AppVersionAPIResponse: Decodable {
let tldsToPurchase: [String]
let dnsTlds: [String]
var dotcoinDeprecationReleased: Bool?
var mobileUnsReleaseVersion: String?
var limits: AppConfigurationLimits?
}

Expand All @@ -103,7 +102,6 @@ struct AppVersionInfo: Codable {
var polygonMintingReleased: Bool = true
var mintingZilTldOnPolygonReleased: Bool = false
var dotcoinDeprecationReleased: Bool?
var mobileUnsReleaseVersion: String?
var tlds: [String] = ["x",
"crypto",
"coin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ enum BlockchainType: BlockchainProtocol {
}
}

/// This is a temporary property to map MATIC->POL transition until all services are updated.
/// Eventually "POL" should be set as a shortCode for Matic and this property should be removed
var migratedShortCode: String {
switch self {
case .Matic:
return "POL"
default:
return shortCode
}
}

var fullName: String {
switch self {
case .Ethereum:
Expand All @@ -59,7 +70,7 @@ enum BlockchainType: BlockchainProtocol {
switch chainShortCode.uppercased().trimmedSpaces {
case "ETH":
self = .Ethereum
case "MATIC":
case "MATIC", "POL":
self = .Matic
case "BASE":
self = .Base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ extension Array where Element == FB_UD_MPC.WalletAccountAsset {
func findWith(symbol: String, chain: String) -> Element? {
guard let id = FB_UD_MPC.WalletAccountAsset.mpcIDFor(symbol: chain) else { return nil }

var symbols: Set<String> = [symbol]
if let blockchainType = BlockchainType(chainShortCode: symbol) {
symbols.insert(blockchainType.migratedShortCode)
}

// TODO: - Check for $0.blockchainAsset.blockchain.symbol when BE ready
return first(where: { $0.blockchainAsset.symbol == symbol && $0.blockchainAsset.blockchain.id == id })
return first(where: { symbols.contains($0.blockchainAsset.symbol) && $0.blockchainAsset.blockchain.id == id })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ private extension AppLaunchService {
Task.detached(priority: .medium) { [weak self] in
guard let self else { return }

appContext.coinRecordsService.refreshCurrencies()
let appVersion = await appContext.userDataService.getLatestAppVersion()
appContext.coinRecordsService.refreshCurrencies(version: appVersion.mobileUnsReleaseVersion ?? Constants.defaultUNSReleaseVersion)
await self.appVersionUpdated(appVersion)
await self.stateMachine.set(appVersionInfo: appVersion)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ extension CoinRecordsService: CoinRecordsServiceProtocol {
return currencies
}

func refreshCurrencies(version: String) {
func refreshCurrencies() {
Task.detached(priority: .background) {
do {
let data = try await self.fetchCurrenciesData(version: version)
let data = try await self.fetchCurrenciesData()

guard let coins = self.parseCurrencies(from: data) else {
Debugger.printFailure("Failed to parse uns version: \(version)", critical: true)
Debugger.printFailure("Failed to parse resolver-keys", critical: true)
return
}

self.setCurrencies(coins)
self.storeCoinRecords(data: data)
self.detectAndReportRecordsWithoutPrimaryChain()
} catch {
Debugger.printFailure("Failed to fetch uns version: \(version)", critical: false)
Debugger.printFailure("Failed to fetch resolver-keys with error \(error.localizedDescription)", critical: false)
}
}
}
Expand All @@ -63,7 +63,7 @@ private extension CoinRecordsService {
}
}

func fetchCurrenciesData(version: String) async throws -> Data {
func fetchCurrenciesData() async throws -> Data {
var cursor: String? = ""
var records: [TokenRecord] = []
var counter = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protocol CoinRecordsServiceProtocol {
var eventsPublisher: PassthroughSubject<CoinRecordsEvent, Never> { get }

func getCurrencies() async -> [CoinRecord]
func refreshCurrencies(version: String)
func refreshCurrencies()
}

enum CoinRecordsEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct NetworkService {
using keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .iso8601) async throws -> T {
let data = try await makeAPIRequest(apiRequest)
logMPC("Raw Response: \(try? JSONSerialization.jsonObject(with: data))")

if let object = T.objectFromData(data,
using: keyDecodingStrategy,
dateDecodingStrategy: dateDecodingStrategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct Constants {
static let standardWebHosts = ["https://", "http://"]
static let downloadedImageMaxSize: CGFloat = 512
static let downloadedIconMaxSize: CGFloat = 128
static let defaultUNSReleaseVersion = "v0.7.6"
static let defaultInitials: String = "N/A"
static let appStoreAppId = "1544748602"
static let refreshDomainBadgesInterval: TimeInterval = 60 * 3 // 3 min
Expand Down