Skip to content

Commit

Permalink
almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
kafann committed Aug 23, 2023
1 parent 864520e commit c9e7d69
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
23 changes: 23 additions & 0 deletions packages/react-app/src/components/modals/create-quest-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export default function QuestModal({
creatorAddress: walletAddress,
rewardToken: values.bounty!.token,
maxPlayers: values.unlimited ? 0 : values.maxPlayers,
isWhitelist: values.isWhitelist,
},
undefined,
(txHash) => {
Expand Down Expand Up @@ -274,6 +275,28 @@ export default function QuestModal({
if (isMountedRef.current) {
setQuestDataState(emptyQuestData);
}

if (values.isWhitelist && values.players?.length) {
let whitelistTxPayload: TransactionModel = {
modalId,
message: `Setting whitelisted players...`,
status: TransactionStatus.WaitingForSignature,
type: TransactionType.QuestSetWhitelist,
};
setTransaction(whitelistTxPayload);
await QuestService.setWhitelist(
walletAddress,
values.players,
newQuestAddress,
(txHash) => {
whitelistTxPayload = { ...whitelistTxPayload, hash: txHash };
setTransaction({
...whitelistTxPayload,
status: TransactionStatus.Pending,
});
},
);
}
} catch (e: any) {
setTransaction(
(oldTx) =>
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/enums/transaction-type.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum TransactionType {
QuestReclaimFunds = 'QuestReclaimFunds',
QuestPlay = 'QuestPlay',
QuestUnplay = 'QuestUnplay',
QuestSetWhitelist = 'QuestSetWhitelist',
ClaimSchedule = 'ClaimSchedule',
ClaimExecute = 'ClaimExecute',
ClaimVeto = 'ClaimVeto',
Expand Down
13 changes: 12 additions & 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: false,
isWhitelist: questEntity.isWhitelist,
status: QuestStatus.Active,
players: questEntity.questPlayers ?? [],
governAddress: toChecksumAddress(questEntity.questGovernAddress),
Expand Down Expand Up @@ -602,6 +602,7 @@ export async function saveQuest(
questExpireTimeUtcSec,
fallbackAddress,
data.maxPlayers,
data.isWhitelist,
{
// gasLimit: 10000000,
},
Expand All @@ -613,6 +614,16 @@ export async function saveQuest(

// #region Quest

export async function setWhitelist(
walletAddress: string,
players: string[],
questAddress: string,
onTx?: onTxCallback,
) {
const tx = await getQuestContract({ address: questAddress }, walletAddress).setWhiteList(players);
return handleTransaction(tx, onTx);
}

export async function recoverFundsAndDeposit(
walletAddress: string,
quest: QuestModel,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-app/src/utils/contract.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ function getContract(
let askedContract = contracts[contractName];
if (Array.isArray(askedContract) && askedContract.length) {
if (abiIndex) {
// If no contract address override, use the last one
askedContract = askedContract[abiIndex];
askedContract = askedContract[abiIndex ?? askedContract.length - 1];
} else if (contractAddressOverride) {
askedContract = askedContract.find(
(c) => c.address.toLowerCase() === contractAddressOverride.toLowerCase(),
Expand Down

0 comments on commit c9e7d69

Please sign in to comment.