Skip to content

Commit cfe52f2

Browse files
authored
Merge pull request #282 from synonymdev/test/transfer
Test/transfer
2 parents 4a27a88 + df37c0f commit cfe52f2

18 files changed

+240
-35
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
# - { name: onchain_boost_receive_widgets, grep: "@onchain|@boost|@receive|@widgets" }
109109
# - { name: settings, grep: "@settings" }
110110
# - { name: security, grep: "@security" }
111-
- { name: e2e, grep: '@send|@lnurl|@lightning|@backup|@onboarding|@onchain_1|@onchain_2|@numberpad|@widgets|@boost|@receive|@settings|@security' }
111+
- { name: e2e, grep: '@transfer|@send|@lnurl|@lightning|@backup|@onboarding|@onchain_1|@onchain_2|@numberpad|@widgets|@boost|@receive|@settings|@security' }
112112

113113
name: e2e-tests - ${{ matrix.shard.name }}
114114

Bitkit/Components/NumberPadTextField.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct NumberPadTextField: View {
7171
}
7272
.contentShape(Rectangle())
7373
.animation(springAnimation, value: currency.primaryDisplay)
74+
.accessibilityElement(children: .contain)
75+
.accessibilityIdentifierIfPresent(testIdentifier)
7476
}
7577

7678
@ViewBuilder
@@ -87,7 +89,6 @@ struct NumberPadTextField: View {
8789
+ Text(viewModel.getPlaceholder(currency: currency))
8890
.foregroundColor(isFocused ? .textSecondary : .textPrimary))
8991
.font(.custom(Fonts.black, size: 44))
90-
.accessibilityIdentifierIfPresent(testIdentifier)
9192
}
9293
}
9394
}

