Skip to content

Commit

Permalink
Merge pull request #131 from P4-Games/feature/complete-album
Browse files Browse the repository at this point in the history
Feature/complete album
  • Loading branch information
dappsar authored Nov 17, 2023
2 parents e1d504c + 3b21607 commit a102ef2
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 74 deletions.
1 change: 1 addition & 0 deletions public/locales/br/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"transfer_pack_error": "Ocorreu um erro ao tentar transferir o pacote",
"finish_album_error": "Ocorreu um erro ao tentar reivindicar o prêmio",
"finish_album_success": "Parabéns! Você completou o álbum. Você receberá seu prêmio em DAIs na sua carteira.",
"finish_album_warning": "As condições necessárias para completar os álbuns e reivindicar os prêmios ainda não estão disponíveis. Tente novamente em alguns dias!",

"rules_alpha_left_text_1": "Um minijogo temático com 60 cartas que completam 10 coleções temáticas diferentes, cada uma com 5 personagens e um álbum.",
"rules_alpha_left_text_2": "O objetivo é completar um álbum com os 5 personagens correspondentes à coleção.",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"transfer_pack_error": "There was an error trying to transfer one pack",
"finish_album_error": "An error occurred while trying to claim the prize",
"finish_album_success": "Congratulations! You completed the album. You will receive your prize in DAIs to your wallet.",
"finish_album_warning": " The conditions required to complete the albums and claim the prizes are not yet met. Please try again in a few days!",

"rules_alpha_left_text_1": "A thematic minigame with 60 cards that complete 10 different thematic collections, each with 5 characters and an album.",
"rules_alpha_left_text_2": "The goal is to complete an album with the 5 characters corresponding to the collection.",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"transfer_pack_error": "Hubo un error al intentar transferir un pack",
"finish_album_error": "Ocurrió un error al intentar reclamar el premio",
"finish_album_success": "Felicitaciones! Completaste el álbum. Recibirás en tu wallet tu premio en DAIs.",

"finish_album_warning": "Aún no están dadas las condiciones para que se puedan completar los álbumnes y reclamas los premios. Intenta en unos días!",

"rules_alpha_left_text_1": "Un minijuego temático con 60 cartas que completan 10 colecciones temáticas diferentes con 5 personajes y un álbum cada uno.",
"rules_alpha_left_text_2": "El objetivo es completar un álbum con los 5 personajes correspondientes a la colección.",
"rules_alpha_left_text_3": "Para jugar es necesario conectar una billetera a la red de Polygon.",
Expand Down
1 change: 0 additions & 1 deletion src/components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function Navbar ({
} else if (window.history.state.url.endsWith('/gamma')) {
setMidButton('Inventory')
}
console.log('page', page, page.endsWith('/alpha'))
}, [page])


