Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes significant changes to the
CouponService
andFaucetForm
components, as well as adjustments to theReCaptcha
class and configuration files, to implement a coupon system for the application. The coupon system will allow users to enter a coupon ID to receive specific amounts of tokens. The system also includes regular synchronization of coupons between memory and the database, and the ability to validate, consume, and reclaim coupon amounts.Key changes:
Coupon Service Implementation:
CouponService/couponService.ts
: Created a newCouponService
class to manage coupons. The class includes methods to validate coupon data, sync coupons with the database, update coupon usage limits, consume coupon amounts, and reclaim coupon amounts. The service uses theDynamoDBClient
andDynamoDBDocumentClient
from the AWS SDK for interactions with the DynamoDB database. Mutexes are used to prevent race conditions when consuming and reclaiming coupon amounts.FaucetForm Component Modifications:
client/src/components/FaucetForm.tsx
: Modified theFaucetForm
component to include a new state variable for the coupon ID and added an input field for the coupon ID in the form. Adjusted thegetChainParams
function to prevent sending theerc20
parameter if it matches thechain
parameter. Modified thecalculateBaseUnit
function to correctly calculate the base unit for token amounts. Added aupdateCouponId
function to update the coupon ID state variable. Modified thegetCaptchaToken
function to default to V2 CAPTCHA. Adjusted theresetRecaptcha
function to not reset theisV2
state variable. [1] [2] [3] [4] [5] [6] [7] [8]ReCaptcha Class Adjustments:
client/src/components/ReCaptcha.ts
: Adjusted thegetToken
function in theReCaptcha
class to default to V2 CAPTCHA. Modified theresetV2Captcha
function to not hide the V2 CAPTCHA container. Adjusted theloadV2Captcha
function to handle the case wherewindow.grecaptcha
is undefined. [1] [2] [3]Configuration Changes:
config.json
: Modified the configuration file to include a newcouponConfig
object withIS_ENABLED
andMAX_LIMIT_CAP
properties. Adjusted theNATIVE_CLIENT
andDEBUG
properties. Modified theDRIP_AMOUNT
,RATELIMIT
, andCOUPON_REQUIRED
properties for chain configurations. [1] [2]Server Adjustments:
server.ts
: Adjusted the server file to import theCouponService
class and create a new instance of it. Modified thegetToken
function to include the coupon ID in the request data. Adjusted thegetBalance
function to usebigint
for the balance instead ofBN
. [1] [2] [3] [4] [5] [6] [7] [8]Other Changes:
package.json
: Added the@aws-sdk/lib-dynamodb
andasync-mutex
packages to the dependencies.types.ts
: Added aCOUPON_REQUIRED
property to theChainType
type.