-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1497 from p2p-org/feature/pwn-9259
[PWN-9259] Home screen outgoing transfer
- Loading branch information
Showing
39 changed files
with
703 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...ages/KeyAppKit/Sources/BankTransfer/Striga/Models/StrigaInitiateSEPAPaymentResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
public struct StrigaInitiateSEPAPaymentResponse: Codable { | ||
let challengeId: String | ||
let dateExpires: String | ||
} |
2 changes: 1 addition & 1 deletion
2
Packages/KeyAppKit/Sources/BankTransfer/Striga/Models/StrigaWithdrawalInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...AppKit/Sources/BankTransfer/UserAction/StrigaBankTransferOutgoingUserActionConsumer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import Combine | ||
import Foundation | ||
import KeyAppBusiness | ||
import KeyAppKitCore | ||
import SolanaSwift | ||
|
||
public enum OutgoingBankTransferUserActionResult: Codable, Equatable { | ||
case requestWithdrawInfo(receiver: String) | ||
case initiated(challengeId: String) | ||
} | ||
|
||
public enum OutgoingBankTransferUserActionEvent: UserActionEvent { | ||
case track(OutgoingBankTransferUserAction, UserActionStatus) | ||
case complete(OutgoingBankTransferUserAction, OutgoingBankTransferUserActionResult) | ||
case sendFailure(OutgoingBankTransferUserAction, String) | ||
} | ||
|
||
public class StrigaBankTransferOutgoingUserActionConsumer: UserActionConsumer { | ||
public typealias Action = OutgoingBankTransferUserAction | ||
public typealias Event = OutgoingBankTransferUserActionEvent | ||
|
||
public let persistence: UserActionPersistentStorage | ||
let database: SynchronizedDatabase<String, Action> = .init() | ||
|
||
private var bankTransferService: AnyBankTransferService<StrigaBankTransferUserDataRepository> | ||
|
||
public init( | ||
persistence: UserActionPersistentStorage, | ||
bankTransferService: AnyBankTransferService<StrigaBankTransferUserDataRepository> | ||
) { | ||
self.persistence = persistence | ||
self.bankTransferService = bankTransferService | ||
} | ||
|
||
public var onUpdate: AnyPublisher<any UserAction, Never> { | ||
database | ||
.onUpdate | ||
.flatMap { data in | ||
Publishers.Sequence(sequence: Array(data.values)) | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
public func start() {} | ||
|
||
public func process(action: any UserAction) { | ||
guard let action = action as? Action else { return } | ||
|
||
Task { [weak self] in | ||
await self?.database.set(for: action.id, action) | ||
self?.handle(event: Event.track(action, .processing)) | ||
/// Checking if all data is available | ||
guard | ||
let service = self?.bankTransferService.value, | ||
let userId = await service.repository.getUserId(), | ||
let withdrawInfo = try await service.repository.getWithdrawalInfo(userId: userId), | ||
let iban = withdrawInfo.IBAN, | ||
let bic = withdrawInfo.BIC | ||
else { | ||
Logger.log( | ||
event: "Striga Confirm Action", | ||
message: "Absence of data", | ||
logLevel: .error | ||
) | ||
let regData = try? await self?.bankTransferService.value.getRegistrationData() | ||
self?.handle(event: Event.complete(action, .requestWithdrawInfo(receiver: [regData?.firstName, regData?.lastName].compactMap({ $0 }).joined(separator: " ")))) | ||
return | ||
} | ||
|
||
do { | ||
let result = try await service.repository.initiateSEPAPayment( | ||
userId: userId, | ||
accountId: action.accountId, | ||
amount: action.amount, | ||
iban: iban, | ||
bic: bic | ||
) | ||
self?.handle(event: Event.complete(action, .initiated(challengeId: result))) | ||
} catch { | ||
self?.handle(event: Event.sendFailure(action, error.localizedDescription)) | ||
} | ||
} | ||
} | ||
|
||
public func handle(event: any UserActionEvent) { | ||
guard let event = event as? Event else { return } | ||
handleInternalEvent(event: event) | ||
} | ||
|
||
func handleInternalEvent(event: Event) { | ||
switch event { | ||
case let .complete(action, result): | ||
Task { [weak self] in | ||
guard let self = self else { return } | ||
let userAction = Action( | ||
id: action.id, | ||
accountId: action.accountId, | ||
amount: action.amount, | ||
status: .ready | ||
) | ||
userAction.result = result | ||
await self.database.set(for: userAction.id, userAction) | ||
} | ||
case let .track(action, status): | ||
Task { [weak self] in | ||
guard let self = self else { return } | ||
let userAction = Action( | ||
id: action.id, | ||
accountId: action.accountId, | ||
amount: action.amount, | ||
status: status | ||
) | ||
await self.database.set(for: userAction.id, userAction) | ||
} | ||
case let .sendFailure(action, _): | ||
Task { [weak self] in | ||
guard let userAction = await self?.database.get(for: action.id) else { return } | ||
userAction.status = .error(UserActionError.networkFailure) | ||
await self?.database.set(for: action.id, userAction) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class OutgoingBankTransferUserAction: UserAction { | ||
public static func == (lhs: OutgoingBankTransferUserAction, rhs: OutgoingBankTransferUserAction) -> Bool { | ||
lhs.id == rhs.id | ||
} | ||
|
||
/// Unique internal id to track. | ||
public let id: String | ||
public let accountId: String | ||
public let amount: String // In cents | ||
/// Abstract status. | ||
public var status: UserActionStatus | ||
public var createdDate: Date | ||
public var updatedDate: Date | ||
public var result: OutgoingBankTransferUserActionResult? | ||
|
||
public init( | ||
id: String, | ||
accountId: String, | ||
amount: String, | ||
status: UserActionStatus, | ||
createdDate: Date = Date(), | ||
updatedDate: Date = Date() | ||
) { | ||
self.id = id | ||
self.accountId = accountId | ||
self.amount = amount | ||
self.status = status | ||
self.createdDate = createdDate | ||
self.updatedDate = updatedDate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.02 KB
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.92 KB
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-298 Bytes
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/Upload.png
Binary file not shown.
Binary file removed
BIN
-534 Bytes
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/[email protected]
Binary file not shown.
Binary file removed
BIN
-765 Bytes
p2p_wallet/Resources/Assets.xcassets/icon-upload.imageset/[email protected]
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.