From b58309d82aea221a5f1f57c4aaeb7383d32db7c4 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Fri, 24 Oct 2025 19:59:48 -0400 Subject: [PATCH] feat(update): Added update button --- .../app-body/nfts-for-sale/index.js | 31 +++++++++++++++++-- .../app-body/nfts-for-sale/info-button.js | 31 +++++++++++++++++-- .../app-body/nfts-for-sale/token-card.js | 3 +- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/components/app-body/nfts-for-sale/index.js b/src/components/app-body/nfts-for-sale/index.js index ad78efe..e5a8578 100644 --- a/src/components/app-body/nfts-for-sale/index.js +++ b/src/components/app-body/nfts-for-sale/index.js @@ -301,8 +301,34 @@ function NftsForSale (props) { return url } + const updateOffer = useCallback(async (offer) => { + try { + if (!offer) return + setOffersAreLoaded(false) + const processedOffer = await processTokenData(offer) + const processedOfferMetadata = await processOfferMetadata(processedOffer) + + setOffers(offers => { + // find offer + const index = offers.findIndex((val) => { return val.tokenId === offer.tokenId }) + // Save existing token data + processedOfferMetadata.tokenData = offers[index].tokenData + // replace with the new data + offers[index] = processedOfferMetadata + return offers + }) + + // Re-render tokens cards , to load the new data. + setTimeout(() => { + setOffersAreLoaded(true) + }, 500) + } catch (error) { + console.warn(error) + } + }, [processOfferMetadata, processTokenData]) + // This function generates a Token Card for each token in the wallet. - function generateCards (offers) { + const generateCards = useCallback(() => { console.log('generateCards() offerData: ', offers) const tokens = offers @@ -318,13 +344,14 @@ function NftsForSale (props) { token={thisToken} handleRefresh={handleRefresh} key={`${thisToken.tokenId + i}`} + updateOffer={updateOffer} /> ) tokenCards.push(thisTokenCard) } return tokenCards - } + }, [offers, appData, handleRefresh, updateOffer]) return ( diff --git a/src/components/app-body/nfts-for-sale/info-button.js b/src/components/app-body/nfts-for-sale/info-button.js index e4f939c..dd95961 100644 --- a/src/components/app-body/nfts-for-sale/info-button.js +++ b/src/components/app-body/nfts-for-sale/info-button.js @@ -7,11 +7,18 @@ // Global npm libraries import React, { useEffect, useState } from 'react' -import { Button, Modal, Container, Row, Col } from 'react-bootstrap' +import { Button, Modal, Container, Row, Col, Spinner } from 'react-bootstrap' +import axios from 'axios' + +// Local libraries +import config from '../../../config' +// Global variables and constants +const SERVER = config.dexServer function InfoButton (props) { const [show, setShow] = useState(false) const [mutableDataCid, setMutableDataCid] = useState(null) + const [loading, setLoading] = useState(false) const handleClose = () => { console.log('handleClose()') @@ -50,6 +57,22 @@ function InfoButton (props) { } }, [props.token, show]) + // Update offer data + const updateOffer = async () => { + try { + setLoading(true) + const inputObj = { tokenId: props.token.tokenId } + const result = await axios.post(`${SERVER}/offer/mutable/sync/`, inputObj) + const offerData = result.data + console.log('offerData: ', offerData) + + if (props.updateOffer) await props.updateOffer(offerData) + setLoading(false) + } catch (error) { + setLoading(false) + } + } + // Replace with dummy button until token data is loaded. if (!props.token.tokenData) { return ( @@ -105,6 +128,7 @@ function InfoButton (props) { href={`/user-data/${props.token.tokenId}#single-view`} target='_blank' rel='noopener noreferrer' + variant='success' > View User Data @@ -114,7 +138,10 @@ function InfoButton (props) { - + + {!loading && } + {loading && } + ) diff --git a/src/components/app-body/nfts-for-sale/token-card.js b/src/components/app-body/nfts-for-sale/token-card.js index 1028580..3c7b80a 100644 --- a/src/components/app-body/nfts-for-sale/token-card.js +++ b/src/components/app-body/nfts-for-sale/token-card.js @@ -20,6 +20,7 @@ function TokenCard (props) { // Update icon state every token.icon and token.tokenData changes useEffect(() => { + console.log('setting icon') setIcon(token.icon) setTokenData(token.tokenData) }, [token.icon, token.tokenData]) @@ -66,7 +67,7 @@ function TokenCard (props) { - + {!hideBuyBtn && (