Skip to content

Commit

Permalink
Ios15 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlivarun5 authored Sep 25, 2021
1 parent 8cf0981 commit 9786883
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 128 deletions.
8 changes: 4 additions & 4 deletions NFTY.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@
CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content";
DEVELOPMENT_TEAM = C28QWE5379;
ENABLE_PREVIEWS = YES;
Expand All @@ -1396,7 +1396,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1413,7 +1413,7 @@
CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content";
DEVELOPMENT_TEAM = C28QWE5379;
ENABLE_PREVIEWS = YES;
Expand All @@ -1423,7 +1423,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
32 changes: 31 additions & 1 deletion NFTY/Model/NFT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,38 @@ struct NFT: Identifiable {

struct NFTPriceInfo {
let price : BigUInt?
let blockNumber : BigUInt?

enum BlockTimeStamp {
case none
case some(BigUInt)
case date(Date)
}

let blockNumber : BlockTimeStamp
let type : TradeEventType

init(price:BigUInt?, blockNumber:BigUInt?,type:TradeEventType) {
self.price = price
self.type = type
switch(blockNumber) {
case .some(let x):
self.blockNumber = BlockTimeStamp.some(x)
case .none:
self.blockNumber = BlockTimeStamp.none
}
}

init(price:BigUInt?, date:Date?,type:TradeEventType) {
self.price = price
self.type = type
switch(date) {
case .some(let x):
self.blockNumber = .date(x)
case .none:
self.blockNumber = .none
}

}
}

enum NFTPriceStatus {
Expand Down
36 changes: 21 additions & 15 deletions NFTY/Model/OpenSeaApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,22 @@ struct OpenSeaApi {

//print(orders)
// remove duplicates, we request ordered by highest first
if (contract == nil || tokenIds == nil) {
var uniqueOrdersDict : [String:AssetOrder] = [:]
orders.orders.forEach { order in
let key = "\(order.asset.asset_contract.address):\(order.asset.token_id)"
uniqueOrdersDict[key] = uniqueOrdersDict[key] ?? order
}

var dict : [String:AssetOrder] = [:]
// print(orders)
orders.orders.forEach { order in

orders = Orders(orders: uniqueOrdersDict.map { $1 })
let key = "\(order.asset.asset_contract.address):\(order.asset.token_id):\(order.side)"
dict[key] = dict[key] ??
orders.orders.filter {
"\($0.asset.asset_contract.address):\($0.asset.token_id):\($0.side)" == key
}.sorted {
$0.payment_token == $1.payment_token && $0.current_price > $1.current_price
}.first!
}

orders = Orders(orders: dict.map { $1 })

seal.fulfill(orders.orders)

} catch {
Expand All @@ -145,7 +151,7 @@ struct OpenSeaApi {
let ask = $0.first { $0.side == .sell }.flatMap { (order:AssetOrder) -> AskInfo? in
switch(order.payment_token,Double(order.current_price).map { BigUInt($0) }) {
case (ETH_ADDRESS,.some(let wei)),
(WETH_ADDRESS,.some(let wei)):
(WETH_ADDRESS,.some(let wei)):
return AskInfo(wei: wei)
default:
return nil
Expand All @@ -155,7 +161,7 @@ struct OpenSeaApi {
let bid = $0.first { $0.side == .buy }.flatMap { (order:AssetOrder) -> BidInfo? in
switch(order.payment_token,Double(order.current_price).map { BigUInt($0) }) {
case (ETH_ADDRESS,.some(let wei)),
(WETH_ADDRESS,.some(let wei)):
(WETH_ADDRESS,.some(let wei)):
return BidInfo(wei: wei)
default:
return nil
Expand All @@ -172,7 +178,7 @@ struct OpenSeaApi {
let ask = $0.first { $0.side == .sell }.flatMap { (order:AssetOrder) -> AskInfo? in
switch(order.payment_token,Double(order.current_price).map { BigUInt($0) }) {
case (ETH_ADDRESS,.some(let wei)),
(WETH_ADDRESS,.some(let wei)):
(WETH_ADDRESS,.some(let wei)):
return AskInfo(wei: wei)
default:
return nil
Expand All @@ -182,7 +188,7 @@ struct OpenSeaApi {
let bid = $0.first { $0.side == .buy }.flatMap { (order:AssetOrder) -> BidInfo? in
switch(order.payment_token,Double(order.current_price).map { BigUInt($0) }) {
case (ETH_ADDRESS,.some(let wei)),
(WETH_ADDRESS,.some(let wei)):
(WETH_ADDRESS,.some(let wei)):
return BidInfo(wei: wei)
default:
return nil
Expand All @@ -196,7 +202,7 @@ struct OpenSeaApi {
static func userOrders(address:QueryAddress,side:Side?) -> Promise<[NFTWithLazyPrice]> {
OpenSeaApi.getOrders(contract: nil, tokenIds: nil, user: address, side: side)
.map(on:DispatchQueue.global(qos:.userInteractive)) { orders in
orders
return orders
.sorted {
switch($0.expiration_time,$1.expiration_time) {
case (0,0):
Expand All @@ -209,7 +215,7 @@ struct OpenSeaApi {
return $0.expiration_time < $1.expiration_time
}
}

.map { order in
collectionsFactory
.getByAddress(
Expand All @@ -223,15 +229,15 @@ struct OpenSeaApi {
.flatMap { (nft:NFT) -> NFTWithLazyPrice? in
switch(order.payment_token,Double(order.current_price).map { BigUInt($0) }) {
case (ETH_ADDRESS,.some(let wei)),
(WETH_ADDRESS,.some(let wei)):
(WETH_ADDRESS,.some(let wei)):
return NFTWithLazyPrice(
nft: nft,
getPrice: {
ObservablePromise<NFTPriceStatus>(
resolved: NFTPriceStatus.known(
NFTPriceInfo(
price: wei,
blockNumber: nil,
date:order.expiration_time == 0 ? nil : Date(timeIntervalSince1970:Double(order.expiration_time)),
type:AssetOrder.sideToEvent(order.side))
)
)
Expand Down
32 changes: 17 additions & 15 deletions NFTY/NFTYApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ struct NFTYApp: App {
WindowGroup {
TabView {

NavigationView {
WalletView()
}
.tabItem {
Label("Wallet",systemImage:"lock.rectangle.stack.fill")
}
.navigationViewStyle(StackNavigationViewStyle())

NavigationView {
FavoritesView()
.navigationBarTitle("Favorites")
}
.tabItem {
Label("Favorites",systemImage:"heart.fill")
}
.navigationViewStyle(StackNavigationViewStyle())

NavigationView {
FeedView(trades:CompositeCollection)
.navigationBarTitle("Recent")
Expand Down Expand Up @@ -76,22 +93,7 @@ struct NFTYApp: App {
.navigationViewStyle(StackNavigationViewStyle())
}

NavigationView {
FavoritesView()
.navigationBarTitle("Favorites")
}
.tabItem {
Label("Favorites",systemImage:"heart.fill")
}
.navigationViewStyle(StackNavigationViewStyle())

NavigationView {
WalletView()
}
.tabItem {
Label("Wallet",systemImage:"lock.rectangle.stack.fill")
}
.navigationViewStyle(StackNavigationViewStyle())
}
// .preferredColorScheme(.dark)
.accentColor(.orange)
Expand Down
3 changes: 1 addition & 2 deletions NFTY/Views/ConnectWalletSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ struct UserWalletConnectorView : View {
}
}
.padding()
.animation(.easeIn)
}

}
Expand Down Expand Up @@ -182,9 +181,9 @@ struct ConnectWalletSheet: View {
Text(badAddressError)
.font(.footnote)
.foregroundColor(.secondary)
.animation(.easeIn)
}
.padding()
.animation(.easeIn)

Spacer()
}
Expand Down
17 changes: 13 additions & 4 deletions NFTY/Views/FeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ struct FeedView: View {
self.refreshButton = .loading
self.trades.loadLatest() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { self.refreshButton = .loaded }

// trigger refresh again after 30 seconds
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 30) { self.triggerRefresh() }
}
let impactMed = UIImpactFeedbackGenerator(style: .light)
impactMed.impactOccurred()
}

var body: some View {
Expand Down Expand Up @@ -130,6 +131,8 @@ struct FeedView: View {
ScrollView {
PullToRefresh(coordinateSpaceName: "RefreshControl") {
self.triggerRefresh()
let impactMed = UIImpactFeedbackGenerator(style: .light)
impactMed.impactOccurred()
}
LazyVStack {
ForEach(trades.recentTrades.indices,id:\.self) { index in
Expand Down Expand Up @@ -171,7 +174,8 @@ struct FeedView: View {
self.trades.getRecentTrades(currentIndex:index)
}
}
}.textCase(nil)
}
.textCase(nil)
}
}.coordinateSpace(name: "RefreshControl")
}
Expand All @@ -185,7 +189,11 @@ struct FeedView: View {
case .loading:
ProgressView()
case .loaded:
Button(action: self.triggerRefresh) {
Button(action: {
self.triggerRefresh()
let impactMed = UIImpactFeedbackGenerator(style: .light)
impactMed.impactOccurred()
}) {
Image(systemName:"arrow.clockwise.circle.fill")
.font(.title3)
.foregroundColor(.accentColor)
Expand All @@ -200,6 +208,7 @@ struct FeedView: View {
DispatchQueue.main.async {
self.isLoading = false
self.refreshButton = .loaded
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 30) { self.triggerRefresh() }
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions NFTY/Views/FriendsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ struct FriendsView: View {
HStack() {
Text(name)
.font(.title3)
Spacer()
AddressLabel(address:address,maxLen:15)
}
.padding()
}
Expand Down
2 changes: 1 addition & 1 deletion NFTY/Views/NftDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct NftDetail: View {
label: {
Image(systemName: "arrowshape.turn.up.forward.circle")
.foregroundColor(themeLabelColor)
.font(.title)
.font(.title3)
}
)
)
Expand Down
2 changes: 0 additions & 2 deletions NFTY/Views/RoundedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ struct RoundedImage: View {
}
}

.animation(.default)

.border(Color.secondary)
.frame(width:frameWidth(width))
.clipShape(RoundedRectangle(cornerRadius:cornerRadius(width), style: .continuous))
Expand Down
8 changes: 1 addition & 7 deletions NFTY/Views/TokenListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ struct TokenListView: View {
init(collection:Collection,tokenIds:[UInt]) {
self.collection = collection
self.nfts = NftTokenList(contract:collection.data.contract,tokenIds:tokenIds)
}

init(collection:Collection,nfts:NftTokenList) {
self.collection = collection
self.nfts = nfts
self.nfts.loadMore { }
}

var body: some View {
Expand Down Expand Up @@ -66,8 +62,6 @@ struct TokenListView: View {
}
}
}
}.onAppear {
nfts.loadMore {} // TODO
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions NFTY/Views/TokenPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,38 @@ struct TokenPriceKnown : View {
.font(.caption2)
.foregroundColor(subtleColor(self.color))
}

case (.some(let wei),.date(let date)):
VStack {

HStack(spacing:4) {
UsdText(wei:wei,fontWeight:.semibold)
.foregroundColor(color(self.color))
Image(systemName: TradeEventIcon.systemName(info.type))
.font(.caption2)
}

if (showEth) {
Text(ethFormatter.string(for:(Double(wei) / 1e18))!)
.font(.body)
.italic()
}

Text(date.timeAgoDisplay())
.font(.caption2)
.foregroundColor(subtleColor(self.color))
}

case (.none,.some(let blockNumber)):
BlockTimeLabel(blockNumber:blockNumber)
.font(.caption2)
.foregroundColor(subtleColor(self.color))
.padding([.top,.bottom],2)
case (.none,.date(let date)):
Text(date.timeAgoDisplay())
.font(.caption2)
.foregroundColor(subtleColor(self.color))
.padding([.top,.bottom],2)
case (.some(let wei),.none):
HStack {
UsdText(wei:wei,fontWeight:.semibold)
Expand Down
3 changes: 1 addition & 2 deletions NFTY/Views/TokenTradeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ struct TokenTradeView: View {
Text("History")
.font(.caption).italic()
.foregroundColor(.secondaryLabel)
.padding(.trailing)
.padding(.leading)
.padding([.trailing,.leading])
.background(Color.systemBackground)
}

Expand Down
Loading

0 comments on commit 9786883

Please sign in to comment.