Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/in kiosk minting messaging #154

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions functions/modules/minting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ exports.mint_code_to_address = async ( { data } ) => {
try {

// Function dependencies
const { sanitise_string } = require( './validations' )
const { sanetise_poap_id, sanetise_eth_or_ens_address } = require( '@poap/sane-data' )

// Get the claim code and address to claim to from data property
let { claim_code, challenge_code, address_to_mint_to } = data

// Sanetise data
claim_code = sanitise_string( claim_code )
address_to_mint_to = sanitise_string( address_to_mint_to )
claim_code = sanetise_poap_id( claim_code )
address_to_mint_to = sanetise_eth_or_ens_address( address_to_mint_to )

// Check if claim code is a mock code
const is_mock = claim_code.includes( 'testing' )
Expand All @@ -36,6 +36,8 @@ exports.mint_code_to_address = async ( { data } ) => {
// Get the claim secret of the mint link
const { call_poap_endpoint } = require( './poap_api' )
const { claimed, secret, error: preclaim_error, message: preclaim_error_message } = await call_poap_endpoint( `/actions/claim-qr`, { qr_hash: claim_code } )

// Handle claim secret errors
if( preclaim_error ) {
log( `Error getting claim secret: `, preclaim_error )
if( preclaim_error_message.includes( "Qr Claim not found" ) ) throw new Error( `Failed to get claim secret: Invalid claim link` )
Expand Down Expand Up @@ -78,12 +80,12 @@ exports.mint_code_to_address = async ( { data } ) => {
}

// Check if the error was due to already being claimed
if( error || message.includes( 'already claimed' ) ) {
if( error && message.includes( 'already claimed' ) ) {
claim_attempts++
continue
}

if( error ) throw new Error( `Failed to mint POAP: ${ error }` )
if( error ) throw new Error( `Failed to mint POAP: ${ message }` )

}

Expand Down
2 changes: 1 addition & 1 deletion functions/modules/poap_api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Firebase interactors
const { db, dataFromSnap } = require( './firebase' )
const { log, dev } = require( './helpers' )
const { log } = require( './helpers' )

// Secrets
const { POAP_API_KEY, AUTH0_CLIENT_ID, AUTH0_ENDPOINT, AUTH0_CLIENT_SECRET, AUTH0_AUDIENCE } = process.env
Expand Down
2 changes: 1 addition & 1 deletion functions/modules/static_qr_drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ exports.create_static_drop = async ( data, context ) => {

exports.update_public_static_drop_data = async function( change, context ) {

const { after, before } = change
const { after } = change
const { drop_id } = context.params

// If this was a deletion, delete public data
Expand Down
68 changes: 0 additions & 68 deletions functions/modules/validations.js

This file was deleted.

11 changes: 11 additions & 0 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"main": "index.js",
"dependencies": {
"@poap/sane-data": "^0.0.2",
"@sendgrid/mail": "^7.7.0",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
Expand All @@ -38,4 +39,4 @@
"devDependencies": {
"firebase-tools": "^12.5.3"
}
}
}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@heroicons/react": "^2.0.18",
"@poap/poap-components": "^0.1.20",
"@poap/sane-data": "^0.0.4",
"@rive-app/react-canvas": "^4.5.0",
"@vitejs/plugin-react": "^4.1.1",
"cypress": "^11.2.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/pages/EventCreate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import FormFooter from '../molecules/FormFooter'
import { UploadButton } from '../molecules/UploadButton'

import { Button, CardContainer, Container, H3, Input, Dropdown, CardDashboard, useViewport } from '@poap/poap-components'
import Modal from '../molecules/Modal'

// ///////////////////////////////
// Render component
Expand Down
12 changes: 8 additions & 4 deletions src/components/pages/MintPOAP.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { log } from "../../modules/helpers"
import Loading from "../molecules/Loading"
import { mint_code_to_address } from "../../modules/firebase"
import { useParams } from "react-router-dom"
import { eth_address_or_ens_regex, valid_email_regex } from "../../modules/validations"
import { serveToast } from '../molecules/Toast'
import { eth_or_ens_address_regex, email_regex } from '@poap/sane-data'

export default function MintPOAP() {

Expand All @@ -18,6 +18,7 @@ export default function MintPOAP() {
const [ loading, set_loading ] = useState( false )
const { claim_code, challenge_code } = useParams( )
const [ claim_success, set_claim_success ] = useState( )
const [ auto_mint_attempted, set_auto_mint_attempted ] = useState( false )

// If a probable address is found, and the user did not supply an address, set the address to state
useEffect( ( ) => {
Expand All @@ -32,10 +33,13 @@ export default function MintPOAP() {

// If no valid address in query, exit
if( !address_in_query ) return
if( !address_to_mint_to?.match( eth_address_or_ens_regex ) ) return
if( !address_to_mint_to?.match( eth_or_ens_address_regex ) ) return

// If auto mint already attempted, exit
if( auto_mint_attempted ) return

// Trigger mint, this handles loading states etc, note it's a promise
handle_mint()
handle_mint().finally( () => set_auto_mint_attempted( true ) )

}, [ address_in_query, address_to_mint_to ] )

Expand All @@ -48,7 +52,7 @@ export default function MintPOAP() {
set_loading( `Minting your POAP` )

// Validate address based on address or email
if( !address_to_mint_to?.match( eth_address_or_ens_regex ) && !address_to_mint_to?.match( valid_email_regex ) ) {
if( !address_to_mint_to?.match( eth_or_ens_address_regex ) && !address_to_mint_to?.match( email_regex ) ) {
throw new Error( 'Please input a valid Ethereum address/ENS or email address.' )
}

Expand Down