Skip to content

Commit

Permalink
Merge pull request #837 from novasamatech/fix/html-parser-improvements
Browse files Browse the repository at this point in the history
Add html formatter for gov referendums
  • Loading branch information
ERussel authored Sep 26, 2023
2 parents ab84756 + f085868 commit 96705c7
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 35 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
24 changes: 20 additions & 4 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
0C7C886A2A95591900DD96A1 /* StakingTotalRewardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7C88692A95591900DD96A1 /* StakingTotalRewardView.swift */; };
0C7C886C2A9622F800DD96A1 /* StakingSelectedEntityViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7C886B2A9622F800DD96A1 /* StakingSelectedEntityViewModel.swift */; };
0C7C886E2A962B0D00DD96A1 /* StackAddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7C886D2A962B0D00DD96A1 /* StackAddressCell.swift */; };
0C7C9B992ABFF355009A0362 /* String+Html.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7C9B982ABFF355009A0362 /* String+Html.swift */; };
0C7C9B9B2AC16D7B009A0362 /* NSAttributedString+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7C9B9A2AC16D7B009A0362 /* NSAttributedString+Helpers.swift */; };
0C7E7FAB2A9F27FB00596628 /* NominationPoolsRedeemCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C7E7FAA2A9F27FB00596628 /* NominationPoolsRedeemCall.swift */; };
0C83775D2A4EEB380072102D /* AssetListState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C83775C2A4EEB380072102D /* AssetListState.swift */; };
0C893E6A2A65591C00781503 /* PoolsMultistakingUpdateService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C893E692A65591C00781503 /* PoolsMultistakingUpdateService.swift */; };
Expand Down Expand Up @@ -676,6 +678,8 @@
77799AEE2A7CFB6A00B7E564 /* DirectStakingTypeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77799AED2A7CFB6A00B7E564 /* DirectStakingTypeViewModel.swift */; };
77799AF02A7CFB7C00B7E564 /* ValidatorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77799AEF2A7CFB7C00B7E564 /* ValidatorViewModel.swift */; };
77799AF22A7CFB8D00B7E564 /* PoolAccountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77799AF12A7CFB8D00B7E564 /* PoolAccountViewModel.swift */; };
777AE2AB2ABCB4A5004989C0 /* HtmlParsingOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777AE2AA2ABCB4A5004989C0 /* HtmlParsingOperationFactory.swift */; };
777AE2AD2ABCB4BD004989C0 /* MarkupParsingOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777AE2AC2ABCB4BD004989C0 /* MarkupParsingOperationFactory.swift */; };
777BD86029F9730F004969A2 /* ReferendumsFilterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777BD85F29F9730F004969A2 /* ReferendumsFilterViewModel.swift */; };
777BD86229F97322004969A2 /* ReferendumsFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777BD86129F97322004969A2 /* ReferendumsFilter.swift */; };
777BD86429F979DA004969A2 /* SelectableFilterCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777BD86329F979DA004969A2 /* SelectableFilterCell.swift */; };
Expand Down Expand Up @@ -2205,7 +2209,7 @@
849D14CA2994D9BC0048E947 /* StackIconTitleValueCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D14C92994D9BC0048E947 /* StackIconTitleValueCell.swift */; };
849D14CC2994EEA50048E947 /* GovernanceDelegateFlowDisplayInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D14CB2994EEA50048E947 /* GovernanceDelegateFlowDisplayInfo.swift */; };
849D3220291C26BA00D25839 /* GovernanceDAppList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D321F291C26BA00D25839 /* GovernanceDAppList.swift */; };
849D3223291CC43D00D25839 /* MarkdownText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D3222291CC43D00D25839 /* MarkdownText.swift */; };
849D3223291CC43D00D25839 /* MarkupAttributedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D3222291CC43D00D25839 /* MarkupAttributedText.swift */; };
849D3225291CC4A500D25839 /* MarkdownParsingOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D3224291CC4A500D25839 /* MarkdownParsingOperationFactory.swift */; };
849D3227291CE25E00D25839 /* MarkdownViewContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D3226291CE25E00D25839 /* MarkdownViewContainer.swift */; };
849D755B2756910A007726C3 /* RoundedView+Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D755A2756910A007726C3 /* RoundedView+Styles.swift */; };
Expand Down Expand Up @@ -4132,6 +4136,8 @@
0C7C88692A95591900DD96A1 /* StakingTotalRewardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingTotalRewardView.swift; sourceTree = "<group>"; };
0C7C886B2A9622F800DD96A1 /* StakingSelectedEntityViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingSelectedEntityViewModel.swift; sourceTree = "<group>"; };
0C7C886D2A962B0D00DD96A1 /* StackAddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackAddressCell.swift; sourceTree = "<group>"; };
0C7C9B982ABFF355009A0362 /* String+Html.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Html.swift"; sourceTree = "<group>"; };
0C7C9B9A2AC16D7B009A0362 /* NSAttributedString+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+Helpers.swift"; sourceTree = "<group>"; };
0C7E7FAA2A9F27FB00596628 /* NominationPoolsRedeemCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NominationPoolsRedeemCall.swift; sourceTree = "<group>"; };
0C83775C2A4EEB380072102D /* AssetListState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListState.swift; sourceTree = "<group>"; };
0C893E692A65591C00781503 /* PoolsMultistakingUpdateService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PoolsMultistakingUpdateService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4632,6 +4638,8 @@
77799AED2A7CFB6A00B7E564 /* DirectStakingTypeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectStakingTypeViewModel.swift; sourceTree = "<group>"; };
77799AEF2A7CFB7C00B7E564 /* ValidatorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidatorViewModel.swift; sourceTree = "<group>"; };
77799AF12A7CFB8D00B7E564 /* PoolAccountViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PoolAccountViewModel.swift; sourceTree = "<group>"; };
777AE2AA2ABCB4A5004989C0 /* HtmlParsingOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HtmlParsingOperationFactory.swift; sourceTree = "<group>"; };
777AE2AC2ABCB4BD004989C0 /* MarkupParsingOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkupParsingOperationFactory.swift; sourceTree = "<group>"; };
777BD85F29F9730F004969A2 /* ReferendumsFilterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferendumsFilterViewModel.swift; sourceTree = "<group>"; };
777BD86129F97322004969A2 /* ReferendumsFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferendumsFilter.swift; sourceTree = "<group>"; };
777BD86329F979DA004969A2 /* SelectableFilterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectableFilterCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6189,7 +6197,7 @@
849D14C92994D9BC0048E947 /* StackIconTitleValueCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackIconTitleValueCell.swift; sourceTree = "<group>"; };
849D14CB2994EEA50048E947 /* GovernanceDelegateFlowDisplayInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GovernanceDelegateFlowDisplayInfo.swift; sourceTree = "<group>"; };
849D321F291C26BA00D25839 /* GovernanceDAppList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GovernanceDAppList.swift; sourceTree = "<group>"; };
849D3222291CC43D00D25839 /* MarkdownText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownText.swift; sourceTree = "<group>"; };
849D3222291CC43D00D25839 /* MarkupAttributedText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkupAttributedText.swift; sourceTree = "<group>"; };
849D3224291CC4A500D25839 /* MarkdownParsingOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownParsingOperationFactory.swift; sourceTree = "<group>"; };
849D3226291CE25E00D25839 /* MarkdownViewContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownViewContainer.swift; sourceTree = "<group>"; };
849D755A2756910A007726C3 /* RoundedView+Styles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RoundedView+Styles.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12855,7 +12863,7 @@
887AFC8628BC95F0002A0422 /* MetaAccountChainResponse.swift */,
8831F0FF28C65B95009F7682 /* AssetLock.swift */,
2AC7BC832731A214001D99B0 /* AssetLocks+Sort.swift */,
849D3222291CC43D00D25839 /* MarkdownText.swift */,
849D3222291CC43D00D25839 /* MarkupAttributedText.swift */,
84BAD21F293B574900C55C49 /* MultichainToken.swift */,
77E255682A16148000B644C3 /* StakingRewardsFilter.swift */,
7756927C2A20B88200220756 /* TokenOperation.swift */,
Expand Down Expand Up @@ -13152,6 +13160,8 @@
0C1BE1A12A46F93B0010933C /* BigUInt+Scientific.swift */,
0CE550B22A49658700F0A7AC /* StakingDuration+Localizable.swift */,
77E0DC9D2A6940C400D03724 /* Calendar+Helpers.swift */,
0C7C9B982ABFF355009A0362 /* String+Html.swift */,
0C7C9B9A2AC16D7B009A0362 /* NSAttributedString+Helpers.swift */,
);
path = Foundation;
sourceTree = "<group>";
Expand Down Expand Up @@ -16258,6 +16268,8 @@
849D3224291CC4A500D25839 /* MarkdownParsingOperationFactory.swift */,
8451720E298C495500489EF1 /* BorderedIconLabelView+TrackStyle.swift */,
777BD86729FA3376004969A2 /* ReferendumsSettingsCell.swift */,
777AE2AA2ABCB4A5004989C0 /* HtmlParsingOperationFactory.swift */,
777AE2AC2ABCB4BD004989C0 /* MarkupParsingOperationFactory.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -19364,6 +19376,7 @@
88F33F1529CC1F92006125D5 /* Slip44CoinList.swift in Sources */,
84B018B026E0450F00C75E28 /* ValidatorStateView.swift in Sources */,
AEE0C43A272A8B1F009F9AD5 /* AddChainAccount+AccountCreateWireframe.swift in Sources */,
0C7C9B992ABFF355009A0362 /* String+Html.swift in Sources */,
0C7E7FAB2A9F27FB00596628 /* NominationPoolsRedeemCall.swift in Sources */,
84038FF226FFBE1900C73F3F /* JsonLocalSubscriptionHandler.swift in Sources */,
842898D1265A955A002D5D65 /* ImageViewModel.swift in Sources */,
Expand Down Expand Up @@ -19763,6 +19776,7 @@
84754C9C2513B26000854599 /* AccountPickerTableViewCell.swift in Sources */,
8472C5B1265CF9C500E2481B /* StakingRewardDestConfirmViewFactory.swift in Sources */,
84532D6128E4234700EF4ADC /* ConvictionVotingForKey.swift in Sources */,
0C7C9B9B2AC16D7B009A0362 /* NSAttributedString+Helpers.swift in Sources */,
F4488CF226143E0000AEE6DB /* EraRewardPoints.swift in Sources */,
849DF02F26C53DB900B702F4 /* RuntimeSyncEvents.swift in Sources */,
844DD65525EAF32D00B1DA97 /* SelectValidatorsStartViewModel.swift in Sources */,
Expand All @@ -19775,7 +19789,7 @@
8444D1BE2671465A00AF6D8C /* CrowdloanBonusServiceError.swift in Sources */,
8448F7A22882ABF50080CEA9 /* CustomSearchView.swift in Sources */,
84D2F1AF2774CEF00040C680 /* DAppURLBarView.swift in Sources */,
849D3223291CC43D00D25839 /* MarkdownText.swift in Sources */,
849D3223291CC43D00D25839 /* MarkupAttributedText.swift in Sources */,
0C77B5632A83747200B5AE08 /* StaticValidatorListViewLayout.swift in Sources */,
84FFE45B2862076F002432BB /* XcmUnweightedTransferRequest.swift in Sources */,
84D1110C26B922D50016D962 /* ConnectionPool.swift in Sources */,
Expand Down Expand Up @@ -20875,6 +20889,7 @@
84CFF1EE26526FBC00DB7CF7 /* StakingBondMoreConfirmationProtocols.swift in Sources */,
8499FE7B27BE58A000712589 /* IdentityMapper.swift in Sources */,
845B89262959627A00EE25B0 /* SecurityLayerWireframe.swift in Sources */,
777AE2AB2ABCB4A5004989C0 /* HtmlParsingOperationFactory.swift in Sources */,
8489A6D227FD5FB80040C066 /* StackActionCell.swift in Sources */,
F429324F26280F6B00752C2C /* StakingRewardDetailsViewModel.swift in Sources */,
F4A11B5A272FEB0B0030E85B /* CrowdloanYourContributionsCell.swift in Sources */,
Expand Down Expand Up @@ -22148,6 +22163,7 @@
0C9C64382A8D6949004DC078 /* NPoolsStakingSharedState.swift in Sources */,
84757E17299A2E1200616C6C /* Gov2SubscriptionFactory+Votes.swift in Sources */,
84F76ED629006A0900D7206C /* ReferendumConvictionView.swift in Sources */,
777AE2AD2ABCB4BD004989C0 /* MarkupParsingOperationFactory.swift in Sources */,
9979A61C1677B7B1D44E58B4 /* ParitySignerTxQrProtocols.swift in Sources */,
0C13D3212A822B220054BB6F /* StartStakingDirectConfirmWireframe.swift in Sources */,
84CFE448292B9CB100CDDD7C /* OnChainTransferBaseInteractor.swift in Sources */,
Expand Down
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
}
}
}
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
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ final class GovernanceDelegateInfoViewLayout: UIView {
if let details = viewModel.details {
optDescriptionView = MarkdownViewContainer(
preferredWidth: UIScreen.main.bounds.width - 2 * UIConstants.horizontalInset,
maxTextLength: MarkdownText.readMoreThreshold
maxTextLength: MarkupAttributedText.readMoreThreshold
)

optDescriptionView?.load(from: details, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ReferendumDetailsTitleView: UIView {

let descriptionView = MarkdownViewContainer(
preferredWidth: UIScreen.main.bounds.width - 2 * UIConstants.horizontalInset,
maxTextLength: MarkdownText.readMoreThreshold
maxTextLength: MarkupAttributedText.readMoreThreshold
)

let moreButton: RoundedButton = .create { button in
Expand Down Expand Up @@ -132,7 +132,7 @@ extension ReferendumDetailsTitleView {
moreButton.isHidden = true

descriptionView.isHidden = false
descriptionView.load(from: details.description) { [weak self] (model: MarkdownText?) in
descriptionView.load(from: details.description) { [weak self] (model: MarkupAttributedText?) in
if let shouldReadMore = model?.isFull {
self?.moreButton.isHidden = shouldReadMore
}
Expand Down
Loading

0 comments on commit 96705c7

Please sign in to comment.