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

feat burn by user #509

Open
wants to merge 29 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e4eb2f8
feat: added the isNonTransferable variable and some functions
yawn-c111 Oct 17, 2023
5302768
feat: restricted transferFrom() and added setEventIdOfTokenIds()
yawn-c111 Oct 27, 2023
8d39eaa
fix: changed transferFrom() to _transfer()
yawn-c111 Oct 28, 2023
515293b
fix: arguments of setEventIdOfTokenIds()
yawn-c111 Oct 28, 2023
b8d29ce
feat: added eventIdOfTokenId into mintParticipateNFT()
yawn-c111 Oct 28, 2023
6a9e3b6
feat: changed _safeMint location
yawn-c111 Oct 28, 2023
8c49bd7
feat: added getEventIdOfTokenId() and tests
yawn-c111 Oct 28, 2023
f75ce79
feat: added setEventIdOfTokenIdsBatch() to MintNFT.sol
yawn-c111 Oct 28, 2023
c0b7621
refactor: functions related to eventIdOfTokenId
yawn-c111 Oct 28, 2023
52a2a0c
feat: added getTOkenIdsByEvent() to MintNFT.sol
yawn-c111 Oct 28, 2023
908e9c0
added: script of setEventIdOfTokenIdsBatch
yawn-c111 Oct 28, 2023
94e8610
Burn by user
takerunakao Nov 7, 2023
b848683
refactor: Removed unnecessary if statements
yawn-c111 Nov 10, 2023
1ade1c5
Burn by user
takerunakao Nov 18, 2023
3d37d04
update: create event form for Non transferable option
yawn-c111 Dec 6, 2023
2b87b0c
add: EventTransferLock component to
yawn-c111 Dec 7, 2023
0f89259
Add: non-transferable flag to createEventRecord tests
yawn-c111 Dec 7, 2023
77c122c
fix: variable name of non-transferable flag
yawn-c111 Dec 7, 2023
f9ce5c1
fix frontend and smartcontract
yu23ki14 Dec 16, 2023
2ef2795
update burn-by-user
takerunakao Dec 21, 2023
7a6b8f1
tmp for deployment
yu23ki14 Dec 27, 2023
162177d
modify initializer
yu23ki14 Jan 2, 2024
e170da5
Merge pull request #464 from hackdays-io/feature/tranferable
yu23ki14 Jan 2, 2024
a160eb8
fix: test for _owner arg in initialize()
yawn-c111 Jan 21, 2024
6546f59
Merge branch 'staging' into feature/burn-by-user
yawn-c111 Jan 21, 2024
c342f9a
fix: proofCalldata in MintNFT.ts
yawn-c111 Jan 21, 2024
1a2883a
Merge pull request #508 from hackdays-io/fix/test
yu23ki14 Jan 22, 2024
80573e3
Merge branch 'staging' into feature/burn-by-user
yawn-c111 Jan 22, 2024
4eec063
update: event and function name and tests
yawn-c111 Jan 22, 2024
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
3 changes: 3 additions & 0 deletions frontend/.sentryclirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

[auth]
token=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
102 changes: 102 additions & 0 deletions frontend/src/components/molecules/EventTransferLock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Box, Button, Flex, Grid, Spinner, Text } from "@chakra-ui/react";
import { BigNumber } from "ethers";
import { FC, useEffect } from "react";
import { useIsNonTransferable, useTransferLock } from "src/hooks/useMintNFT";
import AlertMessage from "../atoms/form/AlertMessage";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faLock, faLockOpen } from "@fortawesome/free-solid-svg-icons";
import { useLocale } from "src/hooks/useLocale";

type Props = {
eventId: BigNumber;
};

