Skip to content

Commit

Permalink
refactor(swap): integrate isExecutingPrice state for improved button …
Browse files Browse the repository at this point in the history
…handling

- Added `isExecutingPrice` to the swap context to manage the execution status during price calculations.
- Updated the `Balance` component to disable the "Select Max" button when a price execution is in progress, enhancing user experience and preventing unintended actions during loading states.
  • Loading branch information
ArturHoncharuk committed Jan 20, 2025
1 parent e99892c commit ecb2fb7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/features/swap/components/composite/balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ interface BalanceProps {

export const Balance = ({ type }: BalanceProps) => {
const { t } = useTranslation();
const { selectedTokens, selectedTokensAmount, setIsExactIn } =
useSwapContextSelector();
const {
selectedTokens,
selectedTokensAmount,
setIsExactIn,
isExecutingPrice
} = useSwapContextSelector();
const { onSelectMaxTokensAmount, updateReceivedTokensOutput } =
useSwapFieldsHandler();

Expand Down Expand Up @@ -112,7 +116,7 @@ export const Balance = ({ type }: BalanceProps) => {
<Text
fontSize={14}
fontFamily="Inter_500Medium"
color={error ? COLORS.error500 : COLORS.neutral500}
color={COLORS[error ? 'error500' : 'neutral500']}
>
{maximumTokenBalance}
</Text>
Expand All @@ -122,7 +126,10 @@ export const Balance = ({ type }: BalanceProps) => {
{!disabled && type !== FIELD.TOKEN_B && (
<>
<Spacer horizontal value={scale(4)} />
<Button onPress={onSelectMaxTokensAmountPress}>
<Button
disabled={isExecutingPrice}
onPress={onSelectMaxTokensAmountPress}
>
<Text
fontSize={15}
fontFamily="Inter_500Medium"
Expand Down

0 comments on commit ecb2fb7

Please sign in to comment.