Skip to content

Commit

Permalink
MOB-2060 Send crypto on Base chain (#579)
Browse files Browse the repository at this point in the history
* introduced case .Base

* removed wrong token

* "can send" eth on base -- enabled

* sending on Base works

let sender = try! CryptoSender(wallet: udWallet)
let chainDesc = CryptoSenderChainDescription.init(symbol: "ETH", chain: "Base", env: .mainnet)
 let hash = try await sender.sendCrypto(dataToSend: .init(chainDesc: chainDesc,
                                                                                amount: 0.0003,
                                                                                txSpeed: .normal,
                                                                                toAddress: "0x94b420da794c1a8f45b70581ae015e6bd1957233"))

* support Base testnet (sepolia)

* removed isValidTxCost() completely

* refactored supportedNetworks

* added constant name for Base icon. removed Zilliqa icon

* Logged attempt to create a Base-based wallet

* added Base icons

* added cases

* removed dead code
  • Loading branch information
rommex authored Jul 8, 2024
1 parent f41f7bf commit 211ebdc
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 51 deletions.
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 @@ -23,6 +23,8 @@ extension BlockchainType {
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 @@ -32,6 +34,8 @@ extension BlockchainType {
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 All @@ -45,6 +49,8 @@ extension BlockchainType {
.ethereumIcon
case .Matic:
.polygonIcon
case .Base:
.baseIcon
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKit
enum BlockchainType: String, CaseIterable, Codable, Hashable {
case Ethereum = "ETH"
case Matic = "MATIC"
case Base = "BASE"

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

enum InitError: Error {
case invalidBlockchainAbbreviation
Expand All @@ -24,6 +24,8 @@ enum BlockchainType: String, CaseIterable, Codable, Hashable {
return "Ethereum"
case .Matic:
return "Polygon"
case .Base:
return "Base"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,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 @@ -49,6 +49,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 @@ -244,6 +246,8 @@ extension UIImage {
return .ethBGLarge
case .Matic:
return .maticBGLarge
case .Base:
return .baseBGLarge
}
}

Expand All @@ -253,6 +257,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,8 +83,10 @@ private extension SelectCryptoAssetToSendView {
}

switch token.blockchainType {
case .Ethereum, .Matic:
guard receiver.regexPattern == .ETH else { return nil }
case .Ethereum, .Matic, .Base:
guard receiver.regexPattern == .ETH else {
Debugger.printFailure("Wrong regex pattern: \(receiver.regexPattern) for chain: \(String(describing: token.blockchainType?.fullName))")
return nil }
return BalanceTokenToSend(token: token, address: receiver.walletAddress)
case .none:
if token.symbol == receiver.regexPattern.rawValue,
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 @@ -164,7 +164,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 @@ -375,6 +375,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 @@ -1103,7 +1103,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 @@ -189,6 +189,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 @@ -201,6 +204,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 @@ -214,6 +221,10 @@ enum BlockchainNetwork: Int, CaseIterable {
return "Polygon"
case .polygonAmoy:
return "Polygon: Amoy"
case .baseMainnet:
return "Base: Mainnet"
case .baseSepolia:
return "Base: Sepolia"
}
}

Expand All @@ -223,6 +234,8 @@ enum BlockchainNetwork: Int, CaseIterable {
return .Ethereum
case .polygonMainnet, .polygonAmoy:
return .Matic
case .baseMainnet, .baseSepolia:
return .Base
}
}
}
Expand Down

0 comments on commit 211ebdc

Please sign in to comment.