-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coupon and Mainnet balance fixes (#130)
* Development (mainnet balance check) (#128) * mainnet balance checks * cfg * logs * typo * json * nits * update prod config (#129) * exclude config field * checks fix * nits
- Loading branch information
1 parent
b9c6e6d
commit 10e97e3
Showing
3 changed files
with
94 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { CouponService } from '../CouponService/couponService' | ||
import { checkMainnetBalance } from './mainnetBalanceCheck' | ||
|
||
export enum PIPELINE_CHECKS { | ||
MAINNET_BALANCE = 'mainnet_check', | ||
COUPON = 'coupon_check' | ||
} | ||
|
||
export type PipelineCheckValidity = { | ||
isValid: boolean, | ||
checkPassedType?: PIPELINE_CHECKS, | ||
errorMessage?: string, | ||
dripAmount: number, | ||
} | ||
|
||
export function pipelineFailureMessage(mainnetBalanceCheckEnabled: boolean | string, couponCheckEnabled: boolean): string { | ||
if (mainnetBalanceCheckEnabled && couponCheckEnabled) { | ||
return "Either mainnet balance or a valid coupon is required!" | ||
} else if (mainnetBalanceCheckEnabled) { | ||
return "Mainnet balance is required!" | ||
} else if (couponCheckEnabled) { | ||
return "A valid coupon is required!" | ||
} | ||
|
||
return "" | ||
} | ||
|
||
export async function checkCouponPipeline( | ||
couponService: CouponService, | ||
pipelineCheckValidity: PipelineCheckValidity, | ||
faucetConfigId: string, | ||
coupon?: string, | ||
) { | ||
// if coupon is required but not passed in request | ||
if (coupon === undefined) { | ||
return | ||
} | ||
|
||
const couponValidity = await couponService.consumeCouponAmount(coupon, faucetConfigId, pipelineCheckValidity.dripAmount) | ||
if (!couponValidity.isValid) { | ||
pipelineCheckValidity.errorMessage = "Invalid or expired coupon provided. Contact support team on Discord! " | ||
return | ||
} else { | ||
pipelineCheckValidity.isValid = true | ||
pipelineCheckValidity.dripAmount = couponValidity.amount | ||
pipelineCheckValidity.checkPassedType = PIPELINE_CHECKS.COUPON | ||
} | ||
} | ||
|
||
export async function checkMainnetBalancePipeline(pipelineCheckValidity: PipelineCheckValidity, faucetConfigId: string, rpc: string, address: string) { | ||
const isValid = await checkMainnetBalance(faucetConfigId, rpc, address) | ||
if (isValid) { | ||
pipelineCheckValidity.isValid = true | ||
pipelineCheckValidity.checkPassedType = PIPELINE_CHECKS.MAINNET_BALANCE | ||
} else { | ||
pipelineCheckValidity.errorMessage = "Mainnet balance check failed! " | ||
} | ||
} |