Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Card background using blockie material, refresh list on network chang…
Browse files Browse the repository at this point in the history
…e & show/hide test networks, small UI, tweaks
  • Loading branch information
StephenHeaps committed Jan 17, 2024
1 parent c995792 commit c263cb0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
28 changes: 21 additions & 7 deletions Sources/BraveWallet/Crypto/Accounts/AccountsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private struct AccountCardView: View {
let isLoading: Bool
let action: (Action) -> Void

@Environment(\.colorScheme) private var colorScheme: ColorScheme
@ScaledMetric private var avatarSize = 40.0
private let maxAvatarSize: CGFloat = 80.0
private let contentPadding: CGFloat = 16
Expand All @@ -195,11 +196,14 @@ private struct AccountCardView: View {
.frame(width: min(avatarSize, maxAvatarSize), height: min(avatarSize, maxAvatarSize))
VStack(alignment: .leading) {
AddressView(address: account.address) {
Text(account.name)
.font(.headline.weight(.semibold))
.foregroundColor(Color(braveSystemName: .textPrimary))
Text(account.address.truncatedAddress)
.font(.footnote)
// VStack keeps views together when showing context menu w/ address
VStack(alignment: .leading) {
Text(account.name)
.font(.headline.weight(.semibold))
.foregroundColor(Color(braveSystemName: .textPrimary))
Text(account.address.truncatedAddress)
.font(.footnote)
}
}
Text(account.accountSupportDisplayString)
.font(.footnote)
Expand Down Expand Up @@ -314,14 +318,17 @@ private struct AccountCardView: View {
}) {
VStack(spacing: 0) {
topSectionContent()
.background(Color.white.opacity(0.5))
.background(colorScheme == .dark ? Color.black.opacity(0.5) : Color.white.opacity(0.5))

bottomSectionContent
.background(
colorScheme == .dark ? Color.black.opacity(0.4) : Color.clear
)
}
.background(
RoundedRectangle(cornerRadius: 8)
.stroke(Color(braveSystemName: .dividerInteractive), lineWidth: 1)
.background(RoundedRectangle(cornerRadius: 8).fill(Color(white: 0.95)))
.background(cardBackground)
)
.clipShape(RoundedRectangle(cornerRadius: 8))
.frame(maxWidth: .infinity)
Expand All @@ -331,6 +338,13 @@ private struct AccountCardView: View {
topSectionContent(hidingButtons: false)
}
}

private var cardBackground: some View {
BlockieMaterial(address: account.address)
.blur(radius: 25, opaque: true)
.opacity(0.3)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
}

private extension BraveWallet.AccountInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct AccountDetailsView: View {
}
.listStyle(InsetGroupedListStyle())
.listBackgroundColor(Color(UIColor.braveGroupedBackground))
.navigationTitle(Strings.Wallet.accountDetailsTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .cancellationAction) {
Expand Down
19 changes: 19 additions & 0 deletions Sources/BraveWallet/Crypto/Stores/AccountsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import BraveCore
import SwiftUI
import Preferences

struct AccountDetails: Equatable, Identifiable {
var id: String { account.id }
Expand Down Expand Up @@ -39,10 +40,12 @@ class AccountsStore: ObservableObject, WalletObserverStore {

private let keyringService: BraveWalletKeyringService
private let rpcService: BraveWalletJsonRpcService
private let walletService: BraveWalletBraveWalletService
private let assetRatioService: BraveWalletAssetRatioService
private let userAssetManager: WalletUserAssetManagerType

private var keyringServiceObserver: KeyringServiceObserver?
private var walletServiceObserver: WalletServiceObserver?

var isObserving: Bool {
keyringServiceObserver != nil
Expand All @@ -51,11 +54,13 @@ class AccountsStore: ObservableObject, WalletObserverStore {
init(
keyringService: BraveWalletKeyringService,
rpcService: BraveWalletJsonRpcService,
walletService: BraveWalletBraveWalletService,
assetRatioService: BraveWalletAssetRatioService,
userAssetManager: WalletUserAssetManagerType
) {
self.keyringService = keyringService
self.rpcService = rpcService
self.walletService = walletService
self.assetRatioService = assetRatioService
self.userAssetManager = userAssetManager
self.setupObservers()
Expand All @@ -69,6 +74,13 @@ class AccountsStore: ObservableObject, WalletObserverStore {
self?.update()
}
)
self.walletServiceObserver = WalletServiceObserver(
walletService: walletService,
_onNetworkListChanged: { [weak self] in
self?.update()
}
)
Preferences.Wallet.showTestNetworks.observe(from: self)
}

func tearDown() {
Expand Down Expand Up @@ -240,3 +252,10 @@ class AccountsStore: ObservableObject, WalletObserverStore {
tokenBalancesCache[account.address]?[tokenId]
}
}

extension AccountsStore: PreferencesObserver {
public func preferencesDidChange(for key: String) {
guard key == Preferences.Wallet.showTestNetworks.key else { return }
update()
}
}
1 change: 1 addition & 0 deletions Sources/BraveWallet/Crypto/Stores/CryptoStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public class CryptoStore: ObservableObject, WalletObserverStore {
self.accountsStore = .init(
keyringService: keyringService,
rpcService: rpcService,
walletService: walletService,
assetRatioService: assetRatioService,
userAssetManager: userAssetManager
)
Expand Down
1 change: 1 addition & 0 deletions Sources/BraveWallet/Preview Content/MockStores.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ extension AccountsStore {
.init(
keyringService: MockKeyringService(),
rpcService: MockJsonRpcService(),
walletService: MockBraveWalletService(),
assetRatioService: MockAssetRatioService(),
userAssetManager: TestableWalletUserAssetManager()
)
Expand Down
4 changes: 4 additions & 0 deletions Tests/BraveWalletTests/AccountsStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ import Preferences
}
}

let walletService = BraveWallet.TestBraveWalletService()
walletService._addObserver = { _ in }

let assetRatioService = BraveWallet.TestAssetRatioService()
assetRatioService._price = { priceIds, _, _, completion in
completion(true, [self.mockETHAssetPrice,
Expand Down Expand Up @@ -190,6 +193,7 @@ import Preferences
let store = AccountsStore(
keyringService: keyringService,
rpcService: rpcService,
walletService: walletService,
assetRatioService: assetRatioService,
userAssetManager: userAssetManager
)
Expand Down

0 comments on commit c263cb0

Please sign in to comment.