Skip to content

Commit

Permalink
feat: add rudimentary decoding for stake txs
Browse files Browse the repository at this point in the history
Instead of showing “unknown operation” we now display the type of stake
tx.
  • Loading branch information
compojoom committed Sep 26, 2024
1 parent 81b9dde commit dff020b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Multisig/Data/Services/Safe Client Gateway Service/SCGModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ extension SCGModels {
case swapOrder(SwapOrder)
case swapTransfer(SwapOrder)
case twapOrder(TwapOrder)
case stake(Stake)
case unknown

init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -206,6 +207,8 @@ extension SCGModels {
self = try .swapTransfer(SwapOrder(from: decoder))
case "TwapOrder":
self = try .twapOrder(TwapOrder(from: decoder))
case "NativeStakingDeposit", "NativeStakingValidatorsExit", "NativeStakingWithdraw":
self = try .stake(Stake(from: decoder))
case "Unknown":
fallthrough
default:
Expand Down Expand Up @@ -382,6 +385,31 @@ extension SCGModels {
var implementation: AddressInfo?
var factory: AddressInfo?
}

struct Stake: Decodable {
let type: StakeType

var displayName: String {
return type.displayName
}
}

enum StakeType: String, Decodable {
case deposit = "NativeStakingDeposit"
case validatorsExit = "NativeStakingValidatorsExit"
case withdraw = "NativeStakingWithdraw"

var displayName: String {
switch self {
case .deposit:
return "Stake"
case .validatorsExit:
return "Withdraw request"
case .withdraw:
return "Claim"
}
}
}

struct SwapOrder: Decodable {
var uid: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ class TransactionDetailCellBuilder {
externalURL(text: "Order details", url: orderInfo.explorerUrl)
case .twapOrder(let order):
text(order.displayName, title: "Contract Interaction", expandableTitle: nil, copyText: nil)
case .stake(let stake):
text(stake.displayName, title: "Contract Interaction", expandableTitle: nil, copyText: nil)

case .creation(_):
// ignore
fallthrough
Expand Down Expand Up @@ -675,6 +678,9 @@ class TransactionDetailCellBuilder {
case .twapOrder(let order):
type = order.displayName
icon = UIImage(named: "ico-custom-tx")
case .stake(let stake):
type = stake.displayName
icon = UIImage(named: "ico-custom-tx")
case .unknown:
type = "Unknown operation"
icon = UIImage(named: "ico-custom-tx")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class TransactionListViewController: LoadableViewController, UITableViewDelegate
case .twapOrder(let order):
image = UIImage(named: "ico-custom-tx")
title = order.displayName
case .stake(let stake):
image = UIImage(named: "ico-custom-tx")
title = stake.displayName
case .unknown:
image = UIImage(named: "ico-custom-tx")
title = "Unknown operation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class WCIncomingTransactionRequestViewController: ReviewSafeTransactionViewContr
case .twapOrder(let order):
imageName = "ico-custom-tx"
name = order.displayName
case .stake(let stake):
imageName = "ico-custom-tx"
name = stake.displayName
case .unknown:
imageName = "ico-custom-tx"
name = "Unknown operation"
Expand Down

0 comments on commit dff020b

Please sign in to comment.