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

IOS-7349 [Staking] Send input token and public key in several requests #3666

Merged
merged 6 commits into from
Aug 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ struct CommonWalletModelsFactory {
)
}

func makeStakingManager(tokenItem: TokenItem, address: String) -> StakingManager? {
func makeStakingManager(publicKey: Data, tokenItem: TokenItem, address: String) -> StakingManager? {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publicKey кладется в additionalAddresses -> cosmosPubKey

guard let integrationId = StakingFeatureProvider().yieldId(for: tokenItem),
let item = tokenItem.stakingTokenItem else {
return nil
}

let wallet = StakingWallet(item: item, address: address)
let wallet = StakingWallet(
item: item,
address: address,
publicKey: publicKey
)
return StakingDependenciesFactory().makeStakingManager(integrationId: integrationId, wallet: wallet)
}
}
Expand Down Expand Up @@ -98,7 +102,11 @@ extension CommonWalletModelsFactory: WalletModelsFactory {
let shouldPerformHealthCheck = shouldPerformHealthCheck(blockchain: currentBlockchain, amountType: .coin)
let mainCoinModel = WalletModel(
walletManager: walletManager,
stakingManager: makeStakingManager(tokenItem: tokenItem, address: walletManager.wallet.address),
stakingManager: makeStakingManager(
publicKey: walletManager.wallet.publicKey.blockchainKey,
tokenItem: tokenItem,
address: walletManager.wallet.address
),
transactionHistoryService: transactionHistoryService,
amountType: .coin,
shouldPerformHealthCheck: shouldPerformHealthCheck,
Expand All @@ -119,7 +127,11 @@ extension CommonWalletModelsFactory: WalletModelsFactory {
let shouldPerformHealthCheck = shouldPerformHealthCheck(blockchain: currentBlockchain, amountType: amountType)
let tokenModel = WalletModel(
walletManager: walletManager,
stakingManager: makeStakingManager(tokenItem: tokenItem, address: walletManager.wallet.address),
stakingManager: makeStakingManager(
publicKey: walletManager.wallet.publicKey.blockchainKey,
tokenItem: tokenItem,
address: walletManager.wallet.address
),
transactionHistoryService: transactionHistoryService,
amountType: amountType,
shouldPerformHealthCheck: shouldPerformHealthCheck,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ extension TokenItem {
StakeKitNetworkType(rawValue: blockchain.coinId).map { network in
StakingTokenItem(
network: network,
contractAddress: contractAddress
contractAddress: contractAddress,
name: name,
decimals: decimalCount,
symbol: currencySymbol
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ extension StakingFeatureProvider {

var testableBlockchainIds: Set<StakingTokenItem> {
[
StakingTokenItem(network: .solana, contractAddress: nil),
StakingTokenItem(network: .cosmos, contractAddress: nil),
StakingTokenItem(network: .ethereum, contractAddress: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0"),
StakingTokenItem(network: .solana, contractAddress: nil, name: "Solana", decimals: 9, symbol: "SOL"),
StakingTokenItem(network: .cosmos, contractAddress: nil, name: "Cosmos", decimals: 6, symbol: "ATOM"),
StakingTokenItem(network: .ethereum, contractAddress: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0", name: "Ethereum", decimals: 18, symbol: "ETH"),
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

блин, тут конечно не очень красиво получилось, ну ок

]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension YieldInfo {
),
],
defaultValidator: nil,
item: .init(network: .tron, contractAddress: nil),
item: .init(network: .tron, contractAddress: nil, name: "", decimals: 0, symbol: ""),
unbondingPeriod: .days(14),
warmupPeriod: .days(0),
rewardClaimingType: .manual,
Expand Down
12 changes: 12 additions & 0 deletions TangemApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
0A0DB7582C48FB0000003450 /* RewardRateValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A0DB7572C48FAFF00003450 /* RewardRateValues.swift */; };
0A0E01772C64AA79009E01F2 /* StakingSendAmountValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A0E01762C64AA79009E01F2 /* StakingSendAmountValidator.swift */; };
0A1992A62B5FBDF800344312 /* CurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A1992A52B5FBDF800344312 /* CurrencyTests.swift */; };
0A3BF9692C6CDAD900163492 /* AdditionalAddresses.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3BF9682C6CDAD900163492 /* AdditionalAddresses.swift */; };
0A3BF96B2C6CE96B00163492 /* StakingAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3BF96A2C6CE96B00163492 /* StakingAction.swift */; };
0A3BF96F2C6DDB9000163492 /* StakingActionRequestParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3BF96E2C6DDB9000163492 /* StakingActionRequestParams.swift */; };
0A81B3732BB2D24A0008F21C /* BlockchainURLSchemesParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A81B3722BB2D24A0008F21C /* BlockchainURLSchemesParser.swift */; };
0A81B38E2BB3018E0008F21C /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = 0A81B38D2BB3018E0008F21C /* ZIPFoundation */; };
0AB5A4732C5267CB00491764 /* SegmentedPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB5A4722C5267CB00491764 /* SegmentedPicker.swift */; };
Expand Down Expand Up @@ -1887,6 +1890,9 @@
0A0E01762C64AA79009E01F2 /* StakingSendAmountValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingSendAmountValidator.swift; sourceTree = "<group>"; };
0A1992A52B5FBDF800344312 /* CurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyTests.swift; sourceTree = "<group>"; };
0A35044D2E5DF9354751E2DE /* Pods-TangemStakingTests.release(alpha).xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TangemStakingTests.release(alpha).xcconfig"; path = "Target Support Files/Pods-TangemStakingTests/Pods-TangemStakingTests.release(alpha).xcconfig"; sourceTree = "<group>"; };
0A3BF9682C6CDAD900163492 /* AdditionalAddresses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionalAddresses.swift; sourceTree = "<group>"; };
0A3BF96A2C6CE96B00163492 /* StakingAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingAction.swift; sourceTree = "<group>"; };
0A3BF96E2C6DDB9000163492 /* StakingActionRequestParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingActionRequestParams.swift; sourceTree = "<group>"; };
0A81B3722BB2D24A0008F21C /* BlockchainURLSchemesParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockchainURLSchemesParser.swift; sourceTree = "<group>"; };
0AB5A4722C5267CB00491764 /* SegmentedPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedPicker.swift; sourceTree = "<group>"; };
0BE949936543D22F51E09DBD /* Pods-Tangem-TangemUITests.release(alpha).xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tangem-TangemUITests.release(alpha).xcconfig"; path = "Target Support Files/Pods-Tangem-TangemUITests/Pods-Tangem-TangemUITests.release(alpha).xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9500,6 +9506,9 @@
0A0DB7572C48FAFF00003450 /* RewardRateValues.swift */,
EF0FBB882C53FFC10095A6BD /* ActionTransaction.swift */,
EF0FBB8A2C53FFCD0095A6BD /* ActionStatus.swift */,
0A3BF9682C6CDAD900163492 /* AdditionalAddresses.swift */,
0A3BF96A2C6CE96B00163492 /* StakingAction.swift */,
0A3BF96E2C6DDB9000163492 /* StakingActionRequestParams.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -12376,6 +12385,7 @@
EFB019472C4172D6009EE857 /* StakeKitDTO+NetworkType.swift in Sources */,
EF407E5D2C04D64B00366733 /* StakingAPIProvider.swift in Sources */,
EFBC5C732C00A74100B662E0 /* YieldInfo.swift in Sources */,
0A3BF9692C6CDAD900163492 /* AdditionalAddresses.swift in Sources */,
EFBC5C752C00A74100B662E0 /* StakingAPIService.swift in Sources */,
EFBC5C902C00B8B800B662E0 /* StakeKitDTO+Yield.swift in Sources */,
EF407E382C04B09A00366733 /* Logger.swift in Sources */,
Expand All @@ -12394,7 +12404,9 @@
EF72DC062C467001003DD97F /* StakingTokenItem.swift in Sources */,
EF031A282C08E65A001535C9 /* StakingCalculator.swift in Sources */,
EF8DBCDD2C060A03009072CF /* StakingManager.swift in Sources */,
0A3BF96F2C6DDB9000163492 /* StakingActionRequestParams.swift in Sources */,
EFBC5C792C00A79E00B662E0 /* StakeKitStakingAPIService.swift in Sources */,
0A3BF96B2C6CE96B00163492 /* StakingAction.swift in Sources */,
EFB019492C4174D1009EE857 /* EnterAction.swift in Sources */,
EF407E5F2C04D65B00366733 /* CommonStakingAPIProvider.swift in Sources */,
EFB019432C41710F009EE857 /* StakingBalanceInfo.swift in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions TangemStaking/Models/AdditionalAddresses.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AdditionalAddresses.swift
// TangemStaking
//
// Created by Dmitry Fedorov on 14.08.2024.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

public struct AdditionalAddresses {
let cosmosPubKey: String?
tureck1y marked this conversation as resolved.
Show resolved Hide resolved
}
27 changes: 27 additions & 0 deletions TangemStaking/Models/StakingAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// StakingAction.swift
// TangemStaking
//
// Created by Dmitry Fedorov on 14.08.2024.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

public struct StakingAction {
let amount: Decimal
let validator: String
let type: ActionType

public init(amount: Decimal, validator: String, type: StakingAction.ActionType) {
self.amount = amount
self.validator = validator
self.type = type
}

public enum ActionType {
case stake
case claimRewards
case unstake
}
}
34 changes: 34 additions & 0 deletions TangemStaking/Models/StakingActionRequestParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// StakingActionRequestParams.swift
// TangemStaking
//
// Created by Dmitry Fedorov on 15.08.2024.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

public struct StakingActionRequestParams {
let amount: Decimal
let address: String
let additionalAddresses: AdditionalAddresses?
let token: StakingTokenItem?
let validator: String
let integrationId: String

init(
amount: Decimal,
address: String,
additionalAddresses: AdditionalAddresses? = nil,
token: StakingTokenItem? = nil,
validator: String,
integrationId: String
) {
self.amount = amount
self.address = address
self.additionalAddresses = additionalAddresses
self.token = token
self.validator = validator
self.integrationId = integrationId
}
}
14 changes: 13 additions & 1 deletion TangemStaking/Models/StakingTokenItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ import Foundation
public struct StakingTokenItem: Hashable {
public let network: StakeKitNetworkType
public let contractAddress: String?
public let name: String
public let decimals: Int
public let symbol: String

public init(network: StakeKitNetworkType, contractAddress: String?) {
public init(
tureck1y marked this conversation as resolved.
Show resolved Hide resolved
network: StakeKitNetworkType,
contractAddress: String? = nil,
name: String,
decimals: Int,
symbol: String
) {
self.network = network
self.contractAddress = contractAddress
self.name = name
self.decimals = decimals
self.symbol = symbol
}
}
4 changes: 3 additions & 1 deletion TangemStaking/Models/StakingWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import Foundation
public struct StakingWallet: Hashable {
public let item: StakingTokenItem
public let address: String
public let publicKey: Data

public init(item: StakingTokenItem, address: String) {
public init(item: StakingTokenItem, address: String, publicKey: Data) {
self.item = item
self.address = address
self.publicKey = publicKey
}
}
19 changes: 18 additions & 1 deletion TangemStaking/Services/StakeKitMapper/StakeKitMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ struct StakeKitMapper {
throw StakeKitMapperError.noData("StakeKitNetworkType not found")
}

return StakingTokenItem(network: network, contractAddress: token.address)
return StakingTokenItem(
network: network,
contractAddress: token.address,
name: token.name,
decimals: token.decimals,
symbol: token.symbol
)
}

func mapToRewardType(from rewardType: StakeKitDTO.Yield.Info.Response.RewardType) -> RewardType {
Expand Down Expand Up @@ -252,6 +258,17 @@ struct StakeKitMapper {
rewardsPendingAction(from: balance)?.passthrough
}

func mapToTokenDTO(from tokenItem: StakingTokenItem) -> StakeKitDTO.Token {
StakeKitDTO.Token(
network: tokenItem.network.rawValue,
name: tokenItem.name,
decimals: tokenItem.decimals,
address: tokenItem.contractAddress,
symbol: tokenItem.symbol,
logoURI: nil
Comment on lines +263 to +268
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А stake kit прям все параметры нужны? Может там без name и без decimals можно?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

наверное можно, но андроид все шлет, я бы оставил пока все сети не заинтегрим.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

окей)

)
}

private func rewardsPendingAction(from balance: StakeKitDTO.Balances.Response.Balance) -> StakeKitDTO.Balances.Response.Balance.PendingAction? {
guard balance.type == .rewards else {
return nil
Expand Down
Loading
Loading