Skip to content

Commit

Permalink
process pending intercepted status
Browse files Browse the repository at this point in the history
  • Loading branch information
svojsu committed Dec 18, 2024
1 parent a8381e9 commit 8c5f67a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ extension MercuryoCardStatusHandler: PayCardMessageHandling {
}

let statusChange = try JSONDecoder().decode(MercuryoCallbackBody.self, from: message)
let statusData = statusChange.data

logger.debug("New status: \(statusChange)")

guard statusChange.type == MercuryoStatusType.fiatCardSell.rawValue else {
guard statusData.type == MercuryoStatusType.fiatCardSell.rawValue else {
return
}

switch MercuryoStatus(rawValue: statusChange.status) {
switch MercuryoStatus(rawValue: statusData.status) {
case .succeeded:
delegate?.didOpenCard()
case .failed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ extension MercuryoSellRequestResponseHandler: PayCardMessageHandling {

lastTransactionStatus = data.status

if data.status == .new {
switch data.status {
case .new:
let model = PayCardTopupModel(
chainAsset: chainAsset,
amount: data.amounts.request.amount.decimalValue,
recipientAddress: data.address
)

delegate?.didRequestTopup(from: model)
case .pending:
delegate?.didReceivePendingCardOpen()
case .completed:
delegate?.didOpenCard()
}
} catch {
logger.error("Unexpected error: \(error)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
struct MercuryoCallbackBody: Decodable {
let data: MercuryoStatusChange
}

struct MercuryoStatusChange: Decodable {
let id: String
let amount: AmountDecimal
Expand All @@ -16,6 +17,7 @@ enum MercuryoStatus: String, Decodable {
case new
case pending
case succeeded
case completed
case failed
}

Expand Down
1 change: 1 addition & 0 deletions novawallet/Modules/PayCard/Model/PayCardHook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ protocol PayCardHookDelegate: AnyObject {
func didReceiveNoCard()
func didOpenCard()
func didFailToOpenCard()
func didReceivePendingCardOpen()
}

protocol PayCardHookFactoryProtocol {
Expand Down
8 changes: 8 additions & 0 deletions novawallet/Modules/PayCard/PayCardInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ extension PayCardInteractor: PayCardHookDelegate {

presenter?.didReceiveCardStatus(failedStatus)
}

func didReceivePendingCardOpen() {
if let cardOpenTimestamp = settingsManager.novaCardOpenTimestamp {
checkPendingTimeout()
} else {
processIssueInit()
}
}
}

0 comments on commit 8c5f67a

Please sign in to comment.