Skip to content
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

Id 2758 balances routes #2474

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f2f918d
Fetch routes from Balances
alejoloaiza Dec 15, 2024
0aa4914
Control price display + some wip on pre-fetching
luads Dec 17, 2024
53eed89
Add displayInsufficientGasWarning
mimi-imtbl Dec 17, 2024
28896c3
Hide insufficient gas warning
mimi-imtbl Dec 17, 2024
3856c7b
Add logic to show all routes, show insufficient balance tag
mimi-imtbl Dec 18, 2024
e81e91e
Add insufficient balance tag
mimi-imtbl Dec 18, 2024
96f10cb
Sort routes by estimatedDuration, then insufficient gas, then insuffi…
mimi-imtbl Dec 18, 2024
5a52594
Merge
mimi-imtbl Dec 18, 2024
e05945d
Hide isInsufficientGas and isInsufficientBalance tag when showing rou…
mimi-imtbl Dec 18, 2024
17a9258
Hide gas drawer
mimi-imtbl Dec 18, 2024
b13c724
Max button added
alejoloaiza Dec 18, 2024
7ffbebb
Merge remote-tracking branch 'refs/remotes/origin/ID-2758-balances-ro…
alejoloaiza Dec 18, 2024
d71efda
Revert strict mode
mimi-imtbl Dec 18, 2024
a4435af
Disable review button if insufficient balance
mimi-imtbl Dec 18, 2024
e8b7327
Merge branch 'main' into ID-2758-balances-routes
mimi-imtbl Dec 18, 2024
a2c5c76
Adding adjustment to Max
alejoloaiza Dec 18, 2024
e69ac62
Merge remote-tracking branch 'refs/remotes/origin/ID-2758-balances-ro…
alejoloaiza Dec 18, 2024
b2535a8
Fix for Max when routes are not preloaded
alejoloaiza Dec 18, 2024
d66a63a
Add i18n for no balance text
mimi-imtbl Dec 18, 2024
2fab6e6
Fix for getting the slippage tier
alejoloaiza Dec 18, 2024
d5cc2cd
Merge remote-tracking branch 'refs/remotes/origin/ID-2758-balances-ro…
alejoloaiza Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface RouteOptionProps<
size?: MenuItemSize;
rc?: RC;
selected?: boolean;
displayPriceDetails?: boolean;
}

