Skip to content

Commit

Permalink
public
Browse files Browse the repository at this point in the history
  • Loading branch information
VPhung24 committed May 2, 2023
1 parent ac167fc commit 8b80254
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 71 deletions.
File renamed without changes.
69 changes: 0 additions & 69 deletions Sources/SnowballKit/NFTListView.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/SnowballKit/SnowballSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import Foundation

public class SnowballSettings: ObservableObject {
@Published var alchemyApiKey: String
@Published var ethAddress: String
@Published public var ethAddress: String
public var alchemyApiKey: String

public init(alchemyApiKey: String, address: String) {
self.alchemyApiKey = alchemyApiKey
Expand Down
29 changes: 29 additions & 0 deletions Sources/SnowballKit/View Models/NFTViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// File.swift
//
//
// Created by Vivian Phung on 5/1/23.
//

import SwiftUI
import Alamofire

class NFTViewModel: ObservableObject {
@EnvironmentObject var settings: SnowballSettings
@Published var nfts = [NFT]()

func fetchNFTs(forAddress address: String, query: String = "") {
let url = "https://eth-mainnet.g.alchemy.com/nft/v2/\(settings.alchemyApiKey)/getNFTs?owner=\(address)&orderBy=transferTime&excludeFilters%5B%5D=SPAM&excludeFilters%5B%5D=AIRDROPS&spamConfidenceLevel=LOW"
let searchQuery = query.isEmpty ? "" : "&search=\(query)"
let urlString = url + searchQuery

AF.request(urlString).responseDecodable(of: NFTList.self) { response in
switch response.result {
case .success(let nftList):
self.nfts = nftList.nfts
case .failure(let error):
print("Error fetching NFTs: \(error)")
}
}
}
}
File renamed without changes.
36 changes: 36 additions & 0 deletions Sources/SnowballKit/Views/NFTListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// File.swift
//
//
// Created by Vivian Phung on 5/1/23.
//

import SwiftUI

public struct NFTListView: View {
@StateObject private var viewModel = NFTViewModel()
let ethAddress: String

public var body: some View {
NavigationView {
List(viewModel.nfts) { nft in
HStack {
SnowballImage(url: URL(string: nft.media.first?.thumbnail ?? "https://www.google.com/url?sa=i&url=https%3A%2F%2Fstock.adobe.com%2Fsearch%3Fk%3Dcat&psig=AOvVaw2Njrhkm-eHhxkL2ygGDl3M&ust=1683068826258000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCMDw6I2e1f4CFQAAAAAdAAAAABAE")!) {
ProgressView()
} image: { image in
Image(uiImage: image)
}
Text(nft.title)
.font(.caption)
.lineLimit(1)
.padding(.top, 5)
}
}

.navigationTitle("NFTs")
.onAppear {
viewModel.fetchNFTs(forAddress: ethAddress)
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8b80254

Please sign in to comment.