Skip to content

Commit

Permalink
Merge receive screen with cex-deposit.
Browse files Browse the repository at this point in the history
Revert balance cells with buttons.
Fix some UI bugs
  • Loading branch information
ant013 committed Aug 14, 2023
1 parent bb36937 commit a65babf
Show file tree
Hide file tree
Showing 40 changed files with 920 additions and 1,120 deletions.
100 changes: 44 additions & 56 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extension TokenType {

var description: String {
switch self {
case .derived(let derivation): return derivation.mnemonicDerivation.addressType
case .addressType(let type): return type.bitcoinCashCoinType.description
case .derived(let derivation): return derivation.mnemonicDerivation.addressType + derivation.mnemonicDerivation.recommended
case .addressType(let type): return type.bitcoinCashCoinType.description + type.bitcoinCashCoinType.recommended
default: return ""
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ enum BitcoinCashCoinType: String, CaseIterable {
}
}

var recommended: String {
self == Self.default ? "blockchain_type.recommended".localized : ""
}

}

extension TokenType.AddressType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enum MnemonicDerivation: String, CaseIterable {
}
}

var recommended: String {
self == Self.default ? "blockchain_type.recommended".localized : ""
}

}

extension Purpose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ struct CexDepositModule {
}

let service = CexDepositService(cexAsset: cexAsset, network: network, provider: cexAccount.depositProvider)
let viewModel = CexDepositViewModel(service: service)
return CexDepositViewController(viewModel: viewModel)
let viewItemFactory = CexDepositViewItemFactory()
let viewModel = ReceiveAddressViewModel(service: service, viewItemFactory: viewItemFactory)

return ReceiveAddressViewController(viewModel: viewModel)
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import Combine
import Foundation
import HsExtensions

class CexDepositService {
typealias ServiceItem = CexDepositService.Item

let cexAsset: CexAsset
let network: CexDepositNetwork?
private let provider: ICexDepositProvider
private var tasks = Set<AnyTask>()

@PostPublished private(set) var state: State = .loading
private(set) var state: DataStatus<ServiceItem> = .loading {
didSet {
stateUpdatedSubject.send(state)
}
}
private let stateUpdatedSubject = PassthroughSubject<DataStatus<ServiceItem>, Never>()

init(cexAsset: CexAsset, network: CexDepositNetwork?, provider: ICexDepositProvider) {
self.cexAsset = cexAsset
Expand All @@ -23,29 +31,78 @@ class CexDepositService {
Task { [weak self, provider, cexAsset, network] in
do {
let (address, memo) = try await provider.deposit(id: cexAsset.id, network: network?.id)
self?.state = .loaded(address: address, memo: memo)

let minAmount = network.flatMap {network -> CoinValue? in
guard network.minAmount > 0 else {
return nil
}

return CoinValue(
kind: .cexAsset(cexAsset: cexAsset),
value: network.minAmount
)
}

let item = ServiceItem(
address: address,
coinCode: cexAsset.coinCode,
imageUrl: cexAsset.coin?.imageUrl,
memo: memo,
networkName: network?.name,
minAmount: minAmount
)

self?.state = .completed(item)
} catch {
self?.state = .failed
let error = ReceiveAddressModule.ErrorItem(
icon: "sync_error_48",
text: "cex_deposit.failed".localized
) { [weak self] in
self?.load()
}

self?.state = .failed(error)
}
}.store(in: &tasks)
}

}

extension CexDepositService {
extension CexDepositService: IReceiveAddressService {

func reload() {
load()
var title: String {
"cex_deposit.title".localized(cexAsset.coinCode)
}

var coinCode: String {
cexAsset.coinCode
}

var statusUpdatedPublisher: AnyPublisher<DataStatus<ServiceItem>, Never> {
stateUpdatedSubject.eraseToAnyPublisher()
}

}

extension CexDepositService {

enum State {
case loading
case loaded(address: String, memo: String?)
case failed
struct Item {
let address: String
let coinCode: String
let imageUrl: String?
let memo: String?
let networkName: String?
let minAmount: CoinValue?
}

enum CexDepositError: LocalizedError {
case syncError

public var errorDescription: String? {
switch self {
case .syncError: return "cex_deposit.failed".localized
}
}
}

}
Loading

0 comments on commit a65babf

Please sign in to comment.