export function RouteOption<RC extends ReactElement | undefined = undefined>({
Expand All @@ -39,6 +40,7 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
size = 'small',
rc = <span />,
selected = false,
displayPriceDetails = true,
}: RouteOptionProps<RC>) {
const { t } = useTranslation();

Expand Down Expand Up @@ -97,7 +99,7 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({

<MenuItem.Caption>
{`${t('views.ADD_TOKENS.fees.balance')} ${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${routeBalanceUsd}`}
{routeData.isInsufficientGas && (
{ displayPriceDetails && routeData.isInsufficientGas && (
<>
<br />
<span style={{ color: '#FF637F' }}>
Expand All @@ -108,9 +110,18 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
</span>
</>
)}

{ displayPriceDetails && routeData.isInsufficientBalance && (
<>
<br />
<span style={{ color: '#FF637F' }}>
{t('views.ADD_TOKENS.noBalanceRouteMessage')}
</span>
</>
)}
</MenuItem.Caption>

<MenuItem.PriceDisplay price={fromAmount}>
<MenuItem.PriceDisplay price={fromAmount} sx={{ visibility: displayPriceDetails ? 'visible' : 'hidden' }}>
<MenuItem.PriceDisplay.Caption>
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${fromAmountUsd}`}
</MenuItem.PriceDisplay.Caption>
Expand Down Expand Up @@ -155,7 +166,7 @@ export function RouteOption<RC extends ReactElement | undefined = undefined>({
/>
)}
{
`${t('views.ADD_TOKENS.fees.fee')} ${t('views.ADD_TOKENS.fees.fiatPricePrefix')}
`${t('views.ADD_TOKENS.fees.fee')} ${t('views.ADD_TOKENS.fees.fiatPricePrefix')}
$${getFormattedAmounts(totalFeesUsd)}`
}
</Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface OptionsProps {
showOnrampOption?: boolean;
insufficientBalance?: boolean;
selectedIndex: number;
displayPriceDetails?: boolean;
}

export function RouteOptions({
Expand All @@ -38,6 +39,7 @@ export function RouteOptions({
showOnrampOption,
insufficientBalance,
selectedIndex,
displayPriceDetails,
}: OptionsProps) {
const { t } = useTranslation();

Expand Down Expand Up @@ -94,6 +96,7 @@ export function RouteOptions({
isFastest={index === 0}
selected={index === selectedIndex}
rc={<motion.div variants={listItemVariants} />}
displayPriceDetails={displayPriceDetails}
/>
))}
{noRoutes && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type OptionsDrawerProps = {
showSwapOption?: boolean;
showBridgeOption?: boolean;
insufficientBalance?: boolean;
displayPriceDetails?: boolean;
};

export function RouteOptionsDrawer({
Expand All @@ -40,6 +41,7 @@ export function RouteOptionsDrawer({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
showBridgeOption,
insufficientBalance,
displayPriceDetails,
}: OptionsDrawerProps) {
const { t } = useTranslation();
const { track } = useAnalytics();
Expand Down Expand Up @@ -126,6 +128,7 @@ export function RouteOptionsDrawer({
showOnrampOption={showOnrampOption}
insufficientBalance={insufficientBalance}
selectedIndex={selectedRouteIndex.current}
displayPriceDetails={displayPriceDetails}
/>
</Drawer.Content>
</Drawer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
AllDualVariantIconKeys,
Box,
MenuItem,
ShimmerBox,
Stack,
Sticker,
Tooltip,
Expand Down Expand Up @@ -28,6 +30,7 @@ export interface SelectedRouteOptionProps {
withSelectedWallet?: boolean;
insufficientBalance?: boolean;
showOnrampOption?: boolean;
displayPriceDetails?: boolean;
}

function SelectedRouteOptionContainer({
Expand Down Expand Up @@ -67,6 +70,7 @@ export function SelectedRouteOption({
withSelectedWallet = false,
insufficientBalance = false,
showOnrampOption = false,
displayPriceDetails = true,
onClick,
}: SelectedRouteOptionProps) {
const { t } = useTranslation();
Expand Down Expand Up @@ -182,24 +186,58 @@ export function SelectedRouteOption({
{`${t('views.ADD_TOKENS.fees.balance')} ${t(
'views.ADD_TOKENS.fees.fiatPricePrefix',
)} $${routeBalanceUsd}`}
{routeData?.isInsufficientGas && (
{ displayPriceDetails && routeData?.isInsufficientGas && (
<>
<br />
<span style={{ color: '#FF637F' }}>
{t('views.ADD_TOKENS.noGasRouteMessage', {
token:
routeData.route.route.estimate.gasCosts[0].token.symbol,
})}
</span>
</>
)}

{ displayPriceDetails && routeData?.isInsufficientBalance && (
<>
<br />
<span style={{ color: '#FF637F' }}>
{t('views.ADD_TOKENS.noGasRouteMessage', {
token:
routeData.route.route.estimate.gasCosts[0].token.symbol,
})}
{t('views.ADD_TOKENS.noBalanceRouteMessage')}
</span>
</>
)}
</MenuItem.Caption>
</Stack>
<MenuItem.PriceDisplay price={fromAmount}>
<MenuItem.PriceDisplay.Caption>
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${fromAmountUsd}`}
</MenuItem.PriceDisplay.Caption>
</MenuItem.PriceDisplay>
{loading && displayPriceDetails ? (
<Box sx={{
display: 'inline-flex',
flexDirection: 'column',
alignItems: 'end',
gap: 'base.spacing.x2',
}}
>
<ShimmerBox
rc={<span />}
sx={{
w: '36px',
h: '16px',
}}
/>
<ShimmerBox
rc={<span />}
sx={{
w: '72px',
h: '16px',
}}
/>
</Box>
) : (
<MenuItem.PriceDisplay price={fromAmount} sx={{ visibility: displayPriceDetails ? 'visible' : 'hidden' }}>
<MenuItem.PriceDisplay.Caption>
{`${t('views.ADD_TOKENS.fees.fiatPricePrefix')} $${fromAmountUsd}`}
</MenuItem.PriceDisplay.Caption>
</MenuItem.PriceDisplay>
)}
</Stack>
</SelectedRouteOptionContainer>
);
Expand Down
6 changes: 6 additions & 0 deletions packages/checkout/widgets-lib/src/lib/squid/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { ChainId } from '@imtbl/checkout-sdk';

export const SQUID_SDK_BASE_URL = 'https://apiplus.squidrouter.com';

export const SQUID_NATIVE_TOKEN = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';

export const DEFAULT_DESTINATION_TOKEN = {
[ChainId.IMTBL_ZKEVM_MAINNET]: '0x6de8aCC0D406837030CE4dd28e7c08C5a96a30d2',
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ export const sortRoutesByFastestTime = (routes: RouteData[]): RouteData[] => {
if (!routes) return [];

return routes.slice().sort((a, b) => {
// Prioritize isInsufficientGas = false
if (a.isInsufficientGas !== b.isInsufficientGas) {
return a.isInsufficientGas ? 1 : -1;
// 1.: Prioritise routes where both isInsufficientGas and isInsufficientBalance are false
if (a.isInsufficientGas !== b.isInsufficientGas || a.isInsufficientBalance !== b.isInsufficientBalance) {
if (!a.isInsufficientGas && !a.isInsufficientBalance) return -1;
if (!b.isInsufficientGas && !b.isInsufficientBalance) return 1;
if (a.isInsufficientGas && !a.isInsufficientBalance) return -1; // isInsufficientGas = true has higher priority
if (b.isInsufficientGas && !b.isInsufficientBalance) return 1;
}

// Sort by estimatedRouteDuration if isInsufficientGas is the same
// 2.: Sort by estimatedRouteDuration
const timeA = a.route.route.estimate.estimatedRouteDuration;
const timeB = b.route.route.estimate.estimatedRouteDuration;

return timeA - timeB;
if (timeA !== timeB) return timeA - timeB;

// 3.: Place isInsufficientGas before isInsufficientBalance
if (a.isInsufficientGas !== b.isInsufficientGas) {
return a.isInsufficientGas ? -1 : 1;
}

return 0;
});
};
Loading
Loading