-
Notifications
You must be signed in to change notification settings - Fork 13
Fix/limit dollar min max checks on offramp claim link #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import { Popover } from '@headlessui/react' | |
import { useAuth } from '@/context/authContext' | ||
import { ActionType, estimatePoints } from '@/components/utils/utils' | ||
import { CrispButton } from '@/components/CrispChat' | ||
import { optimismChainId, usdcAddressOptimism } from '@/components/Offramp/Offramp.consts' | ||
import { MAX_CASHOUT_LIMIT, MIN_CASHOUT_LIMIT, optimismChainId, usdcAddressOptimism } from '@/components/Offramp/Offramp.consts' | ||
|
||
export const InitialClaimLinkView = ({ | ||
onNext, | ||
|
@@ -142,6 +142,22 @@ export const InitialClaimLinkView = ({ | |
let tokenName = utils.getBridgeTokenName(claimLinkData.chainId, claimLinkData.tokenAddress) | ||
let chainName = utils.getBridgeChainName(claimLinkData.chainId) | ||
|
||
if (tokenPrice) { | ||
const cashoutUSDAmount = Number(claimLinkData.tokenAmount) * tokenPrice | ||
if (cashoutUSDAmount < MIN_CASHOUT_LIMIT) { | ||
setErrorState({ | ||
showError: true, | ||
errorMessage: 'offramp_lt_minimum', | ||
}) | ||
return | ||
} else if (cashoutUSDAmount > MAX_CASHOUT_LIMIT) { | ||
setErrorState({ | ||
showError: true, | ||
errorMessage: 'offramp_mt_maximum', | ||
}) | ||
} | ||
} | ||
|
||
if (tokenName && chainName) { | ||
} else { | ||
if (!crossChainDetails) { | ||
|
@@ -616,9 +632,9 @@ export const InitialClaimLinkView = ({ | |
</label> | ||
) : ( | ||
<> | ||
<label className=" text-h8 font-normal text-red ">{errorState.errorMessage}</label> | ||
{errorState.errorMessage === 'No route found for the given token pair.' && ( | ||
<> | ||
<label className=" text-h8 font-normal text-red ">{errorState.errorMessage}</label> | ||
{' '} | ||
<span | ||
className="cursor-pointer text-h8 font-normal text-red underline" | ||
|
@@ -635,6 +651,20 @@ export const InitialClaimLinkView = ({ | |
</span> | ||
</> | ||
)} | ||
{errorState.errorMessage === 'offramp_lt_minimum' && ( | ||
<> | ||
<label className=" text-h8 font-normal text-red "> | ||
You can not claim links with less than ${MIN_CASHOUT_LIMIT} to your bank account.{' '} | ||
</label> | ||
</> | ||
)} | ||
{errorState.errorMessage === 'offramp_mt_maximum' && ( | ||
<> | ||
<label className=" text-h8 font-normal text-red "> | ||
You can not claim links with more than ${MAX_CASHOUT_LIMIT} to your bank account.{' '} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tiny-nit: is this formatted as "$10100" ? not perfect but I VERY MUCH DOUBT anyone will ever run into this 😆 |
||
</label> | ||
</> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ export enum OfframpType { | |
CLAIM = 'CLAIM' | ||
} | ||
|
||
export const MIN_CASHOUT_LIMIT = 10 // $10 minimum | ||
export const MAX_CASHOUT_LIMIT = 101000 // $101,000 maximum | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing the constant declarations for improved maintainability and type safety. The addition of these constants aligns well with the PR objectives and improves code maintainability. However, consider the following suggestions:
const MIN_CASHOUT_DOLLARS = 10;
const MAX_CASHOUT_DOLLARS = 101000;
export const MIN_CASHOUT_LIMIT = MIN_CASHOUT_DOLLARS;
export const MAX_CASHOUT_LIMIT = MAX_CASHOUT_DOLLARS;
export const MIN_CASHOUT_LIMIT = 10 as const; // $10 minimum
export const MAX_CASHOUT_LIMIT = 101000 as const; // $101,000 maximum These changes will further enhance the maintainability and clarity of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
why min: else fees don't make sense (~$1 fee for each cashout roughly) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hugo0, thank you for explaining the reasoning behind the minimum and maximum cashout limits. Adding these comments will improve code readability and assist future developers in understanding these constraints. (❁´◡`❁) ✏️ Learnings added
|
||
|
||
export const usdcAddressOptimism = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' | ||
export const optimismChainId = '10' | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing 'return' after setting error state for exceeding maximum cashout limit
When
cashoutUSDAmount > MAX_CASHOUT_LIMIT
, the error state is set but the function does not return. This may cause the function to continue executing, possibly leading to unintended behavior.Apply this diff to fix the issue:
} else if (cashoutUSDAmount > MAX_CASHOUT_LIMIT) { setErrorState({ showError: true, errorMessage: 'offramp_mt_maximum', }) + return }
📝 Committable suggestion