Skip to content

Commit

Permalink
feat: add stash
Browse files Browse the repository at this point in the history
  • Loading branch information
zafar4aev committed Jul 24, 2023
1 parent c800ecf commit c57a51d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ struct CryptoSolanaAccountsAggregator: DataAggregator {
} else if hideZeroBalance, account.lamports == 0 {
tags.insert(.ignore)
}

let canBeHidden = account.token.keyAppExtensions.canBeHidden ?? true
let extraAction: AccountExtraAction? = canBeHidden ? .showHide : nil

return RenderableSolanaAccount(
account: account,
extraAction: .visiable,
extraAction: extraAction,
tags: tags
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ struct CryptoAccountsView: View {
if !viewModel.transferAccounts.isEmpty {
wrappedList(itemsCount: viewModel.transferAccounts.count) {
ForEach(viewModel.transferAccounts, id: \.id) {
tokenCell(rendableAccount: $0, isVisiable: true)
tokenCell(rendableAccount: $0, isVisible: true)
}
}
}
wrappedList(itemsCount: viewModel.accounts.count) {
ForEach(viewModel.accounts, id: \.id) {
tokenCell(rendableAccount: $0, isVisiable: true)
tokenCell(rendableAccount: $0, isVisible: true)
}
}
.padding(.top, 12)
Expand Down Expand Up @@ -100,7 +100,7 @@ struct CryptoAccountsView: View {
if !isHiddenSectionDisabled {
wrappedList(itemsCount: viewModel.hiddenAccounts.count) {
ForEach(viewModel.hiddenAccounts, id: \.id) {
tokenCell(rendableAccount: $0, isVisiable: false)
tokenCell(rendableAccount: $0, isVisible: false)
}
.transition(AnyTransition.opacity.animation(.linear(duration: 0.3)))
}
Expand All @@ -111,18 +111,18 @@ struct CryptoAccountsView: View {
.background(Color(Asset.Colors.smoke.color))
}

private func tokenCell(rendableAccount: any RenderableAccount, isVisiable: Bool) -> some View {
private func tokenCell(rendableAccount: any RenderableAccount, isVisible: Bool) -> some View {
CryptoAccountCellView(rendable: rendableAccount) {
viewModel.invoke(for: rendableAccount, event: .tap)
} onButtonTap: {
viewModel.invoke(for: rendableAccount, event: .extraButtonTap)
}
.do { view in
switch rendableAccount.extraAction {
case .visiable:
case .showHide:
return AnyView(
view.swipeActions(
isVisible: isVisiable,
isVisible: isVisible,
currentUserInteractionCellID: $currentUserInteractionCellID
) {
viewModel.invoke(for: rendableAccount, event: .visibleToggle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ final class CryptoActionsPanelViewModel: BaseViewModel, ObservableObject {
.map { (state: AsyncValueState<[SolanaAccountsService.Account]>) -> String in
let equityValue: Double = state.value
.filter { !$0.isUSDC }
.reduce(0) { $0 + $1.amountInFiatDouble }
.reduce(0) {
if $1.token.keyAppExtensions.ruleOfProcessingTokenPriceWS == .byCountOfTokensValue {
return $0 + $1.amount
} else {
return $0 + $1.amountInFiatDouble
}
}
return "\(Defaults.fiat.symbol)\(equityValue.toString(maximumFractionDigits: 2))"
}
.receive(on: RunLoop.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct HomeSolanaAccountsAggregator: DataAggregator {

return RenderableSolanaAccount(
account: account,
extraAction: .visiable,
extraAction: .showHide,
tags: tags
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,107 +57,4 @@ struct HomeAccountsView: View {
}
)
}

private var content: some View {
VStack(alignment: .leading, spacing: 0) {
Text(L10n.tokens)
.font(uiFont: .font(of: .title3, weight: .semibold))
.foregroundColor(Color(Asset.Colors.night.color))
.padding(.horizontal, 16)
.padding(.bottom, 8)
wrappedList(itemsCount: viewModel.accounts.count) {
ForEach(viewModel.accounts, id: \.id) {
tokenCell(rendableAccount: $0, isVisiable: true)
}
}
if !viewModel.hiddenAccounts.isEmpty {
Button(
action: {
viewModel.hiddenTokensTapped()
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
withAnimation {
isHiddenSectionDisabled.toggle()
}
},
label: {
HStack(spacing: 8) {
Image(uiImage: isHiddenSectionDisabled ? .eyeHiddenTokens : .eyeHiddenTokensHide)
Text(L10n.hiddenTokens)
.foregroundColor(Color(Asset.Colors.mountain.color))
.font(.system(size: 16))
.padding(.vertical, 12)
Spacer()
}
.frame(maxWidth: .infinity)
.padding(.horizontal, 16)
}
)
if !isHiddenSectionDisabled {
wrappedList(itemsCount: viewModel.hiddenAccounts.count) {
ForEach(viewModel.hiddenAccounts, id: \.id) {
tokenCell(rendableAccount: $0, isVisiable: false)
}
.transition(AnyTransition.opacity.animation(.linear(duration: 0.3)))
}
}
}
}
.padding(.top, 32)
.background(Color(Asset.Colors.snow.color))
}

private func tokenCell(rendableAccount: any RenderableAccount, isVisiable: Bool) -> some View {
HomeAccountView(rendable: rendableAccount) {
viewModel.invoke(for: rendableAccount, event: .tap)
} onButtonTap: {
viewModel.invoke(for: rendableAccount, event: .extraButtonTap)
}
.do { view in
switch rendableAccount.extraAction {
case .visiable:
return AnyView(
view.swipeActions(
isVisible: isVisiable,
currentUserInteractionCellID: $currentUserInteractionCellID
) {
viewModel.invoke(for: rendableAccount, event: .visibleToggle)
}
)
case .none:
return AnyView(view)
}
}
.frame(height: 72)
.padding(.horizontal, 16)
}

@ViewBuilder
private func wrappedList<Content: View>(
itemsCount: Int,
@ViewBuilder content: @escaping () -> Content
) -> some View {
List {
content()
.listRowSeparator(.hidden)
.listRowInsets(EdgeInsets())
}
.listStyle(.plain)
.frame(height: CGFloat(itemsCount) * 72)
}
}

private extension View {
@ViewBuilder func swipeActions(
isVisible: Bool,
currentUserInteractionCellID _: Binding<String?>,
action: @escaping () -> Void
) -> some View {
swipeActions(allowsFullSwipe: true) {
Button(action: action) {
Image(uiImage: isVisible ? .eyeHide : .eyeShow)
}
.tint(.clear)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ final class HomeAccountsViewModel: BaseViewModel, ObservableObject {
.map { (state: AsyncValueState<[SolanaAccountsService.Account]>) -> String in
let equityValue: Double = state.value
.filter { $0.isUSDC }
.filter { $0.token.keyAppExtensions.calculationOfFinalBalanceOnWS ?? true }
.reduce(0) {
$0 + $1.amountInFiatDouble
if $1.token.keyAppExtensions.ruleOfProcessingTokenPriceWS == .byCountOfTokensValue {
return $0 + $1.amount
} else {
return $0 + $1.amountInFiatDouble
}
}
return "\(Defaults.fiat.symbol)\(equityValue.toString(maximumFractionDigits: 2))"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct AccountTags: OptionSet {
}

enum AccountExtraAction {
case visiable
case showHide
}

enum AccountDetail {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct HomeAccountView_Previews: PreviewProvider {
title: "Solana",
subtitle: "0.1747 SOL",
detail: .text("$ 3.67"),
extraAction: .visiable,
extraAction: .showHide,
tags: []
)
) {} onButtonTap: {}
Expand Down

0 comments on commit c57a51d

Please sign in to comment.