8000 feat: Sale flow adjustments by colbr · Pull Request #500 · zer0-os/zNS-dapp · GitHub
[go: up one dir, main page]

Skip to content
Merged
8000
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: 10 additions & 2 deletions src/containers/flows/MintDropNFT/MintDropNFTWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ const MintDropNFTWizard = (props: MintDropNFTWizardProps) => {
errorMessage={transactionError}
isUserWhitelisted={props.isUserWhitelisted}
isWalletConnected={props.userId !== undefined}
maxPurchasesPerUser={props.maxPurchasesPerUser}
maxPurchasesPerUser={
props.dropStage === Stage.Public
? undefined
: props.maxPurchasesPerUser
}
pricePerNFT={props.pricePerNFT}
numberPurchasedByUser={props.numberPurchasedByUser}
>
Expand Down Expand Up @@ -162,7 +166,11 @@ const MintDropNFTWizard = (props: MintDropNFTWizardProps) => {
balanceEth={props.balanceEth!}
error={transactionError}
pricePerNFT={props.pricePerNFT}
maxPurchasesPerUser={props.maxPurchasesPerUser!}
maxPurchasesPerUser={
props.dropStage === Stage.Public
? undefined
: props.maxPurchasesPerUser!
}
numberPurchasedByUser={props.numberPurchasedByUser!}
>
>
Expand Down
107 changes: 92 additions & 15 deletions src/containers/flows/MintDropNFT/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,69 @@ import { Stage, DropData } from './types';
import { WhitelistSimpleSale, ERC20 } from 'types';
import { Instance, SaleData, SaleStatus } from '@zero-tech/zsale-sdk/lib/types';

const TEST_MODE = false;
const TEST_STATE: SaleStatus = SaleStatus.PublicSale;
const IS_ON_WHITELIST = true;

const TEST: { [status in SaleStatus]: SaleData } = {
[SaleStatus.NotStarted]: {
amountSold: 0,
amountForSale: 50,
salePrice: '0.007',
started: false,
privateSaleDuration: 568,
paused: false,
startBlock: 10488021,
publicSaleStartBlock: 10488589,
advanced: {
amountForSalePrivate: 500,
amountForSalePublic: 50,
},
},
[SaleStatus.PrivateSale]: {
amountSold: 10,
amountForSale: 50,
salePrice: '0.007',
started: true,
privateSaleDuration: 568,
paused: false,
startBlock: 10488021,
publicSaleStartBlock: 10488589,
advanced: {
amountForSalePrivate: 500,
amountForSalePublic: 50,
},
},
[SaleStatus.PublicSale]: {
amountSold: 40,
amountForSale: 50,
salePrice: '0.007',
started: true,
privateSaleDuration: 568,
paused: false,
startBlock: 10488021,
publicSaleStartBlock: 10488589,
advanced: {
amountForSalePrivate: 500,
amountForSalePublic: 50,
},
},
[SaleStatus.Ended]: {
amountSold: 50,
amountForSale: 50,
salePrice: '0.007',
started: true,
privateSaleDuration: 568,
paused: true,
startBlock: 10488021,
publicSaleStartBlock: 10488589,
advanced: {
amountForSalePrivate: 500,
amountForSalePublic: 50,
},
},
};

export const getDropData = (
zSaleInstance: Instance,
): Promise<DropData | undefined> => {
Expand All @@ -27,7 +90,7 @@ export const getDropData = (
dropStage,
wheelsTotal: saleData.amountForSale,
wheelsMinted: saleData.amountSold,
} as DropData);
});
} catch (error) {
console.log(error);
reject(error);
Expand All @@ -38,25 +101,32 @@ export const getDropData = (
const getDropStage = async (
zSaleInstance: Instance,
): Promise<Stage | undefined> => {
const status = await zSaleInstance.getSaleStatus();
if (status === SaleStatus.NotStarted) {
return Stage.Upcoming;
let status, data;

if (TEST_MODE) {
await new Promise((r) => setTimeout(r, 2000));
status = TEST_STATE;
data = TEST[TEST_STATE];
} else {
status = await zSaleInstance.getSaleStatus();
data = await zSaleInstance.getSaleData();
}

const data = await zSaleInstance.getSaleData();

if ((status as unknown) === SaleStatus.NotStarted) {
return Stage.Upcoming;
}
if (data.amountSold === data.amountForSale) {
return Stage.Sold;
}

if (status === SaleStatus.PrivateSale) {
if ((status as unknown) === SaleStatus.PrivateSale) {
return Stage.Whitelist;
}

if (status === SaleStatus.Ended) {
if ((status as unknown) === SaleStatus.Ended) {
return Stage.Ended;
}
if (status === SaleStatus.PublicSale) {
if ((status as unknown) === SaleStatus.PublicSale) {
return Stage.Public;
}
};
Expand All @@ -81,16 +151,24 @@ export const getUserEligibility = async (
account: string,
zSaleInstance: Instance,
): Promise<boolean | undefined> => {
const isWhitelisted = await zSaleInstance.isUserOnMintlist(account);
return isWhitelisted;
if (TEST_MODE) {
return IS_ON_WHITELIST;
} else {
const isWhitelisted = await zSaleInstance.isUserOnMintlist(account);
return isWhitelisted;
}
};

const getWheelQuantities = async (
zSaleInstance: Instance,
): Promise<SaleData | undefined> => {
const data = await zSaleInstance.getSaleData();

return data;
if (TEST_MODE) {
await new Promise((r) => setTimeout(r, 2000));
return TEST[TEST_STATE];
} else {
const data = await zSaleInstance.getSaleData();
return data;
}
};

export const getBalanceEth = async (
Expand All @@ -101,7 +179,6 @@ export const getBalanceEth = async (
return Number(asString);
};

// TODO: Migrate these methods to use SDK once they are available
export const getERC20TokenBalance = async (
token: ERC20,
user: string,
Expand Down
16 changes: 12 additions & 4 deletions src/containers/flows/MintDropNFT/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ import {
import { useZSaleSdk } from 'lib/hooks/sdk';
import useAsyncEffect from 'use-async-effect';

const MintDropNFTFlowContainer = () => {
type MintDropNFTFlowContainerProps = {
privateSaleEndTime?: number;
publicSaleStartTime?: number;
};

const MintDropNFTFlowContainer = ({
privateSaleEndTime,
publicSaleStartTime,
}: MintDropNFTFlowContainerProps) => {
// Hardcoded dates
const currentTime = new Date().getTime();

// Temporary values

const PRIVATE_SALE_END_DATE = currentTime + 10000;
const PUBLIC_SALE_START_TIME = currentTime + 20000;
const PRIVATE_SALE_END_DATE = privateSaleEndTime ?? currentTime + 10000;
const PUBLIC_SALE_START_TIME = publicSaleStartTime ?? currentTime + 20000;

// const PUBLIC_SALE_START_TIME = 1642730400655;

Expand Down Expand Up @@ -430,7 +438,7 @@ const MintDropNFTFlowContainer = () => {
);
}
return failedToLoad
? 'Failed to load auction data - refresh to try again'
? 'Failed to load sale data - refresh to try again'
: getBannerLabel(
dropStage,
wheelsMinted,
Expand Down
25 changes: 18 additions & 7 deletions src/containers/flows/MintDropNFT/steps/Info/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const Info = (props: InfoProps) => {
{mintButton()}
</>
);
} else {
} else if (Boolean(props.maxPurchasesPerUser)) {
return (
<>
<p className={styles.Green}>
Expand All @@ -133,6 +133,17 @@ const Info = (props: InfoProps) => {
{dismissButton()}
</>
);
} else {
return (
<>
<p>
You have minted {props.numberPurchasedByUser} Beasts. The cost for
each Beast is <b>{props.pricePerNFT} ETH</b> plus GAS.
</p>

{mintButton()}
</>
);
}
} else {
return (
Expand Down Expand Up @@ -162,27 +173,27 @@ const Info = (props: InfoProps) => {
playsInline
controls
disablePictureInPicture
controlsList="nodownload noremoteplayback noplaybackrate"
controlsList="nodownload noremoteplayback noplaybackrate nofullscreen"
poster={
'https://res.cloudinary.com/fact0ry/video/upload/so_0/c_fit,h_396,w_642/v1649690004/zns/beasts-mint-main.jpg'
10000 'https://res.cloudinary.com/fact0ry/video/upload/so_0/c_fit,h_426,w_672/v1649690004/zns/beasts-mint-main.jpg'
}
preload="metadata"
>
<source
src={
'https://res.cloudinary.com/fact0ry/video/upload/q_60,c_fit,h_396,w_642/v1649690004/zns/beasts-mint-main.webm'
'https://res.cloudinary.com/fact0ry/video/upload/q_100,c_fit,h_426,w_672/v1649690004/zns/beasts-mint-main.webm'
}
type="video/webm"
></source>
<source
src={
'https://res.cloudinary.com/fact0ry/video/upload/q_60,c_fit,h_396,w_642/v1649690004/zns/beasts-mint-main.mp4'
'https://res.cloudinary.com/fact0ry/video/upload/q_100,c_fit,h_426,w_672/v1649690004/zns/beasts-mint-main.mp4'
}
type="video/mp4"
></source>
<source
src={
'https://res.cloudinary.com/fact0ry/video/upload/q_60,c_fit,h_396,w_642/v1649690004/zns/beasts-mint-main.ogv'
'https://res.cloudinary.com/fact0ry/video/upload/q_100,c_fit,h_426,w_672/v1649690004/zns/beasts-mint-main.ogv'
}
type="video/ogg"
></source>
Expand All @@ -194,7 +205,7 @@ const Info = (props: InfoProps) => {
<span>Beasts Available</span>
<h2>{props.wheelsTotal - props.wheelsMinted} Beasts Remaining</h2>
<ArrowLink href="https://zine.wilderworld.com/wolfpack-genesis-drop/">
View Auction Rules
View Sale Details
</ArrowLink>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styles from './SelectAmount.module.scss';
type SelectAmountProps = {
balanceEth: number;
error?: string;
maxPurchasesPerUser: number;
maxPurchasesPerUser?: number;
numberPurchasedByUser: number;
onBack: () => void;
onContinue: (numWheels: number) => void;
Expand All @@ -26,7 +26,9 @@ const SelectAmount = (props: SelectAmountProps) => {
//////////////////

const remainingUserWheels =
props.maxPurchasesPerUser - props.numberPurchasedByUser;
props.maxPurchasesPerUser !== undefined
? props.maxPurchasesPerUser - props.numberPurchasedByUser
: props.remainingWheels;
const maxUserCanAfford = Math.floor(props.balanceEth / props.pricePerNFT);

const maxWheelsRemaining = Math.min(
Expand Down Expand Up @@ -73,13 +75,20 @@ const SelectAmount = (props: SelectAmountProps) => {
return;
}
const numWheels = Number(amount);
if (numWheels <= 0 || numWheels > props.maxPurchasesPerUser) {
if (
numWheels <= 0 ||
(Boolean(props.maxPurchasesPerUser) &&
numWheels > props.maxPurchasesPerUser!)
) {
setInputError(
`Please enter a number between 1 & ${props.maxPurchasesPerUser}`,
);
} else if (numWheels * props.pricePerNFT > props.balanceEth) {
setInputError(`You do not have enough ETH to mint ${numWheels} Beasts`);
} else if (numWheels > remainingUserWheels) {
} else if (
numWheels > remainingUserWheels &&
Boolean(props.maxPurchasesPerUser)
) {
setInputError(
`You have already minted ${props.numberPurchasedByUser}/${props.maxPurchasesPerUser} of the maximum allowed Beasts. Please choose a lower number`,
);
Expand Down Expand Up @@ -123,7 +132,8 @@ const SelectAmount = (props: SelectAmountProps) => {

return (
<section>
{props.numberPurchasedByUser < props.maxPurchasesPerUser && (
{(!props.maxPurchasesPerUser ||
props.numberPurchasedByUser < props.maxPurchasesPerUser) && (
<form >
<p>
How many Beasts would you like to Mint? The number you enter will be
Expand All @@ -132,7 +142,11 @@ const SelectAmount = (props: SelectAmountProps) => {
</p>
<TextInput
>
placeholder={`Number of Beasts (Maximum of ${props.maxPurchasesPerUser})`}
placeholder={`Number of Beasts${
Boolean(props.maxPurchasesPerUser)
? `(Maximum of ${props.maxPurchasesPerUser})`
: ''
}`}
numeric
text={amount}
/>
Expand Down Expand Up @@ -177,12 +191,13 @@ const SelectAmount = (props: SelectAmountProps) => {
</FutureButton>
</form>
)}
{props.numberPurchasedByUser >= props.maxPurchasesPerUser && (
<p className={styles.Green} style={{ textAlign: 'center' }}>
You have already minted {props.numberPurchasedByUser}/
{props.maxPurchasesPerUser} Beasts
</p>
)}
{props.maxPurchasesPerUser !== undefined &&
props.numberPurchasedByUser >= props.maxPurchasesPerUser && (
<p className={styles.Green} style={{ textAlign: 'center' }}>
You have already minted {props.numberPurchasedByUser}/
{props.maxPurchasesPerUser} Beasts
</p>
)}
</section>
);
};
Expand Down
0