Skip to content

Commit

Permalink
Merge pull request #840 from novasamatech/develop
Browse files Browse the repository at this point in the history
v7.1.0
  • Loading branch information
ERussel authored Sep 27, 2023
2 parents d28c4fc + 96705c7 commit 2b5db4a
Show file tree
Hide file tree
Showing 155 changed files with 2,346 additions and 690 deletions.
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ abstract_target 'novawalletAll' do
pod 'WalletConnectSwiftV2', :git => 'https://github.com/WalletConnect/WalletConnectSwiftV2.git', :tag => '1.5.14'
pod 'EthereumSignTypedDataUtil', :git => 'https://github.com/ERussel/EthereumSignTypedDataUtil.git', :tag => '0.1.3'
pod 'SwiftAlgorithms', '~> 1.0.0'

pod 'ZMarkupParser'

target 'novawalletTests' do
inherit! :search_paths

Expand Down
10 changes: 9 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ PODS:
- Starscream (~> 4.0.4)
- Web3Core (~> 3.0.6)
- xxHash-Swift (1.0.13)
- ZMarkupParser (1.6.1):
- ZNSTextAttachment (~> 1.1.6)
- ZNSTextAttachment (1.1.6)

DEPENDENCIES:
- CDMarkdownKit (from `https://github.com/nova-wallet/CDMarkdownKit.git`, tag `2.5.2`)
Expand All @@ -168,6 +171,7 @@ DEPENDENCIES:
- SwiftyBeaver
- WalletConnectSwiftV2 (from `https://github.com/WalletConnect/WalletConnectSwiftV2.git`, tag `1.5.14`)
- web3swift (from `https://github.com/web3swift-team/web3swift.git`, tag `3.0.6`)
- ZMarkupParser

SPEC REPOS:
trunk:
Expand Down Expand Up @@ -195,6 +199,8 @@ SPEC REPOS:
- TweetNacl
- Web3Core
- xxHash-Swift
- ZMarkupParser
- ZNSTextAttachment

EXTERNAL SOURCES:
CDMarkdownKit:
Expand Down Expand Up @@ -294,7 +300,9 @@ SPEC CHECKSUMS:
Web3Core: 4a62a109cac056915d2d5023606438c89e229a1e
web3swift: 944e76579b953a7b7e81dbb351c6dc0ed1defe63
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
ZMarkupParser: a92d31ba40695b790f1da5fec98c3d4505341aff
ZNSTextAttachment: 4a9b4e8ee1ed087fc893ae6657dfb678f1a00340

PODFILE CHECKSUM: b9535fb877c890660e9ff1754c3d7881113d1030
PODFILE CHECKSUM: 9da63967acbaf0ea90ab5cf6e0cef78c59d3668f

