Skip to content

Commit

Permalink
Revert "fix(unlock-app):minting fixes (#14018)"
Browse files Browse the repository at this point in the history
This reverts commit 17edcdf.
  • Loading branch information
julien51 committed Jun 10, 2024
1 parent 17edcdf commit dc411cb
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import LinkedinShareButton from './LinkedInShareButton'
import { useCertification } from '~/hooks/useCertification'
import { useState } from 'react'
import { Checkout } from '~/components/interface/checkout/main'
import { selectProvider } from '~/hooks/useAuthenticate'
import { useConfig } from '~/utils/withConfig'
import { useValidKey } from '~/hooks/useKey'
import { useTransferFee } from '~/hooks/useTransferFee'
import { useQuery } from '@tanstack/react-query'
Expand Down Expand Up @@ -126,6 +128,7 @@ export const CertificationDetails = ({
tokenId,
}: CertificationDetailsProps) => {
const { account } = useAuth()
const config = useConfig()
const [isCheckoutOpen, setCheckoutOpen] = useState(false)

const { lock, isLockLoading: isLockDataLoading } = useLockData({
Expand Down Expand Up @@ -321,6 +324,7 @@ export const CertificationDetails = ({

const showCertification = key || (tokenId && key)

const injectedProvider = selectProvider(config)
const paywallConfig = {
locks: {
[lockAddress]: {
Expand All @@ -342,6 +346,7 @@ export const CertificationDetails = ({
<main className="mt-8">
<Modal isOpen={isCheckoutOpen} setIsOpen={setCheckoutOpen} empty={true}>
<Checkout
injectedProvider={injectedProvider as any}
paywallConfig={paywallConfig}
handleClose={() => setCheckoutOpen(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Button, Modal } from '@unlock-protocol/ui'
import { Checkout } from '~/components/interface/checkout/main'
import { useMemo, useState } from 'react'
import { selectProvider } from '~/hooks/useAuthenticate'
import { useConfig } from '~/utils/withConfig'
import { useRouter } from 'next/router'

export const EmbeddedCheckout = ({ checkoutConfig, refresh }: any) => {
const [isCheckoutOpen, setCheckoutOpen] = useState(false)
const config = useConfig()
const { query } = useRouter()
const injectedProvider = selectProvider(config)
const paywallConfig = useMemo(() => {
if (query.referrer) {
return {
Expand All @@ -20,6 +24,7 @@ export const EmbeddedCheckout = ({ checkoutConfig, refresh }: any) => {
<>
<Modal isOpen={isCheckoutOpen} setIsOpen={setCheckoutOpen} empty={true}>
<Checkout
injectedProvider={injectedProvider as any}
paywallConfig={paywallConfig}
handleClose={() => {
refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const WalletlessRegistrationClaiming = ({
<div className="m-auto mt-20 h-72 mb-36">
<MintingScreen
mint={{
network: network,
status: transactionStatus,
transactionHash: claimResult.hash,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import { useMachine } from '@xstate/react'
interface Props {
oauthConfig: OAuthConfig
injectedProvider: unknown
communication: ReturnType<typeof useCheckoutCommunication>
}

export function Connect({ injectedProvider, oauthConfig }: Props) {
const communication = useCheckoutCommunication()

export function Connect({
injectedProvider,
oauthConfig,
communication,
}: Props) {
// @ts-expect-error - The types returned by 'resolveState(...)' are incompatible between these types
const [state, send, connectService] = useMachine(connectMachine)
const matched = state.value.toString()
Expand Down
3 changes: 3 additions & 0 deletions unlock-app/src/components/interface/checkout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function CheckoutPage() {
<Container>
<Connect
injectedProvider={injectedProvider}
communication={communication}
oauthConfig={oauthConfig}
/>
</Container>
Expand All @@ -99,6 +100,8 @@ export function CheckoutPage() {
return (
<Container>
<Checkout
injectedProvider={injectedProvider}
communication={communication}
paywallConfig={paywallConfig}
redirectURI={
checkoutRedirectURI ? new URL(checkoutRedirectURI) : undefined
Expand Down
8 changes: 4 additions & 4 deletions unlock-app/src/components/interface/checkout/main/Confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CheckoutService } from './checkoutMachine'
import { Fragment } from 'react'
import { useSelector } from '@xstate/react'
import { useCheckoutCommunication } from '~/hooks/useCheckoutCommunication'
import { CheckoutCommunication } from '~/hooks/useCheckoutCommunication'
import { Stepper } from '../Stepper'
import { ToastHelper } from '~/components/helpers/toast.helper'
import { ConfirmClaim } from './Confirm/ConfirmClaim'
Expand All @@ -14,10 +14,10 @@ import { ConfirmCrossChainPurchase } from './Confirm/ConfirmCrossChainPurchase'

interface Props {
checkoutService: CheckoutService
communication?: CheckoutCommunication
}

export function Confirm({ checkoutService }: Props) {
const communication = useCheckoutCommunication()
export function Confirm({ checkoutService, communication }: Props) {
const { payment, paywallConfig, messageToSign, metadata } = useSelector(
checkoutService,
(state) => state.context
Expand All @@ -28,7 +28,7 @@ export function Confirm({ checkoutService }: Props) {
ToastHelper.error(message)
}

const onConfirmed = (lock: string, network: number, hash?: string) => {
const onConfirmed = (lock: string, hash?: string, network?: number) => {
// If not pessimistic, we can emit the transaction info right away
// and pass the signed message as well
if (!paywallConfig.pessimistic && hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -264,7 +264,7 @@ export function ConfirmCard({ checkoutService, onConfirmed, onError }: Props) {
paymentIntent: paymentIntent.id,
})
.then((transactionHash) => {
onConfirmed(lockAddress, lockNetwork, transactionHash)
onConfirmed(lockAddress, transactionHash)
setIsConfirming(false)
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -82,7 +82,7 @@ export function ConfirmClaim({ checkoutService, onConfirmed, onError }: Props) {
})

if (hash) {
onConfirmed(lockAddress, lockNetwork, hash)
onConfirmed(lockAddress, hash)
} else {
onError('No transaction hash returned. Failed to claim membership.')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string, network?: number) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -96,7 +96,7 @@ export function ConfirmCrossChainPurchase({
setIsConfirming(true)
const walletService = await getWalletService(route.network)
const tx = await walletService.signer.sendTransaction(route.tx)
onConfirmed(lockAddress, route.network, tx.hash)
onConfirmed(lockAddress, tx.hash, route.network)
} catch (error: any) {
setIsConfirming(false)
onError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -92,7 +92,7 @@ export function ConfirmCrossmint({
setIsConfirming(true)
listenToMintingEvents(paymentEvent.payload, (mintingEvent) => {
if (mintingEvent.type === 'transaction:fulfillment.succeeded') {
onConfirmed(lock!.address, lock!.network, mintingEvent.payload.txId)
onConfirmed(lock!.address, mintingEvent.payload.txId)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -168,7 +168,7 @@ export function ConfirmCrypto({
transactionHash: hash!,
})
} else if (hash) {
onConfirmed(lockAddress, lockNetwork, hash)
onConfirmed(lockAddress, hash)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Disconnect from '../Disconnect'

interface Props {
checkoutService: CheckoutService
onConfirmed: (lock: string, network: number, hash?: string) => void
onConfirmed: (lock: string, hash?: string) => void
onError: (message: string) => void
}

Expand Down Expand Up @@ -144,7 +144,7 @@ export function ConfirmSwapAndPurchase({
transactionHash: hash!,
})
} else if (hash) {
onConfirmed(lockAddress, lock!.network, hash)
onConfirmed(lockAddress, hash)
}
}
const swap = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Disconnect from './Disconnect'

interface Props {
checkoutService: CheckoutService
communication?: ReturnType<typeof useCheckoutCommunication>
}

export function MessageToSign({ checkoutService }: Props) {
const communication = useCheckoutCommunication()
export function MessageToSign({ communication, checkoutService }: Props) {
const { messageToSign } = useSelector(
checkoutService,
(state) => state.context.paywallConfig
Expand Down
Loading

0 comments on commit dc411cb

Please sign in to comment.