Skip to content

Commit

Permalink
nft loading optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
bnsports committed Oct 20, 2023
1 parent d1e5f30 commit 928216f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract_target 'fearlessAll' do
pod 'SSFUtils', '0.1.21'
pod 'SSFChainRegistry', '0.1.4'
pod 'SSFHelpers', '0.1.7'
pod 'SSFCloudStorage'
pod 'SSFCloudStorage', '0.1.23'
pod 'FearlessKeys'
end
end
Expand Down
10 changes: 5 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ PODS:
- SSFNetwork
- SSFRuntimeCodingService
- SSFUtils
- SSFCloudStorage (0.1.15):
- SSFCloudStorage (0.1.23):
- GoogleAPIClientForREST/Drive (~> 1.2.1)
- GoogleSignIn (~> 7.0.0)
- IrohaCrypto/Scrypt
Expand Down Expand Up @@ -262,7 +262,7 @@ DEPENDENCIES:
- Sourcery (~> 1.4)
- SSFChainConnection (= 0.1.4)
- SSFChainRegistry (= 0.1.4)
- SSFCloudStorage
- SSFCloudStorage (= 0.1.23)
- SSFCrypto (= 0.1.17)
- SSFEraKit
- SSFExtrinsicKit
Expand All @@ -283,7 +283,7 @@ DEPENDENCIES:
- XNetworking (from `https://raw.githubusercontent.com/soramitsu/x-networking/0.0.37/AppCommonNetworking/XNetworking/XNetworking.podspec`)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
https://github.com/cocoapods/Specs.git:
- AppAuth
- BigInt
- Charts
Expand Down Expand Up @@ -389,7 +389,7 @@ SPEC CHECKSUMS:
Sourcery: 179539341c2261068528cd15a31837b7238fd901
SSFChainConnection: 760f0bbe0d711cc0f184b951dea9e840a2962346
SSFChainRegistry: adfcfa6f8e7dae4730e258989c2a58ee674bf1e1
SSFCloudStorage: 37fbba3ad3e93a637d9c1a9b85910f4fa29596de
SSFCloudStorage: c4123454b3084015ea8d88af92f51de79fce7f2c
SSFCrypto: 7ea544e61213538744ef8fd075e5e4487b7cf502
SSFEraKit: a6f2a8bdefcdfa3ad8ff8f48b242000ea50744cd
SSFExtrinsicKit: f5ab32700622894d2e7a5fca254a3f659d3a6a9f
Expand All @@ -412,6 +412,6 @@ SPEC CHECKSUMS:
XNetworking: 516d982bd74ff208222381d27e07052a5d897aaf
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7

PODFILE CHECKSUM: c4e802ef4df1a83d5af2e0466c71b18abb869ed5
PODFILE CHECKSUM: e48910f49a08bcbc644297b13fa44bb24639860d

COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ final class AlchemyNftFetchingService: BaseNftFetchingService {
throw AddressFactoryError.unexpectedAddress
}

return nil
// return try await withCheckedThrowingContinuation { continuation in
// let fetchNftsOperation = operationFactory.fetchNFTs(chain: chain, address: address)
//
// fetchNftsOperation.targetOperation.completionBlock = {
// do {
// let nfts = try fetchNftsOperation.targetOperation.extractNoCancellableResultData()
// continuation.resume(with: .success(nfts))
// } catch {
// continuation.resume(with: .failure(error))
// }
// }
//
// self.operationQueue.addOperations(fetchNftsOperation.allOperations, waitUntilFinished: true)
// }
return try await withCheckedThrowingContinuation { continuation in
let fetchNftsOperation = operationFactory.fetchNFTs(chain: chain, address: address)

fetchNftsOperation.targetOperation.completionBlock = {
do {
let nfts = try fetchNftsOperation.targetOperation.extractNoCancellableResultData()
continuation.resume(with: .success(nfts))
} catch {
continuation.resume(with: .failure(error))
}
}

self.operationQueue.addOperations(fetchNftsOperation.allOperations, waitUntilFinished: true)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class MainNftContainerInteractor {
private let logger: LoggerProtocol
private var wallet: MetaAccountModel
private let eventCenter: EventCenterProtocol
private var isReady: Bool = false

init(
nftFetchingService: NFTFetchingServiceProtocol,
Expand All @@ -32,11 +33,24 @@ final class MainNftContainerInteractor {
// MARK: - MainNftContainerInteractorInput

extension MainNftContainerInteractor: MainNftContainerInteractorInput {
func initialSetup() {
let wasReady = isReady
isReady = true

if !wasReady {
fetchData()
}
}

func setup(with output: MainNftContainerInteractorOutput) {
self.output = output
}

func fetchData() {
guard isReady else {
return
}

Task {
do {
let nfts = try await nftFetchingService.fetchNfts(for: wallet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ extension MainNftContainerPresenter: MainNftContainerViewOutput {
interactor.fetchData()
}

func viewAppeared() {
interactor.initialSetup()
}

func didSelect(collection: NFTCollection) {
guard let address = wallet.fetch(for: collection.chain.accountRequest())?.toAddress() else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ protocol MainNftContainerViewOutput: AnyObject {
func didLoad(view: MainNftContainerViewInput)
func didSelect(collection: NFTCollection)
func didPullToRefresh()
func viewAppeared()
}

protocol MainNftContainerInteractorInput: AnyObject {
func initialSetup()
func setup(with output: MainNftContainerInteractorOutput)
func fetchData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ final class MainNftContainerViewController: UIViewController, ViewHolder {
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
output.viewAppeared()
}

// MARK: - Private methods

@objc private func actionRefresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ extension ChainAssetListInteractor: PriceLocalStorageSubscriber, PriceLocalSubsc
}

extension ChainAssetListInteractor: AccountInfoSubscriptionAdapterHandler {
func handleAccountInfo(result: Result<AccountInfo?, Error>, accountId _: AccountId, chainAsset: ChainAsset) {
func handleAccountInfo(result: Result<AccountInfo?, Error>, accountId: AccountId, chainAsset: ChainAsset) {
guard let selectedAccountId = wallet.fetch(for: chainAsset.chain.accountRequest())?.accountId, selectedAccountId == accountId else {
return
}

output?.didReceiveAccountInfo(result: result, for: chainAsset)
}
}
Expand Down

0 comments on commit 928216f

Please sign in to comment.