const EventTransferLock: FC<Props> = ({ eventId }) => {
const { t } = useLocale();
const { isNonTransferable, refetch, isLoading } =
useIsNonTransferable(eventId);

const {
lock,
isLoading: isLocking,
error,
isSuccess,
status,
} = useTransferLock(eventId, !isNonTransferable);

useEffect(() => {
refetch();
}, [status]);

return (
<>
<Text fontWeight="bold">{t.EVENT_TRANSFERLOCK_SETTING}</Text>
<Text color="grey.600" fontSize="sm" mb={3}>
{t.EVENT_TRANSFERLOCK_SETTING_DESC}
</Text>
{isLoading ? (
<Spinner />
) : (
<Box>
<Flex alignItems="center">
<Flex
borderRadius="full"
backgroundColor="white"
p={2}
alignItems="center"
>
<Box
as="span"
color={isNonTransferable ? "mintGreen.800" : "yellow.800"}
background={isNonTransferable ? "gray.300" : "yellow.300"}
width="40px"
height="40px"
borderRadius="full"
display="inline-flex"
justifyContent="center"
alignItems="center"
mr={2}
>
<FontAwesomeIcon
icon={isNonTransferable ? faLock : faLockOpen}
/>
</Box>
<Box>
<Text fontSize="sm" color="yellow.800">
{isNonTransferable
? t.EVENT_ISNONTRANSFERABLE_TRUE
: t.EVENT_ISNONTRANSFERABLE_FALSE}
</Text>
<Text fontSize="xs" color="gray.600">
{isNonTransferable
? t.EVENT_ISNONTRANSFERABLE_TRUE_DESC
: t.EVENT_ISNONTRANSFERABLE_FALSE_DESC}
</Text>
</Box>
</Flex>
<Button
ml={3}
size="sm"
disabled={isLocking}
isLoading={isLocking}
onClick={() => lock()}
backgroundColor="transparent"
border="1px solid"
borderColor="yellow.800"
color="yellow.800"
>
{t.EVENT_ADMIN_SUBMIT}
</Button>
</Flex>
</Box>
)}
{error && (
<AlertMessage title={t.EVENT_TRANSFERLOCK_FAIL}>
{(error as any).reason}
</AlertMessage>
)}
</>
);
};

export default EventTransferLock;
40 changes: 37 additions & 3 deletions frontend/src/components/organisms/CreateEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface EventFormData {
secretPhrase: string;
mintLimit: number;
useMtx: "true" | "false";
nonTransferable: "true" | "false";
nfts: NFT.NFTImage[];
}

