From c9e7d69f436fa99aa7ba1a785bc70342e2c815c4 Mon Sep 17 00:00:00 2001 From: kafann <75225303+kafann@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:16:31 -0400 Subject: [PATCH] almost there --- .../components/modals/create-quest-modal.tsx | 23 +++++++++++++++++++ .../src/enums/transaction-type.enum.ts | 1 + .../react-app/src/services/quest.service.ts | 13 ++++++++++- packages/react-app/src/utils/contract.util.ts | 3 +-- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/react-app/src/components/modals/create-quest-modal.tsx b/packages/react-app/src/components/modals/create-quest-modal.tsx index f2e559a3..b8428ff7 100644 --- a/packages/react-app/src/components/modals/create-quest-modal.tsx +++ b/packages/react-app/src/components/modals/create-quest-modal.tsx @@ -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) => { @@ -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) => diff --git a/packages/react-app/src/enums/transaction-type.enum.ts b/packages/react-app/src/enums/transaction-type.enum.ts index 532ae856..1d144e62 100644 --- a/packages/react-app/src/enums/transaction-type.enum.ts +++ b/packages/react-app/src/enums/transaction-type.enum.ts @@ -6,6 +6,7 @@ export enum TransactionType { QuestReclaimFunds = 'QuestReclaimFunds', QuestPlay = 'QuestPlay', QuestUnplay = 'QuestUnplay', + QuestSetWhitelist = 'QuestSetWhitelist', ClaimSchedule = 'ClaimSchedule', ClaimExecute = 'ClaimExecute', ClaimVeto = 'ClaimVeto', diff --git a/packages/react-app/src/services/quest.service.ts b/packages/react-app/src/services/quest.service.ts index 9951b90d..923b250a 100644 --- a/packages/react-app/src/services/quest.service.ts +++ b/packages/react-app/src/services/quest.service.ts @@ -96,7 +96,7 @@ async function mapQuest(questEntity: any, claimCountMap: Map) { 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), @@ -602,6 +602,7 @@ export async function saveQuest( questExpireTimeUtcSec, fallbackAddress, data.maxPlayers, + data.isWhitelist, { // gasLimit: 10000000, }, @@ -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, diff --git a/packages/react-app/src/utils/contract.util.ts b/packages/react-app/src/utils/contract.util.ts index d819599b..be029386 100644 --- a/packages/react-app/src/utils/contract.util.ts +++ b/packages/react-app/src/utils/contract.util.ts @@ -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(),