Skip to content

Commit

Permalink
Merge pull request #1255 from novasamatech/feature/updated-receive-sc…
Browse files Browse the repository at this point in the history
…reen

Feature/updated receive screen
  • Loading branch information
svojsu authored Nov 4, 2024
2 parents 69e8930 + de333d3 commit a371d52
Show file tree
Hide file tree
Showing 34 changed files with 1,165 additions and 164 deletions.
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ platform :ios, '14.0'
abstract_target 'novawalletAll' do
use_frameworks!

pod 'DSF_QRCode', '~> 18.0.0'
pod 'SubstrateSdk', :git => 'https://github.com/nova-wallet/substrate-sdk-ios.git', :tag => '3.2.2'
pod 'SwiftLint'
pod 'R.swift', :inhibit_warnings => true
Expand Down
14 changes: 13 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ PODS:
- Cuckoo (1.7.1):
- Cuckoo/Swift (= 1.7.1)
- Cuckoo/Swift (1.7.1)
- DSF_QRCode (18.0.0):
- SwiftImageReadWrite (~> 1.6.1)
- SwiftQRCodeGenerator (~> 2.0.2)
- EthereumSignTypedDataUtil (0.1.2):
- BigInt (~> 5.0)
- CryptoSwift (~> 1.4)
Expand Down Expand Up @@ -894,7 +897,9 @@ PODS:
- SwiftAlgorithms (1.0.0)
- SwiftDraw (0.18.0)
- SwiftFormat/CLI (0.47.13)
- SwiftImageReadWrite (1.6.1)
- SwiftLint (0.43.1)
- SwiftQRCodeGenerator (2.0.2)
- SwiftRLP (1.1):
- BigInt (~> 5.0)
- SwiftyBeaver (1.9.3)
Expand Down Expand Up @@ -959,6 +964,7 @@ PODS:
DEPENDENCIES:
- CDMarkdownKit (from `https://github.com/nova-wallet/CDMarkdownKit.git`, tag `2.5.2`)
- Cuckoo
- DSF_QRCode (~> 18.0.0)
- EthereumSignTypedDataUtil (from `https://github.com/ERussel/EthereumSignTypedDataUtil.git`, tag `0.1.3`)
- FirebaseAppCheck
- FirebaseAuth
Expand Down Expand Up @@ -996,6 +1002,7 @@ SPEC REPOS:
- BoringSSL-GRPC
- CryptoSwift
- Cuckoo
- DSF_QRCode
- FirebaseAppCheck
- FirebaseAppCheckInterop
- FirebaseAuth
Expand Down Expand Up @@ -1031,7 +1038,9 @@ SPEC REPOS:
- SwiftAlgorithms
- SwiftDraw
- SwiftFormat
- SwiftImageReadWrite
- SwiftLint
- SwiftQRCodeGenerator
- SwiftyBeaver
- TweetNacl
- Web3Core
Expand Down Expand Up @@ -1122,6 +1131,7 @@ SPEC CHECKSUMS:
CDMarkdownKit: ed78cf1a5c57dbe362054633a0f802f0534531ff
CryptoSwift: c4f2debceb38bf44c80659afe009f71e23e4a082
Cuckoo: 9e258d68137c411df47c6390f72901d5276b4f03
DSF_QRCode: 3fe0acc968ce8588a9b1dabb9557a364472f5aaf
EthereumSignTypedDataUtil: ae4e33b21e51ee046a86a65b02843090b8bbd3f9
FirebaseAppCheck: 4bb8047366c2c975583c9eff94235f8f2c5b342d
FirebaseAppCheckInterop: e81bdb1cdb82f8e0cef353ba5018a8402682032c
Expand Down Expand Up @@ -1165,7 +1175,9 @@ SPEC CHECKSUMS:
SwiftAlgorithms: 38dda4731d19027fdeee1125f973111bf3386b53
SwiftDraw: f63484562ddd30d9682b5576acc1d98acc2bec8f
SwiftFormat: 73573b89257437c550b03d934889725fbf8f75e5
SwiftImageReadWrite: 69f6521a74fdddbb61b2cc844150ec64de2cb4c7
SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52
SwiftQRCodeGenerator: cc02fed209335064d0b0dd61b2a0874b9bc6bd5a
SwiftRLP: f58417bfceecd45394fc619ccad14cf16e4ae6c1
SwiftyBeaver: 2e8acd6fc90c6d0a27055867a290794926d57c02
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
Expand All @@ -1176,6 +1188,6 @@ SPEC CHECKSUMS:
ZMarkupParser: a92d31ba40695b790f1da5fec98c3d4505341aff
ZNSTextAttachment: 1ddd53660a8d3c42dbb716bf6866ffce22c44181

