Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rudimentary decoding for stake txs #3445

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading