Skip to content

Commit

Permalink
feat(swap): improve ui and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
TrGiLong committed Jan 29, 2024
1 parent 4cf5ff7 commit aead0cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ final class ChooseSwapTokenService: ChooseItemService {
func sortFiltered(by keyword: String, items: [ChooseItemListSection]) -> [ChooseItemListSection] {
let sections = items.map { section in
guard var tokens = section.items as? [SwapToken] else { return section }
tokens = tokens.sorted(by: { lhs, _ in
tokens = tokens.sorted(by: { lhs, rhs in
// Put 'start' matches in the beginning of array, 'contains' after
lhs.token.name.lowercased().starts(with: keyword.lowercased()) ||
lhs.token.symbol.lowercased().starts(with: keyword.lowercased()) ||
lhs.token.mintAddress.lowercased().starts(with: keyword.lowercased())
if !lhs.isNonStrict, rhs.isNonStrict {
return true
} else if lhs.isNonStrict, !rhs.isNonStrict {
return false
} else {
return lhs.token.name.lowercased().starts(with: keyword.lowercased()) ||
lhs.token.symbol.lowercased().starts(with: keyword.lowercased()) ||
lhs.token.mintAddress.lowercased().starts(with: keyword.lowercased())
}
})
if let index = tokens.firstIndex(where: {
$0.token.name.lowercased().elementsEqual(keyword.lowercased()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ struct ChooseSwapTokenItemView: View {
self.token = token
self.chosen = chosen
self.fromToken = fromToken

let formattedMint = RecipientFormatter.format(destination: token.mintAddress)

if fromToken {
subtitle = token.userWallet?.amount?.tokenAmountFormattedString(
let amount = token.userWallet?.amount?.tokenAmountFormattedString(
symbol: token.token.symbol, maximumFractionDigits: Int(token.token.decimals)
) ?? token.token.symbol
)

if let amount {
subtitle = "\(amount)\(formattedMint)"
} else {
subtitle = "\(token.token.symbol)\(formattedMint))"
}
} else {
subtitle = token.token.symbol
subtitle = "\(token.token.symbol)\(formattedMint))"
}
}

Expand All @@ -35,10 +44,17 @@ struct ChooseSwapTokenItemView: View {
.cornerRadius(radius: 48 / 2, corners: .allCorners)

VStack(alignment: .leading, spacing: 4) {
Text(token.token.name)
.font(uiFont: .font(of: .text3, weight: .bold))
.foregroundColor(Color(.night))
.lineLimit(1)
HStack {
Text(token.token.name)
.font(uiFont: .font(of: .text3, weight: .bold))
.foregroundColor(Color(.night))
.lineLimit(1)

Text(token.isNonStrict ? "" : "")
.font(uiFont: .font(of: .text3, weight: .bold))
.foregroundColor(Color(.night))
.lineLimit(1)
}
Text(subtitle)
.apply(style: .label1)
.foregroundColor(Color(.mountain))
Expand Down

0 comments on commit aead0cd

Please sign in to comment.