Skip to content

Commit

Permalink
infinite scrolling fix + downpayment update
Browse files Browse the repository at this point in the history
  • Loading branch information
sypeer committed Oct 3, 2022
1 parent d74fc4f commit bb24d88
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ $(document).ready(() => {

let nextPage
let cursor
let alchemyApiKey = "AEtZpckav3marVzv5FPIbDyddDAkewJ6"
const domain = window.location.origin

// Get collection name from URL
const requestedCollection = window.location.pathname.split("/collections/")[1]
Expand Down Expand Up @@ -51,30 +53,30 @@ $(document).ready(() => {
const collection_address = collectionAddresses[requestedCollection]

function fetchCollections() {

populateCards(requestedCollection, collection_address, collection_name)

$("#submit-token").click(async () => {
const tokenId = $("#token-id").val()
const url = `${window.location.origin}/buy-nft?tokenAddress=${collection_address}&tokenId=${tokenId}`
$(location).attr('href', url)
})
}

$("#reload-collection").click(async () => {
window.location.reload()
})

$(window).scroll(function () {
// End of the document reached?
$("#loading-state").show()
const scrollHeight = $(document).height()
const scrollPos = $(this).height() + $(this).scrollTop()
if (((scrollHeight - 100) >= scrollPos) / scrollHeight == 0) {
if (((scrollHeight - 200) >= scrollPos) / scrollHeight == 0) {
if (nextPage) {
populateCards(requestedCollection, collection_address, collection_name)
}
}
$("#loading-state").hide()
})

let isFetching = false
function populateCards(requestedCollection, collection_address, collection_name) {
$("#loading-state").show()
if (isFetching) return
isFetching = true
// Make api request
var formdata = new FormData()
if (["999 Club", "10K Club", "100K Club"].includes(collection_name)) {
Expand All @@ -94,7 +96,6 @@ $(document).ready(() => {

// Set up routes
const baseURL = `https://api.apenowpaylater.com/api/getOpenseaCollection`
const domain = window.location.origin

// Generate nft cards from api response
fetch(baseURL, requestOptions)
Expand All @@ -109,7 +110,7 @@ $(document).ready(() => {
// Display NFT image and details
newCard.find(`.nft-img`).attr("src", result.data[i].image_url)
newCard.find(`.heading-25.nft-price`).text(Number(result.data[i].nft_price).toFixed(3))
newCard.find(`.heading-25.apenow-price`).text(Number(result.data[i].nft_price/2).toFixed(3))
newCard.find(`.heading-25.apenow-price`).text(Number(result.data[i].down_payment).toFixed(3))
let tokenId = result.data[i].token_id
if (result.data[i].token_id.length > 6) {
tokenId = result.data[i].display_name
Expand Down

0 comments on commit bb24d88

Please sign in to comment.