COCOAPODS: 1.12.1
136 changes: 124 additions & 12 deletions novawallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions novawallet/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ extension ApplicationConfig: ApplicationConfigProtocol {

var xcmTransfersURL: URL {
#if F_RELEASE
URL(string: "https://raw.githubusercontent.com/novasamatech/nova-utils/master/xcm/v4/transfers.json")!
URL(string: "https://raw.githubusercontent.com/novasamatech/nova-utils/master/xcm/v5/transfers.json")!
#else
URL(string: "https://raw.githubusercontent.com/novasamatech/nova-utils/master/xcm/v4/transfers_dev.json")!
URL(string: "https://raw.githubusercontent.com/novasamatech/nova-utils/master/xcm/v5/transfers_dev.json")!
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ protocol StakingDashboardProviderFactoryProtocol {
func getDashboardItemsProvider(
for walletId: MetaAccountModel.Id
) -> StreamableProvider<Multistaking.DashboardItem>?

func getDashboardItemsProvider(
for walletId: MetaAccountModel.Id,
chainAssetId: ChainAssetId
) -> StreamableProvider<Multistaking.DashboardItem>?
}

final class StakingDashboardProviderFactory: SubstrateLocalSubscriptionFactory {
Expand Down Expand Up @@ -63,4 +68,49 @@ extension StakingDashboardProviderFactory: StakingDashboardProviderFactoryProtoc

return provider
}

func getDashboardItemsProvider(
for walletId: MetaAccountModel.Id,
chainAssetId: ChainAssetId
) -> StreamableProvider<Multistaking.DashboardItem>? {
let cacheKey = "dashboard-\(walletId)-\(chainAssetId.stringValue)"

if let provider = getProvider(for: cacheKey) as? StreamableProvider<Multistaking.DashboardItem> {
return provider
}

let repository = repositoryFactory.createDashboardRepository(
for: walletId,
chainAssetId: chainAssetId
)

let source = EmptyStreamableSource<Multistaking.DashboardItem>()

let observable = CoreDataContextObservable(
service: storageFacade.databaseService,
mapper: AnyCoreDataMapper(StakingDashboardItemMapper()),
predicate: { entity in
entity.walletId == walletId &&
entity.chainId == chainAssetId.chainId &&
entity.assetId == Int32(bitPattern: chainAssetId.assetId)
}
)

observable.start { [weak self] error in
if let error = error {
self?.logger.error("Can't start storage observing: \(error)")
}
}

let provider = StreamableProvider(
source: AnyStreamableSource(source),
repository: repository,
observable: AnyDataProviderRepositoryObservable(observable),
operationManager: operationManager
)

saveProvider(provider, for: cacheKey)

return provider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ protocol StakingDashboardLocalStorageHandler {
_ result: Result<[DataProviderChange<Multistaking.DashboardItem>], Error>,
walletId: MetaAccountModel.Id
)

func handleDashboardItems(
_ result: Result<[DataProviderChange<Multistaking.DashboardItem>], Error>,
walletId: MetaAccountModel.Id,
chainAssetId: ChainAssetId
)
}

extension StakingDashboardLocalStorageHandler {
func handleDashboardItems(
_: Result<[DataProviderChange<Multistaking.DashboardItem>], Error>,
walletId _: MetaAccountModel.Id
) {}

func handleDashboardItems(
_: Result<[DataProviderChange<Multistaking.DashboardItem>], Error>,
walletId _: MetaAccountModel.Id,
chainAssetId _: ChainAssetId
) {}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import Foundation
import RobinHood

protocol StakingDashboardLocalStorageSubscriber: AnyObject {
protocol StakingDashboardLocalStorageSubscriber: AnyObject, LocalStorageProviderObserving {
var stakingDashboardProviderFactory: StakingDashboardProviderFactoryProtocol { get }

var stakingDashboardLocalStorageHandler: StakingDashboardLocalStorageHandler { get }

func subscribeDashboardItems(
for walletId: MetaAccountModel.Id
) -> StreamableProvider<Multistaking.DashboardItem>?

func subscribeDashboardItems(
for walletId: MetaAccountModel.Id,
chainAssetId: ChainAssetId
) -> StreamableProvider<Multistaking.DashboardItem>?
}

extension StakingDashboardLocalStorageSubscriber where Self: StakingDashboardLocalStorageHandler {
Expand Down Expand Up @@ -52,4 +57,37 @@ extension StakingDashboardLocalStorageSubscriber where Self: StakingDashboardLoc

return provider
}

func subscribeDashboardItems(
for walletId: MetaAccountModel.Id,
chainAssetId: ChainAssetId
) -> StreamableProvider<Multistaking.DashboardItem>? {
guard
let provider = stakingDashboardProviderFactory.getDashboardItemsProvider(
for: walletId,
chainAssetId: chainAssetId
) else {
return nil
}

addStreamableProviderObserver(
for: provider,
updateClosure: { [weak self] changes in
self?.stakingDashboardLocalStorageHandler.handleDashboardItems(
.success(changes),
walletId: walletId,
chainAssetId: chainAssetId
)
},
failureClosure: { [weak self] error in
self?.stakingDashboardLocalStorageHandler.handleDashboardItems(
.failure(error),
walletId: walletId,
chainAssetId: chainAssetId
)
}
)

return provider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ extension StreamableProviderObserverOptions {
refreshWhenEmpty: false
)
}

static func allNonblocking() -> StreamableProviderObserverOptions {
StreamableProviderObserverOptions(
alwaysNotifyOnRefresh: false,
waitsInProgressSyncOnAdd: false,
initialSize: 0,
refreshWhenEmpty: true
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

extension NSAttributedString {
func truncate(maxLength: Int) -> NSAttributedString {
if length > maxLength, maxLength > 0 {
let range = NSRange(location: 0, length: maxLength)
let mutableString = NSMutableAttributedString(attributedString: attributedSubstring(from: range))

let attributes = mutableString.attributes(at: maxLength - 1, effectiveRange: nil)
let truncation = NSAttributedString(string: String.readMore, attributes: attributes)

mutableString.append(truncation)

return mutableString
} else {
return self
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation

extension NSPredicate {
static func stakingDashboardItem(
for chainAssetId: ChainAssetId,
walletId: MetaAccountModel.Id
) -> NSPredicate {
let chainPredicate = NSPredicate(
format: "%K == %@",
#keyPath(CDStakingDashboardItem.chainId),
chainAssetId.chainId
)

let assetPredicate = NSPredicate(
format: "%K == %d",
#keyPath(CDStakingDashboardItem.assetId),
chainAssetId.assetId
)

let accountPredicate = NSPredicate(
format: "%K == %@",
#keyPath(CDStakingDashboardItem.walletId),
walletId
)

return NSCompoundPredicate(andPredicateWithSubpredicates: [chainPredicate, assetPredicate, accountPredicate])
}
}
9 changes: 9 additions & 0 deletions novawallet/Common/Extension/Foundation/String+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ extension String {
}
}
}

extension Optional where Wrapped == String {
var isNilOrEmpty: Bool {
guard let self = self else {
return true
}
return self.isEmpty
}
}
14 changes: 14 additions & 0 deletions novawallet/Common/Extension/Foundation/String+Html.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

extension String {
private static let htmlSpecificTags: Set<String> = [
"</p>", "</div>", "</body>", "</br>", "</h1>", "</h2>", "</h3>", "</h4>", "</h5>", "</h6>",
"</header>", "</ul>"
]

func isHtml() -> Bool {
Self.htmlSpecificTags.contains { tag in
range(of: tag) != nil
}
}
}
21 changes: 21 additions & 0 deletions novawallet/Common/Helpers/MainTransitionHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,25 @@ struct MainTransitionHelper {
TransitionAnimator(type: .reveal).animate(view: tabBarController.view, completionBlock: nil)
}
}

static func dismissAndPopBack(
from view: ControllerBackedProtocol?,
completion: ((UIViewController?) -> Void)? = nil
) {
var rootNavigationController: UINavigationController?

let presenter = view?.controller.navigationController?.presentingViewController

if let tabBar = presenter as? UITabBarController {
rootNavigationController = tabBar.selectedViewController as? UINavigationController
} else {
rootNavigationController = presenter as? UINavigationController
}

rootNavigationController?.popToRootViewController(animated: false)

presenter?.dismiss(animated: true) {
completion?(presenter)
}
}
}
2 changes: 1 addition & 1 deletion novawallet/Common/Helpers/PredefinedTimeShortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ final class EverydayShortcut: PredefinedTimeShortcutProtocol {
return nil
}

return R.string.localizable.commonEveryDay(preferredLanguages: locale.rLanguages)
return R.string.localizable.commonDaysEveryday(preferredLanguages: locale.rLanguages)
}
}
34 changes: 34 additions & 0 deletions novawallet/Common/Helpers/SharedOperationStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation

enum SharedOperationStatus {
case composing
case sent
}

protocol SharedOperationStatusProtocol: AnyObject {
var isComposing: Bool { get }
}

protocol SharedOperationProtocol: SharedOperationStatusProtocol {
var status: SharedOperationStatus { get set }
}

extension SharedOperationProtocol {
var isComposing: Bool {
status == .composing
}

func markSent() {
status = .sent
}

func markComposing() {
status = .composing
}
}

final class SharedOperation {
var status: SharedOperationStatus = .composing
}

extension SharedOperation: SharedOperationProtocol {}
3 changes: 2 additions & 1 deletion novawallet/Common/Ledger/SupportedLedgerApps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extension SupportedLedgerApp {
SupportedLedgerApp(chainId: KnowChainId.edgeware, coin: 523, cla: 0x94, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.polymesh, coin: 595, cla: 0x91, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.xxNetwork, coin: 1955, cla: 0xA3, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.astar, coin: 810, cla: 0xA9, type: .substrate)
SupportedLedgerApp(chainId: KnowChainId.astar, coin: 810, cla: 0xA9, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.alephZero, coin: 643, cla: 0xA4, type: .substrate)
]
}

Expand Down
6 changes: 5 additions & 1 deletion novawallet/Common/Model/ExternalAssetBalance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ extension ExternalAssetBalance.BalanceType {
case .crowdloan:
return LocalizableResource { R.string.localizable.tabbarCrowdloanTitle(preferredLanguages: $0.rLanguages) }
case .nominationPools:
return LocalizableResource { R.string.localizable.stakingPoolStaking(preferredLanguages: $0.rLanguages) }
return LocalizableResource {
R.string.localizable.stakingTypeNominationPool(
preferredLanguages: $0.rLanguages
)
}
case .unknown:
return LocalizableResource { R.string.localizable.commonUnknown(preferredLanguages: $0.rLanguages) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

struct MarkdownText {
struct MarkupAttributedText {
static let readMoreThreshold = 180

let originalString: String
Expand Down
Loading

0 comments on commit 2b5db4a

Please sign in to comment.