Skip to content

Commit

Permalink
Bit of cleanup and catching errors on minting
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Apr 10, 2022
1 parent aae8bb3 commit 3576b5b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
8 changes: 0 additions & 8 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,5 @@ REACT_APP_SUBSCRIBE_FORM_DOMAIN=
REACT_APP_SUBSCRIBE_FORM_U=
REACT_APP_SUBSCRIBE_FORM_ID=

REACT_APP_ALLOWLIST_001_FORM_DOMAIN=
REACT_APP_ALLOWLIST_001_FORM_U=
REACT_APP_ALLOWLIST_001_FORM_ID=

REACT_APP_ALLOWLIST_TOP_FORM_DOMAIN=
REACT_APP_ALLOWLIST_TOP_FORM_U=
REACT_APP_ALLOWLIST_TOP_FORM_ID=

REACT_APP_ADDEVENT_TOKEN=
REACT_APP_INFURA_ID=
11 changes: 10 additions & 1 deletion src/pages/Home/components/BuyClearanceCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@ const BuyClearanceCard: FunctionComponent<{
}
}
const title = buyingClearanceCardType === "001" ? "001 Clearance Cards" : "Top Clearance Cards"
const clearanceCardIntValue = parseInt(clearanceCardMintValue)
return (
<Modal open={!!buyingClearanceCardType} onClose={handleClose}>
<form className="buy-clearance-card" onSubmit={handleSubmit}>
<h2>Buy ({title})</h2>
<label>Amount</label>
<Input
min={1}
max={5}
name="amount"
type="number"
required
value={clearanceCardMintValue}
onChange={event => setClearanceCardMintValue(event.target.value)}
/>
<Button variant="primary" type="submit" disabled={!clearanceCardMintValue}>
<Button
variant="primary"
type="submit"
disabled={
!clearanceCardMintValue || clearanceCardIntValue < 1 || clearanceCardIntValue > 5
}
>
Mint
</Button>
</form>
Expand Down
71 changes: 32 additions & 39 deletions src/pages/Home/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const useHomePage = (): HomePageState => {
const [viewScheduleOpen, setViewScheduleOpen] = useState(false)
const [buyingClearanceCardType, setBuyingClearanceCardType] = useState<ClearanceCardType>()

const onPurchaseSupportUkraine = useCallback(async () => {
const signIn = async () => {
let signer = null
if (!web3Context.signer) {
// sign in
Expand All @@ -48,6 +48,11 @@ const useHomePage = (): HomePageState => {
} else {
signer = web3Context.signer
}

return signer
}
const onPurchaseSupportUkraine = useCallback(async () => {
const signer = await signIn()
const saleContract = new ethers.Contract(
"0xb7419c7B3ABcf81666B4eD006fa3503aA14F9588",
Ukraine.abi,
Expand All @@ -61,50 +66,38 @@ const useHomePage = (): HomePageState => {
}, [mintValue, web3Context.signer, setWeb3Context])

const onPurchaseClearanceCard = useCallback(async () => {
let signer = null
if (!web3Context.signer) {
// sign in
await web3Modal.clearCachedProvider()
const instance = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(instance)
signer = provider.getSigner()
setWeb3Context({instance, signer})
} else {
signer = web3Context.signer
const signer = await signIn()
try {
const saleContract = new ethers.Contract(
"0x0cB04a31d9c1c6201e7Bb881ECD332241b3d5AFD",
ClearanceCard001.abi,
signer
)
const etherValue = ethers.utils.parseEther("0.15")
const amount = parseInt(clearanceCardMintValue)
const value = etherValue.mul(amount)
await saleContract.mint(amount, {value})
} catch (e) {
console.error(e)
}
const saleContract = new ethers.Contract(
"0x0cB04a31d9c1c6201e7Bb881ECD332241b3d5AFD",
ClearanceCard001.abi,
signer
)
const etherValue = ethers.utils.parseEther("0.15")
const amount = parseInt(clearanceCardMintValue)
const value = etherValue.mul(amount)
await saleContract.mint(amount, {value})
// Do the purchase
}, [clearanceCardMintValue, web3Context.signer, setWeb3Context])

const onPurchaseTopClearanceCard = useCallback(async () => {
let signer = null
if (!web3Context.signer) {
// sign in
await web3Modal.clearCachedProvider()
const instance = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(instance)
signer = provider.getSigner()
setWeb3Context({instance, signer})
} else {
signer = web3Context.signer
const signer = await signIn()
try {
const saleContract = new ethers.Contract(
"0x0cB04a31d9c1c6201e7Bb881ECD332241b3d5AFD",
TopClearanceCard.abi,
signer
)
const etherValue = ethers.utils.parseEther("0.5")
const amount = parseInt(clearanceCardMintValue)
const value = etherValue.mul(amount)
await saleContract.mint(amount, {value})
} catch (e) {
console.error(e)
}
const saleContract = new ethers.Contract(
"0x0cB04a31d9c1c6201e7Bb881ECD332241b3d5AFD",
TopClearanceCard.abi,
signer
)
const etherValue = ethers.utils.parseEther("0.5")
const amount = parseInt(clearanceCardMintValue)
const value = etherValue.mul(amount)
await saleContract.mint(amount, {value})
// Do the purchase
}, [clearanceCardMintValue, web3Context.signer, setWeb3Context])

Expand Down

0 comments on commit 3576b5b

Please sign in to comment.