Skip to content

Commit

Permalink
ens setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sypeer committed Sep 26, 2022
1 parent aa185a4 commit 342ba65
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
30 changes: 23 additions & 7 deletions lib/buy-nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,21 @@ $(document).ready(() => {
fetch(fetchURL, reqOptions)
.then(response => response.json())
.then(result => {
const name = result.contractMetadata.name ? result.contractMetadata.name : $("#NFT-Collection-field option:selected").text()
const id = result.id.tokenId
const name = result.metadata.name ? result.metadata.name : $("#NFT-Collection-field option:selected").text()
let imageLink = result.metadata.image ? result.metadata.image : result.metadata.image_data
imageLink = imageLink.replace("ipfs://", "https://ipfs.io/ipfs/")
let id = result.id.tokenId
if (id.length > 10 ) {
id = result.title
$("#finalized-nft-token-id").text(id)
$(".preapproval-div").hide()
$("#id-label").text("ENS Name")
} else {
$("#finalized-nft-token-id").text(id)
$(".request-div").hide()
}
$("#collection-title").text(name)
$("#nft-token-id").text(id)
$("#finalized-nft-token-id").text(id)
$("#nft-image").attr("src", imageLink)
$("#finalized-collection-title").text(name)
$("#finalized-nft-image").attr("src", imageLink)
Expand All @@ -104,7 +112,10 @@ $(document).ready(() => {
"PudgyPenguins": "pudgypenguins",
"MutantApeYachtClub": "mutant-ape-yacht-club",
"The Saudis": "thesaudis",
"The Possessed": "thepossessed"
"The Possessed": "thepossessed",
"999-club": "ens",
"10k-club": "ens",
"100k-club": "ens"
}
const openseaCollectionLink = `https://opensea.io/collection/${collections[name]}`
$("#opensea-link").attr("href", openseaCollectionLink)
Expand All @@ -116,6 +127,7 @@ $(document).ready(() => {
}

async function getTerms(referrer) {
if(!provider) {}
$("#get-terms").text("Please wait...")
const tokenId = $("#token-id").val()
const contractAddress = $("#NFT-Collection-field").val()
Expand Down Expand Up @@ -168,8 +180,12 @@ $(document).ready(() => {
$(".apr").text(`${apr} %`)
var downPercent = (+result.data.submitBidArgs.downPayment/+result.data.submitBidArgs.totalPurchasePrice)*(10**2)
$(".down-percent").text(`${downPercent.toFixed(2)} %`)
var tokenId = +result.data.openSeaResponse.parameters.offer[0].identifierOrCriteria
$(".token-id").text(`${tokenId.toFixed(0)}`)
let tokenId = result.data.basicOrderParams.offerIdentifier
if (tokenId.length > 10) {
tokenId = result.data.addnlContextData.tokenName
}
$(".token-id").text(`${tokenId}`)
$(".finalized-collection-title").text(`${result.data.addnlContextData.collectionName}`)
$(".borrow-token").text(result.data.encodedOutput)
} else {
$("#final-steps").show()
Expand Down Expand Up @@ -229,7 +245,7 @@ $(document).ready(() => {
provider = new ethers.providers.Web3Provider(window.provider)
signer = provider.getSigner()
signerAddress = await signer.getAddress()
const tellerProfileLink = `https://mp.teller.org/profile/${provider.selectedAddress}/borrower`
const tellerProfileLink = `https://mp.teller.org/profile/${signerAddress}/borrower`
$("#teller-link").attr("href",tellerProfileLink)
const network = await provider.getNetwork()
chainId = network.chainId
Expand Down
41 changes: 34 additions & 7 deletions lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ $(document).ready(() => {
"pudgy-penguins": "pudgypenguins",
"mutant-ape-yacht-club": "mutant-ape-yacht-club",
"the-saudis": "thesaudis",
"the-possessed": "thepossessed"
"the-possessed": "thepossessed",
"999-club": "999 Club",
"10k-club": "10K Club",
"100k-club": "100K Club"
}

const collection_name = collections[requestedCollection]
Expand All @@ -40,7 +43,10 @@ $(document).ready(() => {
"pudgy-penguins": "0xBd3531dA5CF5857e7CfAA92426877b022e612cf8",
"mutant-ape-yacht-club": "0x60E4d786628Fea6478F785A6d7e704777c86a7c6",
"the-saudis": "0xe21EBCD28d37A67757B9Bc7b290f4C4928A430b1",
"the-possessed": "0x3A2096754Df385553C4252E5A82DC862e64169Bb"
"the-possessed": "0x3A2096754Df385553C4252E5A82DC862e64169Bb",
"999-club": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85", // ens
"10k-club": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85", // ens
"100k-club": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85", // ens
}

const collection_address = collectionAddresses[requestedCollection]
Expand All @@ -50,19 +56,34 @@ $(document).ready(() => {

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

$("#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)
})
}

function populateCards(requestedCollection, collection_address, collection_name) {
// Make api request
var formdata = new FormData()
formdata.append("collection", collection_name)
var requestOptions = {
if (["999 Club", "10K Club", "100K Club"].includes(collection_name)) {
formdata.append("category", collection_name)
formdata.append("collection", "ens")
} else {
formdata.append("collection", collection_name)
}
var requestOptions = {
method: 'POST',
body: formdata,
redirect: 'follow'
Expand All @@ -84,8 +105,13 @@ $(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(result.data[i].nft_price)
newCard.find(`.nft-id`).text(`# ${result.data[i].token_id}`)
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))
let tokenId = result.data[i].token_id
if (result.data[i].token_id.length > 6) {
tokenId = result.data[i].display_name
}
newCard.find(`.nft-id`).text(`# ${tokenId}`)

// Set up checkout link
newCard.find(".buynow").attr('href', `${domain}/buy-nft?tokenAddress=${collection_address}&tokenId=${result.data[i].token_id}`)
Expand All @@ -98,6 +124,7 @@ $(document).ready(() => {
})
.catch(error => console.log('error', error))
}

/**
* Main entry point.
*/
Expand Down

0 comments on commit 342ba65

Please sign in to comment.