Skip to content

Commit

Permalink
[ABW-3569, ABW-3586] Asset transfer & Transaction review Presenting s…
Browse files Browse the repository at this point in the history
…ection UI updates (#1214)

Co-authored-by: matiasbzurovski <164921079+matiasbzurovski@users.noreply.github.com>
  • Loading branch information
danvleju-rdx and matiasbzurovski committed Jul 17, 2024
1 parent c2e9c5d commit 3067b2e
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 118 deletions.
18 changes: 12 additions & 6 deletions RadixWallet/Core/FeaturePrelude/AddressView/AddressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public struct AddressView: View {
let identifiable: LedgerIdentifiable
let isTappable: Bool
let imageColor: Color?
let isImageHidden: Bool
private let showLocalIdOnly: Bool

@Dependency(\.gatewaysClient) var gatewaysClient
Expand All @@ -17,12 +18,14 @@ public struct AddressView: View {
_ identifiable: LedgerIdentifiable,
showLocalIdOnly: Bool = false,
isTappable: Bool = true,
imageColor: Color? = nil
imageColor: Color? = nil,
isImageHidden: Bool = false
) {
self.identifiable = identifiable
self.showLocalIdOnly = showLocalIdOnly
self.isTappable = isTappable
self.imageColor = imageColor
self.isImageHidden = isImageHidden
}
}

Expand Down Expand Up @@ -73,11 +76,14 @@ extension AddressView {
HStack(spacing: .small3) {
Text(formattedText)
.lineLimit(1)
if let imageColor {
image
.foregroundStyle(imageColor)
} else {
image

if !isImageHidden {
if let imageColor {
image
.foregroundStyle(imageColor)
} else {
image
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

extension OnLedgerEntity.NonFungibleToken {
public init(resourceAddress: ResourceAddress, nftID: NonFungibleLocalId, nftData: NFTData?) throws {
public init(resourceAddress: ResourceAddress, nftID: NonFungibleLocalId, nftData: NFTData?) {
self.init(
id: NonFungibleGlobalID(
resourceAddress: resourceAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public struct AddAsset: FeatureReducer, Sendable {
case let .allowDenyAssets(exceptionRule):
address = try? .assetException(.init(address: .init(validatingAddress: resourceAddress), exceptionRule: exceptionRule))
case .allowDepositors:
if let resourceAddress = try? ResourceAddress(validatingAddress: resourceAddress) {
if let nonFungibleGlobalId = try? NonFungibleGlobalId(resourceAddress) {
address = .allowedDepositor(.nonFungible(value: nonFungibleGlobalId))
} else if let resourceAddress = try? ResourceAddress(validatingAddress: resourceAddress) {
address = .allowedDepositor(.resource(value: resourceAddress))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,21 @@ extension ResourcesList.View {

@ViewBuilder
func resourceRowView(_ viewState: ResourceViewState, _ viewStore: ViewStoreOf<ResourcesList>) -> some SwiftUI.View {
HStack {
HStack(spacing: .zero) {
if viewState.address.resourceAddress.isNonFungible {
Thumbnail(.nft, url: viewState.iconURL)
} else {
Thumbnail(token: .other(viewState.iconURL))
}

VStack(alignment: .leading, spacing: .zero) {
Text(viewState.name ?? "")
Text(viewState.name ?? "-")
.textStyle(.body1HighImportance)
.foregroundColor(.app.gray1)
AddressView(
viewState.address.ledgerIdentifiable,
isTappable: false
isTappable: false,
isImageHidden: true
)
.foregroundColor(.app.gray2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public struct ManageThirdPartyDeposits: FeatureReducer, Sendable {
.run { send in
do {
/// Wait for user to complete the interaction with Transaction Review
let result = try await dappInteractionClient.addWalletInteraction(
let result = await dappInteractionClient.addWalletInteraction(
.transaction(.init(send: .init(transactionManifest: manifest))),
.accountDepositSettings
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public struct ResourceBalanceView: View {
public let isSelected: Bool?
public let action: (() -> Void)?

public enum Appearance: Equatable {
public enum Appearance: Sendable, Equatable {
case standard
case compact(border: Bool)

Expand Down Expand Up @@ -241,8 +241,8 @@ extension ResourceBalanceView {
VStack(alignment: .leading, spacing: .medium3) {
FungibleView(
thumbnail: .lsu(viewState.icon),
caption1: viewState.title,
caption2: viewState.validatorName,
caption1: viewState.title ?? "-",
caption2: viewState.validatorName ?? "-",
fallback: nil,
amount: viewState.amount,
compact: compact,
Expand Down Expand Up @@ -273,8 +273,8 @@ extension ResourceBalanceView {
VStack(alignment: .leading, spacing: .zero) {
FungibleView(
thumbnail: .poolUnit(viewState.poolIcon),
caption1: viewState.poolName,
caption2: viewState.dAppName.wrappedValue?.flatMap { $0 },
caption1: viewState.poolName ?? "-",
caption2: viewState.dAppName.wrappedValue?.flatMap { $0 } ?? "-",
fallback: nil,
amount: viewState.amount,
compact: compact,
Expand Down Expand Up @@ -314,8 +314,8 @@ extension ResourceBalanceView {
VStack(alignment: .leading, spacing: .zero) {
NonFungibleView(
thumbnail: .stakeClaimNFT(viewState.resourceMetadata.iconURL),
caption1: viewState.resourceMetadata.title ?? "",
caption2: viewState.validatorName ?? "",
caption1: viewState.resourceMetadata.title,
caption2: viewState.validatorName,
compact: compact
)

Expand Down Expand Up @@ -457,17 +457,15 @@ extension ResourceBalanceView {
compact: compact
)

if useSpacer {
if useSpacer, isSelected == nil {
Spacer(minLength: .small2)
}

AmountView(amount: amount, fallback: fallback, compact: compact)
.padding(.leading, isSelected != nil ? .small2 : 0)

if let isSelected {
if !useSpacer, caption1 == nil {
Spacer(minLength: .small2)
}
Spacer(minLength: .small2)
CheckmarkView(appearance: .dark, isChecked: isSelected)
}
}
Expand Down Expand Up @@ -497,8 +495,8 @@ extension ResourceBalanceView {
CaptionedThumbnailView(
type: thumbnail.type,
url: thumbnail.url,
caption1: caption1,
caption2: caption2,
caption1: caption1 ?? "-",
caption2: caption2 ?? "-",
compact: compact
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension TransactionReview {
networkID: networkID
)

let proofs: TransactionReviewProofs.State? = try await exctractProofs(summary.presentedProofs.map(\.resourceAddress))
let proofs: TransactionReviewProofs.State? = try await exctractProofs(summary.presentedProofs)

return Sections(
withdrawals: withdrawals,
Expand Down Expand Up @@ -344,20 +344,45 @@ extension TransactionReview {
return DappEntity(id: dAppDefinitionAddress, metadata: metadata)
}

private func exctractProofs(_ accountProofs: [ResourceAddress]) async throws -> TransactionReviewProofs.State? {
private func exctractProofs(_ accountProofs: [ResourceSpecifier]) async throws -> TransactionReviewProofs.State? {
let proofs = try await accountProofs
.uniqued()
.asyncMap(extractResourceBalanceInfo)
.flatMap { $0 }
.asyncMap(extractProofInfo)

guard !proofs.isEmpty else { return nil }

return TransactionReviewProofs.State(proofs: proofs.asIdentified())
}

private func extractProofInfo(_ address: ResourceAddress) async throws -> ProofEntity {
private func extractResourceBalanceInfo(specifier: ResourceSpecifier) async throws -> [(ResourceAddress, ResourceBalance.Details)] {
switch specifier {
case let .fungible(resourceAddress, amount):
return [(
resourceAddress,
.fungible(
.init(
isXRD: resourceAddress.isXRD,
amount: .init(nominalAmount: amount)
)
)
)]
case let .nonFungible(resourceAddress, ids):
let globalIds = ids.map { NonFungibleGlobalId(resourceAddress: resourceAddress, nonFungibleLocalId: $0) }
let tokens = try await onLedgerEntitiesClient.getNonFungibleTokenData(
.init(resource: resourceAddress, nonFungibleIds: globalIds)
)
return tokens.map { (resourceAddress, .nonFungible($0)) }
}
}

private func extractProofInfo(resourceAddress: ResourceAddress, details: ResourceBalance.Details) async throws -> ProofEntity {
try await ProofEntity(
id: address,
metadata: onLedgerEntitiesClient.getResource(address, metadataKeys: .dappMetadataKeys).metadata
resourceBalance: ResourceBalance(
resource: onLedgerEntitiesClient.getResource(resourceAddress, metadataKeys: .dappMetadataKeys),
details: details
)
)
}

Expand Down
109 changes: 59 additions & 50 deletions RadixWallet/Features/TransactionReviewFeature/TransactionReview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,54 +356,7 @@ public struct TransactionReview: Sendable, FeatureReducer {
switch childAction {
case let .withdrawals(.delegate(.showAsset(transfer, token))),
let .deposits(.delegate(.showAsset(transfer, token))):
switch transfer.details {
case let .fungible(details):
state.destination = .fungibleTokenDetails(
.init(
resourceAddress: transfer.resource.resourceAddress,
resource: .success(transfer.resource),
ownedFungibleResource: .init(
resourceAddress: transfer.resource.resourceAddress,
atLedgerState: transfer.resource.atLedgerState,
amount: details.amount,
metadata: transfer.resource.metadata
),
isXRD: details.isXRD
)
)

case let .nonFungible(details):
state.destination = .nonFungibleTokenDetails(.init(
resourceAddress: transfer.resource.resourceAddress,
resourceDetails: .success(transfer.resource),
token: details,
ledgerState: transfer.resource.atLedgerState
))

case let .liquidStakeUnit(details):
state.destination = .lsuDetails(.init(
validator: details.validator,
stakeUnitResource: .init(resource: details.resource, amount: .init(nominalAmount: details.amount)),
xrdRedemptionValue: details.worth
))

return .none

case let .poolUnit(details):
state.destination = .poolUnitDetails(.init(resourcesDetails: details.details))

case let .stakeClaimNFT(details):
state.destination = .nonFungibleTokenDetails(.init(
resourceAddress: transfer.resource.resourceAddress,
resourceDetails: .success(transfer.resource),
token: token,
ledgerState: transfer.resource.atLedgerState,
stakeClaim: details.stakeClaimTokens.stakeClaims.first,
isClaimStakeEnabled: false
))
}

return .none
return resourceDetailsEffect(state: &state, resource: transfer.resource, details: transfer.details, nft: token)

case let .dAppsUsed(.delegate(.openDapp(dAppID))), let .contributingToPools(.delegate(.openDapp(dAppID))), let .redeemingFromPools(.delegate(.openDapp(dAppID))):
state.destination = .dApp(.init(dAppDefinitionAddress: dAppID))
Expand Down Expand Up @@ -431,6 +384,10 @@ public struct TransactionReview: Sendable, FeatureReducer {

return .none

case let .proofs(.delegate(.showAsset(proof))):
let resource = proof.resourceBalance.resource
return resourceDetailsEffect(state: &state, resource: resource, details: proof.resourceBalance.details)

case .networkFee(.delegate(.showCustomizeFees)):
guard let reviewedTransaction = state.reviewedTransaction else {
return .none
Expand Down Expand Up @@ -731,6 +688,58 @@ extension TransactionReview {
}
}
}

func resourceDetailsEffect(
state: inout State,
resource: OnLedgerEntity.Resource,
details: ResourceBalance.Details,
nft: OnLedgerEntity.NonFungibleToken? = nil
) -> Effect<Action> {
switch details {
case let .fungible(details):
state.destination = .fungibleTokenDetails(.init(
resourceAddress: resource.resourceAddress,
resource: .success(resource),
ownedFungibleResource: .init(
resourceAddress: resource.resourceAddress,
atLedgerState: resource.atLedgerState,
amount: details.amount,
metadata: resource.metadata
),
isXRD: details.isXRD
))

case let .nonFungible(details):
state.destination = .nonFungibleTokenDetails(.init(
resourceAddress: resource.resourceAddress,
resourceDetails: .success(resource),
token: details,
ledgerState: resource.atLedgerState
))

case let .liquidStakeUnit(details):
state.destination = .lsuDetails(.init(
validator: details.validator,
stakeUnitResource: .init(resource: details.resource, amount: .init(nominalAmount: details.amount)),
xrdRedemptionValue: details.worth
))

case let .poolUnit(details):
state.destination = .poolUnitDetails(.init(resourcesDetails: details.details))

case let .stakeClaimNFT(details):
state.destination = .nonFungibleTokenDetails(.init(
resourceAddress: resource.resourceAddress,
resourceDetails: .success(resource),
token: nft,
ledgerState: resource.atLedgerState,
stakeClaim: details.stakeClaimTokens.stakeClaims.first,
isClaimStakeEnabled: false
))
}

return .none
}
}

// MARK: - FailedToAddLockFee
Expand Down Expand Up @@ -783,8 +792,8 @@ extension TransactionReview {

extension TransactionReview {
public struct ProofEntity: Sendable, Identifiable, Hashable {
public let id: ResourceAddress
public let metadata: OnLedgerEntity.Metadata
public var id: ResourceBalance { resourceBalance }
public let resourceBalance: ResourceBalance
}

public struct DappEntity: Sendable, Identifiable, Hashable {
Expand Down
Loading

0 comments on commit 3067b2e

Please sign in to comment.