Skip to content

Commit

Permalink
MOB-1889 - Buy crypto (#443)
Browse files Browse the repository at this point in the history
* Extended pull up view with items list

* Added pull up selection for buying on the home screen

* Added Links to buy crypto to domain or wallet

* Created function to run buy crypto flow

* Open buy crypto page in SafariVC

* Updated buy crypto titles

* Remove timer to load search suggestions if failed or 0
  • Loading branch information
Oleg-Pecheneg authored Mar 15, 2024
1 parent 4d574fa commit b314012
Show file tree
Hide file tree
Showing 19 changed files with 381 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,8 @@
C6B435072A53F42400BC644B /* BaseDiffableCollectionViewControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B435062A53F42400BC644B /* BaseDiffableCollectionViewControllerProtocol.swift */; };
C6B5136228320707001E99B5 /* EnterBackupToRestoreWalletsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B5136128320707001E99B5 /* EnterBackupToRestoreWalletsPresenter.swift */; };
C6B5136828322EA1001E99B5 /* MainWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B5136728322EA1001E99B5 /* MainWindow.swift */; };
C6B540C12BA3F77200A41D42 /* ViewPullUpListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B540C02BA3F77200A41D42 /* ViewPullUpListItemView.swift */; };
C6B540C22BA3F77200A41D42 /* ViewPullUpListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B540C02BA3F77200A41D42 /* ViewPullUpListItemView.swift */; };
C6B659242B68E49500CA6A68 /* HomeWalletTokenNotMatchingRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B659232B68E49500CA6A68 /* HomeWalletTokenNotMatchingRowView.swift */; };
C6B659252B68E49500CA6A68 /* HomeWalletTokenNotMatchingRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B659232B68E49500CA6A68 /* HomeWalletTokenNotMatchingRowView.swift */; };
C6B65F502B54DA84006D1812 /* HomeWalletViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B65F4F2B54DA84006D1812 /* HomeWalletViewModel.swift */; };
Expand Down Expand Up @@ -3451,6 +3453,7 @@
C6B435062A53F42400BC644B /* BaseDiffableCollectionViewControllerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDiffableCollectionViewControllerProtocol.swift; sourceTree = "<group>"; };
C6B5136128320707001E99B5 /* EnterBackupToRestoreWalletsPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterBackupToRestoreWalletsPresenter.swift; sourceTree = "<group>"; };
C6B5136728322EA1001E99B5 /* MainWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindow.swift; sourceTree = "<group>"; };
C6B540C02BA3F77200A41D42 /* ViewPullUpListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPullUpListItemView.swift; sourceTree = "<group>"; };
C6B659232B68E49500CA6A68 /* HomeWalletTokenNotMatchingRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWalletTokenNotMatchingRowView.swift; sourceTree = "<group>"; };
C6B65F4F2B54DA84006D1812 /* HomeWalletViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWalletViewModel.swift; sourceTree = "<group>"; };
C6B65F552B54E42C006D1812 /* HomeWalletTokenRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWalletTokenRowView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5616,6 +5619,7 @@
isa = PBXGroup;
children = (
C6D646442B1E084C00D724AC /* ViewPullUp.swift */,
C6B540C02BA3F77200A41D42 /* ViewPullUpListItemView.swift */,
C64F8DFD2B60F2140075D37F /* ViewPullUpDefaultConfiguration.swift */,
C64F8E032B60F4AF0075D37F /* ViewPullUpCustomContentConfiguration.swift */,
C64F8E002B60F2590075D37F /* ViewPullUpConfigurationType.swift */,
Expand Down Expand Up @@ -8650,6 +8654,7 @@
C6C995C2289D313D00367362 /* CNavigationControllerDefaultNavigationBarPopAnimation.swift in Sources */,
C6FBCAA82B91D00100BA39DF /* HomeExploreUserWalletDomainsView.swift in Sources */,
C6B6B043296FF7D600D4E30F /* DomainsSortOrderStorage.swift in Sources */,
C6B540C12BA3F77200A41D42 /* ViewPullUpListItemView.swift in Sources */,
C617FD992B58BC2900B93433 /* WalletEntitiesStorage.swift in Sources */,
C692C32A282E4C6500C31393 /* SecuritySettingsAuthSelectionCell.swift in Sources */,
C635195128D0441000FC6AF8 /* SetupWalletsReverseResolutionPresenter.swift in Sources */,
Expand Down Expand Up @@ -9821,6 +9826,7 @@
C6D646AC2B1ED16900D724AC /* DomainProfileTutorialViewController.swift in Sources */,
C6D6467A2B1ED12100D724AC /* DomainProfileGenericChangeDescription.swift in Sources */,
C630E4BA2B7F5BAC008F3269 /* Padding.swift in Sources */,
C6B540C22BA3F77200A41D42 /* ViewPullUpListItemView.swift in Sources */,
C6D647192B1ED84500D724AC /* CollectionReusableRoundedBackgroundWhiteWithAlpha.swift in Sources */,
C6C8F8372B217E9600A9834D /* BaseRecoveryPhrasePresenter.swift in Sources */,
C6D646612B1ED11400D724AC /* DomainProfileSectionHeader.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension String {
case communitiesInfo
case setupApplePayInstruction
case unstoppableDomainSearch(searchKey: String)
case buyCryptoToDomain(DomainName), buyCryptoToWallet(HexAddress)

var urlString: String {
switch self {
Expand Down Expand Up @@ -98,7 +99,11 @@ extension String {
case .direct(let url):
return url.absoluteString
case .unstoppableDomainSearch(let searchKey):
return "https://\(NetworkConfig.websiteHost)/search?searchTerm=\(searchKey)&searchRef=homepage&tab=relevant"
return "\(NetworkConfig.websiteBaseUrl)/search?searchTerm=\(searchKey)&searchRef=homepage&tab=relevant"
case .buyCryptoToDomain(let domainName):
return "\(NetworkConfig.buyCryptoUrl)?domain=\(domainName)"
case .buyCryptoToWallet(let walletAddress):
return "\(NetworkConfig.buyCryptoUrl)?address=\(walletAddress)"
}
}

Expand Down Expand Up @@ -1140,6 +1145,12 @@ extension String {
static let profileSuggestionReasonFarcasterFollows = "PROFILE_SUGGESTION_REASON_FARCASTER_FOLLOWS"
static let profileSuggestionReasonFarcasterMutual = "PROFILE_SUGGESTION_REASON_FARCASTER_MUTUAL"
static let searchProfiles = "SEARCH_PROFILES"

static let selectPullUpBuyDomainsTitle = "SELECT_PULL_UP_BUY_DOMAINS_TITLE"
static let selectPullUpBuyTokensTitle = "SELECT_PULL_UP_BUY_TOKENS_TITLE"
static let selectPullUpBuyDomainsSubtitle = "SELECT_PULL_UP_BUY_DOMAINS_SUBTITLE"
static let selectPullUpBuyTokensSubtitle = "SELECT_PULL_UP_BUY_TOKENS_SUBTITLE"

}

enum BlockChainIcons: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ extension UIImage {
static let filterIcon = UIImage(named: "filterIcon")!
static let qrBarCodeIcon = UIImage(named: "qrBarCodeIcon")!
static let walletAddressesIcon = UIImage(named: "walletAddressesIcon")!
static let globeRotated = UIImage(named: "globeRotated")!
static let verticalLines = UIImage(named: "verticalLines")!

static let twitterIcon24 = UIImage(named: "twitterIcon24")!
static let discordIcon24 = UIImage(named: "discordIcon24")!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,14 @@ extension UIViewController {
return presentedViewController?.childOf(type: type)
}
}

import SafariServices

extension UIViewController {
func openLinkInSafari(_ link: String.Links) {
guard let url = link.url else { return }

let safariVC = SFSafariViewController(url: url)
present(safariVC, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ extension HomeTabRouter {
}))
}
}

func runBuyCryptoFlowTo(wallet: WalletEntity) {
Task {
await showHomeScreenList()
guard let topVC else { return }

let link: String.Links
if let rrDomain = wallet.rrDomain {
link = .buyCryptoToDomain(rrDomain.name)
} else {
link = .buyCryptoToWallet(wallet.address)
}

topVC.openLinkInSafari(link)
}
}

func primaryDomainMinted(_ domain: DomainDisplayInfo) async {
if let mintingNav {
Expand Down Expand Up @@ -119,7 +135,7 @@ extension HomeTabRouter {
tabViewSelection = .wallets
}
await askToFinishSetupPurchasedProfileIfNeeded(domains: wallet.domains)
guard let topVC = appContext.coreAppCoordinator.topVC else { return }
guard let topVC else { return }


switch domain.usageType {
Expand Down Expand Up @@ -184,10 +200,9 @@ extension HomeTabRouter {
Task { @MainActor in
let domains = appContext.walletsDataService.wallets.combinedDomains()

let topPresentedViewController = appContext.coreAppCoordinator.topVC
if let mintingNav {
mintingNav.setMode(mode)
} else if let _ = topPresentedViewController as? AddWalletNavigationController {
} else if let _ = topVC as? AddWalletNavigationController {
// MARK: - Ignore minting request when add/import/connect wallet
} else if resolvingPrimaryDomainWallet == nil {
await popToRootAndWait()
Expand Down Expand Up @@ -378,7 +393,7 @@ extension HomeTabRouter: PublicProfileViewDelegate {

func showDomainMintingInProgress(_ domain: DomainDisplayInfo) {
guard domain.isMinting,
let topVC = appContext.coreAppCoordinator.topVC else { return }
let topVC else { return }

let mintingDomains = MintingDomainsStorage.retrieveMintingDomains()

Expand All @@ -392,7 +407,7 @@ extension HomeTabRouter: PublicProfileViewDelegate {
}

func showDomainTransferringInProgress(_ domain: DomainDisplayInfo) {
guard let topVC = appContext.coreAppCoordinator.topVC else { return }
guard let topVC else { return }

UDRouter().showTransferInProgressScreen(domain: domain, transferDomainFlowManager: nil, in: topVC)
}
Expand All @@ -415,16 +430,16 @@ private extension HomeTabRouter {
}

func isMintingAvailable() async -> Bool {
guard let topPresentedViewController = appContext.coreAppCoordinator.topVC else { return false }
guard let topVC else { return false }

guard appContext.networkReachabilityService?.isReachable == true else {
await appContext.pullUpViewService.showYouAreOfflinePullUp(in: topPresentedViewController,
await appContext.pullUpViewService.showYouAreOfflinePullUp(in: topVC,
unavailableFeature: .minting)
return false
}

guard User.instance.getAppVersionInfo().mintingIsEnabled else {
await appContext.pullUpViewService.showMintingNotAvailablePullUp(in: topPresentedViewController)
await appContext.pullUpViewService.showMintingNotAvailablePullUp(in: topVC)
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,40 @@ extension HomeWalletView {
}
}
}

extension HomeWalletView {
enum BuyOptions: String, CaseIterable, PullUpCollectionViewCellItem {
case domains, crypto

var title: String {
switch self {
case .domains:
String.Constants.selectPullUpBuyDomainsTitle.localized()
case .crypto:
String.Constants.selectPullUpBuyTokensTitle.localized()
}
}

var subtitle: String? {
switch self {
case .domains:
String.Constants.selectPullUpBuyDomainsSubtitle.localized()
case .crypto:
String.Constants.selectPullUpBuyTokensSubtitle.localized()
}
}

var disclosureIndicatorStyle: PullUpDisclosureIndicatorStyle { .right }

var icon: UIImage {
switch self {
case .domains:
return .globeRotated
case .crypto:
return .verticalLines
}
}

var analyticsName: String { rawValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,24 @@ extension HomeWalletView {
}))
}
case .buy:
router.runPurchaseFlow()
router.pullUp = .default(.homeWalletBuySelectionPullUp(selectionCallback: { [weak self] buyOption in
self?.router.pullUp = nil
self?.didSelectBuyOption(buyOption)
}))
case .more:
return
}
}

func didSelectBuyOption(_ buyOption: HomeWalletView.BuyOptions) {
switch buyOption {
case .domains:
router.runPurchaseFlow()
case .crypto:
router.runBuyCryptoFlowTo(wallet: selectedWallet)
}
}

func didSelectDomain(_ domain: DomainDisplayInfo) {
showProfile(of: domain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,12 @@ private extension PurchaseSearchDomainsView {
func loadSuggestions() {
guard suggestions.isEmpty else { return }

func waitAndTryAgain() {
Task {
await Task.sleep(seconds: 5)
loadSuggestions()
}
}

Task {
do {
let suggestions = try await purchaseDomainsService.getDomainsSuggestions(hint: nil)
if suggestions.isEmpty {
Debugger.printFailure("Did load 0 suggestions")
waitAndTryAgain()
}
self.suggestions = suggestions
} catch {
Debugger.printFailure("Failed to load suggestions")
waitAndTryAgain()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ struct NetworkConfig {
return "unstoppabledomains.com"
}
}
static var websiteBaseUrl: String {
"https://\(Self.websiteHost)"
}

static var buyCryptoUrl: String {
websiteBaseUrl + "/fiat-ramps"
}

static var baseDomainProfileUrl: String {
let isTestnetUsed = User.instance.getSettings().isTestnetUsed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ extension Analytics {
case finishProfileForPurchasedDomains, failedToFinishProfileForPurchasedDomains
case searchPurchaseDomainNotSupported
case createYourProfile
case homeWalletBuyOptions

// Disabled
case walletTransactionsSelection, copyWalletAddressSelection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "globeRotated.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "verticalLines.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1045,3 +1045,8 @@ More tabs are coming in the next updates.";
"PROFILE_SUGGESTION_REASON_FARCASTER_FOLLOWS" = "Social follow on Farcaster";
"PROFILE_SUGGESTION_REASON_FARCASTER_MUTUAL" = "Both users follow each other on Farcaster";
"SEARCH_PROFILES" = "Search profiles";

"SELECT_PULL_UP_BUY_DOMAINS_TITLE" = "Buy domains";
"SELECT_PULL_UP_BUY_TOKENS_TITLE" = "Buy Crypto";
"SELECT_PULL_UP_BUY_DOMAINS_SUBTITLE" = "Find and acquire new domain names";
"SELECT_PULL_UP_BUY_TOKENS_SUBTITLE" = "With Apple Pay or card";
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ extension Image {
static let exploreIcon = Image("exploreIcon")
static let globeBold = Image("globeBold")
static let searchClearIcon = Image("searchClearIcon")

static let globeRotated = Image("globeRotated")
static let verticalLines = Image("verticalLines")

static let cryptoFaceIcon = Image("cryptoFaceIcon")
static let cryptoPOAPIcon = Image("cryptoPOAPIcon")
static let cryptoTransactionIcon = Image("cryptoTransactionIcon")
Expand Down
Loading

0 comments on commit b314012

Please sign in to comment.