Skip to content

Commit

Permalink
[ABW-2124] transaction review loading (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 committed Aug 31, 2023
1 parent 305b86f commit 4a6a7c9
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ extension AccountPortfoliosClient {
nonFungibleLocalId: .from(stringFormat: item.nonFungibleId)
),
name: details.name,
description: nil,
description: details.tokenDescription,
keyImageURL: details.keyImageURL,
metadata: [],
stakeClaimAmount: details.claimAmount,
Expand Down
7 changes: 6 additions & 1 deletion Sources/Core/SharedModels/Assets/AccountPortfolio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,12 @@ extension [AccountPortfolio.NonFungibleResource.NonFungibleToken.NFTData] {
}

public var keyImageURL: URL? {
self[.keyImageURL]?.url
guard let string = self[Field.keyImageURL]?.string else { return nil }
return URL(string: string)
}

public var tokenDescription: String? {
self[.description]?.string
}

public var claimEpoch: UInt64? {
Expand Down
7 changes: 7 additions & 0 deletions Sources/EngineKit/ReviewedTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ extension MetadataValue {
return nil
}

public var stringArray: [String]? {
if case let .stringArrayValue(value) = self {
return value
}
return nil
}

public var url: URL? {
if case let .urlValue(value) = self {
return URL(string: value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct AssetResourceDetailsSection: View {
.textStyle(.body1Regular)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, .large2)
.transition(transition)

AssetDetailsSeparator()
}
Expand All @@ -35,20 +34,17 @@ struct AssetResourceDetailsSection: View {

if let validatorAddress = viewState.validatorAddress {
KeyValueView(validatorAddress: validatorAddress)
.transition(transition)
}

if let resourceName = viewState.resourceName {
KeyValueView(key: "Name", value: resourceName) // FIXME: Strings - make a common name string for all asset details, remove the specific one(s)
.transition(transition)
}

if let currentSupply = viewState.currentSupply {
KeyValueView(
key: L10n.AssetDetails.currentSupply,
value: currentSupply
)
.transition(transition)
}

AssetBehaviorsView(behaviors: viewState.behaviors)
Expand All @@ -57,10 +53,7 @@ struct AssetResourceDetailsSection: View {
}
.padding(.horizontal, .large2)
}
.animation(.default, value: viewState)
}

private let transition: AnyTransition = .opacity.combined(with: .scale(scale: 0.8))
}

// MARK: - AssetDetailsSeparator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ extension NonFungibleAssetList {
public var body: some SwiftUI.View {
VStack(spacing: .medium1) {
ForEachStore(
store.scope(
state: \.rows,
action: { .child(.asset($0, $1)) }
),
store.scope(state: \.rows) { .child(.asset($0, $1)) },
content: { NonFungibleAssetList.Row.View(store: $0) }
)
}
.sheet(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
store: store.scope(state: \.$destination) { .child(.destination($0)) },
state: /NonFungibleAssetList.Destinations.State.details,
action: NonFungibleAssetList.Destinations.Action.details,
content: { detailsStore in
Expand Down
30 changes: 18 additions & 12 deletions Sources/Features/SettingsFeature/Settings+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extension Settings {
let shouldShowMigrateOlympiaButton: Bool
let appVersion: String

var showsSomeBanner: Bool {
shouldShowAddP2PLinkButton || shouldShowMigrateOlympiaButton
}

init(state: Settings.State) {
#if DEBUG
let retCommitHash: String = buildInformation().version
Expand Down Expand Up @@ -101,22 +105,24 @@ extension Settings.View {
private func settingsView(viewStore: ViewStoreOf<Settings>) -> some View {
ScrollView {
VStack(spacing: .zero) {
VStack(spacing: .medium3) {
if viewStore.shouldShowAddP2PLinkButton {
ConnectExtensionView {
viewStore.send(.addP2PLinkButtonTapped)
if viewStore.showsSomeBanner {
VStack(spacing: .medium3) {
if viewStore.shouldShowAddP2PLinkButton {
ConnectExtensionView {
viewStore.send(.addP2PLinkButtonTapped)
}
}
}
if viewStore.shouldShowMigrateOlympiaButton {
MigrateOlympiaAccountsView {
viewStore.send(.importOlympiaButtonTapped)
} dismiss: {
viewStore.send(.dismissImportOlympiaHeaderButtonTapped)
if viewStore.shouldShowMigrateOlympiaButton {
MigrateOlympiaAccountsView {
viewStore.send(.importOlympiaButtonTapped)
} dismiss: {
viewStore.send(.dismissImportOlympiaHeaderButtonTapped)
}
.transition(headerTransition)
}
.transition(headerTransition)
}
.padding(.medium3)
}
.padding(.medium3)

ForEach(rows) { row in
SettingsRow(row: row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,31 @@ import OnLedgerEntitiesClient
import Prelude
import SharedModels

extension FungibleTokenDetails.State {
init(
transfer: TransactionReview.FungibleTransfer,
metadata: [String: MetadataValue?]? = nil,
resource: OnLedgerEntity.Resource? = nil
) {
extension AccountPortfolio.FungibleResource {
init(resourceAddress: ResourceAddress, amount: BigDecimal, metadata: [String: MetadataValue?]) {
self.init(
resource: .init(transfer: transfer, metadata: metadata, resource: resource),
isXRD: transfer.isXRD
resourceAddress: resourceAddress,
amount: amount,
name: metadata.name,
symbol: metadata.symbol,
description: metadata.description,
iconURL: metadata.iconURL,
tags: metadata.tags
)
}
}

extension AccountPortfolio.FungibleResource {
init(
transfer: TransactionReview.FungibleTransfer,
metadata: [String: MetadataValue?]?,
resource: OnLedgerEntity.Resource? = nil
) {
init(amount: BigDecimal, onLedgerEntity: OnLedgerEntity.Resource) {
self.init(
resourceAddress: transfer.resource,
amount: transfer.amount,
divisibility: resource?.divisibility,
name: resource?.name ?? transfer.name,
symbol: resource?.symbol ?? transfer.symbol,
description: metadata?.description ?? resource?.description,
iconURL: resource?.iconURL ?? metadata?.iconURL ?? transfer.thumbnail,
behaviors: resource?.behaviors ?? [],
tags: resource?.tags ?? [],
totalSupply: resource?.totalSupply
resourceAddress: onLedgerEntity.resourceAddress,
amount: amount,
divisibility: onLedgerEntity.divisibility,
name: onLedgerEntity.name,
symbol: onLedgerEntity.symbol,
description: onLedgerEntity.description,
iconURL: onLedgerEntity.iconURL,
behaviors: onLedgerEntity.behaviors,
tags: onLedgerEntity.tags,
totalSupply: onLedgerEntity.totalSupply
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EngineToolkit
import Foundation
import NonEmpty
import SharedModels

extension [String: MetadataValue?] {
var name: String? {
Expand All @@ -17,4 +19,8 @@ extension [String: MetadataValue?] {
var description: String? {
self["description"]??.string
}

var tags: [AssetTag] {
self["tags"]??.stringArray?.compactMap { NonEmptyString(rawValue: $0) }.map(AssetTag.custom) ?? []
}
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,50 @@
import AssetsFeature
import EngineKit
import EngineToolkit
import Foundation
import GatewayAPI
import OnLedgerEntitiesClient
import Prelude
import SharedModels

extension NonFungibleTokenDetails.State {
init(
transfer: TransactionReview.NonFungibleTransfer,
metadata: [String: MetadataValue?]? = nil,
resource: OnLedgerEntity.Resource? = nil
) throws {
try self.init(
token: .init(transfer: transfer, resource: resource),
resource: .init(transfer: transfer, metadata: metadata, resource: resource)
extension AccountPortfolio.NonFungibleResource {
init(resourceAddress: ResourceAddress, metadata: [String: MetadataValue?]) {
self.init(
resourceAddress: resourceAddress,
name: metadata.name,
description: metadata.description,
iconURL: metadata.iconURL,
tags: metadata.tags
)
}
}

extension AccountPortfolio.NonFungibleResource {
init(
transfer: TransactionReview.NonFungibleTransfer,
metadata: [String: MetadataValue?]?,
resource: OnLedgerEntity.Resource?
) {
init(onLedgerEntity: OnLedgerEntity.Resource, tokens: IdentifiedArrayOf<NonFungibleToken> = []) {
self.init(
resourceAddress: transfer.resource,
name: metadata?.name ?? resource?.name ?? transfer.resourceName,
description: metadata?.description ?? resource?.description,
iconURL: resource?.iconURL ?? metadata?.iconURL ?? transfer.resourceImage,
behaviors: resource?.behaviors ?? [],
tags: resource?.tags ?? [],
tokens: [],
totalSupply: resource?.totalSupply
resourceAddress: onLedgerEntity.resourceAddress,
name: onLedgerEntity.name,
description: onLedgerEntity.description,
iconURL: onLedgerEntity.iconURL,
behaviors: onLedgerEntity.behaviors,
tags: onLedgerEntity.tags,
tokens: tokens,
totalSupply: onLedgerEntity.totalSupply
)
}
}

extension AccountPortfolio.NonFungibleResource.NonFungibleToken {
init(
transfer: TransactionReview.NonFungibleTransfer,
resource: OnLedgerEntity.Resource?
) throws {
init(resourceAddress: ResourceAddress, nftResponseItem: GatewayAPI.StateNonFungibleDetailsResponseItem) throws {
try self.init(
id: transfer.nonFungibleGlobalId(),
name: transfer.tokenName,
description: nil, // FIXME: FIND
keyImageURL: nil, // FIXME: FIND
metadata: [], // FIXME: FIND
id: .fromParts(
resourceAddress: resourceAddress.intoEngine(),
nonFungibleLocalId: .from(stringFormat: nftResponseItem.nonFungibleId)
),
name: nftResponseItem.details.name,
description: nftResponseItem.details.description,
keyImageURL: nftResponseItem.details.keyImageURL,
metadata: [], // FIXME: Find?
stakeClaimAmount: nil,
canBeClaimed: false // FIXME: FIND
)
}
}

extension TransactionReview.NonFungibleTransfer {
func nonFungibleGlobalId() throws -> NonFungibleGlobalId {
try .fromParts(
resourceAddress: resource.intoEngine(),
nonFungibleLocalId: nonFungibleLocalIdFromStr(string: tokenID)
canBeClaimed: false // FIXME: Find?
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@ extension View {
store: destinationStore,
state: /TransactionReview.Destinations.State.nonFungibleTokenDetails,
action: TransactionReview.Destinations.Action.nonFungibleTokenDetails,
content: { NonFungibleTokenDetails.View(store: $0) }
content: { detailsStore in
WithNavigationBar {
destinationStore.send(.dismiss)
} content: {
NonFungibleTokenDetails.View(store: detailsStore)
}
}
)
}

Expand Down
Loading

0 comments on commit 4a6a7c9

Please sign in to comment.