Skip to content

Commit 3892a7b

Browse files
CP-10907 - setting MAX when balance is low shows negative value (#3347)
Signed-off-by: Bogdan Dobritoiu <bogdan.dobri@gmail.com>
1 parent c46218f commit 3892a7b

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

packages/core-mobile/app/new/common/hooks/send/useEVMSend.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,10 @@ const useEVMSend: SendAdapterEVM = ({
180180

181181
const totalFee = gasLimit * maxFee
182182
const maxAmountValue = nativeToken.balance - totalFee
183+
const maxAmount = maxAmountValue > 0n ? maxAmountValue : 0n
183184

184185
if (selectedToken.type === TokenType.NATIVE) {
185-
return new TokenUnit(
186-
maxAmountValue ?? 0n,
187-
nativeToken.decimals,
188-
nativeToken.symbol
189-
)
186+
return new TokenUnit(maxAmount, nativeToken.decimals, nativeToken.symbol)
190187
} else if (selectedToken.type === TokenType.ERC20) {
191188
return new TokenUnit(
192189
selectedToken.balance,

packages/core-mobile/app/new/common/hooks/send/useSVMSend.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ const useSVMSend: SendAdapterSVM = ({
6969
}
7070

7171
if (selectedToken.type === TokenType.NATIVE) {
72-
return new TokenUnit(
73-
selectedToken.balance - SOLANA_FIXED_BASE_FEE,
74-
nativeToken.decimals,
75-
nativeToken.symbol
76-
)
72+
const maxAmountValue = selectedToken.balance - SOLANA_FIXED_BASE_FEE
73+
const maxAmount = maxAmountValue > 0n ? maxAmountValue : 0n
74+
return new TokenUnit(maxAmount, nativeToken.decimals, nativeToken.symbol)
7775
} else {
7876
const splToken = selectedToken as TokenWithBalanceSPL
7977
return new TokenUnit(splToken.balance, splToken.decimals, splToken.symbol)

packages/core-mobile/app/new/features/send/components/SendToken.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const SendToken = ({ onSend }: { onSend: () => void }): JSX.Element => {
204204

205205
return (
206206
<ScrollScreen
207-
bottomOffset={150}
207+
bottomOffset={maxAmount?.eq(0) ? 400 : 150}
208208
isModal
209209
title={`${'How much would\nyou like to send?'}`}
210210
navigationTitle="How much would you like to send?"

packages/k2-alpine/src/components/TokenUnitInput/SendTokenUnitInputWidget.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { TokenUnit } from '@avalabs/core-utils-sdk'
2+
import { SxProp } from 'dripsy'
13
import React, {
2-
useRef,
3-
useState,
4-
useEffect,
5-
useCallback,
64
forwardRef,
7-
useImperativeHandle
5+
useCallback,
6+
useEffect,
7+
useImperativeHandle,
8+
useRef,
9+
useState
810
} from 'react'
9-
import { SxProp } from 'dripsy'
10-
import { TokenUnit } from '@avalabs/core-utils-sdk'
1111
import { ReturnKeyTypeOptions } from 'react-native'
12-
import { normalizeErrorMessage } from '../../utils/tokenUnitInput'
1312
import { useTheme } from '../../hooks'
14-
import { Text, View } from '../Primitives'
13+
import { Icons } from '../../theme/tokens/Icons'
1514
import { alpha } from '../../utils'
15+
import { normalizeErrorMessage } from '../../utils/tokenUnitInput'
1616
import { Button } from '../Button/Button'
17+
import { Text, View } from '../Primitives'
1718
import { TokenUnitInput, TokenUnitInputHandle } from './TokenUnitInput'
1819

1920
interface PresetAmount {
@@ -214,7 +215,7 @@ export const SendTokenUnitInputWidget = forwardRef<
214215
style={{
215216
minWidth: 72
216217
}}
217-
disabled={disabled}
218+
disabled={maxAmount?.eq(0)}
218219
onPress={() => {
219220
handlePressPresetButton(button.amount, index)
220221
}}>
@@ -247,6 +248,27 @@ export const SendTokenUnitInputWidget = forwardRef<
247248
? normalizeErrorMessage(errorMessage)
248249
: `Balance: ${balance.toDisplay()} ${token.symbol}`}
249250
</Text>
251+
252+
{/* Show additional error message if max amount is 0 */}
253+
{maxAmount?.eq(0) && (
254+
<View
255+
sx={{
256+
flexDirection: 'row',
257+
gap: 8,
258+
marginTop: 16,
259+
alignItems: 'center'
260+
}}>
261+
<Icons.Alert.ErrorOutline color={colors.$textDanger} />
262+
<Text
263+
sx={{
264+
flexShrink: 1,
265+
color: '$textDanger',
266+
fontFamily: 'Inter-Medium'
267+
}}>
268+
You don't have enough gas fees for this transaction
269+
</Text>
270+
</View>
271+
)}
250272
</View>
251273
)
252274
}

0 commit comments

Comments
 (0)