Quest Rewards

Each quest can have many types of rewards, most of them are stream lined and require no action from Frontend, but for some other specific types like prizes, there are some additional actions requird.

Different types of Quest Rewards

  • Give Resources

  • Give Assets

  • Give Prizes

  • Give Discord Roles

Each of the above rewards can be identified and dealt with in FE from the following data types:

// Shared properties of a reward
const baseRewardSchema = z.object({
  rewardConfigurationId: z.string(),
  rewardId: z.string(),
  createdAt: z.string().datetime().optional(),
  updatedAt: z.string().datetime().optional(),
  questId: z.string(),
});

In the Quest object, look for the rewardfield. Depending on the reward defined in the admin panel, we need to use the field slugto identify the type of reward. in the SDK you will find the following zod schemas you can use to validate/identify rewards:

const questEventWithRewardsSchema = z.union([
  giveAssetsRewardSchema,
  manualClaimRewardSchema,
  giveResourceRewardSchema,
  assignDiscordRoleRewardSchema,
  giveResourceProgressiveRewardSchema,
]);

Of course if you don't want to opt-in to zod, you can also use plain typescript to identify these rewards with:

Claiming Rewards

Quest reward allocation is manual and require a user action to claim rewards once their quest is completed. Once the quest is completed, use the following methods to identify rewards allocated to the user to prepare for the claim phase:

In server components

The above function will fetch all reward allocations for the given quest id per user. Remember to populate Authorization headers in the axios config beforehand.

In client components

In the client components use the following hook to receive all rewards allocated to the user. an enabled option is provided to pass in when the quest is completed.

Claiming Rewards

Once you have the reward allocation, you can start claiming the rewards by checking whether or not a reward has a requirement, currently only one reward types might have requirements, but you can streamline this by checking the requirementsfield in the allocation.

If there is no requirement, the claiming process is easy as what follows:

In server components

In client components

NOTE: the payload field is not required when there is no requirement, it is mainly used for passing requirements.

Claiming Prizes

Since prizes are custom rewards, their delivery mechanism is a bit different, some of them are automatically distributed, but some other require admin approval. In addition to that, custom rewards may require some additional information from the user before they can be delivered. For example, a Steam gift card may require email address from the user, or for some other prizes a postal address may be required. This information is defined in the requirements field.

In the following section we will deal with prize requirements and how can we prepare data to send to our API.

Currently following requirements are supported via SDK:

Since currently only Prize rewards contain requirements, we can use a similar approach to determine prize requirements:

Then we can identify required fields based on the type definitions we cover previously, note that this example is using react-hook-form, but you can use any form library you prefer:

Each requirement field has its own structure but follows a similar structure:

Email Requirement

Note: data.email might be empty, but if it has value, it means the user has already populated this information, and it can be re-used as a default value.

Wallet Address Requirement

Note: There are no "validation" on the accepted wallet address format, it should be done in the client.

Address Requirement

Attaching requirements to payload

Once you gather all required information, you can pass these information in the format of Record<string, string | Record<string, string>> as the payloadargument we've discussed above in the claiming rewards section.

Determining prize status

Once the claim is completed, make sure you are hooking to distributionStatusfield in the allocation entity.

Distribution status can be one of the following

Note: Only when the status is QUEST_REWARD_DISTRIBUTION_STATUS.DISTRIBUTEDyou can assume that the reward is delivered, otherwise, the reward is pending in the queue to be delivered.

Last updated