Skip to content

Commit

Permalink
Merge pull request #408 from nova-wallet/develop
Browse files Browse the repository at this point in the history
v3.8
  • Loading branch information
ERussel authored Sep 19, 2022
2 parents 6348c84 + 1b96a47 commit 321187a
Show file tree
Hide file tree
Showing 151 changed files with 7,378 additions and 400 deletions.
364 changes: 360 additions & 4 deletions novawallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file modified novawallet/Assets.xcassets/iconBondMore.imageset/iconBondMore.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconControllerAccount.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "iconWallet.pdf",
"filename" : "iconRewardsDest.pdf",
"idiom" : "universal"
}
],
Expand Down
Binary file not shown.
Binary file modified novawallet/Assets.xcassets/iconUnbond.imageset/iconUnbond.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "iconAccount.pdf",
"filename" : "iconYieldBoost.pdf",
"idiom" : "universal"
}
],
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "imageYieldBoostPowered.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
5 changes: 4 additions & 1 deletion novawallet/Common/DataProvider/PriceProviderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ extension PriceProviderFactory: PriceProviderFactoryProtocol {
return AnySingleValueProvider(provider)
}

func getPriceListProvider(for priceIds: [AssetModel.PriceId], currency: Currency) -> AnySingleValueProvider<[PriceData]> {
func getPriceListProvider(
for priceIds: [AssetModel.PriceId],
currency: Currency
) -> AnySingleValueProvider<[PriceData]> {
clearIfNeeded()

let coingeckoId = currency.coingeckoId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Foundation
import RobinHood

protocol AccountAssetBalanceChangeStoreProtocol {
var chainAssetId: ChainAssetId { get }
var accountId: AccountId { get }

func consumeLastBlockHash() -> Data?
}

final class AccountAssetBalanceTrigger: AccountAssetBalanceChangeStoreProtocol {
weak var delegate: DataProviderTriggerDelegate?

private(set) var wrappedTrigger: DataProviderTriggerProtocol?
let eventCenter: EventCenterProtocol
let chainAssetId: ChainAssetId
let accountId: AccountId

private(set) var lastSeenBlockHash: Data?

init(
chainAssetId: ChainAssetId,
eventCenter: EventCenterProtocol,
wrappedTrigger: DataProviderTriggerProtocol?,
accountId: AccountId
) {
self.chainAssetId = chainAssetId
self.accountId = accountId
self.eventCenter = eventCenter
self.wrappedTrigger = wrappedTrigger

self.wrappedTrigger?.delegate = self
self.eventCenter.add(observer: self)
}

func consumeLastBlockHash() -> Data? {
let hash = lastSeenBlockHash
lastSeenBlockHash = nil
return hash
}
}

extension AccountAssetBalanceTrigger: DataProviderTriggerDelegate {
func didTrigger() {
delegate?.didTrigger()
}
}

extension AccountAssetBalanceTrigger: DataProviderTriggerProtocol {
func receive(event: DataProviderEvent) {
wrappedTrigger?.receive(event: event)
}
}

extension AccountAssetBalanceTrigger: EventVisitorProtocol {
func processAssetBalanceChanged(event: AssetBalanceChanged) {
guard
accountId == event.accountId,
chainAssetId == event.chainAssetId else {
return
}

lastSeenBlockHash = event.block

delegate?.didTrigger()
}
}
4 changes: 4 additions & 0 deletions novawallet/Common/EventCenter/EventVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ protocol EventVisitorProtocol: AnyObject {
func processHideZeroBalances(event: HideZeroBalancesChanged)

func processBlockTimeChanged(event: BlockTimeChanged)

func processAssetBalanceChanged(event: AssetBalanceChanged)
}

extension EventVisitorProtocol {
Expand Down Expand Up @@ -54,4 +56,6 @@ extension EventVisitorProtocol {
func processHideZeroBalances(event _: HideZeroBalancesChanged) {}

func processBlockTimeChanged(event _: BlockTimeChanged) {}

func processAssetBalanceChanged(event _: AssetBalanceChanged) {}
}
12 changes: 12 additions & 0 deletions novawallet/Common/EventCenter/Events/AssetBalanceChanged.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

struct AssetBalanceChanged: EventProtocol {
let chainAssetId: ChainAssetId
let accountId: AccountId
let changes: Data?
let block: Data?

func accept(visitor: EventVisitorProtocol) {
visitor.processAssetBalanceChanged(event: self)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Foundation
import BigInt

extension Decimal {
static func fromSubstratePercent(value: UInt8) -> Decimal? {
let decimalValue = NSDecimalNumber(value: value)
return decimalValue.multiplying(byPowerOf10: -2).decimalValue
}

init?(_ bigUInt: BigUInt) {
self.init(string: String(bigUInt))
}
}
4 changes: 4 additions & 0 deletions novawallet/Common/Extension/Foundation/String+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ import Foundation

extension String {
static var returnKey: String { "\n" }

func firstLetterCapitalized() -> String {
prefix(1).capitalized + dropFirst()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ extension TimeInterval {
return components.joined(separator: " ")
}
}

extension UInt {
func localizedDaysPeriod(for locale: Locale) -> String {
if self == 1 {
return R.string.localizable.commonDaysEveryday(preferredLanguages: locale.rLanguages)
} else {
return R.string.localizable.commonEveryDaysFormat(
format: Int(bitPattern: self),
preferredLanguages: locale.rLanguages
)
}
}
}
13 changes: 13 additions & 0 deletions novawallet/Common/Extension/Foundation/TimeInterval+Time.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ extension TimeInterval {
var secondsFromDays: TimeInterval { self * Self.secondsInDay }
var hoursFromSeconds: Int { Int(self / Self.secondsInHour) }
var intervalsInDay: Int { self > 0.0 ? Int(Self.secondsInDay / self) : 0 }

func roundingUpToHour() -> TimeInterval {
let inMillis = milliseconds
let hourInMillis = Self.secondsInHour.milliseconds

guard inMillis % hourInMillis != 0 else {
return UInt64(inMillis).timeInterval
}

let nextHour = (inMillis / hourInMillis) * hourInMillis + hourInMillis

return UInt64(nextHour).timeInterval
}
}
13 changes: 13 additions & 0 deletions novawallet/Common/Extension/UIKit/TriangularedButton+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,17 @@ extension TriangularedButton {

contentOpacityWhenDisabled = 1.0
}

func applyState(title: String, enabled: Bool) {
if enabled {
applyEnabledStyle()
} else {
applyDisabledStyle()
}

isUserInteractionEnabled = enabled

imageWithTitleView?.title = title
invalidateLayout()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension TransactionHistoryItem {
throw CommonError.undefined
}

let callPath = CallCodingPath.assetsTransfer
let callPath = CallCodingPath.assetsTransfer(for: typeExtras.palletName)
let callArgs = AssetsTransfer(
assetId: typeExtras.assetId,
target: .accoundId(receiver),
Expand Down
2 changes: 1 addition & 1 deletion novawallet/Common/Model/BlockWeights.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import SubstrateSdk

struct BlockWeights: Codable {
struct BlockWeights: Decodable {
@StringCodable var maxBlock: UInt64
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ extension ManagedMetaAccountModel {
func replacingInfo(_ newInfo: MetaAccountModel) -> ManagedMetaAccountModel {
ManagedMetaAccountModel(info: newInfo, isSelected: isSelected, order: order)
}

func replacingSelection(_ isSelected: Bool) -> ManagedMetaAccountModel {
ManagedMetaAccountModel(info: info, isSelected: isSelected, order: order)
}
}
1 change: 1 addition & 0 deletions novawallet/Common/Model/StateminAssetExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import Foundation

struct StatemineAssetExtras: Codable {
let assetId: String
let palletName: String?
}
15 changes: 12 additions & 3 deletions novawallet/Common/Network/JSONRPC/PagedKeysRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@ import Foundation

struct PagedKeysRequest: Encodable {
let key: String
let count: UInt32
let count: UInt32?
let offset: String?
let blockHash: Data?

init(key: String, count: UInt32 = 1000, offset: String? = nil) {
init(key: String, count: UInt32? = 1000, offset: String? = nil, blockHash: Data? = nil) {
self.key = key
self.count = count
self.offset = offset
self.blockHash = blockHash
}

func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(key)
try container.encode(count)

if let count = count {
try container.encode(count)
}

if let offset = offset {
try container.encode(offset)
}

if let blockHash = blockHash {
try container.encode(blockHash.toHex(includePrefix: true))
}
}
}
37 changes: 36 additions & 1 deletion novawallet/Common/Network/JSONRPC/RuntimeDispatchInfo.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
import Foundation
import SubstrateSdk

@propertyWrapper
struct FeeWeight: Codable {
let wrappedValue: UInt64

typealias WeightV1 = UInt64

struct WeightV1p5: Codable {
enum CodingKeys: String, CodingKey {
case refTime = "ref_time"
}

let refTime: UInt64
}

init(wrappedValue: UInt64) {
self.wrappedValue = wrappedValue
}

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()

if let compoundWeight = try? container.decode(WeightV1p5.self) {
wrappedValue = compoundWeight.refTime
} else {
wrappedValue = try container.decode(WeightV1.self)
}
}

func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(WeightV1p5(refTime: wrappedValue))
}
}

struct RuntimeDispatchInfo: Codable {
enum CodingKeys: String, CodingKey {
Expand All @@ -9,5 +44,5 @@ struct RuntimeDispatchInfo: Codable {

let dispatchClass: String
let fee: String
let weight: UInt64
@FeeWeight var weight: UInt64
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension WalletNetworkOperationFactory {
let extras = try? asset.typeExtras?.map(to: StatemineAssetExtras.self),
let runtimeProvider = chainRegistry.getRuntimeProvider(for: chain.chainId),
let localKey = try? LocalStorageKeyFactory().createFromStoragePath(
.assetsDetails,
.assetsDetails(from: extras.palletName),
encodableElement: extras.assetId,
chainId: chain.chainId
) else {
Expand All @@ -93,7 +93,7 @@ extension WalletNetworkOperationFactory {
repository: chainStorage,
key: { localKey },
factory: { try codingFactoryOperation.extractNoCancellableResultData() },
params: StorageRequestParams(path: .assetsDetails, shouldFallback: false)
params: StorageRequestParams(path: .assetsDetails(from: extras.palletName), shouldFallback: false)
)

fetchWrapper.addDependency(operations: [codingFactoryOperation])
Expand Down
Loading

0 comments on commit 321187a

Please sign in to comment.