Skip to content

Commit

Permalink
Resolves #62:transfer-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
dappsar committed Nov 15, 2023
1 parent 42a75bb commit 0d494d2
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions src/sections/Gamma/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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(() => {
const {t} = useTranslation()
Expand Down Expand Up @@ -94,7 +95,53 @@ const index = React.forwardRef(() => {
}

const handleTransferPack = async () => {
// TODO
try {
const result = await Swal.fire({
text: `${t('wallet_destinatario')}`,
input: 'text',
inputAttributes: {
min: 43,
max: 43
},
inputValidator: (value) => {
if (!checkInputAddress(value, walletAddress))
return `${t('direccion_destino_error')}`
},
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `${t('trasnferir')}`,
confirmButtonColor: '#005EA3',
color: 'black',
background: 'white',
customClass: {
image: 'cardalertimg',
input: 'alertinput'
}
})

if (result.isConfirmed) {

startLoading()

const packs = await checkPacksByUser(walletAddress, gammaPacksContract)
const packNumber = ethers.BigNumber.from(packs[0]).toNumber()
const transaction = await gammaPacksContract.transferPack(result.value, packNumber)
transaction.wait()
Swal.fire({
title: '',
text: t('confirmado'),
icon: 'success',
showConfirmButton: false,
timer: 1500
})
await checkNumberOfPacks()
stopLoading()
}
} catch (ex) {
stopLoading()
console.error({ ex })
emitError(t('transfer_pack_error'))
}
}

const handleOpenPack = async () => {
Expand Down Expand Up @@ -142,7 +189,7 @@ const index = React.forwardRef(() => {
}
}

const buyPackscontact = async (numberOfPacks) => {
const buyPacksContract = async (numberOfPacks) => {

gammaPacksContract.on('PackPurchase', (returnValue, theEvent) => {
console.log('evento PacksPurchase', returnValue)
Expand Down Expand Up @@ -204,7 +251,7 @@ const index = React.forwardRef(() => {

if (result.isConfirmed) {
const packsToBuy = result.value
await buyPackscontact(packsToBuy)
await buyPacksContract(packsToBuy)
}
}

Expand Down

0 comments on commit 0d494d2

Please sign in to comment.