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

feat(uphold): align Uphold and Coinbase portals #605

Merged
merged 10 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 33 additions & 75 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "icon.buy-dash.png",
"filename" : "buy.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon.buy-dash@2x.png",
"filename" : "buy@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon.buy-dash@3x.png",
"filename" : "buy@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "icon.buy-dash.png",
"filename" : "convert.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon.buy-dash@2x.png",
"filename" : "convert@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon.buy-dash@3x.png",
"filename" : "convert@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "icon.buy-dash.png",
"filename" : "sell.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon.buy-dash@2x.png",
"filename" : "sell@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon.buy-dash@3x.png",
"filename" : "sell@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@
{
"images" : [
{
"filename" : "integration.transfer.disabled.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "integration.transfer.disabled@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "integration.transfer.disabled@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "icon.convert-crypto.png",
"filename" : "transfer.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon.convert-crypto@2x.png",
"filename" : "transfer@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon.convert-crypto@3x.png",
"filename" : "transfer@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
21 changes: 21 additions & 0 deletions DashWallet/Sources/Models/Coinbase/Coinbase+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,34 @@ extension Coinbase {
enum GeneralFailureReason: LocalizedError {
case noActiveUser
case revokedToken
case noPaymentMethods

var errorDescription: String? {
switch self {
case .noActiveUser:
return NSLocalizedString("No active user", comment: "Coinbase")
case .revokedToken:
return NSLocalizedString("For your security, you have been signed out.", comment: "Coinbase")
case .noPaymentMethods:
return NSLocalizedString("Please add a payment method on Coinbase", comment: "Coinbase/Buy Dash")
}
}

var failureReason: String? {
switch self {
case .noPaymentMethods:
return NSLocalizedString("No payment methods found", comment: "Coinbase/Buy Dash")
default:
return ""
}
}

var recoverySuggestion: String? {
switch self {
case .noPaymentMethods:
return NSLocalizedString("Add", comment: "Coinbase/Buy Dash")
default:
return ""
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DashWallet/Sources/Models/URL Handling/DWURLActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN

//

@interface DWURLUpholdAction : DWURLAction
@interface DWURLIntegrationAction : DWURLAction

@property (nonatomic, strong) NSURL *url;

Expand Down
2 changes: 1 addition & 1 deletion DashWallet/Sources/Models/URL Handling/DWURLActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @implementation DWURLAction

//

@implementation DWURLUpholdAction
@implementation DWURLIntegrationAction
@end

//
Expand Down
2 changes: 1 addition & 1 deletion DashWallet/Sources/Models/URL Handling/DWURLParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ + (BOOL)canHandleURL:(NSURL *)url {

+ (nullable DWURLAction *)actionForURL:(NSURL *)url {
if ([url.absoluteString containsString:@"uphold"]) {
DWURLUpholdAction *action = [[DWURLUpholdAction alloc] init];
DWURLIntegrationAction *action = [[DWURLIntegrationAction alloc] init];
action.url = url;

return action;
Expand Down
583 changes: 0 additions & 583 deletions DashWallet/Sources/UI/Coinbase/Base.lproj/Coinbase.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension BaseViewController {
let vc = SuccessfulOperationStatusViewController.initiate(from: sb("OperationStatus"))
vc.closeHandler = { [weak self] in
guard let wSelf = self else { return }
guard let rootController = wSelf.navigationController?.controller(by: CoinbaseEntryPointViewController.self) else {
guard let rootController = wSelf.navigationController?.controller(by: IntegrationViewController.self) else {
wSelf.navigationController?.popToRootViewController(animated: true)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,82 +17,86 @@

import Foundation

// MARK: - CoinbaseEntryPointItem
// MARK: IntegrationEntryPointItem

enum CoinbaseEntryPointItem: CaseIterable {
case buyDash
case sellDash
case convertCrypto
case transferDash
}

extension CoinbaseEntryPointItem {
static let supportedCases: [CoinbaseEntryPointItem] = [.buyDash, .convertCrypto, .transferDash]
struct CoinbaseEntryPointItem: IntegrationEntryPointItem {
let type: IntegrationItemType
static let supportedCases = [.buyDash, .convertCrypto, .transferDash].map { CoinbaseEntryPointItem(type: $0) }

var title: String {
switch self {
case .buyDash:
return NSLocalizedString("Buy Dash", comment: "Coinbase Entry Point")
case .sellDash:
return NSLocalizedString("Sell Dash", comment: "Coinbase Entry Point")
case .convertCrypto:
return NSLocalizedString("Convert Crypto", comment: "Coinbase Entry Point")
case .transferDash:
return NSLocalizedString("Transfer Dash", comment: "Coinbase Entry Point")
}
}
var title: String { type.title }
var icon: String { type.icon }
var alwaysEnabled: Bool { false }
var hasAdditionalInfo: Bool { false }

var description: String {
switch self {
switch type {
case .buyDash:
return NSLocalizedString("Receive directly into Dash Wallet", comment: "Coinbase Entry Point")
case .sellDash:
return NSLocalizedString("Receive directly into Coinbase", comment: "Coinbase Entry Point")
case .convertCrypto:
return NSLocalizedString("Between Dash Wallet and Coinbase.", comment: "Coinbase Entry Point")
case .transferDash:
return NSLocalizedString("Between Dash Wallet and Coinbase.", comment: "Coinbase Entry Point")
}
}

var icon: String {
switch self {
case .buyDash:
return "buyCoinbase"
case .sellDash:
return "sellDash"
case .convertCrypto:
return "convertCrypto"
return NSLocalizedString("Between Dash Wallet and Coinbase", comment: "Coinbase Entry Point")
case .transferDash:
return "transferCoinbase"
return NSLocalizedString("Between Dash Wallet and Coinbase", comment: "Coinbase Entry Point")
}
}
}

// MARK: - CoinbaseEntryPointModel

final class CoinbaseEntryPointModel {
let items: [CoinbaseEntryPointItem] = CoinbaseEntryPointItem.supportedCases
final class CoinbaseEntryPointModel: BaseIntegrationModel {
override var items: [IntegrationEntryPointItem] {
CoinbaseEntryPointItem.supportedCases
}

var hasPaymentMethods = false

var userDidSignOut: (() -> ())?
var userDidChange: (() -> ())?

var balance: UInt64 {
guard let amount = Coinbase.shared.lastKnownBalance else { return 0 }

return amount
}

override var mainAmountString: String {
balance.formattedDashAmount
}

override var supplementaryAmountString: String {
let fiat: String

if let fiatAmount = try? CurrencyExchanger.shared.convertDash(amount: balance.dashAmount, to: App.fiatCurrency) {
fiat = NumberFormatter.fiatFormatter.string(from: fiatAmount as NSNumber)!
} else {
fiat = NSLocalizedString("Syncing...", comment: "Balance")
}

return fiat
}

override var balanceTitle: String {
NSLocalizedString("Dash balance on Coinbase", comment: "Coinbase Entry Point")
}

override var signInTitle: String {
NSLocalizedString("Link Uphold Account", comment: "Uphold Entry Point")
}

override var signOutTitle: String {
NSLocalizedString("Disconnect Coinbase Account", comment: "Coinbase Entry Point")
}

override var shouldPopOnLogout: Bool { true }

private var userDidChangeListenerHandle: UserDidChangeListenerHandle!
private var accountDidChangeHandle: AnyObject?

init() {
super.init(service: .coinbase)

userDidChangeListenerHandle = Coinbase.shared.addUserDidChangeListener { [weak self] user in
if user == nil {
self?.userDidSignOut?()
} else {
self?.isLoggedIn = user != nil

if user != nil {
self?.userDidChange?()
}
}
Expand All @@ -107,34 +111,35 @@ final class CoinbaseEntryPointModel {
}
}

public func signOut() {
override func logOut() {
Task {
try await Coinbase.shared.signOut()
}
}

override func validate(operation type: IntegrationItemType) -> LocalizedError? {
switch type {
case .buyDash:
return hasPaymentMethods ? nil : Coinbase.Error.GeneralFailureReason.noPaymentMethods
default:
return super.validate(operation: type)
}
}

override func handle(error: Swift.Error) {
super.handle(error: error)

if case Coinbase.Error.GeneralFailureReason.noPaymentMethods = error {
addPaymentMethod()
}
}

private func addPaymentMethod() {
UIApplication.shared.open(kCoinbaseAddPaymentMethodsURL)
}

deinit {
NotificationCenter.default.removeObserver(accountDidChangeHandle!)
Coinbase.shared.removeUserDidChangeListener(handle: userDidChangeListenerHandle)
}
}

// MARK: BalanceViewDataSource

extension CoinbaseEntryPointModel: BalanceViewDataSource {
var mainAmountString: String {
balance.formattedDashAmount
}

var supplementaryAmountString: String {
let fiat: String

if let fiatAmount = try? CurrencyExchanger.shared.convertDash(amount: balance.dashAmount, to: App.fiatCurrency) {
fiat = NumberFormatter.fiatFormatter.string(from: fiatAmount as NSNumber)!
} else {
fiat = NSLocalizedString("Syncing...", comment: "Balance")
}

return fiat
}
}
Loading