Skip to content

Commit

Permalink
Merge pull request #3445 from safe-global/feat-add-decoding-staking-tx
Browse files Browse the repository at this point in the history
feat: add rudimentary decoding for stake txs
  • Loading branch information
compojoom authored Sep 30, 2024
2 parents 81b9dde + 0252425 commit 86a076a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set -o pipefail && \
xcrun xcodebuild test \
-project Multisig.xcodeproj \
-scheme "$XCODE_SCHEME" \
-destination "platform=iOS Simulator,name=iPhone 15 Pro" \
-destination "platform=iOS Simulator,name=iPhone 16 Pro" \
-resultBundlePath "$TEST_BUNDLE_PATH" \
| tee "$OUTPUT_DIR/xcodebuild-test.log" | xcpretty -c -r junit

Expand Down

0 comments on commit 86a076a

Please sign in to comment.