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-2097 Blockchains refactoring #608

Merged
merged 17 commits into from
Jul 16, 2024
30 changes: 30 additions & 0 deletions unstoppable-ios-app/SupportedTokensTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SupportedTokensTests.swift
// domains-manager-iosTests
//
// Created by Roman Medvid on 16.07.2024.
//

import XCTest
@testable import domains_manager_ios

final class SupportedTokensTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testUSDCMainnetValue() throws {
let bundler = Bundle.main
let filePath = bundler.url(forResource: "supported-tokens", withExtension: "json")!
let data = try! Data(contentsOf: filePath)
print(String(data: data, encoding: .utf8)!)
let tokensInfo = try! CryptoSender.SupportedToken.getContractArray()
let usdc = tokensInfo[.usdc]![.Ethereum]!.mainnet
XCTAssertEqual(usdc, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
}
}
12 changes: 12 additions & 0 deletions unstoppable-ios-app/domains-manager-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
299713CD28F6931E00743003 /* Function.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299713CC28F6931E00743003 /* Function.swift */; };
299713D228F6933F00743003 /* ABIEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299713D128F6933F00743003 /* ABIEncoder.swift */; };
299713D728F693F600743003 /* EIP712TypedData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299713D628F693F600743003 /* EIP712TypedData.swift */; };
29A42A572C4658CB00CAEA70 /* supported-tokens.json in Resources */ = {isa = PBXBuildFile; fileRef = 29A42A562C4658CB00CAEA70 /* supported-tokens.json */; };
29A42A582C4658CB00CAEA70 /* supported-tokens.json in Resources */ = {isa = PBXBuildFile; fileRef = 29A42A562C4658CB00CAEA70 /* supported-tokens.json */; };
29A42A592C4658CB00CAEA70 /* supported-tokens.json in Resources */ = {isa = PBXBuildFile; fileRef = 29A42A562C4658CB00CAEA70 /* supported-tokens.json */; };
29A42A5B2C46727200CAEA70 /* SupportedTokensTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A42A5A2C46727200CAEA70 /* SupportedTokensTests.swift */; };
29AA6AA42BAAE9F500D24FB5 /* ConcreteCryptoSenderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29AA6AA32BAAE9F500D24FB5 /* ConcreteCryptoSenderProtocol.swift */; };
29AA6AA82BAC389D00D24FB5 /* CryptoSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29AA6AA72BAC389D00D24FB5 /* CryptoSender.swift */; };
29AEA04B292F7D60003BB5B4 /* SecurePersistedStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29AEA04A292F7D60003BB5B4 /* SecurePersistedStorage.swift */; };
Expand Down Expand Up @@ -2674,6 +2678,8 @@
299713CC28F6931E00743003 /* Function.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Function.swift; sourceTree = "<group>"; };
299713D128F6933F00743003 /* ABIEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ABIEncoder.swift; sourceTree = "<group>"; };
299713D628F693F600743003 /* EIP712TypedData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EIP712TypedData.swift; sourceTree = "<group>"; };
29A42A562C4658CB00CAEA70 /* supported-tokens.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "supported-tokens.json"; sourceTree = "<group>"; };
29A42A5A2C46727200CAEA70 /* SupportedTokensTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportedTokensTests.swift; sourceTree = "<group>"; };
29AA6AA32BAAE9F500D24FB5 /* ConcreteCryptoSenderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcreteCryptoSenderProtocol.swift; sourceTree = "<group>"; };
29AA6AA72BAC389D00D24FB5 /* CryptoSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptoSender.swift; sourceTree = "<group>"; };
29AEA04A292F7D60003BB5B4 /* SecurePersistedStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurePersistedStorage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4306,6 +4312,7 @@
306486742527253700388026 = {
isa = PBXGroup;
children = (
29A42A5A2C46727200CAEA70 /* SupportedTokensTests.swift */,
C60C59B32B47FACC00A2522C /* unstoppable-preview.entitlements */,
304C928D25752625007A9F01 /* apple-app-site-association */,
3064867F2527253700388026 /* domains-manager-ios */,
Expand Down Expand Up @@ -4893,6 +4900,7 @@
C683EB542B3B0BFE0026CA41 /* hot-suggestions.json */,
303CB4B5273A894F0064495D /* resolver-keys.json */,
30A280362714217100FD3759 /* wallets-registry.json */,
29A42A562C4658CB00CAEA70 /* supported-tokens.json */,
);
path = Data;
sourceTree = "<group>";
Expand Down Expand Up @@ -8713,6 +8721,7 @@
C6FEA91B2BEB700F004FD740 /* SettingsCollectionViewCell.xib in Resources */,
C6D0F43C283F7DFF00444921 /* MintDomainsConfigurationSelectionCell.xib in Resources */,
C6C57C582869DC810093FD8C /* WallpaperDomainImagePreviewView.xib in Resources */,
29A42A572C4658CB00CAEA70 /* supported-tokens.json in Resources */,
C683EB552B3B0BFE0026CA41 /* hot-suggestions.json in Resources */,
C664B6642914FAC100A76154 /* DomainProfileNoSocialsCell.xib in Resources */,
C6AD181328D319BF0008A479 /* CollectionViewShowHideCell.xib in Resources */,
Expand Down Expand Up @@ -8755,6 +8764,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
29A42A582C4658CB00CAEA70 /* supported-tokens.json in Resources */,
C67B6D5E2AE7F8FB00F74B0B /* Media.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -8803,6 +8813,7 @@
C683EB562B3B0BFE0026CA41 /* hot-suggestions.json in Resources */,
C6D646992B1ED14E00D724AC /* ManageDomainTopInfoCell.xib in Resources */,
C6D646B62B1ED18F00D724AC /* WallpaperDomainImagePreviewView.xib in Resources */,
29A42A592C4658CB00CAEA70 /* supported-tokens.json in Resources */,
C6C8F8DB2B21836400A9834D /* ParkedDomainsFoundViewController.xib in Resources */,
C6C8F91B2B2183A400A9834D /* LaunchViewController.xib in Resources */,
C6D647752B1EE08900D724AC /* DomainTransactionInProgressCell.xib in Resources */,
Expand Down Expand Up @@ -10137,6 +10148,7 @@
C66FFD052B01E2EE00988A6F /* CoreDataMessagingStorageServiceTests.swift in Sources */,
C617CFA82B9EDA2F00663516 /* TestableWalletNFTsService.swift in Sources */,
C60610E829A7469A005DC0D5 /* WCRequestsHandlingServiceTests.swift in Sources */,
29A42A5B2C46727200CAEA70 /* SupportedTokensTests.swift in Sources */,
C6DF9875290F83020098733A /* UnsConfigManagerTests.swift in Sources */,
C6DF986B290F83020098733A /* WalletAutonamingTests.swift in Sources */,
C6DF9871290F83020098733A /* ResolutionInitTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct BalanceTokenUIDescription: Hashable, Identifiable {
private(set) var isSkeleton: Bool = false

var isEssentialTokenException: Bool {
chain == BlockchainType.Matic.rawValue && symbol == CryptoSender.SupportedToken.usdc.rawValue
chain == BlockchainType.Matic.shortCode && symbol == CryptoSender.SupportedToken.usdc.rawValue
}

struct ParentDetails: Hashable {
Expand Down Expand Up @@ -112,7 +112,7 @@ struct BalanceTokenUIDescription: Hashable, Identifiable {
}

var blockchainType: BlockchainType? {
BlockchainType(rawValue: chain)
BlockchainType(chainShortCode: chain)
}
}

Expand Down Expand Up @@ -184,7 +184,12 @@ extension BalanceTokenUIDescription {
extension BalanceTokenUIDescription {
static func createSkeletonEntity() -> BalanceTokenUIDescription {
var token = BalanceTokenUIDescription(address: "",
chain: "ETH", symbol: "000", name: "0000000000000000", balance: 10000, balanceUsd: 10000, marketUsd: 1)
chain: BlockchainType.Ethereum.shortCode,
symbol: "000",
name: "0000000000000000",
balance: 10000,
balanceUsd: 10000,
marketUsd: 1)
token.isSkeleton = true
return token
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension DomainItem {
init(jsonResponse: NetworkService.DomainResponse) {
self.name = jsonResponse.name
self.ownerWallet = jsonResponse.ownerAddress
self.blockchain = try? BlockchainType.getType(abbreviation: jsonResponse.blockchain)
self.blockchain = try? BlockchainType.resolve(shortCode: jsonResponse.blockchain)
}
}

Expand Down Expand Up @@ -128,8 +128,9 @@ extension DomainItem {
func doesRequirePayment() -> Bool {
switch self.getBlockchainType() {
case .Ethereum: return true
case .Matic: return false
case .Base: return false

case .Matic, .Base, .Bitcoin, .Solana:
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension MockEntitiesFabric {
}

static func createPublicDomainMetadata(domain: String, walletAddress: String) -> PublicDomainProfileMetaData {
PublicDomainProfileMetaData(domain: domain, blockchain: "MATIC", networkId: BlockchainType.Matic.supportedChainId(env: .testnet), owner: walletAddress)
PublicDomainProfileMetaData(domain: domain, blockchain: "MATIC", networkId: BlockchainType.Matic.resolveChainId(env: .testnet), owner: walletAddress)
}

static func createPublicProfileAttributes(displayName: String = "Oleg Kuplin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ extension MockEntitiesFabric {

static func createMockTxsResponses(canLoadMore: Bool = false,
amount: Int = 20) -> [WalletTransactionsPerChainResponse] {
[createMockTxsResponse(chain: "ETH",
[createMockTxsResponse(chain: BlockchainType.Ethereum.shortCode,
canLoadMore: canLoadMore,
amount: amount),
createMockTxsResponse(chain: "MATIC",
createMockTxsResponse(chain: BlockchainType.Matic.shortCode,
canLoadMore: canLoadMore,
amount: amount),
createMockTxsResponse(chain: "BASE",
createMockTxsResponse(chain: BlockchainType.Base.shortCode,
canLoadMore: canLoadMore,
amount: amount)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,32 +297,32 @@ extension MockEntitiesFabric {

static func mockUSDTToken(parent: BlockchainType = .Ethereum) -> BalanceTokenUIDescription {
BalanceTokenUIDescription(address: "0x000",
chain: "ETH",
chain: BlockchainType.Ethereum.shortCode,
symbol: "USDT",
name: "USDT",
balance: 10,
balanceUsd: 10,
marketUsd: 1,
parent: .init(symbol: parent.rawValue,
parent: .init(symbol: parent.shortCode,
balance: 0,
marketUsd: 3900))
}

static func mockEthToken() -> BalanceTokenUIDescription {
BalanceTokenUIDescription(address: "0x000",
chain: "ETH",
chain: BlockchainType.Ethereum.shortCode,
symbol: "ETH",
name: "Ethereum",
name: BlockchainType.Ethereum.fullName,
balance: 1,
balanceUsd: 3900.34,
marketUsd: 3900.34)
}

static func mockMaticToken() -> BalanceTokenUIDescription {
BalanceTokenUIDescription(address: "0x000",
chain: "MATIC",
chain: BlockchainType.Matic.shortCode,
symbol: "MATIC",
name: "Polygon",
name: BlockchainType.Matic.fullName,
balance: 1,
balanceUsd: 1,
marketUsd: 1.02)
Expand Down
Loading