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

Tx display info refactoring #595

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct WalletTransactionDisplayInfo: Hashable, Identifiable {
let link: URL?
let imageUrl: URL?
let symbol: String
let chain: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be precise, let's call it chainName. Though having chainID would be the perfect thing to do -- mapping symbol from the response into a proper value representing a chain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update property to chainName. chainId to be discussed

let nftName: String
let type: TransactionType
let from: Participant
Expand Down Expand Up @@ -72,6 +73,7 @@ extension WalletTransactionDisplayInfo {
self.gas = serializedTransaction.gas
self.link = URL(string: serializedTransaction.link)
self.imageUrl = URL(string: serializedTransaction.imageUrl ?? "")
self.chain = serializedTransaction.symbol
if serializedTransaction.type == "erc20" {
self.symbol = serializedTransaction.method
} else {
Expand Down Expand Up @@ -116,3 +118,25 @@ extension WalletTransactionDisplayInfo {
}
}
}

import UIKit

extension WalletTransactionDisplayInfo {
var chainFullName: String {
if let blockchainType = BlockchainType(rawValue: chain) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line and line 135 repeat the code because the chain property just copies the value from response and doesn't map it into our app's data management. Let's think about it again

Copy link
Contributor Author

@Oleg-Pecheneg Oleg-Pecheneg Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is much deeper.
We used to have one enum that reflected blockchains we're working with: ETH, MATIC, ZIL. It is due to the fact that our domains only existing on this chains.
Now, we have different set of supported chains for number of cases.

  • All wallets now also include balances and txs for Base chain
  • ULW also support BTC and SOL
  • Send crypto feature by imported wallets has own set of supported chains

It is not possible to mix them, and therefore there's places where multiple use cases collides.
In this particular case, tx details, they can be from chains that our BlockchainType does not cover. And this functions abstracting it so no other places in the app aware of this details.
I'm open to suggestions how it can be improved in this particular case without mutating existing core structures like BlockchainType. It seems to me the issue should be resolved on the level deeper.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oleg-Pecheneg agreed to make a deeper refactoring. Please create me a ticket, we'll discuss details tomorrow. Thanks!

return blockchainType.fullName
} else if let blockchainType = SemiSupportedBlockchainType(rawValue: chain) {
return blockchainType.fullName
}
return chain
}

var chainIcon: UIImage {
if let blockchainType = BlockchainType(rawValue: chain) {
return blockchainType.chainIcon
} else if let blockchainType = SemiSupportedBlockchainType(rawValue: chain) {
return blockchainType.chainIcon
}
return .alertCircle
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private extension WalletTransactionDisplayInfoListItemView {
var sourceText: String {
switch transaction.type {
case .tokenWithdrawal, .tokenDeposit:
if let chainType = BlockchainType(rawValue: transaction.symbol) {
return chainType.fullName
}
return transaction.symbol
return transaction.chainFullName
case .nftDeposit, .nftWithdrawal:
return transaction.nftName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,13 @@ private extension TransactionDetailsPullUpView {
icon: fromInfoIcon,
value: tx.from.displayName)),
.infoValue(.init(title: String.Constants.chain.localized(),
icon: chainIcon,
value: chainFullName)),
icon: tx.chainIcon,
value: tx.chainFullName)),
.infoValue(.init(title: String.Constants.networkFee.localized(),
icon: .gas,
value: tx.gas.formatted(toMaxNumberAfterComa: 4)))]
}

var chainFullName: String {
if let blockchainType = BlockchainType(rawValue: tx.symbol) {
return blockchainType.fullName
} else if let blockchainType = SemiSupportedBlockchainType(rawValue: tx.symbol) {
return blockchainType.fullName
}
return "-"
}

var chainIcon: UIImage {
if let blockchainType = BlockchainType(rawValue: tx.symbol) {
return blockchainType.chainIcon
} else if let blockchainType = SemiSupportedBlockchainType(rawValue: tx.symbol) {
return blockchainType.chainIcon
}
return .alertCircle
}

@ViewBuilder
func viewTxButton() -> some View {
if let url = tx.link {
Expand Down