Skip to content

Commit

Permalink
Merge branch 'whitelist_players' of https://github.com/1Hive/quests i…
Browse files Browse the repository at this point in the history
…nto whitelist_players
  • Loading branch information
kafann committed Aug 23, 2023
2 parents e793d11 + 880b68e commit 839e16b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 26 deletions.
26 changes: 16 additions & 10 deletions packages/react-app/src/components/address-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { noop } from 'lodash-es';
import { QuestModel } from 'src/models/quest.model';
import React, { BaseSyntheticEvent } from 'react';
import { AddressFieldInput } from './field-input/address-field-input';
import { FieldInput } from './field-input/field-input';

const PlayerWrapperStyled = styled.div`
const AddressListWrapperStyled = styled.div`
width: 100%;
display: flex;
flex-direction: row;
align-items: flex-end;
Expand Down Expand Up @@ -49,7 +51,6 @@ export default function AddressListFieldInput({
formikValues,
setValuesFormik,
}: Props) {
// const [addressList, setAddressList] = useState<string[]>(values);
const addPlayerToWhitelist = () => {
values!.push('');
setValuesFormik?.(formikValues);
Expand All @@ -60,25 +61,30 @@ export default function AddressListFieldInput({
};

return (
<>
<FieldInput
id="players"
label="Players"
error={touched && error}
direction="column"
align="flex-start"
wide
>
{formikValues ? (
<>
{values.map((player, i) => (
<PlayerWrapperStyled>
<AddressListWrapperStyled>
<AddressFieldInput
id={`${id}[${i}]`}
label={`${label} #${i + 1}`}
isEdit={isEdit}
value={player}
onChange={onChange}
onBlur={onBlur}
wide
error={touched && error && touched[i] && error[i]}
/>
{isEdit && (
<Button icon={<IconCross />} onClick={() => removePlayerFromWhitelist(i)} />
)}
</PlayerWrapperStyled>
</AddressListWrapperStyled>
))}

{isEdit && (
Expand All @@ -90,7 +96,7 @@ export default function AddressListFieldInput({
) : (
<>
{values.map((player, i) => (
<PlayerWrapperStyled>
<AddressListWrapperStyled>
<AddressFieldInput
id={`${id}[${i}]`}
label={`${label} #${i + 1}`}
Expand All @@ -102,7 +108,7 @@ export default function AddressListFieldInput({
{isEdit && (
<Button icon={<IconCross />} onClick={() => removePlayerFromWhitelist(i)} />
)}
</PlayerWrapperStyled>
</AddressListWrapperStyled>
))}

{isEdit && (
Expand All @@ -112,6 +118,6 @@ export default function AddressListFieldInput({
)}
</>
)}
</>
</FieldInput>
);
}
20 changes: 19 additions & 1 deletion packages/react-app/src/components/modals/create-quest-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ export default function QuestModal({

if (data.expireTime.getTime() < Date.now())
errors.expireTime = 'Expiration have to be later than now';

if (data.isWhitelist && data.players?.length) {
data.players.forEach((player) => {
try {
toChecksumAddress(player);
} catch (error) {
errors.players = 'One of the player address is not valid';
}
});
}

debounceSave(data);

setIsFormValid(Object.keys(errors).length === 0);
Expand Down Expand Up @@ -282,7 +293,7 @@ export default function QuestModal({
if (values.isWhitelist && values.players?.length) {
let whitelistTxPayload: TransactionModel = {
modalId,
message: `Setting whitelisted players...`,
message: `Setting quest players (${totalTransactionSteps}/${totalTransactionSteps})`,
status: TransactionStatus.WaitingForSignature,
type: TransactionType.QuestSetWhitelist,
};
Expand All @@ -299,6 +310,13 @@ export default function QuestModal({
});
},
);
setTransaction({
...txPayload,
status: txReceiptSaveQuest?.status
? TransactionStatus.Confirmed
: TransactionStatus.Failed,
args: { questAddress: newQuestAddress, players: values.players },
});
}
} catch (e: any) {
setTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default function PlayerListModal({
status: TransactionStatus.Pending,
});
});
onSubmit();
}
};

Expand All @@ -122,7 +123,11 @@ export default function PlayerListModal({
<OpenButtonStyled
onClick={() => setOpened(true)}
icon={<IconGroup />}
label="View Player List"
label={
walletAddress === questData.creatorAddress && questData.isWhitelist
? 'Edit Player List'
: 'View Player List'
}
mode="strong"
title="Player List"
/>
Expand Down
14 changes: 1 addition & 13 deletions packages/react-app/src/components/quest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ const PlayersWrapperStyled = styled.div`
align-items: center;
`;

const PlayersModalWrapperStyled = styled.div`
/* margin-left: ${GUpx(3)}; */
`;

const QuestFooterStyled = styled.div`
width: 100%;
text-align: right;
Expand Down Expand Up @@ -255,7 +251,7 @@ export default function Quest({
if (!depositReleased && questData.createDeposit) {
depositLocked.push(questData.createDeposit);
}
if (players.length && questData.playDeposit) {
if (players.length && questData.playDeposit && !questData.isWhitelist) {
// Multiply by the number of players (each one has a deposit locked)
questData.playDeposit.amount = questData.playDeposit.amount.mul(players.length);
depositLocked.push(questData.playDeposit);
Expand Down Expand Up @@ -363,14 +359,6 @@ export default function Quest({
isLoading={isLoading || !questData}
value={`${players.length} / ${questData.unlimited ? '∞' : questData.maxPlayers}`}
/>
{/* {players.length > 0 && !isSummary && (
<PlayersModalWrapperStyled>
<PlayerListModal
playerList={players}
isEdit={walletAddress === questData.creatorAddress}
/>
</PlayersModalWrapperStyled>
)} */}
</PlayersWrapperStyled>
)}
<DateFieldInput
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/models/transaction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type TransactionModel = {
containerId?: string;
disputeState?: number;
player?: string;
players?: string;
};
type: TransactionType;
};
1 change: 1 addition & 0 deletions packages/react-app/src/queries/quests.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const QuestEntityQuery = gql`
questFundsRecoveryAddress
questMaxPlayers
questPlayers
questIsWhiteListed
}
}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/services/quest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function mapQuest(questEntity: any, claimCountMap: Map<string, number>) {
activeClaimCount: claimCountMap.get(questAddress) ?? 0,
maxPlayers: questEntity.questMaxPlayers ? +questEntity.questMaxPlayers : undefined, // If null put undefined
unlimited: questEntity.questMaxPlayers ? +questEntity.questMaxPlayers === 0 : undefined,
isWhitelist: questEntity.isWhitelist,
isWhitelist: questEntity.questIsWhiteListed,
status: QuestStatus.Active,
players: questEntity.questPlayers ?? [],
governAddress: toChecksumAddress(questEntity.questGovernAddress),
Expand Down

0 comments on commit 839e16b

Please sign in to comment.