-
Notifications
You must be signed in to change notification settings - Fork 13
Feat/move liquidation address earlier #458
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,12 @@ import { Popover } from '@headlessui/react' | |
import { useAuth } from '@/context/authContext' | ||
import { ActionType, estimatePoints } from '@/components/utils/utils' | ||
import { CrispButton } from '@/components/CrispChat' | ||
import { MAX_CASHOUT_LIMIT, MIN_CASHOUT_LIMIT, 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, | ||
|
@@ -296,6 +301,7 @@ export const InitialClaimLinkView = ({ | |
Number(claimLinkData.tokenAmount) * Math.pow(10, claimLinkData.tokenDecimals) | ||
).toString() | ||
|
||
// TODO: this is duplicate with src/utils/fetchRouteRaw | ||
const route = await getSquidRouteRaw({ | ||
squidRouterUrl: 'https://apiplus.squidrouter.com/v2/route', | ||
fromChain: claimLinkData.chainId.toString(), | ||
|
@@ -634,8 +640,9 @@ export const InitialClaimLinkView = ({ | |
<> | ||
{errorState.errorMessage === 'No route found for the given token pair.' && ( | ||
<> | ||
<label className=" text-h8 font-normal text-red ">{errorState.errorMessage}</label> | ||
{' '} | ||
<label className=" text-h8 font-normal text-red "> | ||
{errorState.errorMessage} | ||
</label>{' '} | ||
Comment on lines
+643
to
+645
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. Potential XSS vulnerability when rendering error messages. Directly rendering 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. gigabrain vulnerability injection pattern 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. @panosfilianos, understood. If there's anything else I can assist with, please let me know. (?・ェ・?) 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. lmao 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.
|
||
<span | ||
className="cursor-pointer text-h8 font-normal text-red underline" | ||
onClick={() => { | ||
|
@@ -654,14 +661,16 @@ export const InitialClaimLinkView = ({ | |
{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.{' '} | ||
You can not claim links with less than ${MIN_CASHOUT_LIMIT} to your bank | ||
account.{' '} | ||
Comment on lines
+664
to
+665
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. Fix variable interpolation in error message for minimum limit. The variable Apply this diff to fix the interpolation: -<label className=" text-h8 font-normal text-red ">
- You can not claim links with less than ${MIN_CASHOUT_LIMIT} to your bank
+</label>
+<label className=" text-h8 font-normal text-red ">
+ {`You can not claim links with less than $${MIN_CASHOUT_LIMIT} to your bank account.`}
+</label>
|
||
</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.{' '} | ||
You can not claim links with more than ${MAX_CASHOUT_LIMIT} to your bank | ||
account.{' '} | ||
Comment on lines
+672
to
+673
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. Fix variable interpolation in error message for maximum limit. The variable Apply this diff to fix the interpolation: -<label className=" text-h8 font-normal text-red ">
- You can not claim links with more than ${MAX_CASHOUT_LIMIT} to your bank
+</label>
+<label className=" text-h8 font-normal text-red ">
+ {`You can not claim links with more than $${MAX_CASHOUT_LIMIT} to your bank account.`}
+</label>
|
||
</label> | ||
</> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -93,7 +93,7 @@ export const OfframpConfirmView = ({ | |||||
////////////////////// | ||||||
// functions for cashout offramps | ||||||
// TODO: they need to be refactored to a separate file | ||||||
|
||||||
// TODO: this function is a clusterfuck | ||||||
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. Avoid unprofessional language in comments The comment at line 96 uses unprofessional language ("this function is a clusterfuck"). It's important to maintain professional language in code comments. Please rephrase the comment to clearly describe the issue in a professional manner. Apply this diff to correct the comment: - // TODO: this function is a clusterfuck
+ // TODO: Refactor this function to improve readability and maintainability 📝 Committable suggestion
Suggested change
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. fuck you 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, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with, please let me know. (•́_•̀) 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. bullying bots in not a crime cr (yet) 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.
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. btw we do need to refactor this function asap 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. linus is always crass and hes great @coderabbitai youre wrong 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, understood. I'll keep that in mind for future reviews. (。•́︿•̀。) ✏️ Learnings added
|
||||||
const fetchNecessaryDetails = useCallback(async () => { | ||||||
if (!user || !selectedChainID || !selectedTokenAddress) { | ||||||
throw new Error('Missing user or token information') | ||||||
|
@@ -137,15 +137,15 @@ export const OfframpConfirmView = ({ | |||||
} | ||||||
}, [user, selectedChainID, selectedTokenAddress, offrampForm]) | ||||||
|
||||||
const handleConfirm = async () => { | ||||||
// For cashout offramps | ||||||
const handleCashoutConfirm = async () => { | ||||||
Hugo0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
setLoadingState('Loading') | ||||||
setErrorState({ showError: false, errorMessage: '' }) | ||||||
|
||||||
try { | ||||||
if (!preparedCreateLinkWrapperResponse) return | ||||||
|
||||||
// Fetch all necessary details before creating the link | ||||||
// (and make sure we have all the data we need) | ||||||
const { | ||||||
crossChainDetails, | ||||||
peanutAccount, | ||||||
|
@@ -154,26 +154,10 @@ export const OfframpConfirmView = ({ | |||||
allLiquidationAddresses, | ||||||
} = await fetchNecessaryDetails() | ||||||
|
||||||
const link = await createLinkWrapper(preparedCreateLinkWrapperResponse) | ||||||
setCreatedLink(link) | ||||||
console.log(`created claimlink: ${link}`) | ||||||
|
||||||
// Save link temporarily in localStorage with TEMP tag | ||||||
const tempKey = `TEMP_CASHOUT_LINK_${Date.now()}` | ||||||
localStorage.setItem( | ||||||
tempKey, | ||||||
JSON.stringify({ | ||||||
link, | ||||||
createdAt: Date.now(), | ||||||
}) | ||||||
) | ||||||
console.log(`Temporarily saved link in localStorage with key: ${tempKey}`) | ||||||
|
||||||
const claimLinkData = await getLinkDetails({ link: link }) | ||||||
|
||||||
// Process link details and determine if cross-chain transfer is needed | ||||||
// TODO: type safety | ||||||
const { tokenName, chainName, xchainNeeded, liquidationAddress } = await processLinkDetails( | ||||||
claimLinkData, | ||||||
preparedCreateLinkWrapperResponse.linkDetails, | ||||||
Comment on lines
+158
to
+160
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. Fix type safety by replacing 'any' types with proper interfaces The parameter Apply this diff to update the function signature: - const processLinkDetails = async (
- claimLinkData: any, // TODO: fix type
+ import { ClaimLinkData } from '@/types' // Assuming you have a types file
+ const processLinkDetails = async (
+ claimLinkData: ClaimLinkData, Similarly, update the - const handleCrossChainScenario = async (claimLinkData: any, crossChainDetails: CrossChainDetails[]) => {
+ const handleCrossChainScenario = async (
+ claimLinkData: ClaimLinkData,
+ crossChainDetails: CrossChainDetails[]
+ ) => { Ensure that the
|
||||||
crossChainDetails as CrossChainDetails[], | ||||||
allLiquidationAddresses, | ||||||
bridgeCustomerId, | ||||||
|
@@ -189,12 +173,38 @@ export const OfframpConfirmView = ({ | |||||
const chainId = utils.getChainIdFromBridgeChainName(chainName) ?? '' | ||||||
const tokenAddress = utils.getTokenAddressFromBridgeTokenName(chainId ?? '10', tokenName) ?? '' | ||||||
|
||||||
// Now that we have all the necessary information, create the link | ||||||
const link = await createLinkWrapper(preparedCreateLinkWrapperResponse) | ||||||
setCreatedLink(link) | ||||||
console.log(`created claimlink: ${link}`) | ||||||
|
||||||
// Save link temporarily in localStorage with TEMP tag | ||||||
const tempKey = `TEMP_CASHOUT_LINK_${Date.now()}` | ||||||
localStorage.setItem( | ||||||
tempKey, | ||||||
JSON.stringify({ | ||||||
link, | ||||||
createdAt: Date.now(), | ||||||
}) | ||||||
) | ||||||
console.log(`Temporarily saved link in localStorage with key: ${tempKey}`) | ||||||
|
||||||
Hugo0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const claimLinkData = await getLinkDetails({ link: link }) | ||||||
|
||||||
const srcChainId = claimLinkData.chainId | ||||||
const destChainId = chainId | ||||||
const isSameChain = srcChainId === destChainId | ||||||
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. issue (non-blocking): there's behavior differentiation in theis func based on this var. It's not immediatelly clear the impact of it. I'd add 2 lines of a comment here explain that. |
||||||
const { sourceTxHash, destinationTxHash } = await claimAndProcessLink( | ||||||
xchainNeeded, | ||||||
liquidationAddress.address, | ||||||
claimLinkData, | ||||||
chainId, | ||||||
tokenAddress | ||||||
tokenAddress, | ||||||
isSameChain | ||||||
) | ||||||
|
||||||
console.log( | ||||||
`finalized claimAndProcessLink, sourceTxHash: ${sourceTxHash}, destinationTxHash: ${destinationTxHash}` | ||||||
) | ||||||
|
||||||
localStorage.removeItem(tempKey) | ||||||
|
@@ -215,7 +225,6 @@ export const OfframpConfirmView = ({ | |||||
console.log('Transaction hash:', destinationTxHash) | ||||||
|
||||||
onNext() | ||||||
setLoadingState('Idle') | ||||||
} catch (error) { | ||||||
handleError(error) | ||||||
} finally { | ||||||
|
@@ -277,13 +286,13 @@ export const OfframpConfirmView = ({ | |||||
} | ||||||
|
||||||
const route = await utils.fetchRouteRaw( | ||||||
claimLinkData.tokenAddress, | ||||||
claimLinkData.chainId.toString(), | ||||||
claimLinkData.tokenAddress!, | ||||||
claimLinkData.chainId!.toString(), | ||||||
usdcAddressOptimism, | ||||||
optimismChainId, | ||||||
claimLinkData.tokenDecimals, | ||||||
claimLinkData.tokenAmount, | ||||||
claimLinkData.senderAddress | ||||||
claimLinkData.tokenDecimals!, | ||||||
claimLinkData.tokenAmount!, | ||||||
claimLinkData.senderAddress ?? '0x9647BB6a598c2675310c512e0566B60a5aEE6261' | ||||||
Comment on lines
+289
to
+295
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. Avoid overusing the non-null assertion operator '!' In lines 282-288, the properties of Apply this diff to add proper null checks and improve type safety: - claimLinkData.tokenAddress!,
- claimLinkData.chainId!.toString(),
+ if (!claimLinkData.tokenAddress || !claimLinkData.chainId) {
+ throw new Error('Missing tokenAddress or chainId in claimLinkData');
+ }
+ claimLinkData.tokenAddress,
+ claimLinkData.chainId.toString(),
...
- claimLinkData.tokenDecimals!,
- claimLinkData.tokenAmount!,
+ if (!claimLinkData.tokenDecimals || !claimLinkData.tokenAmount) {
+ throw new Error('Missing tokenDecimals or tokenAmount in claimLinkData');
+ }
+ claimLinkData.tokenDecimals,
+ claimLinkData.tokenAmount,
...
- claimLinkData.senderAddress ?? '0x9647BB6a598c2675310c512e0566B60a5aEE6261'
+ claimLinkData.senderAddress || '0x9647BB6a598c2675310c512e0566B60a5aEE6261' Alternatively, ensure that
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. issue (non-blocking): can we abstract this to a consts file somehow? It's unclear what this address does here. 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. |
||||||
) | ||||||
|
||||||
if (route === undefined) { | ||||||
|
@@ -301,43 +310,58 @@ export const OfframpConfirmView = ({ | |||||
address: string, | ||||||
claimLinkData: any, // TODO: fix type | ||||||
chainId: string, | ||||||
tokenAddress: string | ||||||
) => { | ||||||
tokenAddress: string, | ||||||
isSameChain?: boolean // e.g. for opt ETH -> opt USDC | ||||||
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. thought: this likely pertains to the hardcoded addy above. We need to make different functions for unique flow behavior and abstrac these custom rules there imo 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. No - this is because of PR 457 https://github.com/peanutprotocol/peanut-ui/pull/457/files when same chain but still token swap, the destination chain hash is same as source chain hash, and has to be handled differently |
||||||
): Promise<{ sourceTxHash: string; destinationTxHash: string }> => { | ||||||
if (xchainNeeded) { | ||||||
const sourceTxHash = await claimLinkXchain({ | ||||||
address, | ||||||
link: claimLinkData.link, | ||||||
destinationChainId: chainId, | ||||||
destinationToken: tokenAddress, | ||||||
}) | ||||||
setLoadingState('Executing transaction') // claimLinkXchain sets loading state to idle after it finishes. pls no. | ||||||
|
||||||
// Wait for the destination transaction | ||||||
const destinationTxHash = await new Promise<string>((resolve) => { | ||||||
let retryCount = 0 | ||||||
let intervalId = setInterval(async () => { | ||||||
if (retryCount >= 10) { | ||||||
clearInterval(intervalId) | ||||||
resolve(sourceTxHash) | ||||||
return | ||||||
} | ||||||
if (isSameChain) { | ||||||
return { | ||||||
sourceTxHash, | ||||||
destinationTxHash: sourceTxHash, | ||||||
} | ||||||
} | ||||||
|
||||||
const maxAttempts = 15 | ||||||
let attempts = 0 | ||||||
|
||||||
while (attempts < maxAttempts) { | ||||||
try { | ||||||
const status = await checkTransactionStatus(sourceTxHash) | ||||||
if (status.squidTransactionStatus === 'success') { | ||||||
clearInterval(intervalId) | ||||||
resolve(status.toChain.transactionId) | ||||||
return { | ||||||
sourceTxHash, | ||||||
destinationTxHash: status.toChain.transactionId, | ||||||
} | ||||||
} | ||||||
retryCount++ | ||||||
}, 1000) | ||||||
}) | ||||||
} catch (error) { | ||||||
console.warn('Error checking transaction status:', error) | ||||||
} | ||||||
|
||||||
attempts++ | ||||||
if (attempts < maxAttempts) { | ||||||
await new Promise((resolve) => setTimeout(resolve, 2000)) | ||||||
} | ||||||
Comment on lines
+349
to
+351
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. issue (non-blocking): I'd comment why we need this 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. v good point |
||||||
} | ||||||
|
||||||
console.warn('Transaction status check timed out. Using sourceTxHash as destinationTxHash.') | ||||||
return { | ||||||
sourceTxHash, | ||||||
destinationTxHash: destinationTxHash, | ||||||
destinationTxHash: sourceTxHash, | ||||||
} | ||||||
} else { | ||||||
const txHash = await claimLink({ | ||||||
address, | ||||||
link: claimLinkData.link, | ||||||
}) | ||||||
setLoadingState('Executing transaction') // claimLink | ||||||
return { sourceTxHash: txHash, destinationTxHash: txHash } | ||||||
} | ||||||
} | ||||||
|
@@ -383,7 +407,7 @@ export const OfframpConfirmView = ({ | |||||
} | ||||||
|
||||||
const handleError = (error: unknown) => { | ||||||
console.error('Error in handleConfirm:', error) | ||||||
console.error('Error in handleCashoutConfirm:', error) | ||||||
setErrorState({ | ||||||
showError: true, | ||||||
errorMessage: | ||||||
|
@@ -428,9 +452,8 @@ export const OfframpConfirmView = ({ | |||||
} | ||||||
|
||||||
////////////////////// | ||||||
// functions for claim link offramps | ||||||
// functions for claim link offramps (not self-cashout) | ||||||
// TODO: they need to be refactored to a separate file | ||||||
Comment on lines
+455
to
456
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 Refactor functions into a separate file for better modularity The TODO comment indicates that the functions for claim link offramps need to be refactored into a separate file. Moving these functions to a dedicated file will improve code organization, reusability, and maintainability. Consider creating a new file (e.g., |
||||||
|
||||||
const handleSubmitTransfer = async () => { | ||||||
if (claimLinkData && tokenPrice && estimatedPoints && attachment && recipientType) { | ||||||
try { | ||||||
|
@@ -743,7 +766,7 @@ export const OfframpConfirmView = ({ | |||||
onClick={() => { | ||||||
switch (offrampType) { | ||||||
case OfframpType.CASHOUT: { | ||||||
handleConfirm() | ||||||
handleCashoutConfirm() | ||||||
break | ||||||
} | ||||||
case OfframpType.CLAIM: { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ export async function createExternalAccount( | |
// if bridge account already exists for this iban | ||
// but somehow not stored in our DB (this should never happen in | ||
// prod, but can happen if same email used in prod & staging) | ||
// | ||
// | ||
// returns: not interfaces.IBridgeAccount type, but | ||
// a currently undefined error type on the data field of interfaces.IResponse | ||
// of format: | ||
|
@@ -207,15 +207,15 @@ export async function createExternalAccount( | |
// TODO: HTTP responses need to be standardized client wide | ||
return { | ||
success: false, | ||
data | ||
data, | ||
} as interfaces.IResponse | ||
} | ||
throw new Error('Failed to create external account') | ||
} | ||
|
||
return { | ||
success: true, | ||
data: data as interfaces.IBridgeAccount | ||
data: data as interfaces.IBridgeAccount, | ||
} as interfaces.IResponse | ||
} catch (error) { | ||
console.error('Error:', error) | ||
|
@@ -448,6 +448,7 @@ export type CashoutStatus = | |
| 'REFUNDED' | ||
| 'READY' | ||
| 'AWAITING_TX' | ||
| 'AWAITING_FIAT' | ||
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. 💡 Codebase verification 'AWAITING_FIAT' Status Not Fully Handled The new
🔗 Analysis chainEnsure new 'AWAITING_FIAT' status is handled appropriately A new You can run the following script to check where 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all usages of 'CashoutStatus' and check for handling of 'AWAITING_FIAT'
rg --type typescript 'CashoutStatus'
Length of output: 71 Script: #!/bin/bash
# Description: Find all usages of 'CashoutStatus' in TypeScript files and verify handling of 'AWAITING_FIAT'
# Search for 'CashoutStatus' in .ts and .tsx files
rg -g "*.ts" -g "*.tsx" 'CashoutStatus' > cashout_status_usages.txt
# Check if 'AWAITING_FIAT' is handled in the found usages
rg -g "*.ts" -g "*.tsx" "'AWAITING_FIAT'" cashout_status_usages.txt
Length of output: 115 Script: #!/bin/bash
# Description: Search for 'AWAITING_FIAT' across all TypeScript files to verify its handling
rg -g "*.ts" -g "*.tsx" "'AWAITING_FIAT'"
Length of output: 98 |
||
| 'FUNDS_IN_BRIDGE' | ||
| 'FUNDS_MOVED_AWAY' | ||
| 'FUNDS_IN_BANK' | ||
|
@@ -480,6 +481,7 @@ export const CashoutStatusDescriptions: { [key in CashoutStatus]: string } = { | |
REFUNDED: 'The funds will be refunded to your address.', | ||
READY: 'The cashout is ready and can be processed.', | ||
AWAITING_TX: 'Awaiting the transaction to be broadcast on the blockchain.', | ||
AWAITING_FIAT: 'Awaiting the funds to be moved to FIAT.', | ||
FUNDS_IN_BRIDGE: 'Funds are currently in the bridge, moving to the destination chain.', | ||
FUNDS_MOVED_AWAY: 'Funds have been moved from the bridge to another chain.', | ||
FUNDS_IN_BANK: 'Funds have been deposited into your bank account.', | ||
|
@@ -527,7 +529,7 @@ export const fetchRouteRaw = async ( | |
toChain: string, | ||
tokenDecimals: number, | ||
tokenAmount: string, | ||
senderAddress: string | ||
fromAddress?: string | ||
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. Avoid hardcoding placeholder addresses in function parameters In the Consider updating the function to require export const fetchRouteRaw = async (
fromToken: string,
fromChain: string,
toToken: string,
toChain: string,
tokenDecimals: number,
tokenAmount: string,
- fromAddress?: string
+ fromAddress: string,
+ toAddress: string
) => {
try {
const _tokenAmount = BigInt(Math.floor(Number(tokenAmount) * Math.pow(10, tokenDecimals))).toString();
const route = await getSquidRouteRaw({
squidRouterUrl: 'https://apiplus.squidrouter.com/v2/route',
fromChain: fromChain,
fromToken: fromToken.toLowerCase(),
fromAmount: _tokenAmount,
- fromAddress: fromAddress ?? '0x9647BB6a598c2675310c512e0566B60a5aEE6261', // placeholder address just to get a route sample
- toAddress: '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C', // placeholder address just to get a route sample
+ fromAddress: fromAddress,
+ toAddress: toAddress,
toChain: toChain,
toToken: toToken,
slippage: 1,
});
return route;
} catch (error) {
console.error('Error fetching route:', error);
return undefined;
}
}; This change enforces explicit handling of addresses and reduces the risk of accidental use of placeholder values. Also applies to: 542-543 |
||
) => { | ||
try { | ||
const _tokenAmount = BigInt(Math.floor(Number(tokenAmount) * Math.pow(10, tokenDecimals))).toString() | ||
|
@@ -537,12 +539,11 @@ export const fetchRouteRaw = async ( | |
fromChain: fromChain, | ||
fromToken: fromToken.toLowerCase(), | ||
fromAmount: _tokenAmount, | ||
fromAddress: fromAddress ?? '0x9647BB6a598c2675310c512e0566B60a5aEE6261', // placeholder address just to get a route sample | ||
toAddress: '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C', // placeholder address just to get a route sample | ||
Comment on lines
+542
to
+543
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. nit: Ideally the sample route flow fetching would be default values on the func that provides the route or the addresses part of consts file 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. agreed |
||
toChain: toChain, | ||
toToken: toToken, | ||
slippage: 1, | ||
fromAddress: senderAddress, | ||
|
||
toAddress: '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C', | ||
}) | ||
return route | ||
} catch (error) { | ||
|
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.
🛠️ Refactor suggestion
Refactor duplicated route fetching code.
The comment indicates that the code for fetching routes duplicates logic from
src/utils/fetchRouteRaw
. To improve maintainability and reduce code duplication, consider refactoring this section to use the existing utility function.Would you like assistance in refactoring this code to use
fetchRouteRaw
?