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

Feature/nomis integration #1276

Merged
merged 22 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
crashfix
  • Loading branch information
bnsports committed Jul 16, 2024
commit ccaa9a63c0c6de6652ccc114b593b3cdd829f0c0
5 changes: 5 additions & 0 deletions fearless/Common/Services/ChainRegistry/ChainRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protocol ChainRegistryProtocol: AnyObject {
func getConnection(for chainId: ChainModel.Id) -> ChainConnection?
func getRuntimeProvider(for chainId: ChainModel.Id) -> RuntimeProviderProtocol?
func getChain(for chainId: ChainModel.Id) -> ChainModel?
func getChainUnsafe(for chainId: ChainModel.Id) -> ChainModel?
bnsports marked this conversation as resolved.
Show resolved Hide resolved
func chainsSubscribe(
_ target: AnyObject,
runningInQueue: DispatchQueue,
Expand Down Expand Up @@ -326,6 +327,10 @@ extension ChainRegistry: ChainRegistryProtocol {
readLock.concurrentlyRead { chains.first(where: { $0.chainId == chainId }) }
}

func getChainUnsafe(for chainId: ChainModel.Id) -> ChainModel? {
chains.first(where: { $0.chainId == chainId })
}

func getRuntimeProvider(for chainId: ChainModel.Id) -> RuntimeProviderProtocol? {
runtimeProviderPool.getRuntimeProvider(for: chainId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class PolkaswapAdjustmentAssembly {
let chainRegistry = ChainRegistryFacade.sharedRegistry

guard
let xorChainAsset = chainRegistry.getChain(for: Chain.soraMain.genesisHash)?.utilityChainAssets().first,
let xorChainAsset = chainRegistry.getChainUnsafe(for: Chain.soraMain.genesisHash)?.utilityChainAssets().first,
let connection = chainRegistry.getConnection(for: xorChainAsset.chain.chainId),
let accountResponse = wallet.fetch(for: xorChainAsset.chain.accountRequest()),
let runtimeService = chainRegistry.getRuntimeProvider(for: xorChainAsset.chain.chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ final class PolkaswapAdjustmentPresenter {
private var slippadgeTolerance: Float = Constants.slippadgeTolerance
private var selectedLiquiditySourceType: LiquiditySourceType {
didSet {
view?.didReceive(market: selectedLiquiditySourceType)
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.view?.didReceive(market: self.selectedLiquiditySourceType)
}
}
}

Expand Down Expand Up @@ -103,14 +106,17 @@ final class PolkaswapAdjustmentPresenter {
guard swapFromInputResult != nil || swapToInputResult != nil else {
return
}

view?.setButtonLoadingState(isLoading: true)
DispatchQueue.main.async { [weak self] in
self?.view?.setButtonLoadingState(isLoading: true)
}
loadingCollector.reset()
}

private func checkLoadingState() {
if loadingCollector.isReady {
view?.setButtonLoadingState(isLoading: false)
DispatchQueue.main.async { [weak self] in
self?.view?.setButtonLoadingState(isLoading: false)
}
}
}

Expand Down Expand Up @@ -140,9 +146,11 @@ final class PolkaswapAdjustmentPresenter {
.createBalanceInputViewModel(inputAmount)
.value(for: selectedLocale)

view?.didReceiveSwapFrom(viewModel: viewModel)
if updateAmountInput {
view?.didReceiveSwapFrom(amountInputViewModel: inputViewModel)
DispatchQueue.main.async { [weak self] in
self?.view?.didReceiveSwapFrom(viewModel: viewModel)
if updateAmountInput {
self?.view?.didReceiveSwapFrom(amountInputViewModel: inputViewModel)
}
}

loadingCollector.fromReady = true
Expand Down Expand Up @@ -171,9 +179,11 @@ final class PolkaswapAdjustmentPresenter {
.createBalanceInputViewModel(inputAmount)
.value(for: selectedLocale)

view?.didReceiveSwapTo(viewModel: viewModel)
if updateAmountInput {
view?.didReceiveSwapTo(amountInputViewModel: inputViewModel)
DispatchQueue.main.async { [weak self] in
self?.view?.didReceiveSwapTo(viewModel: viewModel)
if updateAmountInput {
self?.view?.didReceiveSwapTo(amountInputViewModel: inputViewModel)
}
}

loadingCollector.toReady = true
Expand Down Expand Up @@ -300,7 +310,10 @@ final class PolkaswapAdjustmentPresenter {
prices: prices,
locale: selectedLocale
)
view?.didReceiveDetails(viewModel: detailsViewModel)

DispatchQueue.main.async { [weak self] in
self?.view?.didReceiveDetails(viewModel: detailsViewModel)
}

loadingCollector.detailsReady = true
checkLoadingState()
Expand All @@ -317,7 +330,11 @@ final class PolkaswapAdjustmentPresenter {
swapFromInputResult = .absolute(amounts.toAmount)
provideFromAssetVewModel()
}
view?.didReceive(variant: swapVariant)

DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.view?.didReceive(variant: self.swapVariant)
}
}

private func fetchSwapFee(amounts: SwapQuoteAmounts) {
Expand Down Expand Up @@ -377,7 +394,10 @@ final class PolkaswapAdjustmentPresenter {
swapToInputResult = nil
provideFromAssetVewModel()
provideToAssetVewModel()
view?.didReceiveDetails(viewModel: nil)

DispatchQueue.main.async { [weak self] in
self?.view?.didReceiveDetails(viewModel: nil)
}
}

private func preparePreviewParams() -> PolkaswapPreviewParams? {
Expand Down Expand Up @@ -936,7 +956,10 @@ extension PolkaswapAdjustmentPresenter: SelectAssetModuleOutput {
extension PolkaswapAdjustmentPresenter: PolkaswapTransaktionSettingsModuleOutput {
func didReceive(market: LiquiditySourceType, slippadgeTolerance: Float) {
loadingCollector.detailsReady = false
view?.setButtonLoadingState(isLoading: true)

DispatchQueue.main.async { [weak self] in
self?.view?.setButtonLoadingState(isLoading: true)
}

if selectedLiquiditySourceType != market {
selectedLiquiditySourceType = market
Expand All @@ -959,6 +982,8 @@ extension PolkaswapAdjustmentPresenter: BannersModuleOutput {
func reloadBannersView() {}

func didTapCloseBanners() {
view?.hideBanners()
DispatchQueue.main.async { [weak self] in
self?.view?.hideBanners()
}
}
}