Skip to content

Commit

Permalink
Merge pull request #300 from P4-Games/fix/fixs-20231225
Browse files Browse the repository at this point in the history
Fix/fixs 20231225
  • Loading branch information
dappsar authored Dec 26, 2023
2 parents deeb4ba + af677a7 commit b889cfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
40 changes: 24 additions & 16 deletions src/sections/Gamma/GammaAlbum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,28 @@ const GammaAlbum = (props) => {
}

const updateCardOffers = async (cardNumber) => {
const offers = await getOffersByCardNumber(gammaOffersContract, gammaCardsContract, cardNumber)
if (offers && offers.length > 0) {
// filtro mis ofertas
const filterMyoffes = offers.filter(
(item) => item.offerWallet.toUpperCase() !== walletAddress.toUpperCase()
try {
const offers = await getOffersByCardNumber(
gammaOffersContract,
gammaCardsContract,
cardNumber
)
setOffersObj(filterMyoffes)
} else {
setOffersObj(null)
/* Si el usuario2 confirma el intercambio de la carta X y el usuario1 abre el cardInfo
de la carta X, va a tener objeto.offered = true (porque no tiene el update del usuario1)
A diferencia de ello, el OffersObj está actualizado, por lo que es nulo, se quita
el offered. del paginationObj */
paginationObj.user[cardNumber].offered = false
if (offers && offers.length > 0) {
// filtro mis ofertas
const filterMyoffes = offers.filter(
(item) => item.offerWallet.toUpperCase() !== walletAddress.toUpperCase()
)
setOffersObj(filterMyoffes)
} else {
setOffersObj(null)
/* Si el usuario2 confirma el intercambio de la carta X y el usuario1 abre el cardInfo
de la carta X, va a tener objeto.offered = true (porque no tiene el update del usuario1)
A diferencia de ello, el OffersObj está actualizado, por lo que es nulo, se quita
el offered. del paginationObj */
paginationObj.user[cardNumber].offered = false
}
} catch (ex) {
// avoid show error
}
}

Expand Down Expand Up @@ -229,7 +237,7 @@ const GammaAlbum = (props) => {
pageNumber: PropTypes.number
}

const getuserCardObject = (imageNumber) => {
const getUserCardObject = (imageNumber) => {
const data = paginationObj
? Object.values(paginationObj.user).find((entry) => entry.name === imageNumber.toString())
: {}
Expand Down Expand Up @@ -262,15 +270,15 @@ const GammaAlbum = (props) => {

{cardInfo && (
<GammaCardInfo
userCard={getuserCardObject(imageNumber)}
userCard={getUserCardObject(imageNumber)}
handleOpenCardOffers={handleOpenCardOffers}
handleFinishInfoCard={handleFinishInfoCard}
/>
)}

{albumInfo && (
<GammaAlbumInfo
userCard={getuserCardObject(imageNumber)}
userCard={getUserCardObject(imageNumber)}
handleFinishInfoCard={handleFinishInfoCard}
/>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/sections/Gamma/GammaMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const GammaMain = () => {
}

useEffect(() => {
if (!gammaCardsContract || !walletAddress) return
if (!gammaCardsContract || !gammaPacksContract || !walletAddress) return
gammaCardsContract.on('OfferCardsExchanged', (from, to) => {
if (
to.toUpperCase() === walletAddress.toUpperCase() ||
Expand All @@ -119,6 +119,14 @@ const GammaMain = () => {
updateUserData()
}
})
gammaPacksContract.on('PacksTransfered', (from, to) => {
if (
to.toUpperCase() === walletAddress.toUpperCase() ||
from.toUpperCase() === walletAddress.toUpperCase()
) {
checkNumberOfPacks()
}
})
}, [gammaCardsContract, walletAddress]) //eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
Expand Down

0 comments on commit b889cfe

Please sign in to comment.