[Wallet/iOS] Fix #36266: Buy/Send/Swap buttons not opening from Asset Details (#22229)

This commit is contained in:
Nuo Xu
2024-02-21 18:21:30 -08:00
committed by GitHub
parent 6043dd036a
commit e6e076d055
3 changed files with 38 additions and 15 deletions
@@ -98,12 +98,12 @@ struct AssetDetailView: View {
@ViewBuilder private var accountsBalanceView: some View {
VStack {
if assetDetailStore.accounts.isEmpty {
if assetDetailStore.nonZeroBalanceAccounts.isEmpty {
emptyAccountState
} else {
accountsBalanceHeader
ForEach(assetDetailStore.accounts) { viewModel in
ForEach(assetDetailStore.nonZeroBalanceAccounts) { viewModel in
accontBalanceRow(viewModel)
}
}
@@ -192,7 +192,7 @@ struct AssetDetailView: View {
kind: .buy,
initialToken: assetDetailStore.assetDetailToken
)
if assetDetailStore.accounts.isEmpty {
if assetDetailStore.allAccountsForTokenCoin.isEmpty {
onAccountCreationNeeded(destination)
} else {
buySendSwapDestination = destination
@@ -205,7 +205,7 @@ struct AssetDetailView: View {
kind: .send,
initialToken: assetDetailStore.assetDetailToken
)
if assetDetailStore.accounts.isEmpty {
if assetDetailStore.allAccountsForTokenCoin.isEmpty {
onAccountCreationNeeded(destination)
} else {
buySendSwapDestination = destination
@@ -218,7 +218,7 @@ struct AssetDetailView: View {
kind: .swap,
initialToken: assetDetailStore.assetDetailToken
)
if assetDetailStore.accounts.isEmpty {
if assetDetailStore.allAccountsForTokenCoin.isEmpty {
onAccountCreationNeeded(destination)
} else {
buySendSwapDestination = destination
@@ -274,7 +274,7 @@ struct AssetDetailView: View {
tokenContentContainer
.padding(.bottom, 12)
if (selectedContent == .accounts && !assetDetailStore.accounts.isEmpty) || (selectedContent == .transactions && !assetDetailStore.transactionSections.isEmpty) {
if (selectedContent == .accounts && !assetDetailStore.nonZeroBalanceAccounts.isEmpty) || (selectedContent == .transactions && !assetDetailStore.transactionSections.isEmpty) {
Text(Strings.Wallet.coinGeckoDisclaimer)
.multilineTextAlignment(.center)
.font(.footnote)
@@ -446,6 +446,25 @@ struct AssetDetailView: View {
isShowingAuroraBridgeAlert = false
}
}
.addAccount(
keyringStore: keyringStore,
networkStore: networkStore,
accountNetwork: networkStore.network(for: assetDetailStore.assetDetailToken),
isShowingConfirmation: $isPresentingAddAccountConfirmation,
isShowingAddAccount: $isPresentingAddAccount,
onConfirmAddAccount: { isPresentingAddAccount = true },
onCancelAddAccount: nil,
onAddAccountDismissed: {
Task { @MainActor in
if await assetDetailStore.handleDismissAddAccount() {
if let savedBSSDestination {
buySendSwapDestination = savedBSSDestination
self.savedBSSDestination = nil
}
}
}
}
)
}
private func onAccountCreationNeeded(_ destination: BuySendSwapDestination) {
@@ -48,7 +48,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}
}
@Published private(set) var isLoadingAccountBalances: Bool = false
@Published private(set) var accounts: [AccountAssetViewModel] = []
@Published private(set) var nonZeroBalanceAccounts: [AccountAssetViewModel] = []
@Published private(set) var transactionSections: [TransactionSection] = []
@Published private(set) var isBuySupported: Bool = false
@Published private(set) var isSendSupported: Bool = false
@@ -67,7 +67,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
let currencyFormatter: NumberFormatter = .usdCurrencyFormatter
var totalBalance: Double {
accounts
nonZeroBalanceAccounts
.compactMap { Double($0.balance) }
.reduce(0, +)
}
@@ -119,6 +119,9 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
var isObserving: Bool {
keyringServiceObserver != nil && txServiceObserver != nil && walletServiceObserver != nil
}
// All account info that has the same coin type as this asset's
var allAccountsForTokenCoin: [BraveWallet.AccountInfo] = []
init(
assetRatioService: BraveWalletAssetRatioService,
@@ -207,7 +210,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
self.isSwapSupported = await swapService.isSwapSupported(token.chainId)
// fetch accounts
let allAccountsForTokenCoin = await keyringService.allAccounts().accounts.filter { $0.coin == token.coin }
self.allAccountsForTokenCoin = await keyringService.allAccounts().accounts.filter { $0.coin == token.coin }
var updatedAccounts = allAccountsForTokenCoin.map {
AccountAssetViewModel(account: $0, decimalBalance: 0.0, balance: "", fiatBalance: "")
}
@@ -233,7 +236,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}
// fetch accounts balance
self.accounts = await fetchAccountBalances(updatedAccounts, network: network)
self.nonZeroBalanceAccounts = await fetchAccountBalances(updatedAccounts, network: network)
// fetch transactions
let userAssets = assetManager.getAllUserAssetsInNetworkAssets(networks: [network], includingUserDeleted: true).flatMap { $0.tokens }
@@ -315,7 +318,8 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
// below is all not supported from Market tab
self.isSendSupported = false
self.isSwapSupported = false
self.accounts = []
self.allAccountsForTokenCoin = []
self.nonZeroBalanceAccounts = []
self.transactionSections = []
}
}
@@ -156,7 +156,7 @@ class AssetDetailStoreTests: XCTestCase {
XCTAssertEqual($0, "1%")
}
.store(in: &cancellables)
store.$accounts
store.$nonZeroBalanceAccounts
.dropFirst()
.sink { accounts in
defer { assetDetailException.fulfill() }
@@ -368,7 +368,7 @@ class AssetDetailStoreTests: XCTestCase {
.sink { values in
defer {
XCTAssertNil(store.network)
XCTAssertTrue(store.accounts.isEmpty)
XCTAssertTrue(store.nonZeroBalanceAccounts.isEmpty)
XCTAssertTrue(store.transactionSections.isEmpty)
assetDetailBitcoinException.fulfill()
@@ -450,7 +450,7 @@ class AssetDetailStoreTests: XCTestCase {
.sink {
defer {
XCTAssertNil(store.network)
XCTAssertTrue(store.accounts.isEmpty)
XCTAssertTrue(store.nonZeroBalanceAccounts.isEmpty)
XCTAssertTrue(store.transactionSections.isEmpty)
assetDetailNonBitcoinException.fulfill()
@@ -484,7 +484,7 @@ class AssetDetailStoreTests: XCTestCase {
.sink { values in
defer {
XCTAssertNil(store.network)
XCTAssertTrue(store.accounts.isEmpty)
XCTAssertTrue(store.nonZeroBalanceAccounts.isEmpty)
XCTAssertTrue(store.transactionSections.isEmpty)
assetDetailNonBitcoinException.fulfill()