Skip to content

Commit 928216f

Browse files
committed
nft loading optimization
1 parent d1e5f30 commit 928216f

File tree

8 files changed

+50
-22
lines changed

8 files changed

+50
-22
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract_target 'fearlessAll' do
4747
pod 'SSFUtils', '0.1.21'
4848
pod 'SSFChainRegistry', '0.1.4'
4949
pod 'SSFHelpers', '0.1.7'
50-
pod 'SSFCloudStorage'
50+
pod 'SSFCloudStorage', '0.1.23'
5151
pod 'FearlessKeys'
5252
end
5353
end

Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ PODS:
146146
- SSFNetwork
147147
- SSFRuntimeCodingService
148148
- SSFUtils
149-
- SSFCloudStorage (0.1.15):
149+
- SSFCloudStorage (0.1.23):
150150
- GoogleAPIClientForREST/Drive (~> 1.2.1)
151151
- GoogleSignIn (~> 7.0.0)
152152
- IrohaCrypto/Scrypt
@@ -262,7 +262,7 @@ DEPENDENCIES:
262262
- Sourcery (~> 1.4)
263263
- SSFChainConnection (= 0.1.4)
264264
- SSFChainRegistry (= 0.1.4)
265-
- SSFCloudStorage
265+
- SSFCloudStorage (= 0.1.23)
266266
- SSFCrypto (= 0.1.17)
267267
- SSFEraKit
268268
- SSFExtrinsicKit
@@ -283,7 +283,7 @@ DEPENDENCIES:
283283
- XNetworking (from `https://raw.githubusercontent.com/soramitsu/x-networking/0.0.37/AppCommonNetworking/XNetworking/XNetworking.podspec`)
284284

285285
SPEC REPOS:
286-
https://github.com/CocoaPods/Specs.git:
286+
https://github.com/cocoapods/Specs.git:
287287
- AppAuth
288288
- BigInt
289289
- Charts
@@ -389,7 +389,7 @@ SPEC CHECKSUMS:
389389
Sourcery: 179539341c2261068528cd15a31837b7238fd901
390390
SSFChainConnection: 760f0bbe0d711cc0f184b951dea9e840a2962346
391391
SSFChainRegistry: adfcfa6f8e7dae4730e258989c2a58ee674bf1e1
392-
SSFCloudStorage: 37fbba3ad3e93a637d9c1a9b85910f4fa29596de
392+
SSFCloudStorage: c4123454b3084015ea8d88af92f51de79fce7f2c
393393
SSFCrypto: 7ea544e61213538744ef8fd075e5e4487b7cf502
394394
SSFEraKit: a6f2a8bdefcdfa3ad8ff8f48b242000ea50744cd
395395
SSFExtrinsicKit: f5ab32700622894d2e7a5fca254a3f659d3a6a9f
@@ -412,6 +412,6 @@ SPEC CHECKSUMS:
412412
XNetworking: 516d982bd74ff208222381d27e07052a5d897aaf
413413
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
414414

415-
PODFILE CHECKSUM: c4e802ef4df1a83d5af2e0466c71b18abb869ed5
415+
PODFILE CHECKSUM: e48910f49a08bcbc644297b13fa44bb24639860d
416416

417417
COCOAPODS: 1.11.3

fearless/ApplicationLayer/Services/NFT/Ethereum/AlchemyNftFetchingService.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,20 @@ final class AlchemyNftFetchingService: BaseNftFetchingService {
4141
throw AddressFactoryError.unexpectedAddress
4242
}
4343