PODFILE CHECKSUM: 4bc772db3908838fe1eb2aeeed28f5f2a60d65ed
PODFILE CHECKSUM: d8eff34136ac9f5e9008628c43040eaebe7d557d

COCOAPODS: 1.15.2
104 changes: 88 additions & 16 deletions novawallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0x00",
"red" : "0x00"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.560",
"blue" : "0x00",
"green" : "0x00",
"red" : "0x00"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
1 change: 1 addition & 0 deletions novawallet/Common/Extension/UIKit/RoundedView+Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extension RoundedView {
func applyControlBackgroundStyle() {
strokeColor = R.color.colorContainerBorder()!
highlightedStrokeColor = .clear
shadowOpacity = .zero
fillColor = .clear
highlightedFillColor = R.color.colorCellBackgroundPressed()!
}
Expand Down
10 changes: 10 additions & 0 deletions novawallet/Common/Extension/UIKit/Style/UILabel+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extension UILabel.Style {
font: .regularFootnote
)

static let footnoteSecondaryOnWhite = UILabel.Style(
textColor: R.color.colorTextSecondaryOnWhite(),
font: .regularFootnote
)

static let semiboldSubhedlineSecondary = UILabel.Style(
textColor: R.color.colorTextSecondary(),
font: .semiBoldSubheadline
Expand Down Expand Up @@ -151,6 +156,11 @@ extension UILabel.Style {
font: .regularSubheadline
)

static let regularSubhedlinePrimaryOnWhite = UILabel.Style(
textColor: R.color.colorTextPrimaryOnWhite(),
font: .regularSubheadline
)

static let regularSubhedlineInactive = UILabel.Style(
textColor: R.color.colorIconInactive(),
font: .regularSubheadline
Expand Down
28 changes: 28 additions & 0 deletions novawallet/Common/Extension/UIKit/UIImage+Drawing.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import UIKit

extension UIImage {
enum Shape {
case rectangle
case circle
}

static func background(
from color: UIColor,
size: CGSize = CGSize(width: 1.0, height: 1.0),
Expand All @@ -25,6 +30,29 @@ extension UIImage {
return image
}

func redrawWithBackground(
color: UIColor,
shape: Shape = .rectangle
) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: size, format: UIGraphicsImageRendererFormat.default())

return renderer.image { context in
let rect = CGRect(origin: .zero, size: size)

color.setFill()

switch shape {
case .rectangle:
context.fill(rect)

case .circle:
context.cgContext.fillEllipse(in: rect)
}

self.draw(in: rect)
}
}

func crop(targetSize: CGSize, cornerRadius: CGFloat, contentScale: CGFloat) -> UIImage? {
guard size.width > 0, size.height > 0 else {
return nil
Expand Down
18 changes: 18 additions & 0 deletions novawallet/Common/IconRetrieve/IconRetrieveOperationFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import Kingfisher
import Operation_iOS

protocol IconRetrieveOperationFactoryProtocol {
func checkCacheOperation(using cacheKey: String) -> ClosureOperation<Bool>

func downloadImageOperation(
using logoInfo: IconInfo
) -> AsyncClosureOperation<UIImage>

func retrieveImageOperation(using cacheKey: String) -> AsyncClosureOperation<UIImage>
}

enum ImageRetrievingError: Error {
case logoDownloadError
case logoRetrievingError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import Foundation
import Kingfisher
import Operation_iOS

struct KingfisherIconRetrieveOperationFactory {
let imageManager: KingfisherManager
let operationQueue: OperationQueue

init(
imageManager: KingfisherManager = KingfisherManager.shared,
operationQueue: OperationQueue
) {
self.imageManager = imageManager
self.operationQueue = operationQueue
}
}

// MARK: IconRetrieveOperationFactoryProtocol

extension KingfisherIconRetrieveOperationFactory: IconRetrieveOperationFactoryProtocol {
func checkCacheOperation(using cacheKey: String) -> Operation_iOS.ClosureOperation<Bool> {
let cache = imageManager.cache

return ClosureOperation {
let cachedType = cache.imageCachedType(forKey: cacheKey)

return cachedType.cached
}
}

func downloadImageOperation(using iconInfo: IconInfo) -> Operation_iOS.AsyncClosureOperation<UIImage> {
let downloader = imageManager.downloader

return AsyncClosureOperation { resultClosure in
let scale = UIScreen.main.scale

let scaledSize = CGSize(
width: iconInfo.size.width * scale,
height: iconInfo.size.height * scale
)

guard let url = iconInfo.url else {
resultClosure(.failure(ImageRetrievingError.logoDownloadError))

return
}

let processor = SVGImageProcessor() |> ResizingImageProcessor(referenceSize: scaledSize)

let options: KingfisherOptionsInfo = [.processor(processor)]

downloader.downloadImage(with: url, options: options) { result in
var resultImage: UIImage

switch result {
case let .success(imageResult) where imageResult.image.cgImage != nil:
resultImage = imageResult.image
default:
resultClosure(.failure(ImageRetrievingError.logoDownloadError))

return
}

let sizeBeforeProcessing = resultImage.size

if case .remoteTransparent = iconInfo.type {
resultImage = resultImage.redrawWithBackground(
color: R.color.colorTextPrimaryOnWhite()!,
shape: .circle
)
}

if let cacheKey = iconInfo.type?.cacheKey {
let cacheOptions = KingfisherOptionsInfo.cacheOptions

imageManager.cache.store(
resultImage,
forKey: cacheKey,
options: KingfisherParsedOptionsInfo(cacheOptions)
)
}

resultClosure(.success(resultImage))
}
}
}

func retrieveImageOperation(using cacheKey: String) -> Operation_iOS.AsyncClosureOperation<UIImage> {
let cache = imageManager.cache

return AsyncClosureOperation { resultClosure in
cache.retrieveImage(forKey: cacheKey) { result in
if
case let .success(cacheResult) = result,
let image = cacheResult.image {
resultClosure(.success(image))
} else {
resultClosure(.failure(ImageRetrievingError.logoRetrievingError))
}
}
}
}
}

extension KingfisherOptionsInfo {
static let cacheOptions: KingfisherOptionsInfo = [
.cacheSerializer(RemoteImageSerializer.shared),
.cacheOriginalImage,
.diskCacheExpiration(.days(1))
]
}
26 changes: 26 additions & 0 deletions novawallet/Common/Protocols/CopyAddressPresentable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import UIKit

protocol CopyAddressPresentable {
func copyAddress(
from view: ControllerBackedProtocol?,
address: String,
locale: Locale
)
}

extension CopyAddressPresentable where Self: ModalAlertPresenting {
func copyAddress(
from view: ControllerBackedProtocol?,
address: String,
locale: Locale
) {
UIPasteboard.general.string = address

let title = R.string.localizable.commonAddressCoppied(preferredLanguages: locale.rLanguages)

presentSuccessNotification(
title,
from: view
)
}
}
5 changes: 5 additions & 0 deletions novawallet/Common/QRCreation/BarcodeCreationError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum BarcodeCreationError: Error {
case generatorUnavailable
case generatedImageInvalid
case bitmapImageCreationFailed
}
38 changes: 38 additions & 0 deletions novawallet/Common/QRCreation/Logo/IconInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Foundation
import UIKit

struct IconInfo {
let size: CGSize
let type: IconType?

var url: URL? {
type?.url
}

func byChangingToLocal(_ image: UIImage) -> IconInfo? {
switch type {
case .remoteColored:
IconInfo(
size: size,
type: .localColored(image)
)
case .remoteTransparent:
IconInfo(
size: size,
type: .localTransparent(image)
)
default:
IconInfo(
size: size,
type: nil
)
}
}

func withNoLogo() -> IconInfo {
IconInfo(
size: size,
type: nil
)
}
}
Loading

0 comments on commit a371d52

Please sign in to comment.