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

Mob 1832 tokens from diff layers are confused #389

Merged
merged 3 commits into from
Feb 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ extension HomeWalletView {

extension HomeWalletView {
struct TokenDescription: Hashable, Identifiable {
var id: String { symbol }
var id: String { "\(chain)/\(symbol)" }

let chain: String
let symbol: String
let name: String
let balance: Double
Expand All @@ -230,6 +231,7 @@ extension HomeWalletView {
static let iconStyle: InitialsView.Style = .gray

init(walletBalance: WalletTokenPortfolio) {
self.chain = walletBalance.symbol
self.symbol = walletBalance.symbol
self.name = walletBalance.name
self.balance = walletBalance.balanceAmt.rounded(toDecimalPlaces: 2)
Expand All @@ -238,9 +240,10 @@ extension HomeWalletView {
self.marketPctChange24Hr = walletBalance.value.marketPctChange24Hr
}

init(symbol: String, name: String, balance: Double, balanceUsd: Double, marketUsd: Double? = nil,
init(chain: String, symbol: String, name: String, balance: Double, balanceUsd: Double, marketUsd: Double? = nil,
marketPctChange24Hr: Double? = nil,
icon: UIImage? = nil) {
self.chain = chain
self.symbol = symbol
self.name = name
self.balance = balance
Expand All @@ -249,7 +252,8 @@ extension HomeWalletView {
self.marketPctChange24Hr = marketPctChange24Hr
}

init(walletToken: WalletTokenPortfolio.Token, parentSymbol: String, parentLogoURL: URL?) {
init(chain: String, walletToken: WalletTokenPortfolio.Token, parentSymbol: String, parentLogoURL: URL?) {
self.chain = chain
self.symbol = walletToken.symbol
self.name = walletToken.name
self.balance = walletToken.balanceAmt.rounded(toDecimalPlaces: 2)
Expand All @@ -264,13 +268,18 @@ extension HomeWalletView {
let tokenDescription = TokenDescription(walletBalance: walletBalance)
let parentSymbol = walletBalance.symbol
let parentLogoURL = URL(string: walletBalance.logoUrl ?? "")
let subTokenDescriptions = walletBalance.tokens?.map({ TokenDescription(walletToken: $0, parentSymbol: parentSymbol, parentLogoURL: parentLogoURL) }).filter({ $0.balanceUsd >= 1 }) ?? []
let chainSymbol = walletBalance.symbol
let subTokenDescriptions = walletBalance.tokens?.map({ TokenDescription(chain: chainSymbol,
walletToken: $0,
parentSymbol: parentSymbol,
parentLogoURL: parentLogoURL) })
.filter({ $0.balanceUsd >= 1 }) ?? []

return [tokenDescription] + subTokenDescriptions
}

static func createSkeletonEntity() -> TokenDescription {
var token = TokenDescription(symbol: "000", name: "0000000000000000", balance: 10000, balanceUsd: 10000, marketUsd: 1)
var token = TokenDescription(chain: "ETH", symbol: "000", name: "0000000000000000", balance: 10000, balanceUsd: 10000, marketUsd: 1)
token.isSkeleton = true
return token
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private extension HomeWalletTokenRowView {
}

#Preview {
HomeWalletTokenRowView(token: .init(symbol: "ETH",
HomeWalletTokenRowView(token: .init(chain: "ETH",
symbol: "ETH",
name: "ETH",
balance: 1,
balanceUsd: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private extension WalletsDataService {

func refreshDataForWalletSync(_ wallet: WalletEntity) async {
async let domainsTask: () = refreshWalletDomainsSync(wallet, shouldRefreshPFP: true)
async let walletsTask: () = refreshWalletBalancesSync(wallet)
async let walletsTask: () = refreshWalletBalancesAsync(wallet)
async let NFTsTask: () = refreshWalletNFTsSync(wallet)

await (_) = (domainsTask, walletsTask, NFTsTask)
Expand Down Expand Up @@ -468,11 +468,11 @@ private extension WalletsDataService {
private extension WalletsDataService {
func refreshWalletBalancesAsync(_ wallet: WalletEntity) {
Task {
await refreshWalletBalancesSync(wallet)
await refreshWalletBalancesAsync(wallet)
}
}

func refreshWalletBalancesSync(_ wallet: WalletEntity) async {
func refreshWalletBalancesAsync(_ wallet: WalletEntity) async {
do {
let walletBalance = try await loadBalanceFor(wallet: wallet)
mutateWalletEntity(wallet) { wallet in
Expand Down