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-2060 Send crypto on Base chain #579

Merged
merged 13 commits into from
Jul 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ extension DomainItem: APIRepresentable {

// Decision methods based on DomainItem values

extension DomainItem {
/// This method checks whether or not TxCost that came from backend is valid.
/// Domains of ZNS should always have TxCost == nil
/// Domains from UNS should have TxCost as value only when the backend is real
/// - Parameters:
/// - service: NamingService
/// - txCost: Optional TxCost that needs to be validated
/// - Returns: validation
static func isValidTxCost(blockchain: BlockchainType, txCost: NetworkService.TxCost?) -> Bool {
switch blockchain {
case .Ethereum: return txCost != nil
case .Matic: return txCost == nil
}
}
}

extension DomainItem {
public func ethSign(message: String) async throws -> String {
guard let ownerAddress = self.ownerWallet,
Expand Down Expand Up @@ -145,6 +129,7 @@ extension DomainItem {
switch self.getBlockchainType() {
case .Ethereum: return true
case .Matic: return false
case .Base: return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
enum BlockchainType: String, CaseIterable, Codable, Hashable {
case Ethereum = "ETH"
case Matic = "MATIC"
case Base = "BASE"

static let cases = Self.allCases
static func getType(abbreviation: String?) throws -> Self {
Expand All @@ -21,14 +22,14 @@ enum BlockchainType: String, CaseIterable, Codable, Hashable {
return result
}

static let supportedCases: [BlockchainType] = [.Ethereum, .Matic]

var icon: UIImage {
switch self {
case .Ethereum:
return UIImage(named: String.BlockChainIcons.ethereum.rawValue)!
case .Matic:
return UIImage(named: String.BlockChainIcons.matic.rawValue)!
case .Base:
return UIImage(named: String.BlockChainIcons.base.rawValue)!
}
}

Expand All @@ -38,6 +39,8 @@ enum BlockchainType: String, CaseIterable, Codable, Hashable {
return "Ethereum"
case .Matic:
return "Polygon"
case .Base:
return "Base"
}
}

Expand All @@ -47,6 +50,9 @@ enum BlockchainType: String, CaseIterable, Codable, Hashable {
return isTestNet ? BlockchainNetwork.ethSepolia.id : BlockchainNetwork.ethMainnet.id // Sepolia or Mainnet
case .Matic:
return isTestNet ? BlockchainNetwork.polygonAmoy.id : BlockchainNetwork.polygonMainnet.id // Amoy or Polygon
case .Base:
return isTestNet ? BlockchainNetwork.baseSepolia.id : BlockchainNetwork.baseMainnet.id // Base Sepolia or Base Mainnet

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ struct UDWallet: Codable, @unchecked Sendable {
return UDWallet(aliasName: aliasName,
walletType: .importedUnverified,
ethWallet: wallet)
case .Base: Debugger.printWarning("Attempt to create unverified wallet based on Base chain: failed")
return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,8 @@ extension String {

enum BlockChainIcons: String {
case ethereum = "smallEthereum"
case zilliqa = "smallZilliqa"
case matic = "smallMatic"
case base = "BASE"
}

func isMatchingRegexPattern(_ regexPattern: String) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extension UIImage {
static let searchIcon = UIImage(named: "searchIcon")!
static let ethBGLarge = UIImage(named: "ethBGLarge")!
static let maticBGLarge = UIImage(named: "maticBGLarge")!
static let baseBGLarge = UIImage(named: "BASE")!
static let baseBGSmall = UIImage(named: "BASE")!
static let ethBGSmall = UIImage(named: "ethBGSmall")!
static let maticBGSmall = UIImage(named: "maticBGSmall")!
static let checkBadge = UIImage(named: "checkBadge")!
Expand Down Expand Up @@ -241,6 +243,8 @@ extension UIImage {
return .ethBGLarge
case .Matic:
return .maticBGLarge
case .Base:
return .baseBGLarge
}
}

Expand All @@ -250,6 +254,8 @@ extension UIImage {
return .ethBGSmall
case .Matic:
return .maticBGSmall
case .Base:
return .baseBGSmall
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extension CryptoSender {
case bnb = "BNB"
case weth = "WETH"

static let array: [CryptoSender.SupportedToken :
static let contractArray: [CryptoSender.SupportedToken :
[BlockchainType : (mainnet: String,
testnet: String?,
decimals: UInt8)]] =
Expand Down Expand Up @@ -183,7 +183,7 @@ extension CryptoSender {
}

func getContractAddress(for chain: ChainSpec) throws -> HexAddress {
guard let addresses = Self.array[self]?[chain.blockchainType] else {
guard let addresses = Self.contractArray[self]?[chain.blockchainType] else {
throw CryptoSender.Error.tokenNotSupportedOnChain
}
guard let contract = chain.env == .mainnet ? addresses.mainnet : addresses.testnet else {
Expand All @@ -193,7 +193,7 @@ extension CryptoSender {
}

func getContractDecimals(for chainType: BlockchainType) throws -> UInt8 {
guard let decimals = Self.array[self]?[chainType]?.decimals else {
guard let decimals = Self.contractArray[self]?[chainType]?.decimals else {
throw CryptoSender.Error.decimalsNotIdentified
}
return decimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ struct NativeCoinCryptoSender: ConcreteCryptoSenderProtocol, EVMCryptoSender {
func canSendCrypto(token: CryptoSender.SupportedToken, chain: ChainSpec) -> Bool {
// only native tokens supported
return (token == CryptoSender.SupportedToken.eth && chain.blockchainType == .Ethereum) ||
(token == CryptoSender.SupportedToken.matic && chain.blockchainType == .Matic)
(token == CryptoSender.SupportedToken.matic && chain.blockchainType == .Matic) ||
(token == CryptoSender.SupportedToken.eth && chain.blockchainType == .Base)
}

internal func createSendTransaction(crypto: CryptoSendingSpec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct CryptoSenderChainDescription {
}

func getChain() throws -> ChainSpec {
guard let chainType = BlockchainType(rawValue: self.chain) else {
guard let chainType = BlockchainType(rawValue: self.chain.uppercased()) else {
throw CryptoSender.Error.sendingNotSupported
}
let chain = ChainSpec(blockchainType: chainType, env: self.env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private extension SelectCryptoAssetToSendView {
}

switch token.blockchainType {
case .Ethereum, .Matic:
case .Ethereum, .Matic, .Base:
return BalanceTokenToSend(token: token, address: receiver.walletAddress)
case .none:
/// As we don't currently support Base chain but MPC does
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private extension ConnectedAppsListViewPresenter {
}

let blockchainTypes = NonEmptyArray(items: blockchainTypesArray)! // safe after the previous lines
let supportedNetworks = BlockchainType.supportedCases.map({ $0.fullName })
let supportedNetworks = WalletConnectServiceV2.supportedNetworks.map({ $0.fullName })

let actions: [ConnectedAppsListViewController.ItemAction] = [.networksInfo(networks: supportedNetworks),
.disconnect]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ extension QRScannerViewPresenter: WalletConnectServiceConnectionListener {
// MARK: - Private functions
private extension QRScannerViewPresenter {
func setBlockchainTypePicker() {
view?.setBlockchainTypeSelectionWith(availableTypes: BlockchainType.supportedCases, selectedType: blockchainType)
view?.setBlockchainTypeSelectionWith(availableTypes: WalletConnectServiceV2.supportedNetworks, selectedType: blockchainType)
}

func setSelected(wallet: WalletEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ extension NetworkService {

switch blockchain {
case .Ethereum, .Matic: return .UNS
case .Base: return nil
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ extension PullUpViewService: PullUpViewServiceProtocol {
case .Matic:
description = String.Constants.mintedOnPolygonDescription.localized()
selectionViewHeight = 304
case .Base: Debugger.printFailure("Minting cannot be on Base", critical: true)
description = "Base should not be used for minting"
selectionViewHeight = 304

}
let selectionView = PullUpSelectionView(configuration: .init(title: .text(chain.fullName),
contentAlignment: .center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ extension WalletConnectServiceV2 {

// Client V2 part
extension WalletConnectServiceV2 {

static let supportedNetworks: [BlockchainType] = [.Ethereum, .Matic]

// namespaces required from wallets by UD app as Client
var requiredNamespaces: [String: ProposalNamespace] { [
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ enum BlockchainNetwork: Int, CaseIterable {
case polygonMainnet = 137
case polygonAmoy = 80002

case baseMainnet = 8453
case baseSepolia = 84532

var id: Int { rawValue }

var name: String {
Expand All @@ -202,6 +205,10 @@ enum BlockchainNetwork: Int, CaseIterable {
return "polygon-mainnet"
case .polygonAmoy:
return "polygon-amoy"
case .baseMainnet:
return "base-mainnet"
case .baseSepolia:
return "base-sepolia"
}
}

Expand All @@ -215,6 +222,10 @@ enum BlockchainNetwork: Int, CaseIterable {
return "Polygon"
case .polygonAmoy:
return "Polygon: Amoy"
case .baseMainnet:
return "Base: Mainnet"
case .baseSepolia:
return "Base: Sepolia"
}
}
}
Expand Down