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

Commit

Permalink
Fix #7759: Send token view default token (#7763)
Browse files Browse the repository at this point in the history
* Select the native asset by default, fallback to BAT token, fallback to first visible user token (sorted alphabetically)

* Auto-present Select Token to Send view when opening Send.
  • Loading branch information
StephenHeaps authored Jul 21, 2023
1 parent bd53681 commit 4aaecd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Sources/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct SendTokenView: View {

@State private var isShowingScanner = false
@State private var isShowingError = false
@State private var didAutoShowSelectAccountToken = false
@State private var isShowingSelectAccountTokenView: Bool = false

@ScaledMetric private var length: CGFloat = 16.0
Expand Down Expand Up @@ -292,6 +293,10 @@ struct SendTokenView: View {
}
}
.task {
if !didAutoShowSelectAccountToken {
isShowingSelectAccountTokenView = true
didAutoShowSelectAccountToken = true
}
sendTokenStore.update()
await sendTokenStore.selectTokenStore.update()
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ public class SendTokenStore: ObservableObject {
let allTokens = await self.blockchainRegistry.allTokens(network.chainId, coin: network.coin)
guard !Task.isCancelled else { return }
if selectedSendToken == nil {
self.selectedSendToken = userAssets.first
self.selectedSendToken = userAssets.first(where: { network.isNativeAsset($0) })
?? userAssets.first(where: { $0.symbol.caseInsensitiveCompare("bat") == .orderedSame })
?? userAssets.sorted(by: { $0.name < $1.name }).first
}
self.userAssets = userAssets
self.allTokens = allTokens
Expand Down

0 comments on commit 4aaecd7

Please sign in to comment.