Skip to content

Commit

Permalink
Account Details - Stakes redesign (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP authored Jan 18, 2024
1 parent 1291bcf commit c5ebdbb
Show file tree
Hide file tree
Showing 48 changed files with 1,230 additions and 771 deletions.
96 changes: 54 additions & 42 deletions RadixWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ extension OnLedgerEntitiesClient {
return OnLedgerEntity.Account.PoolUnit(resource: poolUnitResource, resourcePoolAddress: pool.address)
}

return .init(radixNetworkStakes: stakeUnits, poolUnits: poolUnits)
return .init(radixNetworkStakes: stakeUnits.asIdentifiable(), poolUnits: poolUnits)
}

static func extractOwnedFungibleResources(
Expand Down Expand Up @@ -448,18 +448,37 @@ extension OnLedgerEntitiesClient {
return nil
}()

let stakeClaimTokens: NonFunbileResourceWithTokens? = try await {
let stakeClaimTokens: NonFunbileResourceWithTokens? = try await { () -> NonFunbileResourceWithTokens? in
if let stakeClaimResource = stake.stakeClaimResource, stakeClaimResource.nonFungibleIdsCount > 0 {
guard let stakeClaimResourceDetails = resourceDetails.first(where: { $0.resourceAddress == stakeClaimResource.resourceAddress }) else {
assertionFailure("Did not load stake unit details")
return nil
}
let tokenData = try await getAccountOwnedNonFungibleTokenData(.init(
let tokens = try await getAccountOwnedNonFungibleTokenData(.init(
accountAddress: account.address,
resource: stakeClaimResource,
mode: .loadAll
)).tokens
return .init(resource: stakeClaimResourceDetails, tokens: tokenData)

return .init(
resource: stakeClaimResourceDetails,
stakeClaims: tokens.compactMap { token -> OnLedgerEntitiesClient.StakeClaim? in
guard
let claimEpoch = token.data?.claimEpoch,
let claimAmount = token.data?.claimAmount,
claimAmount > 0
else {
return nil
}

return OnLedgerEntitiesClient.StakeClaim(
validatorAddress: stake.validatorAddress,
token: token,
claimAmount: claimAmount,
reamainingEpochsUntilClaim: Int(claimEpoch) - Int(currentEpoch.rawValue)
)
}.asIdentifiable()
)
}

return nil
Expand Down Expand Up @@ -502,7 +521,7 @@ extension OnLedgerEntity.Account.PoolUnitResources {
return nil
}

return .init(radixNetworkStakes: stakes, poolUnits: poolUnits)
return .init(radixNetworkStakes: stakes.asIdentifiable(), poolUnits: poolUnits)
}
}

Expand Down Expand Up @@ -555,9 +574,24 @@ extension OnLedgerEntitiesClient {
public let amount: RETDecimal
}

public struct StakeClaim: Hashable, Sendable, Identifiable {
public var id: NonFungibleGlobalId {
token.id
}

let validatorAddress: ValidatorAddress
let token: OnLedgerEntity.NonFungibleToken
let claimAmount: RETDecimal
let reamainingEpochsUntilClaim: Int

var isReadyToBeClaimed: Bool {
reamainingEpochsUntilClaim <= .zero
}
}

public struct NonFunbileResourceWithTokens: Hashable, Sendable {
public let resource: OnLedgerEntity.Resource
public let tokens: [OnLedgerEntity.NonFungibleToken]
public let stakeClaims: IdentifiedArrayOf<StakeClaim>
}
}

Expand Down
26 changes: 23 additions & 3 deletions RadixWallet/Core/DesignSystem/Components/TokenBalanceView.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@

// MARK: - TokenBalanceView
public struct TokenBalanceView: View {
public struct ViewState {
public let thumbnail: TokenThumbnail.Content
public let name: String
public let balance: RETDecimal
public let iconSize: HitTargetSize

public init(thumbnail: TokenThumbnail.Content, name: String, balance: RETDecimal) {
public init(
thumbnail: TokenThumbnail.Content,
name: String,
balance: RETDecimal,
iconSize: HitTargetSize = .smallest
) {
self.thumbnail = thumbnail
self.name = name
self.balance = balance
self.iconSize = iconSize
}
}

Expand All @@ -20,8 +27,9 @@ public struct TokenBalanceView: View {

public var body: some View {
HStack(alignment: .center) {
TokenThumbnail(viewState.thumbnail, size: .small)
TokenThumbnail(viewState.thumbnail, size: viewState.iconSize)
.padding(.trailing, .small1)

Text(viewState.name)
.foregroundColor(.app.gray1)
.textStyle(.body2HighImportance)
Expand All @@ -34,3 +42,15 @@ public struct TokenBalanceView: View {
}
}
}

extension TokenBalanceView {
public static func xrd(balance: RETDecimal) -> Self {
TokenBalanceView(
viewState: .init(
thumbnail: .xrd,
name: "XRD",
balance: balance
)
)
}
}
11 changes: 11 additions & 0 deletions RadixWallet/Core/DesignSystem/Extensions/View+Extra.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extension View {
func withDottedCircleOverlay() -> some View {
self
.padding(.small3)
.overlay {
Circle()
.stroke(style: StrokeStyle(lineWidth: 1, dash: [3, 3]))
.foregroundColor(.app.gray3)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct PrimaryRectangularButtonStyle: ButtonStyle {
public func makeBody(configuration: ButtonStyle.Configuration) -> some View {
ZStack {
configuration.label
.lineLimit(nil)
.foregroundColor(foregroundColor)
.font(.app.body1Header)
.frame(maxWidth: shouldExpand ? .infinity : nil)
Expand Down Expand Up @@ -44,7 +45,7 @@ extension PrimaryRectangularButtonStyle {
case .loading:
.clear
case .disabled:
.app.gray3
.app.gray2
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions RadixWallet/Core/FeaturePrelude/LoadableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ extension View {
@ViewBuilder
public func loadable<T>(
_ loadable: Loadable<T>,
loadingViewHeight: CGFloat = .large1,
@ViewBuilder successContent: (T) -> some View
) -> some View {
self.loadable(
loadable,
loadingView: {
Spacer()
.frame(height: .large1)
.background(.app.gray4)
.shimmer(active: true, config: .accountResourcesLoading)
.cornerRadius(.small1)
shimmeringLoadingView(height: loadingViewHeight)
},
successContent: successContent
)
}

@ViewBuilder
func shimmeringLoadingView(height: CGFloat = .large1) -> some View {
Spacer()
.frame(height: height)
.background(.app.gray4)
.shimmer(active: true, config: .accountResourcesLoading)
.cornerRadius(.small1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum AssetResource {
public static let fungibleTokens = ImageAsset(name: "fungible-tokens")
public static let nonfungbileTokens = ImageAsset(name: "nonfungbile-tokens")
public static let poolUnits = ImageAsset(name: "pool-units")
public static let stakes = ImageAsset(name: "stakes")
public static let freezableByAnyone = ImageAsset(name: "freezable-by-anyone")
public static let freezableByThirdParty = ImageAsset(name: "freezable-by-third-party")
public static let informationChangeableByAnyone = ImageAsset(name: "information-changeable-by-anyone")
Expand Down Expand Up @@ -71,6 +72,7 @@ public enum AssetResource {
public static let iconHardwareLedger = ImageAsset(name: "icon-hardware-ledger")
public static let iconHistory = ImageAsset(name: "icon-history")
public static let iconLinkOut = ImageAsset(name: "icon-link-out")
public static let iconValidator = ImageAsset(name: "icon-validator")
public static let info = ImageAsset(name: "info")
public static let lock = ImageAsset(name: "lock")
public static let minusCircle = ImageAsset(name: "minus-circle")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icon-Staking.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icon-validator.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
11 changes: 5 additions & 6 deletions RadixWallet/Core/SharedModels/Assets/OnLedgerEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,15 @@ extension OnLedgerEntity {

extension OnLedgerEntity.Account {
public struct PoolUnitResources: Sendable, Hashable, Codable {
public let radixNetworkStakes: [RadixNetworkStake]
public let radixNetworkStakes: IdentifiedArrayOf<RadixNetworkStake>
public let poolUnits: [PoolUnit]
}

public init(radixNetworkStakes: [RadixNetworkStake], poolUnits: [PoolUnit]) {
self.radixNetworkStakes = radixNetworkStakes
self.poolUnits = poolUnits
public struct RadixNetworkStake: Sendable, Hashable, Codable, Identifiable {
public var id: ValidatorAddress {
validatorAddress
}
}

public struct RadixNetworkStake: Sendable, Hashable, Codable {
public let validatorAddress: ValidatorAddress
public let stakeUnitResource: OnLedgerEntity.OwnedFungibleResource?
public let stakeClaimResource: OnLedgerEntity.OwnedNonFungibleResource?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
import EngineToolkit

extension ManifestBuilder {
public struct StakeClaim: Sendable {
public let validatorAddress: ValidatorAddress
public let resourceAddress: ResourceAddress
public let ids: [NonFungibleLocalId]
}

public static func stakeClaimsManifest(
accountAddress: AccountAddress,
stakeClaims: [StakeClaim]
) throws -> TransactionManifest {
try make {
for stakeClaim in stakeClaims {
let bucket = ManifestBuilderBucket.unique
try accountWithdrawNonFungibles(
accountAddress.intoEngine(),
stakeClaim.resourceAddress.intoEngine(),
stakeClaim.ids
)
try takeAllFromWorktop(stakeClaim.resourceAddress.intoEngine(), bucket)
try validatorClaimXrd(stakeClaim.validatorAddress.intoEngine(), bucket)
}
try accountDepositEntireWorktop(accountAddress.intoEngine())
}
.build(networkId: accountAddress.intoEngine().networkId())
}
}

// MARK: Manifests for testing
extension ManifestBuilder {
public static func manifestForFaucet(
includeLockFeeInstruction: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ extension ManifestBuilder {
public static let faucetFreeXrd = flip(faucetFreeXrd)
public static let accountTryDepositBatchOrAbort = flip(accountTryDepositBatchOrAbort)
public static let accountTryDepositEntireWorktopOrAbort = flip(accountTryDepositEntireWorktopOrAbort)
public static let accountDepositEntireWorktop = flip(accountDepositEntireWorktop)
public static let withdrawAmount = flip(accountWithdraw)
public static let withdrawTokens = flip(accountWithdrawNonFungibles)
public static let takeFromWorktop = flip(takeFromWorktop)
public static let takeAllFromWorktop = flip(takeAllFromWorktop)
public static let accountTryDepositOrAbort = flip(accountTryDepositOrAbort)
public static let accountDeposit = flip(accountDeposit)
public static let takeNonFungiblesFromWorktop = flip(takeNonFungiblesFromWorktop)
public static let accountWithdrawNonFungibles = flip(accountWithdrawNonFungibles)
public static let setOwnerKeys = flip(setOwnerKeys)
public static let createFungibleResourceManager = flip(createFungibleResourceManager)
public static let validatorClaimXrd = flip(validatorClaimXrd)

@resultBuilder
public enum InstructionsChain {
Expand Down
3 changes: 3 additions & 0 deletions RadixWallet/EngineKit/Models+Sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extension TransactionManifest: @unchecked Sendable {}
// MARK: - NonFungibleGlobalId + Sendable
extension NonFungibleGlobalId: @unchecked Sendable {}

// MARK: - NonFungibleGlobalId + Identifiable
extension NonFungibleGlobalId: Identifiable {}

// MARK: - Instructions + Sendable
extension Instructions: @unchecked Sendable {}

Expand Down
Loading

0 comments on commit c5ebdbb

Please sign in to comment.