Refactor: rename since name mentions fungible but actually used for NFT too

master
Hwee-Boon Yar 4 months ago
parent 3554b0fbdc
commit e4e5cc89ed
  1. 2
      AlphaWallet/Tokens/Collectibles/ViewControllers/NFTAssetViewController.swift
  2. 6
      AlphaWallet/Tokens/Collectibles/ViewModels/NFTAssetViewModel.swift
  3. 2
      AlphaWallet/Tokens/ViewControllers/FungibleTokenDetailsViewController.swift
  4. 16
      AlphaWallet/Tokens/ViewModels/FungibleTokenDetailsViewModel.swift
  5. 9
      AlphaWallet/Tokens/ViewModels/TokenInstanceActionButton.swift

@ -153,7 +153,7 @@ class NFTAssetViewController: UIViewController, TokenVerifiableStatusViewControl
} }
} }
private func configureActionButtons(_ buttons: [FungibleTokenDetailsViewModel.ActionButton]) { private func configureActionButtons(_ buttons: [TokenInstanceActionButton]) {
buttonsBar.cancellable.cancellAll() buttonsBar.cancellable.cancellAll()
buttonsBar.configure(.combined(buttons: buttons.count)) buttonsBar.configure(.combined(buttons: buttons.count))

@ -192,12 +192,12 @@ class NFTAssetViewModel {
} }
} }
private func buildActionButtons(trigger: AnyPublisher<Void, Never>) -> AnyPublisher<[FungibleTokenDetailsViewModel.ActionButton], Never> { private func buildActionButtons(trigger: AnyPublisher<Void, Never>) -> AnyPublisher<[TokenInstanceActionButton], Never> {
return trigger return trigger
.map { _ in self.actionAdapter.availableActions() } .map { _ in self.actionAdapter.availableActions() }
.map { actions in .map { actions in
actions.map { actions.map {
FungibleTokenDetailsViewModel.ActionButton( TokenInstanceActionButton(
actionType: $0, actionType: $0,
name: $0.name, name: $0.name,
state: self.actionAdapter.state(for: $0, fungibleBalance: nil)) state: self.actionAdapter.state(for: $0, fungibleBalance: nil))
@ -331,7 +331,7 @@ extension NFTAssetViewModel {
struct ViewState { struct ViewState {
let title: String let title: String
let actionButtons: [FungibleTokenDetailsViewModel.ActionButton] let actionButtons: [TokenInstanceActionButton]
let viewTypes: [NFTAssetViewModel.ViewType] let viewTypes: [NFTAssetViewModel.ViewType]
let previewViewParams: NFTPreviewViewType.Params let previewViewParams: NFTPreviewViewType.Params
let previewViewContentBackgroundColor: UIColor let previewViewContentBackgroundColor: UIColor

@ -139,7 +139,7 @@ class FungibleTokenDetailsViewController: UIViewController {
return nil return nil
} }
private func configureActionButtons(with buttons: [FungibleTokenDetailsViewModel.ActionButton]) { private func configureActionButtons(with buttons: [TokenInstanceActionButton]) {
buttonsBar.configure(.combined(buttons: buttons.count)) buttonsBar.configure(.combined(buttons: buttons.count))
for (button, view) in zip(buttons, buttonsBar.buttons) { for (button, view) in zip(buttons, buttonsBar.buttons) {

@ -88,9 +88,9 @@ final class FungibleTokenDetailsViewModel {
let viewState = Publishers.CombineLatest3(tokenActionButtonsPublisher(), hasTokenScriptSubject, viewTypes) let viewState = Publishers.CombineLatest3(tokenActionButtonsPublisher(), hasTokenScriptSubject, viewTypes)
.map { .map {
//This does work for creating button to open TokenScript viewer for fungible, but /script-uri must say the fungible token has a TokenScript URL (file) //This does work for creating button to open TokenScript viewer for fungible, but /script-uri must say the fungible token has a TokenScript URL (file)
let buttons: [ActionButton] let buttons: [TokenInstanceActionButton]
if $1 { if $1 {
let tokenScriptViewerBtn = FungibleTokenDetailsViewModel.ActionButton(actionType: TokenInstanceAction(type: TokenInstanceAction.ActionType.openTokenScriptViewer), name: "Open", state: TokenInstanceActionAdapter.ActionState.isDisplayed(true)) let tokenScriptViewerBtn = TokenInstanceActionButton(actionType: TokenInstanceAction(type: TokenInstanceAction.ActionType.openTokenScriptViewer), name: "Open", state: TokenInstanceActionAdapter.ActionState.isDisplayed(true))
buttons = $0 + [tokenScriptViewerBtn ] buttons = $0 + [tokenScriptViewerBtn ]
} else { } else {
buttons = $0 buttons = $0
@ -119,7 +119,7 @@ final class FungibleTokenDetailsViewModel {
} }
} }
private func tokenActionButtonsPublisher() -> AnyPublisher<[ActionButton], Never> { private func tokenActionButtonsPublisher() -> AnyPublisher<[TokenInstanceActionButton], Never> {
let whenTokenHolderHasChanged = tokenHolder.objectWillChange let whenTokenHolderHasChanged = tokenHolder.objectWillChange
.flatMap { [tokensService, token] _ in asFuture { await tokensService.tokenViewModel(for: token) } } .flatMap { [tokensService, token] _ in asFuture { await tokensService.tokenViewModel(for: token) } }
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
@ -138,7 +138,7 @@ final class FungibleTokenDetailsViewModel {
asFuture { asFuture {
let fungibleBalance = await tokensService.tokenViewModel(for: token)?.balance.value let fungibleBalance = await tokensService.tokenViewModel(for: token)?.balance.value
return actions.map { return actions.map {
ActionButton(actionType: $0, name: $0.name, state: self.actionAdapter.state(for: $0, fungibleBalance: fungibleBalance)) TokenInstanceActionButton(actionType: $0, name: $0.name, state: self.actionAdapter.state(for: $0, fungibleBalance: fungibleBalance))
} }
} }
}.eraseToAnyPublisher() }.eraseToAnyPublisher()
@ -280,16 +280,10 @@ extension FungibleTokenDetailsViewModel {
} }
struct ViewState { struct ViewState {
let actionButtons: [ActionButton] let actionButtons: [TokenInstanceActionButton]
let views: [FungibleTokenDetailsViewModel.ViewType] let views: [FungibleTokenDetailsViewModel.ViewType]
} }
struct ActionButton {
let actionType: TokenInstanceAction
let name: String
let state: TokenInstanceActionAdapter.ActionState
}
enum FungibleTokenAction { enum FungibleTokenAction {
case swap(swapTokenFlow: SwapTokenFlow) case swap(swapTokenFlow: SwapTokenFlow)
case erc20Transfer(token: Token) case erc20Transfer(token: Token)

@ -0,0 +1,9 @@
import Foundation
import AlphaWalletFoundation
struct TokenInstanceActionButton {
let actionType: TokenInstanceAction
let name: String
let state: TokenInstanceActionAdapter.ActionState
}
Loading…
Cancel
Save