Skip to content

Commit

Permalink
ABW-1695 Pool Unit asset type (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciek-rdx authored Aug 8, 2023
1 parent 1c5f4ea commit ede37d7
Show file tree
Hide file tree
Showing 28 changed files with 1,444 additions and 26 deletions.
549 changes: 542 additions & 7 deletions App/BabylonWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE68BE1D2A77F01B006024B8"
BuildableName = "AssetsFeaturePreview.app"
BlueprintName = "AssetsFeaturePreview"
ReferencedContainer = "container:BabylonWallet.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug-Dev"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug-Dev"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE68BE1D2A77F01B006024B8"
BuildableName = "AssetsFeaturePreview.app"
BlueprintName = "AssetsFeaturePreview"
ReferencedContainer = "container:BabylonWallet.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE68BE1D2A77F01B006024B8"
BuildableName = "AssetsFeaturePreview.app"
BlueprintName = "AssetsFeaturePreview"
ReferencedContainer = "container:BabylonWallet.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug-Dev">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
18 changes: 18 additions & 0 deletions App/Previews/AssetsFeaturePreview/AssetsFeaturePreviewApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import AssetsFeature
import ComposableArchitecture
import SwiftUI

// MARK: - AssetsFeaturePreviewApp
@main
struct AssetsFeaturePreviewApp: App {
var body: some Scene {
WindowGroup {
AssetsView.View(
store: .init(
initialState: .init(account: .previewValue0),
reducer: AssetsView.init
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
22 changes: 18 additions & 4 deletions Sources/Core/DesignSystem/Layouts/StackedViewsLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public struct StackedViewsLayout: Layout {
return properties
}

public func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
public func sizeThatFits(
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) -> CGSize {
let container = proposal.replacingUnspecifiedDimensions()
guard !subviews.isEmpty else {
return container
Expand All @@ -47,15 +51,25 @@ public struct StackedViewsLayout: Layout {
return .init(width: container.width, height: height)
}

public func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
public func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) {
let container = proposal.replacingUnspecifiedDimensions()
var offset: CGFloat = 0
for (index, subview) in subviews.enumerated() {
let place = CGPoint(x: bounds.minX, y: bounds.minY + offset)
subview.place(at: place, proposal: .init(width: container.width, height: nil))
subview.place(
at: place,
proposal: .init(width: container.width, height: nil)
)

if isExpanded {
let subviewSize = subview.sizeThatFits(.init(width: container.width, height: nil))
let subviewSize = subview.sizeThatFits(
.init(width: container.width, height: nil)
)
offset += subviewSize.height + spacing
} else {
// The rest of the cards that go over `collapsedViewsCount` will go behind the last card.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import SwiftUI
// MARK: - TokenRowShadow
extension View {
public func tokenRowShadow(_ show: Bool = true) -> some View {
shadow(color: show ? .app.shadowBlack : .clear, radius: .small2, x: .zero, y: .small2)
shadow(
color: show ? .app.shadowBlack : .clear,
radius: .small2,
x: .zero,
y: .small2
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extension TaskResult where Success == Prelude.Unit {
public init(catching body: @Sendable () async throws -> Void) async {
do {
try await body()
self = .success(Prelude.Unit())
self = .success(Prelude.Unit.instance)
} catch {
self = .failure(error)
}
Expand Down
31 changes: 27 additions & 4 deletions Sources/Features/AssetsFeature/AssetsView+Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ public struct AssetsView: Sendable, FeatureReducer {
public enum AssetKind: String, Sendable, Hashable, CaseIterable, Identifiable {
case fungible
case nonFungible
case poolUnits

var displayText: String {
switch self {
case .fungible:
return L10n.Account.tokens
case .nonFungible:
return L10n.Account.nfts
case .poolUnits:
return L10n.Account.poolUnits
}
}
}

public var activeAssetKind: AssetKind
public var assetKinds: NonEmpty<[AssetKind]>

public var fungibleTokenList: FungibleAssetList.State
public var nonFungibleTokenList: NonFungibleAssetList.State
public var poolUnitsList: PoolUnitsList.State

public let account: Profile.Network.Account
public var isLoadingResources: Bool = false
Expand All @@ -33,22 +38,26 @@ public struct AssetsView: Sendable, FeatureReducer {
account: account,
fungibleTokenList: .init(),
nonFungibleTokenList: .init(rows: []),
// FIXME: Rewire
poolUnitsList: .preview,
mode: mode
)
}

init(
account: Profile.Network.Account,
assetKinds: NonEmpty<[AssetKind]> = .init([.fungible, .nonFungible])!,
assetKinds: NonEmpty<[AssetKind]> = .init(rawValue: AssetKind.allCases)!,
fungibleTokenList: FungibleAssetList.State,
nonFungibleTokenList: NonFungibleAssetList.State,
poolUnitsList: PoolUnitsList.State,
mode: Mode
) {
self.account = account
self.assetKinds = assetKinds
self.activeAssetKind = assetKinds.first
self.fungibleTokenList = fungibleTokenList
self.nonFungibleTokenList = nonFungibleTokenList
self.poolUnitsList = poolUnitsList
self.mode = mode
}
}
Expand All @@ -64,6 +73,7 @@ public struct AssetsView: Sendable, FeatureReducer {
public enum ChildAction: Sendable, Equatable {
case fungibleTokenList(FungibleAssetList.Action)
case nonFungibleTokenList(NonFungibleAssetList.Action)
case poolUnitsList(PoolUnitsList.Action)
}

public enum InternalAction: Sendable, Equatable {
Expand All @@ -80,12 +90,25 @@ public struct AssetsView: Sendable, FeatureReducer {
public init() {}

public var body: some ReducerProtocolOf<Self> {
Scope(state: \.nonFungibleTokenList, action: /Action.child .. ChildAction.nonFungibleTokenList) {
Scope(
state: \.fungibleTokenList,
action: /Action.child .. ChildAction.fungibleTokenList
) {
FungibleAssetList()
}
Scope(
state: \.nonFungibleTokenList,
action: /Action.child .. ChildAction.nonFungibleTokenList
) {
NonFungibleAssetList()
}
Scope(state: \.fungibleTokenList, action: /Action.child .. ChildAction.fungibleTokenList) {
FungibleAssetList()
Scope(
state: \.poolUnitsList,
action: /Action.child .. ChildAction.poolUnitsList
) {
PoolUnitsList()
}

Reduce(core)
}

Expand Down
17 changes: 15 additions & 2 deletions Sources/Features/AssetsFeature/AssetsView+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension AssetsView {
}

public var body: some SwiftUI.View {
WithViewStore(store, observe: { $0 }, send: { .view($0) }) { viewStore in
WithViewStore(store, observe: identity, send: FeatureAction.view) { viewStore in
ScrollView {
VStack(spacing: .medium3) {
assetTypeSelectorView(viewStore)
Expand All @@ -38,6 +38,13 @@ extension AssetsView {
action: { .child(.nonFungibleTokenList($0)) }
)
)
case .poolUnits:
PoolUnitsList.View(
store: store.scope(
state: \.poolUnitsList,
action: { .child(.poolUnitsList($0)) }
)
)
}
}
.padding(.bottom, .medium1)
Expand Down Expand Up @@ -101,7 +108,13 @@ struct AssetsView_Preview: PreviewProvider {
static var previews: some View {
AssetsView.View(
store: .init(
initialState: .init(account: .previewValue0, fungibleTokenList: .init(), nonFungibleTokenList: .init(rows: []), mode: .normal),
initialState: .init(
account: .previewValue0,
fungibleTokenList: .init(),
nonFungibleTokenList: .init(rows: []),
poolUnitsList: .init(),
mode: .normal
),
reducer: AssetsView()
)
)
Expand Down
Loading

0 comments on commit ede37d7

Please sign in to comment.