Skip to content

Commit

Permalink
Merge pull request #11 from soramitsu/feature/icon-generator
Browse files Browse the repository at this point in the history
FLW-106 Implement icon generation from public key
  • Loading branch information
ERussel authored Aug 14, 2020
2 parents d182aa3 + ea4cecc commit 353ce94
Show file tree
Hide file tree
Showing 13 changed files with 585 additions and 81 deletions.
34 changes: 22 additions & 12 deletions Example/FearlessUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
842D1E2324C98CEA00C30A7A /* StorageKeyFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E2224C98CEA00C30A7A /* StorageKeyFactoryTests.swift */; };
Expand All @@ -22,6 +21,8 @@
845D80ED24C8D91A00EC2540 /* SeedFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845D80EC24C8D91A00EC2540 /* SeedFactoryTests.swift */; };
8467FD1424E677C2005D486C /* ed25519HDKD.json in Resources */ = {isa = PBXBuildFile; fileRef = 8467FD1124E675D0005D486C /* ed25519HDKD.json */; };
8467FD1524E677C6005D486C /* ecdsaHDKD.json in Resources */ = {isa = PBXBuildFile; fileRef = 8467FD1024E675D0005D486C /* ecdsaHDKD.json */; };
8467FD2624E71A37005D486C /* IconGenerationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8467FD2524E71A37005D486C /* IconGenerationTests.swift */; };
8467FD2824E72CCD005D486C /* HSLColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8467FD2724E72CCD005D486C /* HSLColorTests.swift */; };
84A0DE3124DBF49400F436A8 /* keystore-ed25519.json in Resources */ = {isa = PBXBuildFile; fileRef = 84A0DE2D24DBF3F300F436A8 /* keystore-ed25519.json */; };
84A0DE3224DBF49700F436A8 /* keystore-ecdsa.json in Resources */ = {isa = PBXBuildFile; fileRef = 84A0DE2F24DBF40900F436A8 /* keystore-ecdsa.json */; };
84CB472424DBE82C00837E11 /* KeystoreExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CB472324DBE82C00837E11 /* KeystoreExtractorTests.swift */; };
Expand Down Expand Up @@ -57,7 +58,6 @@
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
607FACE51AFB9204008FA782 /* FearlessUtils_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FearlessUtils_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -72,6 +72,8 @@
845D80EC24C8D91A00EC2540 /* SeedFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedFactoryTests.swift; sourceTree = "<group>"; };
8467FD1024E675D0005D486C /* ecdsaHDKD.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ecdsaHDKD.json; sourceTree = "<group>"; };
8467FD1124E675D0005D486C /* ed25519HDKD.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ed25519HDKD.json; sourceTree = "<group>"; };
8467FD2524E71A37005D486C /* IconGenerationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconGenerationTests.swift; sourceTree = "<group>"; };
8467FD2724E72CCD005D486C /* HSLColorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HSLColorTests.swift; sourceTree = "<group>"; };
84A0DE2D24DBF3F300F436A8 /* keystore-ed25519.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "keystore-ed25519.json"; sourceTree = "<group>"; };
84A0DE2F24DBF40900F436A8 /* keystore-ecdsa.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "keystore-ecdsa.json"; sourceTree = "<group>"; };
84CB472024DBE7E100837E11 /* keystore-sr25519.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "keystore-sr25519.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,7 +143,6 @@
children = (
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
Expand Down Expand Up @@ -201,10 +202,19 @@
isa = PBXGroup;
children = (
842D1E2224C98CEA00C30A7A /* StorageKeyFactoryTests.swift */,
8467FD2724E72CCD005D486C /* HSLColorTests.swift */,
);
path = Common;
sourceTree = "<group>";
};
8467FD2324E71A0E005D486C /* Icon */ = {
isa = PBXGroup;
children = (
8467FD2524E71A37005D486C /* IconGenerationTests.swift */,
);
path = Icon;
sourceTree = "<group>";
};
84CB471F24DBE7BD00837E11 /* Keystore */ = {
isa = PBXGroup;
children = (
Expand All @@ -226,6 +236,7 @@
84DA3B3024C8CE5900B5E27F /* Tests */ = {
isa = PBXGroup;
children = (
8467FD2324E71A0E005D486C /* Icon */,
84CB472224DBE81100837E11 /* Keystore */,
842D1E7424D0066100C30A7A /* Resources */,
842D1E6E24CFF2DC00C30A7A /* Helpers */,
Expand Down Expand Up @@ -330,10 +341,12 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = YLWWUD25VZ;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = YLWWUD25VZ;
LastSwiftMigration = 0900;
TestTargetID = 607FACCF1AFB9204008FA782;
};
Expand Down Expand Up @@ -364,7 +377,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
);
Expand Down Expand Up @@ -483,7 +495,9 @@
84DA3B4224C8CE5A00B5E27F /* ScaleUInt64Tests.swift in Sources */,
842D1E6A24CF800400C30A7A /* JunctionFactoryTests.swift in Sources */,
84DA3B4124C8CE5A00B5E27F /* ScaleInt32Tests.swift in Sources */,
8467FD2624E71A37005D486C /* IconGenerationTests.swift in Sources */,
842D1E2324C98CEA00C30A7A /* StorageKeyFactoryTests.swift in Sources */,
8467FD2824E72CCD005D486C /* HSLColorTests.swift in Sources */,
842D1E2724C9B63300C30A7A /* ScaleOptionTests.swift in Sources */,
842D1E7324CFF4EC00C30A7A /* KeypairDeriviationTests.swift in Sources */,
84CB472424DBE82C00837E11 /* KeystoreExtractorTests.swift in Sources */,
Expand All @@ -506,14 +520,6 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
607FACD91AFB9204008FA782 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
607FACDA1AFB9204008FA782 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -629,6 +635,7 @@
baseConfigurationReference = 93F24F5EEC204E4B0F918C39 /* Pods-FearlessUtils_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = YLWWUD25VZ;
INFOPLIST_FILE = FearlessUtils/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand All @@ -644,6 +651,7 @@
baseConfigurationReference = C0EC4D272FE196149F4492DE /* Pods-FearlessUtils_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = YLWWUD25VZ;
INFOPLIST_FILE = FearlessUtils/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand All @@ -658,6 +666,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 7BCE5EB68B0A48835979E64A /* Pods-FearlessUtils_Tests.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = YLWWUD25VZ;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -680,6 +689,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = B82F3EE26AAEE44C6E7F9962 /* Pods-FearlessUtils_Tests.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = YLWWUD25VZ;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
Expand Down
27 changes: 5 additions & 22 deletions Example/FearlessUtils/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
let rootContoller = ViewController()

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
window = UIWindow()
window?.rootViewController = rootContoller

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
window?.makeKeyAndVisible()

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
return true
}


}

30 changes: 0 additions & 30 deletions Example/FearlessUtils/Base.lproj/Main.storyboard

This file was deleted.

2 changes: 0 additions & 2 deletions Example/FearlessUtils/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
39 changes: 34 additions & 5 deletions Example/FearlessUtils/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,47 @@
//

import UIKit
import FearlessUtils

class ViewController: UIViewController {
private struct Constants {
static let address = "Fewyw2YrQgjtnuRsYQXfeHoTMoazKJKkfKkT8hc1WLjPsUP"
static let radius: CGFloat = 128.0
}

private var iconView: PolkadotIconView = PolkadotIconView()

override func loadView() {
let view = UIView()
view.backgroundColor = .lightGray

iconView.backgroundColor = .clear
iconView.translatesAutoresizingMaskIntoConstraints = false
iconView.fillColor = UIColor.white.withAlphaComponent(0.5)

view.addSubview(iconView)

iconView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
iconView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
iconView.widthAnchor.constraint(equalToConstant: 2.0 * Constants.radius).isActive = true
iconView.heightAnchor.constraint(equalToConstant: 2.0 * Constants.radius).isActive = true

self.view = view
}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
loadIcon()
}

private func loadIcon() {
do {
let icon = try PolkadotIconGenerator().generateFromAddress(Constants.address)
iconView.bind(icon: icon)
} catch {
print("Unexpected error: \(error)")
}
}
}

20 changes: 10 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
PODS:
- BigInt (5.0.0)
- FearlessUtils (0.4.0):
- FearlessUtils (0.5.0):
- BigInt (~> 5.0)
- IrohaCrypto/ed25519 (~> 0.7.0)
- IrohaCrypto/Scrypt (~> 0.7.0)
- IrohaCrypto/secp256k1 (~> 0.7.0)
- IrohaCrypto/sr25519 (~> 0.7.0)
- TweetNacl (~> 1.0.0)
- xxHash-Swift (~> 1.0.0)
- IrohaCrypto/BIP39 (0.7.0):
- IrohaCrypto/BIP39 (0.7.2):
- IrohaCrypto/Common
- IrohaCrypto/blake2 (0.7.0)
- IrohaCrypto/Common (0.7.0)
- IrohaCrypto/ed25519 (0.7.0):
- IrohaCrypto/blake2 (0.7.2)
- IrohaCrypto/Common (0.7.2)
- IrohaCrypto/ed25519 (0.7.2):
- IrohaCrypto/Common
- IrohaCrypto/Scrypt (0.7.0):
- IrohaCrypto/Scrypt (0.7.2):
- IrohaCrypto/Common
- scrypt.c (~> 0.1)
- IrohaCrypto/secp256k1 (0.7.0):
- IrohaCrypto/secp256k1 (0.7.2):
- IrohaCrypto/Common
- IrohaCrypto/sr25519 (0.7.0):
- IrohaCrypto/sr25519 (0.7.2):
- IrohaCrypto/BIP39
- IrohaCrypto/blake2
- IrohaCrypto/Common
Expand All @@ -44,8 +44,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
FearlessUtils: 9950c46435d41c8b5b16b93209ed4f470bfd655c
IrohaCrypto: 965cf029d83be1f50152464d591bb165ecccb657
FearlessUtils: 8cec323272fe5dd811996b2c7c50587b857946d0
IrohaCrypto: bddf15865c4df189b9c5273ba9c675afae8b7f4c
scrypt.c: b42ae06183251329d2b2c620c226fb541a4a3592
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
Expand Down
70 changes: 70 additions & 0 deletions FearlessUtils/Classes/Common/UIColor+HSL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import UIKit

public extension UIColor {

//MARK: - Public method

/**
Creates UIColor object based on given HSL values.
- parameter hue: CGFloat with the hue value. Hue value must be between 0 and 360.
- parameter saturation: CGFloat with the saturation value. Saturation value must be between 0 and 1.
- parameter lightness: CGFloat with the lightness value. Lightness value must be between 0 and 1.
- returns: A UIColor from the given HSL values.
*/

class func colorWithHSL(hue: CGFloat, saturation: CGFloat, lightness: CGFloat) -> UIColor {

var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0

let h = max(min(hue, 360.0), 0.0)
let s = max(min(saturation, 1.0), 0.0)
let l = max(min(lightness, 1.0), 0.0)

let c: CGFloat = (1 - abs((2.0 * l) - 1)) * s
let h60: CGFloat = h / 60.0
let x: CGFloat = c * CGFloat(1 - abs(h60.truncatingRemainder(dividingBy: 2.0) - 1))

if (h < 60.0) {

r = c
g = x
}
else if (h < 120.0)
{
r = x
g = c
}
else if (h < 180.0)
{
g = c
b = x
}
else if (h < 240.0)
{
g = x
b = c
}
else if (h < 300.0)
{
r = x
b = c
}
else if (h < 360.0)
{
r = c
b = x
}

let m: CGFloat = lightness - (c / 2.0)

r = r + m
g = g + m
b = b + m

return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
}
Loading

0 comments on commit 353ce94

Please sign in to comment.