Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
kafann committed Aug 23, 2023
1 parent 9587e7c commit 737e2d0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
47 changes: 42 additions & 5 deletions packages/react-app/src/components/modals/player-list-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { useMemo, useState } from 'react';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
import { setWhitelist } from 'src/services/quest.service';
import { TransactionStatus } from 'src/enums/transaction-status.enum';
import { TransactionType } from 'src/enums/transaction-type.enum';
import { TransactionModel } from 'src/models/transaction.model';
import { QuestModel } from 'src/models/quest.model';
import { useTransactionContext } from 'src/contexts/transaction.context';
import { useWallet } from 'src/contexts/wallet.context';
import { AddressFieldInput } from '../field-input/address-field-input';
import { Outset } from '../utils/spacer-util';
import ModalBase, { ModalCallback } from './modal-base';
Expand Down Expand Up @@ -46,15 +52,23 @@ const AddWrapperStyled = styled.div`
// #endregion

type Props = {
playerList: string[] | undefined;
questData: QuestModel;
isEdit: boolean;
onClose?: ModalCallback;
onSubmit?: Function;
};

export default function PlayerListModal({ playerList, isEdit, onClose = noop }: Props) {
export default function PlayerListModal({
questData,
isEdit,
onClose = noop,
onSubmit = noop,
}: Props) {
const [opened, setOpened] = useState(false);
const [players, setPlayers] = useState<string[]>(playerList ?? ['']);
const [players, setPlayers] = useState<string[]>(questData.players ?? ['']);
const modalId = useMemo(() => uniqueId('whitelist-modal'), []);
const { setTransaction } = useTransactionContext();
const { walletAddress } = useWallet();

const onModalClosed = (success: boolean) => {
setOpened(false);
Expand All @@ -79,7 +93,25 @@ export default function PlayerListModal({ playerList, isEdit, onClose = noop }:
setPlayers(newList);
};

const onWhitelistSubmit = () => {};
const onWhitelistSubmit = async () => {
if (players.length) {
let whitelistTxPayload: TransactionModel = {
modalId,
message: `Setting whitelisted players...`,
status: TransactionStatus.WaitingForSignature,
type: TransactionType.QuestSetWhitelist,
};
setTransaction(whitelistTxPayload);
await setWhitelist(walletAddress, players, questData.address!, (txHash) => {
whitelistTxPayload = { ...whitelistTxPayload, hash: txHash };
setTransaction({
...whitelistTxPayload,
status: TransactionStatus.Pending,
});
});
}
};

return (
<>
<ModalBase
Expand Down Expand Up @@ -120,7 +152,12 @@ export default function PlayerListModal({ playerList, isEdit, onClose = noop }:
{isEdit && (
<AddWrapperStyled>
<Button icon={<IconPlus />} label="Add" onClick={() => addPlayerToWhitelist()} />
<Button icon={<IconCheck />} onClick={() => onWhitelistSubmit()} />
<Button
icon={<IconPlus />}
label="Confirm list"
mode="strong"
onClick={() => onWhitelistSubmit()}
/>
</AddWrapperStyled>
)}
</Outset>
Expand Down
10 changes: 5 additions & 5 deletions packages/react-app/src/components/quest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,23 @@ export default function Quest({
walletAddress === questData.creatorAddress) && (
// <PlayersModalWrapperStyled>
<PlayerListModal
playerList={players}
questData={questData}
isEdit={walletAddress === questData.creatorAddress}
/>
)}
{/* </PlayersModalWrapperStyled> */}
<FundModal quest={questData} />
{(!isPlayingQuest ||
questData.creatorAddress === walletAddress ||
{(((!isPlayingQuest || questData.creatorAddress === walletAddress) &&
questData.isWhitelist) ||
(waitForClose && transaction?.type === TransactionType.QuestPlay)) &&
questData.features?.playableQuest && (
<PlayModal
questData={{ ...questData, players }}
onClose={() => setWaitForClose(false)}
/>
)}
{(isPlayingQuest ||
questData.creatorAddress === walletAddress ||
{(((isPlayingQuest || questData.creatorAddress === walletAddress) &&
questData.isWhitelist) ||
(waitForClose && transaction?.type === TransactionType.QuestUnplay)) &&
questData.features.playableQuest &&
questData.players?.length !== 0 && (
Expand Down

0 comments on commit 737e2d0

Please sign in to comment.