Expand Down
2 changes: 1 addition & 1 deletion src/context/Web3Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Web3ContextProvider({ children }) {
]
})
} catch (e) {
console.log(e.message)
console.error(e.message)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/context/Web3ContextNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const Web3ContextProvider = ({ children }) => {
*/

function switchNetwork() {
console.log(web3Onboard)
// console.log(web3Onboard)
// const currentNetwork = web3Onboard.getCurrentNetwork()
// const desiredNetwork = 'mumbai'
// const isCorrectNetwork = currentNetwork === desiredNetwork
Expand Down Expand Up @@ -167,7 +167,7 @@ const Web3ContextProvider = ({ children }) => {

const getProvider = (wlt) => {
if (wlt) {
console.log(wlt)
// console.log(wlt)
return new ethers.providers.Web3Provider(wlt.provider, 'any')
} else {
return new ethers.providers.JsonRpcProvider(
Expand Down
4 changes: 2 additions & 2 deletions src/context/abis/GammaCards.v2.sol/NofGammaCardsV2.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/context/abis/GammaPacks.v2.sol/NofGammaPacksV2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/pages/api/characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default async function handler(req, res) {
// Enviar la imagen como respuesta
return res.status(200).send(collageBuffer)
} catch (error) {
console.log(error)
console.error(error)
return res.status(500).json({ error: 'An error occurred while processing your request.' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default async function handler(req, res) {
// Enviar la imagen como respuesta
return res.status(200).send(collageBuffer)
} catch (error) {
console.log(error)
console.error(error)
return res.status(500).json({ error: 'An error occurred while processing your request.' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function handler(req, res) {
res.setHeader('Content-Type', 'application/json')
res.status(200).json(newRandomInt)
} catch (error) {
console.log(error)
console.error(error)
res.status(500).json({ error: 'An error occurred while processing your request.' })
}
}
2 changes: 1 addition & 1 deletion src/pages/api/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function handler(req, res) {
res.setHeader('Content-Type', 'application/json')
res.status(200).json(newRandomInt)
} catch (error) {
console.log(error)
console.error(error)
res.status(500).json({ error: 'An error occurred while processing your request.' })
}
}
2 changes: 1 addition & 1 deletion src/pages/api/reset-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function handler(req, res) {

return res.status(200).json({ message: 'Characters and medals arrays cleared for all users.' })
} catch (error) {
console.log(error)
console.error(error)
return res.status(500).json({ error: 'An error occurred while processing your request.' })
}
}
2 changes: 1 addition & 1 deletion src/sections/Alpha/AlphaAlbums.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const AlphaAlbums = ({
}
}
}
console.log('albumsArr', albumsArr)
// console.log('albumsArr', albumsArr)
return albumsArr
}

Expand Down
4 changes: 2 additions & 2 deletions src/sections/Alpha/AlphaCards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const AlphaCards = ({ alphaMidButton }) => {
text: message,
icon: 'success',
showConfirmButton: false,
timer: 1500
timer: 2000
})
}

Expand Down Expand Up @@ -393,7 +393,7 @@ const AlphaCards = ({ alphaMidButton }) => {
text: t('no_dai'),
icon: 'error',
showConfirmButton: false,
timer: 1500
timer: 2000
})
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/sections/Gamma/GammaAlbum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ const GammaAlbum = React.forwardRef((props, book) => {
const { paginationObj, setImageNumber, setCardInfo, showInventory } = props
const { size } = useLayoutContext()

console.log(paginationObj)


const getStyle = (item) => {
return (paginationObj.user[item]?.quantity === 0 || !paginationObj.user[item]?.quantity)
? { filter: 'grayscale(1)' }
: {}
}


const PageContent = ({ page, pageNumber}) => {
let divWrapperClassName = 'grid-wrapper'
if (pageNumber % 2 === 0) { // par
Expand Down
8 changes: 4 additions & 4 deletions src/sections/Gamma/GammaInfoCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const GammaInfoCard = React.forwardRef((props, book) => {
text: t('confirmado'),
icon: 'success',
showConfirmButton: false,
timer: 1500
timer: 2000
})
// Swal.fire({
// text: 'Publicar?',
Expand Down Expand Up @@ -165,13 +165,13 @@ const GammaInfoCard = React.forwardRef((props, book) => {
if (result.isConfirmed) {
startLoading()
const transaction = await gammaCardsContract.transferCard(result.value, imageNumber)
transaction.wait()
await transaction.wait()
Swal.fire({
title: '',
text: t('confirmado'),
icon: 'success',
showConfirmButton: false,
timer: 1500
timer: 2000
})
stopLoading()
handleFinishInfoCard()
Expand All @@ -195,7 +195,7 @@ const GammaInfoCard = React.forwardRef((props, book) => {
try {
startLoading()
const transaction = await gammaCardsContract.mintCard(imageNumber)
transaction.wait()
await transaction.wait()
stopLoading()
Swal.fire({
title: '',
Expand Down
48 changes: 26 additions & 22 deletions src/sections/Gamma/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { CONTRACTS } from '../../config'
import { showRules, closeRules } from '../../utils/rules'
import { useWeb3Context } from '../../hooks'
import { useLayoutContext } from '../../hooks'
import gammaCardsPages from './gammaCardsPages'
import { checkInputAddress } from '../../utils/addresses'

const index = React.forwardRef(() => {
Expand All @@ -37,8 +36,7 @@ const index = React.forwardRef(() => {

const { mobile, startLoading, stopLoading } = useLayoutContext()
const [paginationObj, setPaginationObj] = useState({})
const [paginationObjKey, setPaginationObjKey] = useState(0);
const [cardsQtty, setCardsQtty] = useState(0)
const [cardsQtty, setCardsQtty] = useState(0)

const getCardsQtty = (paginationObj) => {
let total = 0
Expand Down Expand Up @@ -72,13 +70,20 @@ const index = React.forwardRef(() => {
return authorization
}

const updateUserData = async () => {
const userCards = await getCardsByUser(gammaCardsContract, walletAddress)
setPaginationObj(userCards)
setCardsQtty(getCardsQtty(userCards))
}

const fetchInventory = async () => {
try {
const userCards = await getCardsByUser(gammaCardsContract, walletAddress, gammaCardsPages)
startLoading()
const userCards = await getCardsByUser(gammaCardsContract, walletAddress)
setPaginationObj(userCards)
// actualiza la clave para forzar el renderizado de gammaAlbumInventory
setPaginationObjKey(paginationObjKey => paginationObjKey + 1);
stopLoading()
} catch (error) {
stopLoading()
console.error(error)
}
}
Expand All @@ -96,7 +101,7 @@ const index = React.forwardRef(() => {

useEffect(() => {
fetchInventory()
}, [walletAddress, gammaCardsContract, gammaCardsPages])
}, [walletAddress, gammaCardsContract])

useEffect(() => {
checkNumberOfPacks()
Expand All @@ -116,10 +121,8 @@ const index = React.forwardRef(() => {
try {
startLoading()
const result = await finishAlbum(gammaCardsContract, walletAddress)

if (result) {
await fetchInventory()
setCardsQtty(getCardsQtty(paginationObj))
await updateUserData()
Swal.fire({
title: '',
text: t('finish_album_success'),
Expand All @@ -129,7 +132,13 @@ const index = React.forwardRef(() => {
})

} else {
emitError(t('finish_album_error'))
Swal.fire({
title: '',
text: t('finish_album_warning'),
icon: 'warning',
showConfirmButton: false,
timer: 8000
})
}
stopLoading()
} catch (ex) {
Expand Down Expand Up @@ -171,13 +180,14 @@ const index = React.forwardRef(() => {
const packs = await checkPacksByUser(walletAddress, gammaPacksContract)
const packNumber = ethers.BigNumber.from(packs[0]).toNumber()
const transaction = await gammaPacksContract.transferPack(result.value, packNumber)
await transaction.wait()
transaction.wait()
Swal.fire({
title: '',
text: t('confirmado'),
icon: 'success',
showConfirmButton: false,
timer: 1500
timer: 2000
})
await checkNumberOfPacks()
stopLoading()
Expand All @@ -201,7 +211,7 @@ const index = React.forwardRef(() => {
text: t('no_paquetes_para_abrir'),
icon: 'success',
showConfirmButton: false,
timer: 1500
timer: 2000
})
}

Expand All @@ -217,14 +227,12 @@ const index = React.forwardRef(() => {

setOpenPackCardsNumbers(packet_data)
const openedPack = await openPack(gammaCardsContract, packNumber, packet_data, signature.signature)

if (openedPack) {
await openedPack.wait()
setOpenPackage(true)
setLoaderPack(false)
await checkNumberOfPacks()
await fetchInventory()
setCardsQtty(getCardsQtty(paginationObj))
await updateUserData()
return openedPack
}
}
Expand Down Expand Up @@ -301,10 +309,9 @@ const index = React.forwardRef(() => {
}
}


const handleFinishInfoCard = async () => {
setCardInfo(false)
await fetchInventory()
await updateUserData()
}

const NotConnected = () => {
Expand Down Expand Up @@ -394,20 +401,17 @@ const index = React.forwardRef(() => {
{!inventory &&
<GammaAlbum
showInventory={false}
dummyKey={paginationObjKey}
paginationObj={paginationObj}
setImageNumber={setImageNumber}
setCardInfo={setCardInfo}/>
/*
<GammaAlbumStatistics
key={paginationObjKey}
paginationObj={paginationObj}
/>
*/}
{inventory && !cardInfo &&
<GammaAlbum
showInventory={true}
dummyKey={paginationObjKey}
paginationObj={paginationObj}
setImageNumber={setImageNumber}
setCardInfo={setCardInfo}/>
Expand Down
Loading

0 comments on commit a102ef2

Please sign in to comment.