Skip to content

Commit

Permalink
Add stats to Transaction Info page
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Apr 17, 2024
1 parent b1d6231 commit a01fbf2
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 63 deletions.
23 changes: 21 additions & 2 deletions UnstoppableWallet/UnstoppableWallet/Models/Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum StatPage: String {
case blockchainSettingsBtc = "blockchain_settings_btc"
case blockchainSettingsEvm = "blockchain_settings_evm"
case blockchainSettingsEvmAdd = "blockchain_settings_evm_add"
case cexWithdrawConfirmation = "cex_withdraw_confirmation"
case cloudBackup = "cloud_backup"
case coinAnalytics = "coin_analytics"
case coinAnalyticsActiveAddresses = "coin_analytics_active_addresses"
Expand All @@ -42,10 +43,13 @@ enum StatPage: String {
case coinRankHolders = "coin_rank_holders"
case coinRankRevenue = "coin_rank_revenue"
case coinRankTxCount = "coin_rank_tx_count"
case contactAddToExisting = "contact_add_to_existing"
case contactNew = "contact_new"
case contacts
case contactUs = "contact_us"
case donate
case donateAddressList = "donate_address_list"
case doubleSpend = "double_spend"
case evmAddress = "evm_address"
case evmPrivateKey = "evm_private_key"
case exportFull = "export_full"
Expand Down Expand Up @@ -96,10 +100,12 @@ enum StatPage: String {
case receive
case receiveTokenList = "receive_token_list"
case recoveryPhrase = "recovery_phrase"
case resend
case restoreSelect = "restore_select"
case scanQrCode = "scan_qr_code"
case security
case send
case sendConfirmation = "send_confirmation"
case sendTokenList = "send_token_list"
case settings
case swap
Expand All @@ -122,9 +128,16 @@ enum StatPage: String {
}

enum StatSection: String {
case addressFrom = "address_from"
case addressRecipient = "address_recipient"
case addressSpender = "address_spender"
case addressTo = "address_to"
case input
case popular
case recent
case searchResults = "search_results"
case status
case timeLock = "time_lock"
case topGainers = "top_gainers"
case topLosers = "top_losers"
case topPlatforms = "top_platforms"
Expand Down Expand Up @@ -156,6 +169,7 @@ enum StatEvent {
case openCoin(coinUid: String)
case openPlatform(chainUid: String)
case openReceive(token: Token)
case openResend(chainUid: String, type: String)
case openSend(token: Token)
case openTokenInfo(token: Token)
case openTokenPage(element: WalletModule.Element)
Expand All @@ -167,7 +181,7 @@ enum StatEvent {
case scanQr(entity: StatEntity)
case select(entity: StatEntity)
case setAmount
case share
case share(entity: StatEntity)
case switchBtcSource(chainUid: String, type: BtcRestoreMode)
case switchChartPeriod(period: StatPeriod)
case switchEvmSource(chainUid: String, name: String)
Expand All @@ -182,6 +196,7 @@ enum StatEvent {
case toggleConversionCoin
case toggleHidden
case toggleIndicators(shown: Bool)
case togglePrice
case toggleSortDirection
case toggleTvlField
case watchWallet(walletType: String)
Expand All @@ -203,7 +218,7 @@ enum StatEvent {
case .exportFull: return "export_full"
case .importFull: return "import_full"
case .importWallet: return "import_wallet"
case .open, .openCategory, .openCoin, .openPlatform, .openReceive, .openSend, .openTokenPage,
case .open, .openCategory, .openCoin, .openPlatform, .openReceive, .openResend, .openSend, .openTokenPage,
.openBlockchainSettingsBtc, .openBlockchainSettingsEvm, .openBlockchainSettingsEvmAdd: return "open_page"
case .openTokenInfo: return "open_token_info"
case .paste: return "paste"
Expand All @@ -229,6 +244,7 @@ enum StatEvent {
case .toggleConversionCoin: return "toggle_conversion_coin"
case .toggleHidden: return "toggle_hidden"
case .toggleIndicators: return "toggle_indicators"
case .togglePrice: return "toggle_price"
case .toggleSortDirection: return "toggle_sort_direction"
case .toggleTvlField: return "toggle_tvl_field"
case .watchWallet: return "watch_wallet"
Expand Down Expand Up @@ -259,6 +275,7 @@ enum StatEvent {
case let .openCoin(coinUid): return [.page: StatPage.coinPage.rawValue, .coinUid: coinUid]
case let .openPlatform(chainUid): return [.page: StatPage.topPlatform.rawValue, .chainUid: chainUid]
case let .openReceive(token): return params(token: token).merging([.page: StatPage.receive.rawValue]) { $1 }
case let .openResend(chainUid, type): return [.page: StatPage.resend.rawValue, .chainUid: chainUid, .type: type]
case let .openSend(token): return params(token: token).merging([.page: StatPage.send.rawValue]) { $1 }
case let .openTokenPage(element):
var params: [StatParam: Any] = [.page: StatPage.tokenPage.rawValue]
Expand All @@ -272,6 +289,7 @@ enum StatEvent {
case let .removeFromWatchlist(coinUid): return [.coinUid: coinUid]
case let .scanQr(entity): return [.entity: entity.rawValue]
case let .select(entity): return [.entity: entity.rawValue]
case let .share(entity): return [.entity: entity.rawValue]
case let .switchBtcSource(chainUid, type): return [.chainUid: chainUid, .type: type.rawValue]
case let .switchChartPeriod(period): return [.period: period.rawValue]
case let .switchEvmSource(chainUid, name): return [.chainUid: chainUid, .type: name]
Expand Down Expand Up @@ -375,6 +393,7 @@ enum StatEntity: String {
case receiveAddress = "receive_address"
case recoveryPhrase = "recovery_phrase"
case token
case transactionId = "transaction_id"
case wallet
case walletName = "wallet_name"
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ extension CexWithdrawConfirmViewController: SectionsDataSource {
switch viewItem {
case let .amount(title, iconUrl, iconPlaceholderImageName, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, imageUrl: iconUrl, placeholderImageName: iconPlaceholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, contactAddress):
case let .address(title, value, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
onAddToContact = { [weak self] in
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self)
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self, statPage: .cexWithdrawConfirmation, statSection: statSection)
}
}
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: nil, onAddToContact: onAddToContact)
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: nil, statPage: .cexWithdrawConfirmation, statSection: statSection, onAddToContact: onAddToContact)
case let .value(title, value, type):
return CellComponent.valueRow(tableView: tableView, rowInfo: rowInfo, iconName: nil, title: title, value: value, type: type)
case let .feeValue(title, coinAmount, currencyAmount):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class CexWithdrawConfirmViewModel {
.address(
title: "send.confirmation.to".localized,
value: service.address,
contactAddress: contactData?.contactAddress
contactAddress: contactData?.contactAddress,
statSection: .addressTo
),
]

Expand Down Expand Up @@ -111,7 +112,7 @@ extension CexWithdrawConfirmViewModel {

enum ViewItem {
case amount(title: String, iconUrl: String?, iconPlaceholderImageName: String, coinAmount: String, currencyAmount: String?, type: AmountType)
case address(title: String, value: String, contactAddress: ContactAddress?)
case address(title: String, value: String, contactAddress: ContactAddress?, statSection: StatSection)
case value(title: String, value: String, type: ValueType)
case feeValue(title: String, coinAmount: String, currencyAmount: String?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ protocol ContactBookSelectorDelegate: AnyObject {
}

enum ContactBookModule {
private static func showAddContact(mode: ContactBookModule.AddContactMode, contactAddress: ContactAddress) -> UIViewController? {
private static func showAddContact(mode: ContactBookModule.AddContactMode, contactAddress: ContactAddress, statPage: StatPage, statSection: StatSection? = nil) -> UIViewController? {
switch mode {
case .new:
guard let module = ContactBookContactModule.viewController(mode: .add(contactAddress)) else {
return nil
}

stat(page: statPage, section: statSection, event: .open(page: .contactNew))

return module
case .exist:
guard let module = ContactBookModule.viewController(mode: .addToContact(contactAddress), presented: true) else {
return nil
}

stat(page: statPage, section: statSection, event: .open(page: .contactAddToExisting))

return module
}
}
Expand Down Expand Up @@ -59,16 +63,16 @@ extension ContactBookModule {
}
}

static func showAddition(contactAddress: ContactAddress, parentViewController: UIViewController?) {
static func showAddition(contactAddress: ContactAddress, parentViewController: UIViewController?, statPage: StatPage, statSection: StatSection? = nil) {
// if all contacts has address for blockchain just show add-new controller
if App.shared.contactManager.all?.isEmpty ?? true, let controller = showAddContact(mode: .new, contactAddress: contactAddress) {
if App.shared.contactManager.all?.isEmpty ?? true, let controller = showAddContact(mode: .new, contactAddress: contactAddress, statPage: statPage, statSection: statSection) {
parentViewController?.present(controller, animated: true)
return
}

// show alert and choose make new contact or add to existed
let alertController = ContactBookModule.chooseAddContactMode(resultAfterClose: true) { [weak parentViewController] mode in
guard let controller = showAddContact(mode: mode, contactAddress: contactAddress) else {
guard let controller = showAddContact(mode: mode, contactAddress: contactAddress, statPage: statPage, statSection: statSection) else {
return
}
parentViewController?.present(controller, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ class ResendBitcoinViewController: KeyboardAwareViewController, SectionsDataSour
switch viewItem {
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, valueTitle, contactAddress):
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
onAddToContact = { [weak self] in
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self)
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self, statPage: .resend, statSection: statSection)
}
}
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, onAddToContact: onAddToContact)
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, statPage: .resend, statSection: statSection, onAddToContact: onAddToContact)
case let .value(iconName, title, value, type):
return CellComponent.valueRow(tableView: tableView, rowInfo: rowInfo, iconName: iconName, title: title, value: value, type: type)
case let .fee(title, coinValue, currencyValue):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class ResendBitcoinViewModel {
title: item.sentToSelf ? "send.confirmation.own".localized : "send.confirmation.to".localized,
value: item.receiver.raw,
valueTitle: item.receiver.title,
contactAddress: contactData.contactAddress
contactAddress: contactData.contactAddress,
statSection: .addressTo
)
)
if let contactName = contactData.name {
Expand Down Expand Up @@ -210,7 +211,7 @@ extension ResendBitcoinViewModel {
extension ResendBitcoinViewModel {
enum ViewItem {
case amount(title: String, token: Token, coinAmount: String, currencyAmount: String?, type: AmountType)
case address(title: String, value: String, valueTitle: String?, contactAddress: ContactAddress?)
case address(title: String, value: String, valueTitle: String?, contactAddress: ContactAddress?, statSection: StatSection)
case value(iconName: String?, title: String, value: String, type: ValueType)
case fee(title: String, coinAmount: String, currencyAmount: String?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class SendConfirmationViewController: ThemeViewController, SectionsDataSource {
switch viewItem {
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, valueTitle, contactAddress):
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
onAddToContact = { [weak self] in
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self)
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self, statPage: .sendConfirmation, statSection: statSection)
}
}
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, onAddToContact: onAddToContact)
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, statPage: .sendConfirmation, statSection: statSection, onAddToContact: onAddToContact)
case let .value(iconName, title, value, type):
return CellComponent.valueRow(tableView: tableView, rowInfo: rowInfo, iconName: iconName, title: title, value: value, type: type)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class SendConfirmationViewModel {
title: "send.confirmation.to".localized,
value: item.receiver.raw,
valueTitle: item.receiver.title,
contactAddress: contactData.contactAddress
contactAddress: contactData.contactAddress,
statSection: .addressTo
)
)
if let contactName = contactData.name {
Expand Down Expand Up @@ -163,7 +164,7 @@ extension SendConfirmationViewModel {
extension SendConfirmationViewModel {
enum ViewItem {
case amount(title: String, token: Token, coinAmount: String, currencyAmount: String?, type: AmountType)
case address(title: String, value: String, valueTitle: String?, contactAddress: ContactAddress?)
case address(title: String, value: String, valueTitle: String?, contactAddress: ContactAddress?, statSection: StatSection)
case value(iconName: String?, title: String, value: String, type: ValueType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extension SendEvmConfirmationModule {
}
}

enum ResendTransactionType {
case speedUp
enum ResendTransactionType: String {
case speedUp = "speed_up"
case cancel
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ class SendEvmTransactionViewController: ThemeViewController {
return CellComponent.nftAmountRow(tableView: tableView, rowInfo: rowInfo, iconUrl: iconUrl, iconPlaceholderImageName: iconPlaceholderImageName, nftAmount: nftAmount, type: type, onTapOpenNft: nil)
case let .doubleAmount(title, coinValue, currencyValue):
return CellComponent.doubleAmountRow(tableView: tableView, rowInfo: rowInfo, title: title, coinValue: coinValue, currencyValue: currencyValue)
case let .address(title, value, valueTitle, contactAddress):
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
onAddToContact = { [weak self] in
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self)
ContactBookModule.showAddition(contactAddress: contactAddress, parentViewController: self, statPage: .send, statSection: statSection)
}
}
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, onAddToContact: onAddToContact)
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: title, value: value, valueTitle: valueTitle, statPage: .send, statSection: statSection, onAddToContact: onAddToContact)
case let .value(title, value, type):
return CellComponent.valueRow(tableView: tableView, rowInfo: rowInfo, iconName: nil, title: title, value: value, type: type)
case let .input(value):
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: "Input", value: value, valueTitle: nil)
return CellComponent.fromToRow(tableView: tableView, rowInfo: rowInfo, title: "Input", value: value, valueTitle: nil, statPage: .send, statSection: .input)
}
}

Expand Down
Loading

0 comments on commit a01fbf2

Please sign in to comment.