Bitkit/ViewModels/ChannelDetailsViewModel.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ class ChannelDetailsViewModel: ObservableObject {
1414
@Published var error: Error? = nil
1515

1616
private let coreService: CoreService
17+
private let transferStorage: TransferStorage
1718

1819
/// Private initializer for the singleton instance
19-
private init(coreService: CoreService = .shared) {
20+
private init(coreService: CoreService = .shared, transferStorage: TransferStorage = .shared) {
2021
self.coreService = coreService
22+
self.transferStorage = transferStorage
2123
}
2224

2325
/// Find a channel by ID, checking open channels, pending channels, pending orders, then closed channels
@@ -124,15 +126,31 @@ class ChannelDetailsViewModel: ObservableObject {
124126
connections.append(contentsOf: channels.filter { !$0.isChannelReady })
125127
}
126128

129+
// Only show pending orders that have been paid (aligns with Android/RN behavior)
130+
let paidOrderIds: Set<String> = {
131+
guard let activeTransfers = try? transferStorage.getActiveTransfers() else {
132+
return []
133+
}
134+
return Set(
135+
activeTransfers
136+
.filter { $0.type.isToSpending() }
137+
.compactMap(\.lspOrderId)
138+
)
139+
}()
140+
141+
if paidOrderIds.isEmpty {
142+
return connections
143+
}
144+
127145
// Create fake channels from pending orders
128146
guard let orders = try? await coreService.blocktank.orders(refresh: false) else {
129147
return connections
130148
}
131149

132-
let pendingOrders = orders.filter { order in
133-
// Include orders that are created or paid but not yet opened
134-
order.state2 == .created || order.state2 == .paid
135-
}
150+
let pendingOrders = Self.pendingOrders(
151+
orders: orders,
152+
paidOrderIds: paidOrderIds
153+
)
136154

137155
for order in pendingOrders {
138156
let fakeChannel = createFakeChannel(from: order)
@@ -142,6 +160,12 @@ class ChannelDetailsViewModel: ObservableObject {
142160
return connections
143161
}
144162

163+
static func pendingOrders(orders: [IBtOrder], paidOrderIds: Set<String>) -> [IBtOrder] {
164+
orders.filter { order in
165+
paidOrderIds.contains(order.id) && (order.state2 == .created || order.state2 == .paid)
166+
}
167+
}
168+
145169
/// Creates a fake channel from a Blocktank order for UI display purposes
146170
private func createFakeChannel(from order: IBtOrder) -> ChannelDetails {
147171
return ChannelDetails(

Bitkit/ViewModels/TransferViewModel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class TransferViewModel: ObservableObject {
113113
uiState.isAdvanced = true
114114
}
115115

116+
func displayOrder(for order: IBtOrder) -> IBtOrder {
117+
uiState.order ?? order
118+
}
119+
116120
func payOrder(order: IBtOrder, speed: TransactionSpeed) async throws {
117121
var fees = try? await coreService.blocktank.fees(refresh: true)
118122
if fees == nil {

Bitkit/Views/Settings/Advanced/LightningConnectionsView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ struct LightningConnectionsView: View {
7070
.padding(.top, 16)
7171

7272
ForEach(Array(pendingConnections.enumerated()), id: \.element.channelId) { index, channel in
73+
let labelIndex = pendingConnections.count - index
7374
Button {
7475
navigation.navigate(.connectionDetail(channelId: channel.channelIdString))
7576
} label: {
7677
VStack(spacing: 0) {
7778
HStack {
78-
SubtitleText("\(t("lightning__connection")) \(index + 1)")
79+
SubtitleText("\(t("lightning__connection")) \(labelIndex)")
7980
Spacer()
8081
Image("chevron")
8182
.resizable()
@@ -109,12 +110,13 @@ struct LightningConnectionsView: View {
109110
.padding(.top, 16)
110111

111112
ForEach(Array(openChannels.enumerated()), id: \.element.channelId) { index, channel in
113+
let labelIndex = openChannels.count - index
112114
Button {
113115
navigation.navigate(.connectionDetail(channelId: channel.channelIdString))
114116
} label: {
115117
VStack(spacing: 0) {
116118
HStack {
117-
SubtitleText("\(t("lightning__connection")) \(index + 1)")
119+
SubtitleText("\(t("lightning__connection")) \(labelIndex)")
118120
Spacer()
119121
Image("chevron")
120122
.resizable()
@@ -147,12 +149,13 @@ struct LightningConnectionsView: View {
147149
.padding(.top, 16)
148150

149151
ForEach(Array(closedChannels.enumerated()), id: \.element.channelId) { index, channel in
152+
let labelIndex = closedChannels.count - index
150153
Button {
151154
navigation.navigate(.connectionDetail(channelId: channel.channelIdString))
152155
} label: {
153156
VStack(spacing: 0) {
154157
HStack {
155-
SubtitleText("\(t("lightning__connection")) \(index + 1)")
158+
SubtitleText("\(t("lightning__connection")) \(labelIndex)")
156159
Spacer()
157160
Image("chevron")
158161
.resizable()

Bitkit/Views/Transfer/FundManualAmountView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct FundManualAmountView: View {
5757
isDisabled: amountSats == 0,
5858
destination: FundManualConfirmView(lnPeer: lnPeer, amountSats: amountSats)
5959
)
60+
.accessibilityIdentifier("ExternalAmountContinue")
6061
}
6162
}
6263
.navigationBarHidden(true)

Bitkit/Views/Transfer/SavingsAvailabilityView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct SavingsAvailabilityView: View {
3333
CustomButton(title: t("common__continue")) {
3434
navigation.navigate(.savingsConfirm)
3535
}
36+
.accessibilityIdentifier("AvailabilityContinue")
3637
}
3738
}
3839
.navigationBarHidden(true)

Bitkit/Views/Transfer/SavingsProgressView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct SavingsProgressContentView: View {
9999
.frame(width: 256, height: 256)
100100
.padding()
101101
.frame(maxWidth: .infinity, maxHeight: .infinity)
102+
.accessibilityIdentifierIfPresent(progressState == .success ? "TransferSuccess" : nil)
102103
}
103104

104105
Spacer()
@@ -109,6 +110,7 @@ struct SavingsProgressContentView: View {
109110
) {
110111
navigation.reset()
111112
}
113+
.accessibilityIdentifierIfPresent(progressState == .success ? "TransferSuccess-button" : nil)
112114
}
113115
.navigationBarHidden(true)
114116
.padding(.horizontal, 16)

Bitkit/Views/Transfer/SettingUpView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ struct SettingUpView: View {
169169

170170
if isTransferring {
171171
SettingUpLoadingView()
172+
.accessibilityIdentifier("LightningSettingUp")
172173
} else {
173174
Image("check")
174175
.resizable()
175176
.aspectRatio(contentMode: .fit)
176177
.frame(width: 256, height: 256)
177178
.padding()
178179
.frame(maxWidth: .infinity, maxHeight: .infinity)
180+
.accessibilityIdentifier("TransferSuccess")
179181
}
180182

181183
Spacer()
@@ -188,6 +190,7 @@ struct SettingUpView: View {
188190
CustomButton(title: buttonTitle) {
189191
navigation.reset()
190192
}
193+
.accessibilityIdentifier("TransferSuccess-button")
191194
}
192195
}
193196
.navigationBarHidden(true)

Bitkit/Views/Transfer/SpendingAdvancedView.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ struct SpendingAdvancedView: View {
3434
DisplayText(t("lightning__spending_advanced__title"), accentColor: .purpleAccent)
3535
.fixedSize(horizontal: false, vertical: true)
3636

37-
NumberPadTextField(viewModel: amountViewModel, showConversion: false)
38-
.onTapGesture {
39-
amountViewModel.togglePrimaryDisplay(currency: currency)
40-
}
41-
.padding(.top, 32)
37+
NumberPadTextField(
38+
viewModel: amountViewModel,
39+
showConversion: false,
40+
testIdentifier: "SpendingAdvancedNumberField"
41+
)
42+
.onTapGesture {
43+
amountViewModel.togglePrimaryDisplay(currency: currency)
44+
}
45+
.padding(.top, 32)
4246

4347
// Fee estimate
4448
HStack(spacing: 4) {
@@ -91,6 +95,7 @@ struct SpendingAdvancedView: View {
9195
app.toast(error)
9296
}
9397
}
98+
.accessibilityIdentifier("SpendingAdvancedContinue")
9499
}
95100
}
96101
.navigationBarHidden(true)
@@ -118,18 +123,21 @@ struct SpendingAdvancedView: View {
118123
NumberPadActionButton(text: t("common__min")) {
119124
amountViewModel.updateFromSats(transfer.transferValues.minLspBalance, currency: currency)
120125
}
126+
.accessibilityIdentifier("SpendingAdvancedMin")
121127

122128
Spacer()
123129

124130
NumberPadActionButton(text: t("common__default")) {
125131
amountViewModel.updateFromSats(transfer.transferValues.defaultLspBalance, currency: currency)
126132
}
133+
.accessibilityIdentifier("SpendingAdvancedDefault")
127134

128135
Spacer()
129136

130137
NumberPadActionButton(text: t("common__max")) {
131138
amountViewModel.updateFromSats(transfer.transferValues.maxLspBalance, currency: currency)
132139
}
140+
.accessibilityIdentifier("SpendingAdvancedMax")
133141
}
134142
}
135143

0 commit comments

Comments
 (0)