Skip to content

Commit

Permalink
1.2.7 : Add accent & add friend (#59)
Browse files Browse the repository at this point in the history
* .

* .

* .

* .

* .

* .

* .

* .

* .

* merge acentColoir

* merge acentColoir

* merge acentColoir

* merge acentColoir

Co-authored-by: Varun Kohli <[email protected]>
  • Loading branch information
kohlivarun5 and Varun Kohli authored Jun 26, 2021
1 parent d5c8382 commit edba10a
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 206 deletions.
12 changes: 8 additions & 4 deletions NFTY.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
4F27A7C0267F9000008CCB0A /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 4F27A7BF267F9000008CCB0A /* Kingfisher */; };
4F27A7C3267F9760008CCB0A /* Cache in Frameworks */ = {isa = PBXBuildFile; productRef = 4F27A7C2267F9760008CCB0A /* Cache */; };
4F27A7C5267FB702008CCB0A /* BAYC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F27A7C4267FB702008CCB0A /* BAYC.swift */; };
4F27A7DC26876110008CCB0A /* LogsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F27A7DB26876110008CCB0A /* LogsFetcher.swift */; };
4F36013A2640CD99005D7587 /* FeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3601392640CD99005D7587 /* FeedView.swift */; };
4F43153D2638EF7400C16872 /* TokenPrice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F43153C2638EF7400C16872 /* TokenPrice.swift */; };
4F43153F263E4E9500C16872 /* AsciiPunkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F43153E263E4E9500C16872 /* AsciiPunkView.swift */; };
Expand Down Expand Up @@ -135,6 +136,7 @@
4F08724A2651E740002DD748 /* PrivateCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateCollectionView.swift; sourceTree = "<group>"; };
4F08724C2651EAC0002DD748 /* FriendsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsView.swift; sourceTree = "<group>"; };
4F27A7C4267FB702008CCB0A /* BAYC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BAYC.swift; sourceTree = "<group>"; };
4F27A7DB26876110008CCB0A /* LogsFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogsFetcher.swift; sourceTree = "<group>"; };
4F3601392640CD99005D7587 /* FeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedView.swift; sourceTree = "<group>"; };
4F43153C2638EF7400C16872 /* TokenPrice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenPrice.swift; sourceTree = "<group>"; };
4F43153E263E4E9500C16872 /* AsciiPunkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AsciiPunkView.swift; path = NFTY/Model/AsciiPunkView.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -453,6 +455,7 @@
4F27A7C6267FE1EB008CCB0A /* CollectionContracts */,
4FC744692630F9130060FC6D /* TokenProtocols.swift */,
4FC639DC264F5EC000ECF7CF /* Erc721Contract.swift */,
4F27A7DB26876110008CCB0A /* LogsFetcher.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -782,6 +785,7 @@
files = (
4FB9A811262B508700C58AF9 /* UsdText.swift in Sources */,
4F4DD21F265F480A00AD320D /* AddressLabelWithShare.swift in Sources */,
4F27A7DC26876110008CCB0A /* LogsFetcher.swift in Sources */,
4FA20038264DE73700E81BE6 /* OwnerProfileLinkButton.swift in Sources */,
4FC7446A2630F9130060FC6D /* TokenProtocols.swift in Sources */,
4F667F6E264B291000E7A214 /* ObservablePromise.swift in Sources */,
Expand Down Expand Up @@ -1108,7 +1112,7 @@
CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content";
DEVELOPMENT_TEAM = C28QWE5379;
ENABLE_PREVIEWS = YES;
Expand All @@ -1118,7 +1122,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.6;
MARKETING_VERSION = 1.2.7;
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1135,7 +1139,7 @@
CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content";
DEVELOPMENT_TEAM = C28QWE5379;
ENABLE_PREVIEWS = YES;
Expand All @@ -1145,7 +1149,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.6;
MARKETING_VERSION = 1.2.7;
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<key>DownloadCryptoPunks.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>2</integer>
</dict>
<key>MyPlayground (Playground) 1.xcscheme</key>
<dict>
Expand All @@ -54,7 +54,7 @@
<key>NFTY.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
<integer>5</integer>
</dict>
<key>ParseTokenDistances.xcscheme_^#shared#^_</key>
<dict>
Expand Down Expand Up @@ -106,12 +106,12 @@
<key>RankImages.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>4</integer>
</dict>
<key>RarityRanking.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<key>SimpleStorage (Playground) 1.xcscheme</key>
<dict>
Expand Down Expand Up @@ -158,7 +158,7 @@
<key>TestUI.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions NFTY/Model/AsciiPunkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AsciiPunkView: View {
VStack {
ObservedPromiseView(
data:asciiPunk,
progress:
progress: {
ZStack {
Text(String(repeating: "\n", count: 12))
.font(.system(size:fontSize, design: .monospaced))
Expand All @@ -47,7 +47,7 @@ struct AsciiPunkView: View {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: Color.tertiarySystemBackground))
.scaleEffect(2,anchor: .center)
}) {
}}) {
AsciiText(ascii:$0,fontSize: fontSize)
}
}
Expand Down
9 changes: 7 additions & 2 deletions NFTY/Model/CollectionContracts/BAYC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ class BAYC_Contract : ContractInterface {

// BAYC has too much noise, so we skip nil prices
if let price = priceIfNotZero(indicativePriceWei) {

let ipfsImage = Media.IpfsImageLazy(tokenId:BigUInt(tokenId), download: self.download)
// ipfsImage.image.load()

response(NFTWithPrice(
nft:NFT(
address:self.contractAddressHex,
tokenId:tokenId,
name:self.name,
media:.ipfsImage(Media.IpfsImageLazy(tokenId:BigUInt(tokenId), download: self.download))),
media:.ipfsImage(ipfsImage)),
indicativePriceWei:NFTPriceInfo(
price:price,
blockNumber:log.blockNumber?.quantity)
Expand Down Expand Up @@ -171,7 +175,8 @@ class BAYC_Contract : ContractInterface {
event:self.ethContract.Transfer,
fromBlock:self.ethContract.initFromBlock,
address:self.contractAddressHex,
indexedTopics: [nil,nil,tokenIdTopic])
indexedTopics: [nil,nil,tokenIdTopic],
blockDecrements: 10000)

let p =
self.ethContract.getTokenHistory(tokenId,fetcher:transerFetcher,retries:30)
Expand Down
5 changes: 3 additions & 2 deletions NFTY/Model/Erc721Contract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Erc721Contract {
self.contractAddressHex = address
ethContract = EthContract(address)
initFromBlock = (UserDefaults.standard.string(forKey: "\(address).initFromBlock").flatMap { BigUInt($0)}) ?? INIT_BLOCK
transfer = LogsFetcher(event:Transfer,fromBlock:initFromBlock,address:contractAddressHex,indexedTopics: [])
transfer = LogsFetcher(event:Transfer,fromBlock:initFromBlock,address:contractAddressHex,indexedTopics: [],blockDecrements: nil)
// name = ethContract.name()
}

Expand Down Expand Up @@ -287,7 +287,8 @@ class Erc721Contract {
event:self.Transfer,
fromBlock:self.initFromBlock,
address:self.contractAddressHex,
indexedTopics: [nil,nil,tokenIdTopic])
indexedTopics: [nil,nil,tokenIdTopic],
blockDecrements: 10000)

let p =
self.getTokenHistory(tokenId,fetcher:transerFetcher,retries:30)
Expand Down
120 changes: 120 additions & 0 deletions NFTY/Model/LogsFetcher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// LogsFetcher.swift
// NFTY
//
// Created by Varun Kohli on 6/26/21.
//

import Foundation
import BigInt
import Web3
import Web3ContractABI

class LogsFetcher {
private let blockDecrements : BigUInt
private let searchBlocks : BigUInt
private var toBlock = EthereumQuantityTag.latest
private var mostRecentBlock = EthereumQuantityTag.latest

let event : SolidityEvent
var fromBlock : BigUInt
var address : String
var topics : [String?]

init(event:SolidityEvent,fromBlock:BigUInt,address:String,indexedTopics:[String?],blockDecrements:BigUInt?) {
self.event = event;
self.fromBlock = fromBlock;
self.address = address
self.topics = [
web3.eth.abi.encodeEventSignature(self.event)
]
self.topics.append(contentsOf: indexedTopics)
self.searchBlocks = 500
self.blockDecrements = blockDecrements ?? 500 * 4
}

private func updateMostRecent(_ blockNumber:EthereumQuantity?) {

switch (blockNumber) {
case .some(let blockNum):
switch (self.mostRecentBlock.tagType) {
case .block(let seen):
self.mostRecentBlock = .block(max(seen,blockNum.quantity + 1)) // +1 as fromBlock is inclusive otherwise
default:
self.mostRecentBlock = .block(blockNum.quantity + 1)
}

switch (self.mostRecentBlock.tagType) {
case .block(let seen):
switch (UserDefaults.standard.string(forKey: "\(address).initFromBlock").flatMap { BigUInt($0)}) {
case .some(let prev):
UserDefaults.standard.set(String(max(prev,seen - searchBlocks)),forKey: "\(address).initFromBlock")
case .none:
UserDefaults.standard.set(String(seen - searchBlocks),forKey: "\(address).initFromBlock")
}
default:
break
}

case .none:
break
}
}

func updateLatest(onDone: @escaping () -> Void,_ response: @escaping (EthereumLogObject) -> Void) {
if (self.mostRecentBlock == .latest) {
return onDone()
}

return web3.eth.getLogs(
params:EthereumGetLogParams(
fromBlock:self.mostRecentBlock,
toBlock: EthereumQuantityTag.latest,
address:try! EthereumAddress(hex: self.address, eip55: false),
topics: self.topics
)
) { result in
if case let logs? = result.result {
logs.indices.forEach { index in
let log = logs[index];
response(log)
self.updateMostRecent(log.blockNumber)
}
} else {
print(result)
}
onDone()
}
}

func fetch(onDone: @escaping () -> Void,retries:Int = 0,_ response: @escaping (EthereumLogObject) -> Void) {

return web3.eth.getLogs(
params:EthereumGetLogParams(
fromBlock:.block(self.fromBlock),
toBlock: self.toBlock,
address:try! EthereumAddress(hex: self.address, eip55: false),
topics: self.topics
)
) { result in
if case let logs? = result.result {
self.toBlock = EthereumQuantityTag.block(self.fromBlock)
self.fromBlock = self.fromBlock - self.blockDecrements

logs.indices.forEach { index in
let log = logs[index];
response(log)
self.updateMostRecent(log.blockNumber)
}

if (logs.count == 0 && retries > 0) {
return self.fetch(onDone:onDone,retries:retries-1,response);
}

} else {
print(result)
}
onDone()
}
}
}
18 changes: 11 additions & 7 deletions NFTY/Model/NFT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ enum TokenPriceType {
case lazy(ObservablePromise<NFTPriceStatus>)
}

typealias SimilarTokensGetter = (UInt) -> [UInt]?
struct SimilarTokensGetter {
let label : String
let get : (UInt) -> [UInt]?
}

typealias RarityRankGetter = (UInt) -> UInt?
struct CollectionInfo {
let address: String
Expand All @@ -191,7 +195,7 @@ struct CollectionInfo {
let disableRecentTrades : Bool
let blur:CGFloat
let samplePadding:CGFloat
let similarTokens : SimilarTokensGetter
let similarTokens : SimilarTokensGetter?
let rarityRank : RarityRankGetter
}

Expand Down Expand Up @@ -283,7 +287,7 @@ let CompositeCollection = CompositeRecentTradesObject([
disableRecentTrades:false,
blur:0,
samplePadding:10,
similarTokens : { tokenId in CryptoPunks_nearestTokens[safe:Int(tokenId)] },
similarTokens : SimilarTokensGetter(label:"Punks") { tokenId in CryptoPunks_nearestTokens[safe:Int(tokenId)] },
rarityRank : { tokenId in CryptoPunks_rarityRanks[safe:Int(tokenId)] }),
contract:cryptoPunksContract),
CompositeRecentTradesObject.CollectionInitializer(
Expand All @@ -302,7 +306,7 @@ let CompositeCollection = CompositeRecentTradesObject([
disableRecentTrades:false,
blur:0,
samplePadding:10,
similarTokens: { tokenId in nil },
similarTokens: nil,
rarityRank : { tokenId in nil }),
contract:autoGlyphsContract),
CompositeRecentTradesObject.CollectionInitializer(
Expand All @@ -321,7 +325,7 @@ let CompositeCollection = CompositeRecentTradesObject([
disableRecentTrades:false,
blur:0,
samplePadding:10,
similarTokens : { tokenId in AsciiPunks_nearestTokens[safe:Int(tokenId)] },
similarTokens : SimilarTokensGetter(label:"Punks") { tokenId in AsciiPunks_nearestTokens[safe:Int(tokenId)] },
rarityRank : { tokenId in AsciiPunks_rarityRanks[safe:Int(tokenId)] }),
contract:asciiPunksContract),
CompositeRecentTradesObject.CollectionInitializer(
Expand All @@ -340,7 +344,7 @@ let CompositeCollection = CompositeRecentTradesObject([
disableRecentTrades:false,
blur:0,
samplePadding:15,
similarTokens: { tokenId in nil },
similarTokens: nil,
rarityRank : { tokenId in nil }),
contract:baycContract),
CompositeRecentTradesObject.CollectionInitializer(
Expand All @@ -358,7 +362,7 @@ let CompositeCollection = CompositeRecentTradesObject([
collectionColor:/* 78e08f */ Color(red: 120/255, green: 224/255, blue: 143/255),
disableRecentTrades:true,
blur:0,samplePadding:0,
similarTokens: { tokenId in nil },
similarTokens: nil,
rarityRank : { tokenId in nil }),
contract:cryptoKittiesContract),
]
Expand Down
2 changes: 1 addition & 1 deletion NFTY/Model/ObservablePromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ObservablePromise<T> : ObservableObject {
func load() {
switch(state) {
case .loading:
self.promise.done { val in
self.promise.done(on:.main) { val in
self.state = .resolved(val)
self.onDone.map {
$0(val)
Expand Down
Loading

0 comments on commit edba10a

Please sign in to comment.