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

Ton updates 2 #5951

Merged
merged 2 commits into from
Sep 6, 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 @@ -2963,6 +2963,8 @@
D3A580952BE8AA80003953F4 /* BitcoinSendSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A580932BE8AA80003953F4 /* BitcoinSendSettingsView.swift */; };
D3A580972BE8AA90003953F4 /* BitcoinSendSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A580962BE8AA90003953F4 /* BitcoinSendSettingsViewModel.swift */; };
D3A580982BE8AA90003953F4 /* BitcoinSendSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A580962BE8AA90003953F4 /* BitcoinSendSettingsViewModel.swift */; };
D3A87D592C89BEAE00F6F619 /* AddJettonBlockchainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A87D582C89BEAE00F6F619 /* AddJettonBlockchainService.swift */; };
D3A87D5A2C89BEAE00F6F619 /* AddJettonBlockchainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A87D582C89BEAE00F6F619 /* AddJettonBlockchainService.swift */; };
D3AF5A8929FFD85800C1399E /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = D3AF5A8829FFD85800C1399E /* RxCocoa */; };
D3AF5A8B29FFD85800C1399E /* RxRelay in Frameworks */ = {isa = PBXBuildFile; productRef = D3AF5A8A29FFD85800C1399E /* RxRelay */; };
D3AF5A8D29FFD85800C1399E /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = D3AF5A8C29FFD85800C1399E /* RxSwift */; };
Expand Down Expand Up @@ -4641,6 +4643,7 @@
D3A5808A2BE4DB11003953F4 /* WalletConnectSendHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletConnectSendHandler.swift; sourceTree = "<group>"; };
D3A580932BE8AA80003953F4 /* BitcoinSendSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitcoinSendSettingsView.swift; sourceTree = "<group>"; };
D3A580962BE8AA90003953F4 /* BitcoinSendSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitcoinSendSettingsViewModel.swift; sourceTree = "<group>"; };
D3A87D582C89BEAE00F6F619 /* AddJettonBlockchainService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddJettonBlockchainService.swift; sourceTree = "<group>"; };
D3B476A321D0D64E008B0C3E /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
D3B476A421D0D64E008B0C3E /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
D3B476A521D0D659008B0C3E /* zh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh; path = zh.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4956,6 +4959,7 @@
11B355267E1A6678B7B5FCF1 /* AddTokenModule.swift */,
11B35102BB1E66987670CD1F /* AddBep2TokenBlockchainService.swift */,
D05F132D2A31FE0D00C3193F /* AddTronTokenBlockchainService.swift */,
D3A87D582C89BEAE00F6F619 /* AddJettonBlockchainService.swift */,
);
path = AddToken;
sourceTree = "<group>";
Expand Down Expand Up @@ -9793,6 +9797,7 @@
11B35AC33360F772120B9562 /* RestoreSettingsStorage.swift in Sources */,
11B35729848FDBC47F038553 /* AppVersionRecordStorage.swift in Sources */,
D3DB519A2BD63D680091BBDB /* MarketSearchViewModel.swift in Sources */,
D3A87D5A2C89BEAE00F6F619 /* AddJettonBlockchainService.swift in Sources */,
11B35DB339D0E7CF183760F4 /* EnabledWalletCacheStorage.swift in Sources */,
ABC9A80BCDA72347C6619E6C /* SendTimeLockErrorService.swift in Sources */,
11B350ADB6D0D0C3E97F73D6 /* NftCollectionViewController.swift in Sources */,
Expand Down Expand Up @@ -11248,6 +11253,7 @@
ABC9A63B2AABC0414000DEC2 /* SendConfirmationViewModel.swift in Sources */,
11B3572E55D689C7414621EE /* SectionsTableView.swift in Sources */,
11B350CB4E7C006C26AE5FB3 /* EnabledWalletStorage.swift in Sources */,
D3A87D592C89BEAE00F6F619 /* AddJettonBlockchainService.swift in Sources */,
11B356C081AC552CBDA9147B /* AccountRecordStorage.swift in Sources */,
D3DB51992BD63D680091BBDB /* MarketSearchViewModel.swift in Sources */,
11B35727A4950C1E066F2244 /* LogRecordStorage.swift in Sources */,
Expand Down Expand Up @@ -12868,7 +12874,7 @@
repositoryURL = "https://github.com/horizontalsystems/TonKit.Swift";
requirement = {
kind = exactVersion;
version = 1.0.1;
version = 1.0.2;
};
};
6BF66DD82BA1A73300963242 /* XCRemoteSwiftPackageReference "ObjectMapper" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TonEventConverter {
case let .jettonMint(action):
return .unsupported(type: "Jetton Mint")
case let .contractDeploy(action):
return .unsupported(type: "Contract Deploy")
return .contractDeploy(interfaces: action.interfaces)
case let .jettonSwap(action):
return .unsupported(type: "Jetton Swap")
case let .smartContract(action):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,12 @@ enum StorageMigrator {
}
}

migrator.registerMigration("Add coinImage to EnabledWallet") { db in
try db.alter(table: EnabledWallet.databaseTableName) { t in
t.add(column: EnabledWallet.Columns.coinImage.name, .text)
}
}

try migrator.migrate(dbPool)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WalletStorage {
accountId: wallet.account.id,
coinName: wallet.coin.name,
coinCode: wallet.coin.code,
coinImage: wallet.coin.image,
tokenDecimals: wallet.token.decimals
)
}
Expand Down Expand Up @@ -46,7 +47,7 @@ extension WalletStorage {
let coinUid = tokenQuery.customCoinUid

let token = Token(
coin: Coin(uid: coinUid, name: coinName, code: coinCode),
coin: Coin(uid: coinUid, name: coinName, code: coinCode, image: enabledWallet.coinImage),
blockchain: blockchain,
type: tokenQuery.tokenType,
decimals: tokenDecimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class EnabledWallet: Record {

let coinName: String?
let coinCode: String?
let coinImage: String?
let tokenDecimals: Int?

init(tokenQueryId: String, accountId: String, coinName: String? = nil, coinCode: String? = nil, tokenDecimals: Int? = nil) {
init(tokenQueryId: String, accountId: String, coinName: String? = nil, coinCode: String? = nil, coinImage: String? = nil, tokenDecimals: Int? = nil) {
self.tokenQueryId = tokenQueryId
self.accountId = accountId
self.coinName = coinName
self.coinCode = coinCode
self.coinImage = coinImage
self.tokenDecimals = tokenDecimals

super.init()
Expand All @@ -24,14 +26,15 @@ class EnabledWallet: Record {
}

enum Columns: String, ColumnExpression {
case tokenQueryId, accountId, coinName, coinCode, tokenDecimals
case tokenQueryId, accountId, coinName, coinCode, coinImage, tokenDecimals
}

required init(row: Row) throws {
tokenQueryId = row[Columns.tokenQueryId]
accountId = row[Columns.accountId]
coinName = row[Columns.coinName]
coinCode = row[Columns.coinCode]
coinImage = row[Columns.coinImage]
tokenDecimals = row[Columns.tokenDecimals]

try super.init(row: row)
Expand All @@ -42,6 +45,7 @@ class EnabledWallet: Record {
container[Columns.accountId] = accountId
container[Columns.coinName] = coinName
container[Columns.coinCode] = coinCode
container[Columns.coinImage] = coinImage
container[Columns.tokenDecimals] = tokenDecimals
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TonTransactionRecord: TransactionRecord {
switch action.type {
case let .send(value, _, _, _): return value
case let .receive(value, _, _): return value
case .unsupported: return nil
default: return nil
}
}

Expand All @@ -52,6 +52,7 @@ extension TonTransactionRecord {
enum `Type` {
case send(value: TransactionValue, to: String, sentToSelf: Bool, comment: String?)
case receive(value: TransactionValue, from: String, comment: String?)
case contractDeploy(interfaces: [String])
case unsupported(type: String)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import Foundation
import HsToolKit
import MarketKit
import RxSwift
import TonKit
import TonSwift

class AddJettonBlockchainService {
private let blockchain: Blockchain

init(blockchain: Blockchain) {
self.blockchain = blockchain
}
}

extension AddJettonBlockchainService: IAddTokenBlockchainService {
var placeholder: String {
"add_token.input_placeholder.jetton_master_address".localized
}

func validate(reference: String) throws {
do {
_ = try TonSwift.Address.parse(reference)
} catch {
throw TokenError.invalidAddress
}
}

func tokenQuery(reference: String) -> TokenQuery {
var reference = reference

do {
let address = try TonSwift.Address.parse(reference)
reference = address.toString(bounceable: true)
} catch {}

return TokenQuery(blockchainType: blockchain.type, tokenType: .jetton(address: reference))
}

func tokenSingle(reference: String) -> Single<Token> {
guard let address = try? TonSwift.Address.parse(reference) else {
return Single.error(TokenError.invalidAddress)
}

let tokenQuery = tokenQuery(reference: reference)

return Single.create { [blockchain] observer in
Task { [blockchain] in
do {
let jetton = try await TonKit.Kit.jetton(address: address)

let token = Token(
coin: Coin(uid: tokenQuery.customCoinUid, name: jetton.name, code: jetton.symbol, image: jetton.image),
blockchain: blockchain,
type: tokenQuery.tokenType,
decimals: jetton.decimals
)

observer(.success(token))
} catch {
observer(.error(TokenError.notFound(blockchainName: blockchain.name)))
}
}

return Disposables.create()
}
}
}

extension AddJettonBlockchainService {
enum TokenError: LocalizedError {
case invalidAddress
case notFound(blockchainName: String)

var errorDescription: String? {
switch self {
case .invalidAddress: return "add_token.invalid_ton_address".localized
case let .notFound(blockchainName): return "add_token.jetton_master_not_found".localized(blockchainName)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ enum AddTokenModule {
items.append(item)
}

if let blockchain = try? App.shared.marketKit.blockchain(uid: BlockchainType.ton.uid), blockchain.type.supports(accountType: account.type) {
let service: IAddTokenBlockchainService = AddJettonBlockchainService(blockchain: blockchain)
let item = Item(blockchain: blockchain, service: service)
items.append(item)
}

let service = AddTokenService(account: account, items: items, coinManager: App.shared.coinManager, walletManager: App.shared.walletManager)
let viewModel = AddTokenViewModel(service: service)
let viewController = AddTokenViewController(viewModel: viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TransactionInfoService {
switch action.type {
case let .send(value, _, _, _): tokens.append(value.token)
case let .receive(value, _, _): tokens.append(value.token)
case .unsupported: ()
default: ()
}
}
tokens.append(tx.fee?.token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ class TransactionInfoViewItemFactory {
}
case let .receive(value, from, comment):
sections.append(.init(receiveSection(source: record.source, transactionValue: value, from: from, rates: item.rates, memo: comment, status: action.status, balanceHidden: balanceHidden)))
case let .contractDeploy(interfaces):
sections.append(.init([
.actionTitle(iconName: nil, iconDimmed: false, title: "transactions.contract_deploy".localized, subTitle: interfaces.joined(separator: ", "))
]))
case let .unsupported(type):
sections.append(.init([.fee(title: "Action", value: type)]))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ class TransactionsViewItemFactory {
if let currencyValue = item.currencyValue {
secondaryValue = BaseTransactionsViewModel.Value(text: currencyString(from: currencyValue), type: .secondary)
}
case let .contractDeploy(interfaces):
iconType = .localIcon(imageName: item.record.source.blockchainType.iconPlain32)
title = "transactions.contract_deploy".localized
subTitle = interfaces.joined(separator: ", ")
case let .unsupported(type):
iconType = .localIcon(imageName: item.record.source.blockchainType.iconPlain32)
title = "transactions.ton_transaction.title".localized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@
"transactions.contract_call" = "Contract Call";
"transactions.contract_creation" = "Contract Creation";
"transactions.external_call" = "External Call";
"transactions.contract_deploy" = "Contract Deploy";

"transactions.to" = "To %@";
"transactions.from" = "From %@";
Expand Down Expand Up @@ -1722,10 +1723,13 @@
"add_token.already_added" = "This token is already in the Coin Manager list";
"add_token.invalid_contract_address" = "Invalid contract address";
"add_token.invalid_bep2_symbol" = "Invalid BEP2 symbol";
"add_token.invalid_ton_address" = "Invalid Ton address";
"add_token.contract_address_not_found" = "Contract address not found in %@ blockchain";
"add_token.jetton_master_not_found" = "Jetton Master not found in %@ blockchain";
"add_token.bep2_symbol_not_found" = "BEP2 symbol not found";
"add_token.input_placeholder.contract_address" = "Contract Address";
"add_token.input_placeholder.bep2_symbol" = "BEP2 Symbol";
"add_token.input_placeholder.jetton_master_address" = "Jetton Master Address";
"add_token.coin_name" = "Coin Name";
"add_token.symbol" = "Symbol";
"add_token.decimals" = "Decimals";
Expand Down