44-
return nil
45-
// return try await withCheckedThrowingContinuation { continuation in
46-
// let fetchNftsOperation = operationFactory.fetchNFTs(chain: chain, address: address)
47-
//
48-
// fetchNftsOperation.targetOperation.completionBlock = {
49-
// do {
50-
// let nfts = try fetchNftsOperation.targetOperation.extractNoCancellableResultData()
51-
// continuation.resume(with: .success(nfts))
52-
// } catch {
53-
// continuation.resume(with: .failure(error))
54-
// }
55-
// }
56-
//
57-
// self.operationQueue.addOperations(fetchNftsOperation.allOperations, waitUntilFinished: true)
58-
// }
44+
return try await withCheckedThrowingContinuation { continuation in
45+
let fetchNftsOperation = operationFactory.fetchNFTs(chain: chain, address: address)
46+
47+
fetchNftsOperation.targetOperation.completionBlock = {
48+
do {
49+
let nfts = try fetchNftsOperation.targetOperation.extractNoCancellableResultData()
50+
continuation.resume(with: .success(nfts))
51+
} catch {
52+
continuation.resume(with: .failure(error))
53+
}
54+
}
55+
56+
self.operationQueue.addOperations(fetchNftsOperation.allOperations, waitUntilFinished: true)
57+
}
5958
}
6059
}
6160

fearless/Modules/NFT/MainNftContainer/MainNftContainerInteractor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class MainNftContainerInteractor {
1414
private let logger: LoggerProtocol
1515
private var wallet: MetaAccountModel
1616
private let eventCenter: EventCenterProtocol
17+
private var isReady: Bool = false
1718

1819
init(
1920
nftFetchingService: NFTFetchingServiceProtocol,
@@ -32,11 +33,24 @@ final class MainNftContainerInteractor {
3233
// MARK: - MainNftContainerInteractorInput
3334

3435
extension MainNftContainerInteractor: MainNftContainerInteractorInput {
36+
func initialSetup() {
37+
let wasReady = isReady
38+
isReady = true
39+
40+
if !wasReady {
41+
fetchData()
42+
}
43+
}
44+
3545
func setup(with output: MainNftContainerInteractorOutput) {
3646
self.output = output
3747
}
3848

3949
func fetchData() {
50+
guard isReady else {
51+
return
52+
}
53+
4054
Task {
4155
do {
4256
let nfts = try await nftFetchingService.fetchNfts(for: wallet)

fearless/Modules/NFT/MainNftContainer/MainNftContainerPresenter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extension MainNftContainerPresenter: MainNftContainerViewOutput {
4343
interactor.fetchData()
4444
}
4545

46+
func viewAppeared() {
47+
interactor.initialSetup()
48+
}
49+
4650
func didSelect(collection: NFTCollection) {
4751
guard let address = wallet.fetch(for: collection.chain.accountRequest())?.toAddress() else {
4852
return

fearless/Modules/NFT/MainNftContainer/MainNftContainerProtocols.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ protocol MainNftContainerViewOutput: AnyObject {
88
func didLoad(view: MainNftContainerViewInput)
99
func didSelect(collection: NFTCollection)
1010
func didPullToRefresh()
11+
func viewAppeared()
1112
}
1213

1314
protocol MainNftContainerInteractorInput: AnyObject {
15+
func initialSetup()
1416
func setup(with output: MainNftContainerInteractorOutput)
1517
func fetchData()
1618
}

fearless/Modules/NFT/MainNftContainer/MainNftContainerViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ final class MainNftContainerViewController: UIViewController, ViewHolder {
4545
}
4646
}
4747

48+
override func viewWillAppear(_ animated: Bool) {
49+
super.viewWillAppear(animated)
50+
output.viewAppeared()
51+
}
52+
4853
// MARK: - Private methods
4954

5055
@objc private func actionRefresh() {

fearless/Modules/NewWallet/ChainAssetList/ChainAssetListInteractor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ extension ChainAssetListInteractor: PriceLocalStorageSubscriber, PriceLocalSubsc
288288
}
289289

290290
extension ChainAssetListInteractor: AccountInfoSubscriptionAdapterHandler {
291-
func handleAccountInfo(result: Result<AccountInfo?, Error>, accountId _: AccountId, chainAsset: ChainAsset) {
291+
func handleAccountInfo(result: Result<AccountInfo?, Error>, accountId: AccountId, chainAsset: ChainAsset) {
292+
guard let selectedAccountId = wallet.fetch(for: chainAsset.chain.accountRequest())?.accountId, selectedAccountId == accountId else {
293+
return
294+
}
295+
292296
output?.didReceiveAccountInfo(result: result, for: chainAsset)
293297
}
294298
}

0 commit comments

Comments
 (0)