Expand Down Expand Up @@ -89,7 +90,8 @@ const CreateEventForm: FC<Props> = ({ address }) => {
endTime: "",
secretPhrase: "",
mintLimit: 10,
useMtx: undefined,
useMtx: "false",
nonTransferable: "false",
nfts: [
{
name: "",
Expand Down Expand Up @@ -138,6 +140,7 @@ const CreateEventForm: FC<Props> = ({ address }) => {
secretPhrase: formData.secretPhrase,
mintLimit: Number(formData.mintLimit),
useMtx: formData.useMtx === "true",
nonTransferable: formData.nonTransferable === "true",
attributes: nftAttributes,
};
await createEvent(params);
Expand Down Expand Up @@ -191,7 +194,6 @@ const CreateEventForm: FC<Props> = ({ address }) => {
);
if (foundEvent && copiedPastEventId) {
const pastAttributeRecords = await copyPastAttribute(copiedPastEventId);
console.log(pastAttributeRecords);

setValue("eventName", foundEvent.name);
setValue("description", foundEvent.description);
Expand Down Expand Up @@ -557,7 +559,7 @@ const CreateEventForm: FC<Props> = ({ address }) => {
formState: { errors },
}) => (
<>
<RadioGroup onChange={onChange}>
<RadioGroup onChange={onChange} value={value}>
<Radio value="false" mr={6}>
{t.EVENT_USE_MTX_FALSE}
</Radio>
Expand All @@ -579,6 +581,38 @@ const CreateEventForm: FC<Props> = ({ address }) => {
)}
</FormControl>

<FormControl mb={5}>
<FormLabel mb={0}>{t.EVENT_USE_NTT}</FormLabel>

<Text fontSize="sm" mb={3} color="gray.600">
{t.EVENT_USE_NTT_DESC}
</Text>

<Controller
control={control}
name="nonTransferable"
rules={{
required: "required",
}}
render={({
field: { onChange, value },
formState: { errors },
}) => (
<>
<RadioGroup onChange={onChange} value={value}>
<Radio value="false" mr={6}>
{t.EVENT_USE_NTT_FALSE}
</Radio>
<Radio value="true">{t.EVENT_USE_NTT_TRUE}</Radio>
</RadioGroup>
<ErrorMessage>
{errors.nonTransferable?.message}
</ErrorMessage>
</>
)}
/>
</FormControl>

<FormControl mb={5}>
<FormLabel htmlFor="secret">
{t.EVENT_SECRETPHRASE}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/organisms/EventEditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FC, useMemo } from "react";
import { useCollaboratorAccessEventGroups } from "src/hooks/useEvent";
import { Event } from "types/Event";
import EventMintLock from "../molecules/EventMintLock";
import EventTransferLock from "../molecules/EventTransferLock";
import ResetSecretPhrase from "../molecules/ResetSecretPhrase";
import { useLocale } from "src/hooks/useLocale";
import DropNFTs from "./nft/DropNFTs";
Expand Down Expand Up @@ -44,6 +45,10 @@ const EventEditSection: FC<Props> = ({ event }) => {

<Divider my={3} />

<EventTransferLock eventId={event.eventRecordId} />

<Divider my={3} />

<ResetSecretPhrase eventId={event.eventRecordId} />

<Divider my={3} />
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/contracts/EventManager.json

Large diffs are not rendered by default.

134 changes: 132 additions & 2 deletions frontend/src/contracts/MintNFT.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/src/hooks/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ export const useCreateEvent = (address: string) => {
).toISOString();
await mutateAsync({
args: [
params.groupId,
Number(params.groupId),
params.eventName,
params.description,
`${startDateTime}/${endDateTime}`,
params.mintLimit,
params.useMtx,
params.nonTransferable,
proof?.publicInputCalldata[0],
params.attributes,
],
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/hooks/useMintNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ export const useIsMintLocked = (eventId: number | BigNumber) => {
return { isMintLocked: data, isLoading, refetch };
};

export const useIsNonTransferable = (eventId: number | BigNumber) => {
const { mintNFTContract } = useMintNFTContract();
const { data, isLoading, refetch } = useContractRead(
mintNFTContract,
"getIsNonTransferable",
[eventId]
);

return { isNonTransferable: data, isLoading, refetch };
};

export const useMintLock = (eventId: number | BigNumber, locked: boolean) => {
const { mintNFTContract } = useMintNFTContract();
const { mutateAsync, isLoading, error, status } = useContractWrite(
Expand Down Expand Up @@ -508,6 +519,47 @@ export const useMintLock = (eventId: number | BigNumber, locked: boolean) => {
return { lock, isLoading, error, status, isSuccess };
};

export const useTransferLock = (
eventId: number | BigNumber,
locked: boolean
) => {
const { mintNFTContract } = useMintNFTContract();
const { mutateAsync, isLoading, error, status } = useContractWrite(
mintNFTContract,
"changeNonTransferable"
);

const fromBlock = useCurrentBlock();
const { data } = useContractEvents(mintNFTContract, "NonTransferable", {
queryFilter: {
filters: {
eventId: eventId,
fromBlock,
},
},
subscribe: true,
});

const lock = useCallback(async () => {
try {
await mutateAsync({ args: [eventId, locked] });
} catch (_) {}
}, [eventId, locked, mutateAsync]);

const isSuccess = useMemo(() => {
const includesEvent = (data: ContractEvent<Record<string, any>>[]) => {
if (!fromBlock) return false;
return data.some((event) => {
return event.transaction.blockNumber > fromBlock;
});
};
if (status !== "success" || !data || !includesEvent(data)) return false;
return true;
}, [data, status, eventId, locked]);

return { lock, isLoading, error, status, isSuccess };
};

export const useResetSecretPhrase = (eventId: number | BigNumber) => {
const { mintNFTContract } = useMintNFTContract();
const {
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export default {
EVENT_USE_MTX: "Taking on gas fee for participants",
EVENT_USE_MTX_TRUE: "Yes",
EVENT_USE_MTX_FALSE: "No",
EVENT_USE_NTT: "Transfer setting for NFTs",
EVENT_USE_NTT_DESC:
"If you set it to non-transferable, the person who receives the NFT in this event will not be able to transfer it to others. This setting can be changed later.",
EVENT_USE_NTT_TRUE: "Non-transferable",
EVENT_USE_NTT_FALSE: "Transferable",
EVENT_ESTIMATED_GAS_MTX: "Estimated deposit amount required to take on",
EVENT_SECRETPHRASE: "SecretPhrase to mint",
EVENT_SECRETPHRASE_DESC:
Expand Down Expand Up @@ -134,12 +139,20 @@ export default {
EVENT_ADMIN_MENU: "Admin Menu",
EVENT_MINTLOCK_SETTING: "MintLock Setting",
EVENT_MINTLOCK_SETTING_DESC:
"While locked, participants will not be able to Mint (receive proof of participation) for NFT.",
EVENT_ISLOCKED_TRUE: "Locked",
EVENT_ISLOCKED_FALSE: "Unlocked",
"While mint locked, participants will not be able to Mint (receive proof of participation) for NFT.",
EVENT_ISLOCKED_TRUE: "MintLocked",
EVENT_ISLOCKED_FALSE: "MintUnlocked",
EVENT_ISLOCKED_TRUE_DESC: "NFT cannot be Minted.",
EVENT_ISLOCKED_FALSE_DESC: "NFT can be Minted.",
EVENT_MINTLOCK_FAIL: "Failed to change MintLock.",
EVENT_TRANSFERLOCK_SETTING: "TransferLock Setting",
EVENT_TRANSFERLOCK_SETTING_DESC:
"While transfer locked, participants will not be able to Transfer (send proof of participation) to others.",
EVENT_ISNONTRANSFERABLE_TRUE: "Non-Transferable",
EVENT_ISNONTRANSFERABLE_FALSE: "Transferable",
EVENT_ISNONTRANSFERABLE_TRUE_DESC: "NFT cannot be Transfer",
EVENT_ISNONTRANSFERABLE_FALSE_DESC: "NFT can be Transfer",
EVENT_TRANSFERLOCK_FAIL: "Failed to change TransferLock.",
EVENT_ADMIN_SUBMIT: "Confirm",
SECRET_PHRASE_RESET: "Reset Secret Phrase",
SECRET_PHRASE_RESET_NEW: "New secret phrase",
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export default {
"ガス代を肩代わりして、参加者が無料でNFTを受け取れるようにする。",
EVENT_USE_MTX_TRUE: "肩代わりする",
EVENT_USE_MTX_FALSE: "肩代わりしない",
EVENT_USE_NTT: "NFTの譲渡設定",
EVENT_USE_NTT_DESC:
"譲渡不可にすると、このイベントで配布されるNFTは他の人に譲渡することができなくなります。この設定は後から変更できます。",
EVENT_USE_NTT_TRUE: "譲渡不可",
EVENT_USE_NTT_FALSE: "譲渡可",
EVENT_ESTIMATED_GAS_MTX: "肩代わりに必要な予想デポジット金額",
EVENT_SECRETPHRASE: "NFT受け取りのひみつの「あいことば」",
EVENT_SECRETPHRASE_DESC:
Expand Down Expand Up @@ -135,12 +140,20 @@ export default {
EVENT_ADMIN_MENU: "管理者メニュー",
EVENT_MINTLOCK_SETTING: "Mintロック設定",
EVENT_MINTLOCK_SETTING_DESC:
"ロック中は、NFTのMint(参加証明の受け取り)ができなくなります。",
EVENT_ISLOCKED_TRUE: "ロック中",
EVENT_ISLOCKED_FALSE: "ロックされていません",
"Mintロック中は、NFTのMint(参加証明の受け取り)ができなくなります。",
EVENT_ISLOCKED_TRUE: "Mintロック中",
EVENT_ISLOCKED_FALSE: "Mintロックされていません",
EVENT_ISLOCKED_TRUE_DESC: "NFTの配布をストップしています。",
EVENT_ISLOCKED_FALSE_DESC: "NFTをMintすることが可能です。",
EVENT_MINTLOCK_FAIL: "MintLock中にエラーが発生しました",
EVENT_TRANSFERLOCK_SETTING: "Transferロック設定",
EVENT_TRANSFERLOCK_SETTING_DESC:
"Transferロック中は、NFTのTransfer(参加証明の他者への送信)ができなくなります。",
EVENT_ISNONTRANSFERABLE_TRUE: "Transferロック中",
EVENT_ISNONTRANSFERABLE_FALSE: "Transferはロックされていません",
EVENT_ISNONTRANSFERABLE_TRUE_DESC: "NFTのTransferを制限しています。",
EVENT_ISNONTRANSFERABLE_FALSE_DESC: "NFTをTransferすることが可能です。",
EVENT_TRANSFERLOCK_FAIL: "TransferLock中にエラーが発生しました",
SECRET_PHRASE_RESET: "あいことばのリセット",
SECRET_PHRASE_RESET_NEW: "新しいあいことば",
SECRET_PHRASE_RESET_NEW_PLACEHOLDER: "新しいあいことばを入力",
Expand Down
1 change: 1 addition & 0 deletions frontend/types/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export namespace Event {
secretPhrase: string;
mintLimit: number;
useMtx: boolean;
nonTransferable: boolean;
attributes: { metaDataURL: string; requiredParticipateCount: number }[];
}

Expand Down
Loading