Skip to content

Commit 64439ba

Browse files
[trello.com/c/XEj672SB] feat: replaced request to check exist account
1 parent 02bcdf0 commit 64439ba

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

Adamant/Modules/Wallets/Lisk/LskTransferViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ final class LskTransferViewController: TransferViewControllerBase {
4444
return
4545
}
4646

47-
let recepientBalance = try await service.getBalance(address: recipientAddress)
48-
guard recepientBalance == .zero else {
47+
let exist = try await service.isExist(address: recipientAddress)
48+
49+
guard !exist else {
4950
addAdditionalFee = false
5051
return
5152
}

Adamant/Modules/Wallets/Lisk/LskWalletService.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ final class LskWalletService: WalletService {
313313

314314
return (fee: fee, lastHeight: height)
315315
}
316+
317+
func isExist(address: String) async throws -> Bool {
318+
let result = try await lskServiceApiService.requestServiceApi { api, completion in
319+
api.exist(address: address) { result in
320+
switch result {
321+
case .success(let response):
322+
completion(.success(response: response.data.isExists))
323+
case .error(let error):
324+
completion(.error(response: mapError(error)))
325+
}
326+
}
327+
}.get()
328+
329+
return result
330+
}
316331
}
317332

318333
// MARK: - WalletInitiatedWithPassphrase

Adamant/Modules/Wallets/WalletService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ protocol WalletService: AnyObject {
284284
func loadTransactions(offset: Int, limit: Int) async throws -> Int
285285
func getLocalTransactionHistory() -> [TransactionDetails]
286286
func updateStatus(for id: String, status: TransactionStatus?)
287+
func isExist(address: String) async throws -> Bool
288+
}
289+
290+
extension WalletService {
291+
func isExist(address: String) async throws -> Bool { return true }
287292
}
288293

289294
protocol SwinjectDependentService: WalletService {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// ExistModel.swift
3+
//
4+
//
5+
// Created by Stanislav Jelezoglo on 19.12.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct ExistModel: APIResponse {
11+
public struct ExistData: Decodable {
12+
public let isExists: Bool
13+
}
14+
15+
public let data: ExistData
16+
}

LiskKit/Sources/API/Service/Service.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ extension Service {
3838
client.get(path: "\(Version.v2.rawValue)/fees", completionHandler: completionHandler)
3939
}
4040

41+
public func exist(address: String, completionHandler: @escaping (Response<ExistModel>) -> Void) {
42+
client.get(
43+
path: "\(Version.v3.rawValue)/token/account/exists",
44+
options: ["address": address, "tokenID": Constants.tokenID],
45+
completionHandler: completionHandler
46+
)
47+
}
48+
4149
/// List transaction objects
4250
public func transactions(
4351
ownerAddress: String?,

0 commit comments

Comments
 (0)